use of com.orientechnologies.orient.core.db.ODatabaseDocumentInternal in project orientdb by orientechnologies.
the class OIndexRIDContainer method convertToSbTree.
private void convertToSbTree() {
final ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.get();
final OIndexRIDContainerSBTree tree = new OIndexRIDContainerSBTree(fileId, (OAbstractPaginatedStorage) db.getStorage().getUnderlying());
tree.addAll(underlying);
underlying = tree;
isEmbedded = false;
}
use of com.orientechnologies.orient.core.db.ODatabaseDocumentInternal in project orientdb by orientechnologies.
the class OMetadataDefault method init.
private void init(final boolean iLoad) {
final ODatabaseDocumentInternal database = getDatabase();
schemaClusterId = database.getClusterIdByName(CLUSTER_INTERNAL_NAME);
final AtomicBoolean schemaLoaded = new AtomicBoolean(false);
schema = new OSchemaProxy(database.getStorage().getResource(OSchema.class.getSimpleName(), new Callable<OSchemaShared>() {
public OSchemaShared call() {
ODatabaseDocumentInternal database = getDatabase();
final OSchemaShared instance = new OSchemaShared(database.getStorageVersions().classesAreDetectedByClusterId());
if (iLoad)
instance.load();
schemaLoaded.set(true);
return instance;
}
}), database);
indexManager = new OIndexManagerProxy(database.getStorage().getResource(OIndexManager.class.getSimpleName(), new Callable<OIndexManager>() {
public OIndexManager call() {
OIndexManager instance;
if (database.getStorage() instanceof OStorageProxy)
instance = new OIndexManagerRemote(database);
else
instance = new OIndexManagerShared(database);
if (iLoad)
try {
instance.load();
} catch (Exception e) {
OLogManager.instance().error(this, "[OMetadata] Error on loading index manager, reset index configuration", e);
instance.create();
}
return instance;
}
}), database);
security = new OSecurityProxy(database.getStorage().getResource(OSecurity.class.getSimpleName(), new Callable<OSecurity>() {
public OSecurity call() {
final OSecurity instance = OSecurityManager.instance().newSecurity();
if (iLoad) {
security = instance;
instance.load();
}
return instance;
}
}), database);
commandCache = database.getStorage().getResource(OCommandCache.class.getSimpleName(), new Callable<OCommandCache>() {
public OCommandCache call() {
return new OCommandCacheSoftRefs(database.getName());
}
});
final Class<? extends OSecurity> securityClass = (Class<? extends OSecurity>) database.getProperty(ODatabase.OPTIONS.SECURITY.toString());
if (securityClass != null)
// INSTALL CUSTOM WRAPPED SECURITY
try {
final OSecurity wrapped = security;
security = securityClass.getDeclaredConstructor(OSecurity.class, ODatabaseDocumentInternal.class).newInstance(wrapped, database);
} catch (Exception e) {
throw OException.wrapException(new OSecurityException("Cannot install custom security implementation (" + securityClass + ")"), e);
}
functionLibrary = new OFunctionLibraryProxy(database.getStorage().getResource(OFunctionLibrary.class.getSimpleName(), new Callable<OFunctionLibrary>() {
public OFunctionLibrary call() {
final OFunctionLibraryImpl instance = new OFunctionLibraryImpl();
if (iLoad && !(database.getStorage() instanceof OStorageProxy))
instance.load();
return instance;
}
}), database);
sequenceLibrary = new OSequenceLibraryProxy(database.getStorage().getResource(OSequenceLibrary.class.getSimpleName(), new Callable<OSequenceLibrary>() {
@Override
public OSequenceLibrary call() throws Exception {
final OSequenceLibraryImpl instance = new OSequenceLibraryImpl();
if (iLoad) {
instance.load();
}
return instance;
}
}), database);
scheduler = new OSchedulerProxy(database.getStorage().getResource(OScheduler.class.getSimpleName(), new Callable<OScheduler>() {
public OScheduler call() {
final OSchedulerImpl instance = new OSchedulerImpl();
if (iLoad && !(database.getStorage() instanceof OStorageProxy))
instance.load();
return instance;
}
}), database);
if (schemaLoaded.get())
schema.onPostIndexManagement();
}
use of com.orientechnologies.orient.core.db.ODatabaseDocumentInternal in project orientdb by orientechnologies.
the class OClassImpl method addProperty.
private OProperty addProperty(final String propertyName, final OType type, final OType linkedType, final OClass linkedClass, final boolean unsafe) {
if (type == null)
throw new OSchemaException("Property type not defined.");
if (propertyName == null || propertyName.length() == 0)
throw new OSchemaException("Property name is null or empty");
if (getDatabase().getStorage().getConfiguration().isStrictSql()) {
validatePropertyName(propertyName);
}
if (getDatabase().getTransaction().isActive())
throw new OSchemaException("Cannot create property '" + propertyName + "' inside a transaction");
final ODatabaseDocumentInternal database = getDatabase();
database.checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
if (linkedType != null)
OPropertyImpl.checkLinkTypeSupport(type);
if (linkedClass != null)
OPropertyImpl.checkSupportLinkedClass(type);
acquireSchemaWriteLock();
try {
final StringBuilder cmd = new StringBuilder("create property ");
// CLASS.PROPERTY NAME
if (getDatabase().getStorage().getConfiguration().isStrictSql())
cmd.append('`');
cmd.append(name);
if (getDatabase().getStorage().getConfiguration().isStrictSql())
cmd.append('`');
cmd.append('.');
if (getDatabase().getStorage().getConfiguration().isStrictSql())
cmd.append('`');
cmd.append(propertyName);
if (getDatabase().getStorage().getConfiguration().isStrictSql())
cmd.append('`');
// TYPE
cmd.append(' ');
cmd.append(type.name);
if (linkedType != null) {
// TYPE
cmd.append(' ');
cmd.append(linkedType.name);
} else if (linkedClass != null) {
// TYPE
cmd.append(' ');
if (getDatabase().getStorage().getConfiguration().isStrictSql())
cmd.append('`');
cmd.append(linkedClass.getName());
if (getDatabase().getStorage().getConfiguration().isStrictSql())
cmd.append('`');
}
if (unsafe)
cmd.append(" unsafe ");
final OStorage storage = database.getStorage();
if (storage instanceof OStorageProxy) {
database.command(new OCommandSQL(cmd.toString())).execute();
reload();
return getProperty(propertyName);
} else if (isDistributedCommand()) {
final OProperty prop = (OProperty) OScenarioThreadLocal.executeAsDistributed(new Callable<OProperty>() {
@Override
public OProperty call() throws Exception {
return addPropertyInternal(propertyName, type, linkedType, linkedClass, unsafe);
}
});
final OCommandSQL commandSQL = new OCommandSQL(cmd.toString());
commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
database.command(commandSQL).execute();
return prop;
} else
return (OProperty) OScenarioThreadLocal.executeAsDistributed(new Callable<OProperty>() {
@Override
public OProperty call() throws Exception {
return addPropertyInternal(propertyName, type, linkedType, linkedClass, unsafe);
}
});
} finally {
releaseSchemaWriteLock();
}
}
use of com.orientechnologies.orient.core.db.ODatabaseDocumentInternal in project orientdb by orientechnologies.
the class OClassImpl method clearCustom.
public void clearCustom() {
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 class `%s` custom clear", getName());
database.command(new OCommandSQL(cmd)).execute();
} else if (isDistributedCommand()) {
final String cmd = String.format("alter class `%s` custom clear", getName());
final OCommandSQL commandSQL = new OCommandSQL(cmd);
commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
database.command(commandSQL).execute();
clearCustomInternal();
} else
clearCustomInternal();
} finally {
releaseSchemaWriteLock();
}
}
use of com.orientechnologies.orient.core.db.ODatabaseDocumentInternal in project orientdb by orientechnologies.
the class ODocument method fetchSchemaIfCan.
private void fetchSchemaIfCan() {
if (_schema == null) {
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
if (db != null && !db.isClosed()) {
OMetadataInternal metadata = (OMetadataInternal) db.getMetadata();
_schema = metadata.getImmutableSchemaSnapshot();
}
}
}
Aggregations