use of com.orientechnologies.orient.core.metadata.schema.OClassImpl in project orientdb by orientechnologies.
the class OCommandExecutorSQLDropProperty method execute.
/**
* Execute the CREATE PROPERTY.
*/
public Object execute(final Map<Object, Object> iArgs) {
if (fieldName == null)
throw new OCommandExecutionException("Cannot execute the command because it has not yet been parsed");
final ODatabaseDocument database = getDatabase();
final OClassImpl sourceClass = (OClassImpl) database.getMetadata().getSchema().getClass(className);
if (sourceClass == null)
throw new OCommandExecutionException("Source class '" + className + "' not found");
if (ifExists && !sourceClass.existsProperty(fieldName)) {
return null;
}
final List<OIndex<?>> indexes = relatedIndexes(fieldName);
if (!indexes.isEmpty()) {
if (force) {
dropRelatedIndexes(indexes);
} else {
final StringBuilder indexNames = new StringBuilder();
boolean first = true;
for (final OIndex<?> index : sourceClass.getClassInvolvedIndexes(fieldName)) {
if (!first) {
indexNames.append(", ");
} else {
first = false;
}
indexNames.append(index.getName());
}
throw new OCommandExecutionException("Property used in indexes (" + indexNames.toString() + "). Please drop these indexes before removing property or use FORCE parameter.");
}
}
// REMOVE THE PROPERTY
sourceClass.dropProperty(fieldName);
return null;
}
use of com.orientechnologies.orient.core.metadata.schema.OClassImpl in project orientdb by orientechnologies.
the class OIndexManagerShared method notifyInvolvedClasses.
protected void notifyInvolvedClasses(int[] clusterIdsToIndex) {
if (clusterIdsToIndex == null || clusterIdsToIndex.length == 0)
return;
final ODatabaseDocumentInternal database = getDatabase();
// UPDATE INVOLVED CLASSES
final Set<String> classes = new HashSet<String>();
for (int clusterId : clusterIdsToIndex) {
final OClass cls = database.getMetadata().getSchema().getClassByClusterId(clusterId);
if (cls != null && cls instanceof OClassImpl && !classes.contains(cls.getName())) {
((OClassImpl) cls).onPostIndexManagement();
classes.add(cls.getName());
}
}
}
use of com.orientechnologies.orient.core.metadata.schema.OClassImpl in project orientdb by orientechnologies.
the class OSequenceLibraryImpl method init.
private void init() {
final ODatabaseDocument db = ODatabaseRecordThreadLocal.INSTANCE.get();
if (db.getMetadata().getSchema().existsClass(OSequence.CLASS_NAME)) {
return;
}
final OClassImpl sequenceClass = (OClassImpl) db.getMetadata().getSchema().createClass(OSequence.CLASS_NAME);
OSequence.initClass(sequenceClass);
}
use of com.orientechnologies.orient.core.metadata.schema.OClassImpl in project orientdb by orientechnologies.
the class OCommandExecutorSQLCreateProperty method execute.
/**
* Execute the CREATE PROPERTY.
*/
public Object execute(final Map<Object, Object> iArgs) {
if (type == null)
throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
final ODatabaseDocument database = getDatabase();
final OClassImpl sourceClass = (OClassImpl) database.getMetadata().getSchema().getClass(className);
if (sourceClass == null)
throw new OCommandExecutionException("Source class '" + className + "' not found");
OPropertyImpl prop = (OPropertyImpl) sourceClass.getProperty(fieldName);
if (prop != null) {
if (ifNotExists) {
return sourceClass.properties().size();
}
throw new OCommandExecutionException("Property '" + className + "." + fieldName + "' already exists. Remove it before to retry.");
}
// CREATE THE PROPERTY
OClass linkedClass = null;
OType linkedType = null;
if (linked != null) {
// FIRST SEARCH BETWEEN CLASSES
linkedClass = database.getMetadata().getSchema().getClass(linked);
if (linkedClass == null)
// NOT FOUND: SEARCH BETWEEN TYPES
linkedType = OType.valueOf(linked.toUpperCase(Locale.ENGLISH));
}
// CREATE IT LOCALLY
OPropertyImpl internalProp = sourceClass.addPropertyInternal(fieldName, type, linkedType, linkedClass, unsafe);
boolean toSave = false;
if (readonly) {
internalProp.setReadonly(true);
toSave = true;
}
if (mandatory) {
internalProp.setMandatory(true);
toSave = true;
}
if (notnull) {
internalProp.setNotNull(true);
toSave = true;
}
if (max != null) {
internalProp.setMax(max);
toSave = true;
}
if (min != null) {
internalProp.setMin(min);
toSave = true;
}
if (defaultValue != null) {
internalProp.setDefaultValue(defaultValue);
toSave = true;
}
if (collate != null) {
internalProp.setCollate(collate);
toSave = true;
}
if (regex != null) {
internalProp.setRegexp(regex);
toSave = true;
}
if (toSave) {
internalProp.save();
}
return sourceClass.properties().size();
}
use of com.orientechnologies.orient.core.metadata.schema.OClassImpl in project orientdb by orientechnologies.
the class OCommandExecutorSQLAlterClass method execute.
/**
* Execute the ALTER CLASS.
*/
public Object execute(final Map<Object, Object> iArgs) {
final ODatabaseDocument database = getDatabase();
if (attribute == null)
throw new OCommandExecutionException("Cannot execute the command because it has not been parsed yet");
final OClassImpl cls = (OClassImpl) database.getMetadata().getSchema().getClass(className);
if (cls == null)
throw new OCommandExecutionException("Cannot alter class '" + className + "' because not found");
if (!unsafe && attribute == ATTRIBUTES.NAME && cls.isSubClassOf("E"))
throw new OCommandExecutionException("Cannot alter class '" + className + "' because is an Edge class and could break vertices. Use UNSAFE if you want to force it");
// REMOVE CACHE OF COMMAND RESULTS
for (int clId : cls.getPolymorphicClusterIds()) getDatabase().getMetadata().getCommandCache().invalidateResultsOfCluster(getDatabase().getClusterNameById(clId));
if (value != null && attribute == ATTRIBUTES.SUPERCLASS) {
checkClassExists(database, className, decodeClassName(value));
}
if (value != null && attribute == ATTRIBUTES.SUPERCLASSES) {
List<String> classes = Arrays.asList(value.split(",\\s*"));
for (String cName : classes) {
checkClassExists(database, className, decodeClassName(cName));
}
}
if (!unsafe && value != null && attribute == ATTRIBUTES.NAME) {
if (!cls.getIndexes().isEmpty()) {
throw new OCommandExecutionException("Cannot rename class '" + className + "' because it has indexes defined on it. Drop indexes before or use UNSAFE (at your won risk)");
}
}
cls.set(attribute, value);
return Boolean.TRUE;
}
Aggregations