Team,
Index.contains() of NOTUNIQUE_HASH_INDEX always returns true for any key
even in empty DB.
Is it the behavior???
Should I always get the Set from Index and check its size for existence?
Attaching the simple code, that just creates the database and an
NOTUNIQUE_HASH_INDEX index. Then immediate calling Index.contains() for any
random value returns true always...!!!
Reg,
K Adithyan
--
---
You received this message because you are subscribed to the Google Groups
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.
package adi.orientdb.eval;
import com.orientechnologies.orient.core.db.OPartitionedDatabasePool;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.index.OIndex;
import com.orientechnologies.orient.core.index.OIndexManagerProxy;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OType;
import java.util.concurrent.ExecutionException;
/**
*
* @author K Adithyan
*/
public class IndexContains
{
static final String URL = "plocal:/tmp/plocaldb";
static final String DATATYPE = "docnode";
static final String KEYFIELD = "name";
public static void main(String[] args) throws Exception
{
read();
System.out.println("done!");
}
private static String indexName()
{
return DATATYPE + "." + KEYFIELD;
}
private static ODatabaseDocumentTx db() throws InterruptedException, ExecutionException
{
System.out.println("starting.....");
try (ODatabaseDocumentTx base = new ODatabaseDocumentTx(URL))
{
if (!base.exists())
{
System.out.println("creating....");
base.create();
base.getMetadata().getSecurity().createUser("root", "root", "admin");
}
base.close();
}
OPartitionedDatabasePool pool = new OPartitionedDatabasePool(URL, "root", "root");
ODatabaseDocumentTx db = pool.acquire();
if (!db.getMetadata().getSchema().existsClass(DATATYPE))
{
OClass dataTypeClass = db.getMetadata().getSchema().createClass(DATATYPE);
dataTypeClass.createProperty(KEYFIELD, OType.STRING);
dataTypeClass.createIndex(indexName(), OClass.INDEX_TYPE.NOTUNIQUE_HASH_INDEX, KEYFIELD);
System.out.println("created class = " + dataTypeClass);
}
final OIndexManagerProxy im = db.getMetadata().getIndexManager();
OIndex index = im.getIndex(indexName());
System.out.println("index = " + index.getConfiguration().toJSON());
long doccount = db.countClass(DATATYPE);
System.out.println("doccount of " + DATATYPE + " = " + doccount);
return db;
}
private static void read() throws Exception
{
ODatabaseDocumentTx db = db();
OIndexManagerProxy im = db.getMetadata().getIndexManager();
OIndex<?> index = im.getIndex(indexName());
System.out.println("contains1 = " + index.contains("Random-Key-1"));
System.out.println("contains1 = " + index.contains("Random-Key-2"));
System.out.println("contains1 = " + index.contains("Random-Key-3"));
System.out.println("contains1 = " + index.contains("Random-Key-4"));
System.out.println("index.get()-1 = " + index.get("Random-Key-1"));
System.out.println("index.get()-2 = " + index.get("Random-Key-2"));
System.out.println("index.get()-3 = " + index.get("Random-Key-3"));
System.out.println("index.get()-4 = " + index.get("Random-Key-4"));
}
}