use of com.orientechnologies.orient.core.exception.OCommandExecutionException in project orientdb by orientechnologies.
the class OrientBaseGraph method dropVertexType.
/**
* Drop a vertex class.
*
* @param iTypeName Vertex class name
*/
public void dropVertexType(final String iTypeName) {
makeActive();
if (getDatabase().countClass(iTypeName) > 0)
throw new OCommandExecutionException("cannot drop vertex type '" + iTypeName + "' because it contains Vertices. Use 'DELETE VERTEX' command first to remove data");
executeOutsideTx(new OCallable<OClass, OrientBaseGraph>() {
@Override
public OClass call(final OrientBaseGraph g) {
ODatabaseDocumentTx rawGraph = getRawGraph();
rawGraph.command(new OCommandSQL("delete vertex " + iTypeName)).execute();
rawGraph.getMetadata().getSchema().dropClass(iTypeName);
return null;
}
}, "drop vertex type '", iTypeName, "'");
}
use of com.orientechnologies.orient.core.exception.OCommandExecutionException in project orientdb by orientechnologies.
the class SQLDeleteEdgeTest method testDropClassVandEwithUnsafe.
public void testDropClassVandEwithUnsafe() {
database.command(new OCommandSQL("CREATE CLASS SuperE extends E")).execute();
database.command(new OCommandSQL("CREATE CLASS SuperV extends V")).execute();
OIdentifiable v1 = database.command(new OCommandSQL("create vertex SuperV set name = 'Luca'")).execute();
OIdentifiable v2 = database.command(new OCommandSQL("create vertex SuperV set name = 'Mark'")).execute();
database.command(new OCommandSQL("CREATE EDGE SuperE from " + v1.getIdentity() + " to " + v2.getIdentity())).execute();
try {
database.command(new OCommandSQL("DROP CLASS SuperV")).execute();
Assert.assertTrue(false);
} catch (OCommandExecutionException e) {
Assert.assertTrue(true);
}
try {
database.command(new OCommandSQL("DROP CLASS SuperE")).execute();
Assert.assertTrue(false);
} catch (OCommandExecutionException e) {
Assert.assertTrue(true);
}
try {
database.command(new OCommandSQL("DROP CLASS SuperV unsafe")).execute();
Assert.assertTrue(true);
} catch (OCommandExecutionException e) {
Assert.assertTrue(false);
}
try {
database.command(new OCommandSQL("DROP CLASS SuperE UNSAFE")).execute();
Assert.assertTrue(true);
} catch (OCommandExecutionException e) {
Assert.assertTrue(false);
}
}
use of com.orientechnologies.orient.core.exception.OCommandExecutionException in project orientdb by orientechnologies.
the class SQLDeleteEdgeTest method testDropClassVandEwithDeleteElements.
public void testDropClassVandEwithDeleteElements() {
database.command(new OCommandSQL("CREATE CLASS SuperE extends E")).execute();
database.command(new OCommandSQL("CREATE CLASS SuperV extends V")).execute();
OIdentifiable v1 = database.command(new OCommandSQL("create vertex SuperV set name = 'Luca'")).execute();
OIdentifiable v2 = database.command(new OCommandSQL("create vertex SuperV set name = 'Mark'")).execute();
database.command(new OCommandSQL("CREATE EDGE SuperE from " + v1.getIdentity() + " to " + v2.getIdentity())).execute();
try {
database.command(new OCommandSQL("DROP CLASS SuperV")).execute();
Assert.assertTrue(false);
} catch (OCommandExecutionException e) {
Assert.assertTrue(true);
}
try {
database.command(new OCommandSQL("DROP CLASS SuperE")).execute();
Assert.assertTrue(false);
} catch (OCommandExecutionException e) {
Assert.assertTrue(true);
}
int deleted = database.command(new OCommandSQL("DELETE VERTEX SuperV")).execute();
try {
database.command(new OCommandSQL("DROP CLASS SuperV")).execute();
Assert.assertTrue(true);
} catch (OCommandExecutionException e) {
Assert.assertTrue(false);
}
try {
database.command(new OCommandSQL("DROP CLASS SuperE")).execute();
Assert.assertTrue(true);
} catch (OCommandExecutionException e) {
Assert.assertTrue(false);
}
}
use of com.orientechnologies.orient.core.exception.OCommandExecutionException in project orientdb by orientechnologies.
the class SQLDropPropertyIndexTest method testForcePropertyDisabledBrokenCase.
@Test
public void testForcePropertyDisabledBrokenCase() throws Exception {
database.command(new OCommandSQL("CREATE INDEX DropPropertyIndexCompositeIndex ON DropPropertyIndexTestClass (prop1, prop2) UNIQUE")).execute();
try {
database.command(new OCommandSQL("DROP PROPERTY DropPropertyIndextestclaSS.proP1")).execute();
Assert.fail();
} catch (OCommandExecutionException e) {
Assert.assertTrue(e.getMessage().contains("Property used in indexes (" + "DropPropertyIndexCompositeIndex" + "). Please drop these indexes before removing property or use FORCE parameter."));
}
database.getMetadata().getIndexManager().reload();
final OIndex<?> index = database.getMetadata().getSchema().getClass("DropPropertyIndexTestClass").getClassIndex("DropPropertyIndexCompositeIndex");
Assert.assertNotNull(index);
final OIndexDefinition indexDefinition = index.getDefinition();
Assert.assertTrue(indexDefinition instanceof OCompositeIndexDefinition);
Assert.assertEquals(indexDefinition.getFields(), Arrays.asList("prop1", "prop2"));
Assert.assertEquals(indexDefinition.getTypes(), new OType[] { EXPECTED_PROP1_TYPE, EXPECTED_PROP2_TYPE });
Assert.assertEquals(index.getType(), "UNIQUE");
}
use of com.orientechnologies.orient.core.exception.OCommandExecutionException in project orientdb by orientechnologies.
the class OIndexAbstract method indexCluster.
protected long[] indexCluster(final String clusterName, final OProgressListener iProgressListener, long documentNum, long documentIndexed, long documentTotal) {
try {
for (final ORecord record : getDatabase().browseCluster(clusterName)) {
if (Thread.interrupted())
throw new OCommandExecutionException("The index rebuild has been interrupted");
if (record instanceof ODocument) {
final ODocument doc = (ODocument) record;
if (indexDefinition == null)
throw new OConfigurationException("Index '" + name + "' cannot be rebuilt because has no a valid definition (" + indexDefinition + ")");
final Object fieldValue = indexDefinition.getDocumentValueToIndex(doc);
if (fieldValue != null || !indexDefinition.isNullValuesIgnored()) {
try {
populateIndex(doc, fieldValue);
} catch (OTooBigIndexKeyException e) {
OLogManager.instance().error(this, "Exception during index rebuild. Exception was caused by following key/ value pair - key %s, value %s." + " Rebuild will continue from this point", e, fieldValue, doc.getIdentity());
} catch (OIndexException e) {
OLogManager.instance().error(this, "Exception during index rebuild. Exception was caused by following key/ value pair - key %s, value %s." + " Rebuild will continue from this point", e, fieldValue, doc.getIdentity());
}
++documentIndexed;
}
}
documentNum++;
if (iProgressListener != null)
iProgressListener.onProgress(this, documentNum, (float) (documentNum * 100.0 / documentTotal));
}
} catch (NoSuchElementException e) {
// END OF CLUSTER REACHED, IGNORE IT
}
return new long[] { documentNum, documentIndexed };
}
Aggregations