use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class OSchemaShared method dropClassIndexes.
private void dropClassIndexes(final OClass cls) {
final ODatabaseDocument database = getDatabase();
final OIndexManager indexManager = database.getMetadata().getIndexManager();
for (final OIndex<?> index : indexManager.getClassIndexes(cls.getName())) indexManager.dropIndex(index.getName());
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class OBalancedClusterSelectionStrategy method getCluster.
public int getCluster(final OClass iClass, final ODocument doc) {
final int[] clusters = iClass.getClusterIds();
if (clusters.length == 1)
// ONLY ONE: RETURN THE FIRST ONE
return clusters[0];
final ODatabaseDocument db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
if (db == null)
return clusters[0];
if (lastCount < 0 || System.currentTimeMillis() - lastCount > REFRESH_TIMEOUT) {
// REFRESH COUNTERS
long min = Long.MAX_VALUE;
for (int cluster : clusters) {
final long count = db.countClusterElements(cluster);
if (count < min) {
min = count;
smallerClusterId = cluster;
}
}
lastCount = System.currentTimeMillis();
}
return smallerClusterId;
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class OSecurityShared method createMetadata.
/**
* Repairs the security structure if broken by creating the ADMIN role and user with default password.
*
* @return
*/
public OUser createMetadata() {
final ODatabaseDocument database = getDatabase();
// SINCE 1.2.0
OClass identityClass = database.getMetadata().getSchema().getClass(OIdentity.CLASS_NAME);
if (identityClass == null)
identityClass = database.getMetadata().getSchema().createAbstractClass(OIdentity.CLASS_NAME);
OClass roleClass = createOrUpdateORoleClass(database, identityClass);
createOrUpdateOUserClass(database, identityClass, roleClass);
// CREATE ROLES AND USERS
ORole adminRole = getRole(ORole.ADMIN);
if (adminRole == null) {
adminRole = createRole(ORole.ADMIN, ORole.ALLOW_MODES.ALLOW_ALL_BUT);
adminRole.addRule(ORule.ResourceGeneric.BYPASS_RESTRICTED, null, ORole.PERMISSION_ALL).save();
}
OUser adminUser = getUser(OUser.ADMIN);
if (adminUser == null) {
// This will return the global value if a local storage context configuration value does not exist.
boolean createDefUsers = getDatabase().getStorage().getConfiguration().getContextConfiguration().getValueAsBoolean(OGlobalConfiguration.CREATE_DEFAULT_USERS);
if (createDefUsers) {
adminUser = createUser(OUser.ADMIN, OUser.ADMIN, adminRole);
}
}
// SINCE 1.2.0
createOrUpdateORestrictedClass(database);
return adminUser;
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class OSequenceLibraryImpl method load.
@Override
public void load() {
sequences.clear();
final ODatabaseDocument db = ODatabaseRecordThreadLocal.INSTANCE.get();
if (((OMetadataInternal) db.getMetadata()).getImmutableSchemaSnapshot().existsClass(OSequence.CLASS_NAME)) {
final List<ODocument> result = db.query(new OSQLSynchQuery<ODocument>("SELECT FROM " + OSequence.CLASS_NAME));
for (ODocument document : result) {
document.reload();
final OSequence sequence = OSequenceHelper.createSequence(document);
if (sequence != null) {
sequences.put(sequence.getName().toUpperCase(), sequence);
}
}
}
}
use of com.orientechnologies.orient.core.db.document.ODatabaseDocument in project orientdb by orientechnologies.
the class OLiveQueryHook method addOp.
protected void addOp(ODocument iDocument, byte iType) {
if (Boolean.FALSE.equals(database.getConfiguration().getValue(OGlobalConfiguration.QUERY_LIVE_SUPPORT)))
return;
ODatabaseDocument db = database;
OLiveQueryOps ops = getOpsReference((ODatabaseInternal) db);
if (!ops.queueThread.hasListeners())
return;
if (db.getTransaction() == null || !db.getTransaction().isActive()) {
// TODO synchronize
ORecordOperation op = new ORecordOperation(iDocument.copy(), iType);
ops.queueThread.enqueue(op);
return;
}
ORecordOperation result = new ORecordOperation(iDocument, iType);
synchronized (ops.pendingOps) {
List<ORecordOperation> list = ops.pendingOps.get(db);
if (list == null) {
list = new ArrayList<ORecordOperation>();
ops.pendingOps.put(db, list);
}
list.add(result);
}
}
Aggregations