I have a database with two indexes on a particular class. When I query
within against the non-unique single field index it always works inside and
outside a transaction. But If I query against the composite unique index
inside the transaction it doesn't work.
Below is code that demonstrates the issue. If you comment out the
db.begin()/db.commit() lines then this works.
I would expect the queries against key+row would always work the same as
the queries against just key , but they don't.
Did I miss something, or is this not working?
OrientDb 1.6.4.
package fathom.test;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OSchema;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.OCommandSQL;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
public class MultiComponentShift {
public static final String VTYPE_GRAPHROOT = "graphroot";
public static final String VTYPE_GRAPHDATA = "graphdata";
public static final String VTYPE_GRAPHROW = "graphrow";
public static final String IDX_GRAPHDATA_KEY = VTYPE_GRAPHDATA + ".KEY";
public static final String IDX_GRAPHROW_KEY = VTYPE_GRAPHROW + ".KEY";
public static final String IDX_GRAPHROW_KEY_ROW = VTYPE_GRAPHROW +
".KEY.ROW";
@Test
public void testIndexShift() {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("plocal:c:\\temp\\test");
if (!db.exists()) {
db.create();
OSchema schema = db.getMetadata().getSchema();
OClass rowType = schema.createClass(VTYPE_GRAPHROW);
rowType.createProperty("key", OType.STRING);
rowType.createProperty("row", OType.INTEGER);
rowType.createIndex(IDX_GRAPHROW_KEY, OClass.INDEX_TYPE.NOTUNIQUE,
"key");
rowType.createIndex(IDX_GRAPHROW_KEY_ROW, OClass.INDEX_TYPE.UNIQUE,
"key", "row");
} else {
db.open("admin", "admin");
}
String key = "test1";
int origRow = 5;
int startAt = 2;
int newRow = 3;
db.begin();
ODocument doc = db.newInstance(VTYPE_GRAPHROW);
doc.field("key", key);
doc.field("row", origRow);
db.save(doc);
System.out.println("Saved document: " + doc);
OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>("select
from " + VTYPE_GRAPHROW
+ " where key = :key and row = :row");
Map<String, Object> args = new HashMap<>();
args.put("key", key);
args.put("row", origRow);
Object result = db.command(query).execute(args);
System.out.println("Rows by key " + key + " and row " + origRow + ": " +
result);
query = new OSQLSynchQuery<ODocument>("select from " + VTYPE_GRAPHROW
+ " where key = :key");
result = db.command(query).execute(args);
System.out.println("Rows by key " + key + ": " + result);
OCommandSQL cmd = new OCommandSQL("update " + VTYPE_GRAPHROW + "
INCREMENT row = "
+ String.valueOf(startAt * -1) + " where key = ?");
result = db.command(cmd).execute(key);
System.out.println("Rows updated: " + result);
args.put("row", newRow);
query = new OSQLSynchQuery<ODocument>("select from " + VTYPE_GRAPHROW
+ " where key = :key and row = :row");
args.put("key", key);
args.put("row", newRow);
result = db.command(query).execute(args);
System.out.println("Found rows with key " + key + " and row " + newRow +
": " + result);
query = new OSQLSynchQuery<ODocument>("select from " + VTYPE_GRAPHROW
+ " where key = :key");
result = db.command(query).execute(args);
System.out.println("Found rows with key " + key + ": " + result);
db.commit();
}
}
--
---
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.