Search in sources :

Example 46 with OCommandExecutionException

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, "'");
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException)

Example 47 with OCommandExecutionException

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);
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 48 with OCommandExecutionException

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);
    }
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Example 49 with OCommandExecutionException

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");
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OCompositeIndexDefinition(com.orientechnologies.orient.core.index.OCompositeIndexDefinition) OIndexDefinition(com.orientechnologies.orient.core.index.OIndexDefinition) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException)

Example 50 with OCommandExecutionException

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 };
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) ORecord(com.orientechnologies.orient.core.record.ORecord) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OTooBigIndexKeyException(com.orientechnologies.orient.core.exception.OTooBigIndexKeyException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Aggregations

OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)82 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)20 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)19 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)16 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)15 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)14 OException (com.orientechnologies.common.exception.OException)9 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)9 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)6 IOException (java.io.IOException)6 OCommandRequestText (com.orientechnologies.orient.core.command.OCommandRequestText)5 OType (com.orientechnologies.orient.core.metadata.schema.OType)5 OQueryParsingException (com.orientechnologies.orient.core.exception.OQueryParsingException)4 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)4 ORecord (com.orientechnologies.orient.core.record.ORecord)4 OHazelcastPlugin (com.orientechnologies.orient.server.hazelcast.OHazelcastPlugin)4 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)4 ArrayList (java.util.ArrayList)4 ORID (com.orientechnologies.orient.core.id.ORID)3 ORecordId (com.orientechnologies.orient.core.id.ORecordId)3