use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class OChainIndexFetchTest method testFetchChaninedIndex.
@Test
public void testFetchChaninedIndex() {
OClass baseClass = db.getMetadata().getSchema().createClass("BaseClass");
OProperty propr = baseClass.createProperty("ref", OType.LINK);
OClass linkedClass = db.getMetadata().getSchema().createClass("LinkedClass");
OProperty id = linkedClass.createProperty("id", OType.STRING);
id.createIndex(INDEX_TYPE.UNIQUE);
propr.setLinkedClass(linkedClass);
propr.createIndex(INDEX_TYPE.NOTUNIQUE);
ODocument doc = new ODocument(linkedClass);
doc.field("id", "referred");
db.save(doc);
ODocument doc1 = new ODocument(baseClass);
doc1.field("ref", doc);
db.save(doc1);
List<ODocument> res = db.query(new OSQLSynchQuery(" select from BaseClass where ref.id ='wrong_referred' "));
assertEquals(0, res.size());
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class FaultDuringWritingWithOperationRedirectScenarioTest method executeTest.
@Override
public void executeTest() throws Exception {
// TO-CHANGE
List<ODocument> result = null;
ODatabaseDocumentTx dbServer3 = new ODatabaseDocumentTx(getRemoteDatabaseURL(serverInstance.get(2))).open("admin", "admin");
String dbServerUrl1 = getRemoteDatabaseURL(serverInstance.get(0));
try {
/*
* Test with quorum = 2
*/
banner("Test with quorum = 2");
// writes on server3 (remote access) while a task is monitoring the inserted records amount and shutdown server
// after 1/3 of total number of records to insert, and restarting it when 2/3 of records were inserted.
ODatabaseRecordThreadLocal.INSTANCE.set(null);
Callable shutdownAndRestartTask = new ShutdownAndRestartServer(serverInstance.get(2), dbServerUrl1, "net-fault");
final ExecutorService executor = Executors.newSingleThreadExecutor();
Future f = executor.submit(shutdownAndRestartTask);
executeMultipleWrites(this.executeTestsOnServers, "remote");
// waiting for task ending
f.get();
// waiting for changes propagation
waitForMultipleInsertsInClassPropagation(500L, "Person", 5000L);
// preliminar check
ODatabaseRecordThreadLocal.INSTANCE.set(dbServer3);
result = dbServer3.query(new OSQLSynchQuery<OIdentifiable>("select from Person"));
assertEquals(500, result.size());
// check consistency on all the server:
// all the records destined to server3 were redirected to an other server, so we must inspect consistency for all 500 records
checkWritesAboveCluster(serverInstance, executeTestsOnServers);
} catch (Exception e) {
e.printStackTrace();
fail();
} finally {
if (!dbServer3.isClosed()) {
ODatabaseRecordThreadLocal.INSTANCE.set(dbServer3);
dbServer3.close();
ODatabaseRecordThreadLocal.INSTANCE.set(null);
}
}
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class TestDistributeConfigSerialization method executeTest.
@Override
protected void executeTest() throws Exception {
ODatabaseDocumentTx db = new ODatabaseDocumentTx("plocal:target/server0/databases/" + getDatabaseName());
try {
db.setSerializer(new ORecordSerializerSchemaAware2CSV());
db.create();
db.getMetadata().getSchema().createClass("TestMessaging");
db.activateOnCurrentThread();
db.save(new ODocument("TestMessaging").field("test", "test"));
db.query(new OSQLSynchQuery("select from TestMessaging "));
db.close();
} catch (OException e) {
e.printStackTrace();
Assert.fail("error on creating a csv database in distributed environment");
}
try {
db = new ODatabaseDocumentTx("remote:localhost/" + getDatabaseName());
db.open("admin", "admin");
db.query(new OSQLSynchQuery("select from TestMessaging "));
db.close();
} catch (OException e) {
e.printStackTrace();
Assert.fail("error on creating a csv database in distributed environment");
}
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class OrientGraphQuery method vertices.
/**
* Returns the result set of the query as iterable vertices.
*/
@Override
public Iterable<Vertex> vertices() {
if (limit == 0)
return Collections.emptyList();
OTransaction transaction = ((OrientBaseGraph) graph).getRawGraph().getTransaction();
if (transaction.isActive() && transaction.getEntryCount() > 0 || hasCustomPredicate()) {
// INSIDE TRANSACTION QUERY DOESN'T SEE IN MEMORY CHANGES, UNTIL
// SUPPORTED USED THE BASIC IMPL
String[] classes = allSubClassesLabels();
return new OrientGraphQueryIterable<Vertex>(true, classes);
}
final StringBuilder text = new StringBuilder(512);
// GO DIRECTLY AGAINST E CLASS AND SUB-CLASSES
text.append(QUERY_SELECT_FROM);
if (((OrientBaseGraph) graph).isUseClassForVertexLabel() && labels != null && labels.length > 0) {
// FILTER PER CLASS SAVING CHECKING OF LABEL PROPERTY
if (labels.length == 1)
// USE THE CLASS NAME
text.append(OrientBaseGraph.encodeClassName(labels[0]));
else {
// MULTIPLE CLASSES NOT SUPPORTED DIRECTLY: CREATE A SUB-QUERY
String[] classes = allSubClassesLabels();
return new OrientGraphQueryIterable<Vertex>(true, classes);
}
} else
text.append(OrientVertexType.CLASS_NAME);
final boolean usedWhere = manageFilters(text);
if (!((OrientBaseGraph) graph).isUseClassForVertexLabel())
manageLabels(usedWhere, text);
if (orderBy.length() > 1) {
text.append(ORDERBY);
text.append(orderBy);
text.append(" ").append(orderByDir).append(" ");
}
if (skip > 0 && skip < Integer.MAX_VALUE) {
text.append(SKIP);
text.append(skip);
}
if (limit > 0 && limit < Integer.MAX_VALUE) {
text.append(LIMIT);
text.append(limit);
}
final OSQLSynchQuery<OIdentifiable> query = new OSQLSynchQuery<OIdentifiable>(text.toString());
if (fetchPlan != null)
query.setFetchPlan(fetchPlan);
return new OrientElementIterable<Vertex>(((OrientBaseGraph) graph), ((OrientBaseGraph) graph).getRawGraph().query(query));
}
use of com.orientechnologies.orient.core.sql.query.OSQLSynchQuery in project orientdb by orientechnologies.
the class OrientIndex method removeElement.
protected void removeElement(final T element) {
graph.setCurrentGraphInThreadLocal();
graph.autoStartTransaction();
final OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<ODocument>("select from index:" + recordKeyValueIndex.getName() + " where key between [" + element.getIdentity() + "] and [" + element.getIdentity() + "]");
final Collection<ODocument> entries = (Collection<ODocument>) graph.getRawGraph().query(query);
for (ODocument entry : entries) {
final OCompositeKey key = entry.field("key");
final List<Object> keys = key.getKeys();
underlying.remove(keys.get(1).toString(), element.getIdentity());
recordKeyValueIndex.remove(key, element.getIdentity());
}
}
Aggregations