use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class OPropertyImpl method setDefaultValue.
public OPropertyImpl setDefaultValue(final String defaultValue) {
getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
acquireSchemaWriteLock();
try {
final ODatabaseDocumentInternal database = getDatabase();
final OStorage storage = database.getStorage();
if (storage instanceof OStorageProxy) {
final String cmd = String.format("alter property %s default %s", getFullNameQuoted(), quoteString(defaultValue));
database.command(new OCommandSQL(cmd)).execute();
} else if (isDistributedCommand()) {
final String cmd = String.format("alter property %s default %s", getFullNameQuoted(), quoteString(defaultValue));
final OCommandSQL commandSQL = new OCommandSQL(cmd);
commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
database.command(commandSQL).execute();
setDefaultValueInternal(defaultValue);
} else {
setDefaultValueInternal(defaultValue);
}
} finally {
releaseSchemaWriteLock();
}
return this;
}
use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class OPropertyImpl method setCollate.
public OProperty setCollate(String collate) {
if (collate == null)
collate = ODefaultCollate.NAME;
getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
acquireSchemaWriteLock();
try {
final ODatabaseDocumentInternal database = getDatabase();
final OStorage storage = database.getStorage();
final String cmd = String.format("alter property %s collate %s", getFullNameQuoted(), quoteString(collate));
final OCommandSQL commandSQL = new OCommandSQL(cmd);
if (storage instanceof OStorageProxy) {
database.command(commandSQL).execute();
} else if (isDistributedCommand()) {
commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
database.command(commandSQL).execute();
setCollateInternal(collate);
} else
setCollateInternal(collate);
} finally {
releaseSchemaWriteLock();
}
return this;
}
use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class OPropertyImpl method setReadonly.
public OPropertyImpl setReadonly(final boolean isReadonly) {
getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
acquireSchemaWriteLock();
try {
final ODatabaseDocumentInternal database = getDatabase();
final OStorage storage = database.getStorage();
if (storage instanceof OStorageProxy) {
final String cmd = String.format("alter property %s readonly %s", getFullNameQuoted(), isReadonly);
database.command(new OCommandSQL(cmd)).execute();
} else if (isDistributedCommand()) {
final String cmd = String.format("alter property %s readonly %s", getFullNameQuoted(), isReadonly);
final OCommandSQL commandSQL = new OCommandSQL(cmd);
commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
database.command(commandSQL).execute();
setReadonlyInternal(isReadonly);
} else
setReadonlyInternal(isReadonly);
} finally {
releaseSchemaWriteLock();
}
return this;
}
use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class OPropertyImpl method setRegexp.
public OPropertyImpl setRegexp(final String regexp) {
getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
acquireSchemaWriteLock();
try {
final ODatabaseDocumentInternal database = getDatabase();
final OStorage storage = database.getStorage();
if (storage instanceof OStorageProxy) {
final String cmd = String.format("alter property %s regexp %s", getFullNameQuoted(), quoteString(regexp));
database.command(new OCommandSQL(cmd)).execute();
} else if (isDistributedCommand()) {
final String cmd = String.format("alter property %s regexp %s", getFullNameQuoted(), quoteString(regexp));
final OCommandSQL commandSQL = new OCommandSQL(cmd);
commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
database.command(commandSQL).execute();
setRegexpInternal(regexp);
} else
setRegexpInternal(regexp);
} finally {
releaseSchemaWriteLock();
}
return this;
}
use of com.orientechnologies.orient.core.storage.OStorage in project orientdb by orientechnologies.
the class OSchemaShared method createClassInternal.
private OClass createClassInternal(final String className, final int[] clusterIdsToAdd, final List<OClass> superClasses) throws ClusterIdsAreEmptyException {
acquireSchemaWriteLock();
try {
if (className == null || className.length() == 0)
throw new OSchemaException("Found class name null or empty");
if (Character.isDigit(className.charAt(0)))
throw new OSchemaException("Found invalid class name. Cannot start with numbers");
final Character wrongCharacter = checkClassNameIfValid(className);
if (wrongCharacter != null)
throw new OSchemaException("Found invalid class name. Character '" + wrongCharacter + "' cannot be used in class name.");
final ODatabaseDocumentInternal database = getDatabase();
final OStorage storage = database.getStorage();
checkEmbedded(storage);
checkClustersAreAbsent(clusterIdsToAdd);
final int[] clusterIds;
if (clusterIdsToAdd == null || clusterIdsToAdd.length == 0) {
throw new ClusterIdsAreEmptyException();
} else
clusterIds = clusterIdsToAdd;
database.checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_CREATE);
final String key = className.toLowerCase();
if (classes.containsKey(key))
throw new OSchemaException("Class '" + className + "' already exists in current database");
OClassImpl cls = new OClassImpl(this, className, clusterIds);
classes.put(key, cls);
if (superClasses != null && superClasses.size() > 0) {
cls.setSuperClassesInternal(superClasses);
for (OClass superClass : superClasses) {
// UPDATE INDEXES
final int[] clustersToIndex = superClass.getPolymorphicClusterIds();
final String[] clusterNames = new String[clustersToIndex.length];
for (int i = 0; i < clustersToIndex.length; i++) clusterNames[i] = database.getClusterNameById(clustersToIndex[i]);
for (OIndex<?> index : superClass.getIndexes()) for (String clusterName : clusterNames) if (clusterName != null)
database.getMetadata().getIndexManager().addClusterToIndex(clusterName, index.getName());
}
}
addClusterClassMap(cls);
return cls;
} finally {
releaseSchemaWriteLock();
}
}
Aggregations