Search in sources :

Example 6 with OSchemaException

use of com.orientechnologies.orient.core.exception.OSchemaException in project orientdb by orientechnologies.

the class OClassImpl method dropProperty.

public void dropProperty(final String propertyName) {
    if (getDatabase().getTransaction().isActive())
        throw new IllegalStateException("Cannot drop a property inside a transaction");
    getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_DELETE);
    final String lowerName = propertyName.toLowerCase();
    acquireSchemaWriteLock();
    try {
        if (!properties.containsKey(lowerName))
            throw new OSchemaException("Property '" + propertyName + "' not found in class " + name + "'");
        final ODatabaseDocumentInternal database = getDatabase();
        final OStorage storage = database.getStorage();
        if (storage instanceof OStorageProxy) {
            if (getDatabase().getStorage().getConfiguration().isStrictSql()) {
                database.command(new OCommandSQL("drop property " + name + ".`" + propertyName + "`")).execute();
            } else {
                database.command(new OCommandSQL("drop property " + name + '.' + propertyName)).execute();
            }
        } else if (isDistributedCommand()) {
            OScenarioThreadLocal.executeAsDistributed(new Callable<OProperty>() {

                @Override
                public OProperty call() throws Exception {
                    dropPropertyInternal(propertyName);
                    return null;
                }
            });
            String stm;
            if (getDatabase().getStorage().getConfiguration().isStrictSql()) {
                stm = "drop property " + name + ".`" + propertyName + "`";
            } else {
                stm = "drop property " + name + "." + propertyName;
            }
            final OCommandSQL commandSQL = new OCommandSQL(stm);
            commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
            database.command(commandSQL).execute();
        } else
            OScenarioThreadLocal.executeAsDistributed(new Callable<OProperty>() {

                @Override
                public OProperty call() throws Exception {
                    dropPropertyInternal(propertyName);
                    return null;
                }
            });
    } finally {
        releaseSchemaWriteLock();
    }
}
Also used : OSchemaException(com.orientechnologies.orient.core.exception.OSchemaException) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) Callable(java.util.concurrent.Callable) OException(com.orientechnologies.common.exception.OException) OSchemaException(com.orientechnologies.orient.core.exception.OSchemaException) OSecurityException(com.orientechnologies.orient.core.exception.OSecurityException) ODatabaseException(com.orientechnologies.orient.core.exception.ODatabaseException) IOException(java.io.IOException) OSecurityAccessException(com.orientechnologies.orient.core.exception.OSecurityAccessException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL)

Example 7 with OSchemaException

use of com.orientechnologies.orient.core.exception.OSchemaException in project orientdb by orientechnologies.

the class OClassImpl method dropPropertyInternal.

private void dropPropertyInternal(final String iPropertyName) {
    if (getDatabase().getTransaction().isActive())
        throw new IllegalStateException("Cannot drop a property inside a transaction");
    getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_DELETE);
    acquireSchemaWriteLock();
    try {
        checkEmbedded();
        final OProperty prop = properties.remove(iPropertyName.toLowerCase());
        if (prop == null)
            throw new OSchemaException("Property '" + iPropertyName + "' not found in class " + name + "'");
    } finally {
        releaseSchemaWriteLock();
    }
}
Also used : OSchemaException(com.orientechnologies.orient.core.exception.OSchemaException)

Example 8 with OSchemaException

use of com.orientechnologies.orient.core.exception.OSchemaException in project orientdb by orientechnologies.

the class OClassImpl method addCluster.

@Override
public OClass addCluster(final String clusterNameOrId) {
    getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
    if (isAbstract()) {
        throw new OSchemaException("Impossible to associate a cluster to an abstract class class");
    }
    acquireSchemaWriteLock();
    try {
        final ODatabaseDocumentInternal database = getDatabase();
        final OStorage storage = database.getStorage();
        if (storage instanceof OStorageProxy) {
            final String cmd = String.format("alter class `%s` addcluster `%s`", name, clusterNameOrId);
            database.command(new OCommandSQL(cmd)).execute();
        } else if (isDistributedCommand()) {
            final int clusterId = owner.createClusterIfNeeded(clusterNameOrId);
            addClusterIdInternal(clusterId);
            final String cmd = String.format("alter class `%s` addcluster `%s`", name, clusterNameOrId);
            final OCommandSQL commandSQL = new OCommandSQL(cmd);
            commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
            database.command(commandSQL).execute();
        } else {
            final int clusterId = owner.createClusterIfNeeded(clusterNameOrId);
            addClusterIdInternal(clusterId);
        }
    } finally {
        releaseSchemaWriteLock();
    }
    return this;
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchemaException(com.orientechnologies.orient.core.exception.OSchemaException) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 9 with OSchemaException

use of com.orientechnologies.orient.core.exception.OSchemaException in project orientdb by orientechnologies.

the class OClassImpl method addClusterId.

public OClass addClusterId(final int clusterId) {
    getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
    if (isAbstract()) {
        throw new OSchemaException("Impossible to associate a cluster to an abstract class class");
    }
    acquireSchemaWriteLock();
    try {
        final ODatabaseDocumentInternal database = getDatabase();
        final OStorage storage = database.getStorage();
        if (storage instanceof OStorageProxy) {
            final String cmd = String.format("alter class `%s` addcluster %d", name, clusterId);
            database.command(new OCommandSQL(cmd)).execute();
        } else if (isDistributedCommand()) {
            final String cmd = String.format("alter class `%s` addcluster %d", name, clusterId);
            final OCommandSQL commandSQL = new OCommandSQL(cmd);
            commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
            database.command(commandSQL).execute();
            addClusterIdInternal(clusterId);
        } else
            addClusterIdInternal(clusterId);
    } finally {
        releaseSchemaWriteLock();
    }
    return this;
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OSchemaException(com.orientechnologies.orient.core.exception.OSchemaException) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 10 with OSchemaException

use of com.orientechnologies.orient.core.exception.OSchemaException in project orientdb by orientechnologies.

the class OObjectSerializerHelper method getFieldValue.

public static Object getFieldValue(final Object iPojo, final String iProperty) {
    final Class<?> c = iPojo.getClass();
    final String className = c.getName();
    getClassFields(c);
    try {
        Object o = getters.get(className + "." + iProperty);
        if (o instanceof Method)
            return ((Method) o).invoke(iPojo);
        else if (o instanceof Field)
            return ((Field) o).get(iPojo);
        return null;
    } catch (Exception e) {
        throw OException.wrapException(new OSchemaException("Cannot get the value of the property: " + iProperty), e);
    }
}
Also used : Field(java.lang.reflect.Field) ODatabaseObject(com.orientechnologies.orient.core.db.object.ODatabaseObject) Method(java.lang.reflect.Method) OSchemaException(com.orientechnologies.orient.core.exception.OSchemaException) OException(com.orientechnologies.common.exception.OException) OSchemaException(com.orientechnologies.orient.core.exception.OSchemaException) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OTransactionException(com.orientechnologies.orient.core.exception.OTransactionException) OObjectNotDetachedException(com.orientechnologies.orient.object.db.OObjectNotDetachedException) OSerializationException(com.orientechnologies.orient.core.exception.OSerializationException)

Aggregations

OSchemaException (com.orientechnologies.orient.core.exception.OSchemaException)26 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)10 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)10 OException (com.orientechnologies.common.exception.OException)7 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)5 OStorage (com.orientechnologies.orient.core.storage.OStorage)5 OSerializationException (com.orientechnologies.orient.core.exception.OSerializationException)4 ODatabaseLifecycleListener (com.orientechnologies.orient.core.db.ODatabaseLifecycleListener)3 ODatabaseObject (com.orientechnologies.orient.core.db.object.ODatabaseObject)3 OTransactionException (com.orientechnologies.orient.core.exception.OTransactionException)3 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)3 OAutoshardedStorage (com.orientechnologies.orient.core.storage.OAutoshardedStorage)3 OStorageProxy (com.orientechnologies.orient.core.storage.OStorageProxy)3 OObjectNotDetachedException (com.orientechnologies.orient.object.db.OObjectNotDetachedException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Field (java.lang.reflect.Field)3 Method (java.lang.reflect.Method)3 OConcurrentModificationException (com.orientechnologies.orient.core.exception.OConcurrentModificationException)2 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)2 OSecurityAccessException (com.orientechnologies.orient.core.exception.OSecurityAccessException)2