use of com.orientechnologies.orient.core.db.ODatabaseDocumentInternal in project orientdb by orientechnologies.
the class OGremlinHelper method getGraphDatabase.
public static ODatabaseDocumentTx getGraphDatabase(final ODatabaseDocumentInternal iCurrentDatabase) {
ODatabaseDocumentInternal currentDb = ODatabaseRecordThreadLocal.INSTANCE.get();
if (currentDb == null && iCurrentDatabase != null)
// GET FROM THE RECORD
currentDb = iCurrentDatabase;
if (currentDb != null)
currentDb = (ODatabaseDocumentInternal) currentDb.getDatabaseOwner();
final ODatabaseDocumentTx db;
if (currentDb instanceof ODatabaseDocumentTx)
db = (ODatabaseDocumentTx) currentDb;
else
throw new OCommandExecutionException("Cannot find a database of type ODatabaseDocumentTx or ODatabaseDocumentTx");
return db;
}
use of com.orientechnologies.orient.core.db.ODatabaseDocumentInternal in project orientdb by orientechnologies.
the class OIndexManagerShared method dropIndex.
public OIndexManager dropIndex(final String iIndexName) {
if (getDatabase().getTransaction().isActive())
throw new IllegalStateException("Cannot drop an index inside a transaction");
int[] clusterIdsToIndex = null;
acquireExclusiveLock();
try {
final Locale locale = getServerLocale();
final OIndex<?> idx = indexes.remove(iIndexName.toLowerCase(locale));
if (idx != null) {
final Set<String> clusters = idx.getClusters();
if (clusters != null && !clusters.isEmpty()) {
final ODatabaseDocumentInternal db = getDatabase();
clusterIdsToIndex = new int[clusters.size()];
int i = 0;
for (String cl : clusters) {
clusterIdsToIndex[i++] = db.getClusterIdByName(cl);
}
}
removeClassPropertyIndex(idx);
idx.delete();
setDirty();
save();
notifyInvolvedClasses(clusterIdsToIndex);
}
} finally {
releaseExclusiveLock();
}
return this;
}
use of com.orientechnologies.orient.core.db.ODatabaseDocumentInternal 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.db.ODatabaseDocumentInternal in project orientdb by orientechnologies.
the class OIndexManagerShared method recreateIndexes.
@Override
public void recreateIndexes() {
final ODatabaseDocumentInternal db;
acquireExclusiveLock();
try {
if (recreateIndexesThread != null && recreateIndexesThread.isAlive())
// BUILDING ALREADY IN PROGRESS
return;
db = getDatabase();
document = db.load(new ORecordId(db.getStorage().getConfiguration().indexMgrRecordId));
final Runnable recreateIndexesTask = new RecreateIndexesTask(db.getURL());
recreateIndexesThread = new Thread(recreateIndexesTask, "OrientDB rebuild indexes");
recreateIndexesThread.start();
} finally {
releaseExclusiveLock();
}
if (OGlobalConfiguration.INDEX_SYNCHRONOUS_AUTO_REBUILD.getValueAsBoolean()) {
waitTillIndexRestore();
db.getMetadata().reload();
}
}
use of com.orientechnologies.orient.core.db.ODatabaseDocumentInternal in project orientdb by orientechnologies.
the class OEmbeddedRidBag method serialize.
@Override
public int serialize(byte[] stream, int offset, UUID ownerUuid) {
OIntegerSerializer.INSTANCE.serializeLiteral(size, stream, offset);
offset += OIntegerSerializer.INT_SIZE;
ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
final int totEntries = entries.length;
for (int i = 0; i < totEntries; ++i) {
final Object entry = entries[i];
if (entry instanceof OIdentifiable) {
OIdentifiable link = (OIdentifiable) entry;
final ORID rid = link.getIdentity();
if (db != null && db.getTransaction().isActive()) {
if (!link.getIdentity().isPersistent()) {
link = db.getTransaction().getRecord(link.getIdentity());
entries[i] = link;
}
}
if (link == null)
throw new OSerializationException("Found null entry in ridbag with rid=" + rid);
OLinkSerializer.INSTANCE.serialize(link, stream, offset);
offset += OLinkSerializer.RID_SIZE;
}
}
return offset;
}
Aggregations