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();
}
}
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();
}
}
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;
}
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;
}
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);
}
}
Aggregations