Search in sources :

Example 86 with ODatabaseDocumentInternal

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;
}
Also used : ODatabaseDocumentTx(com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 87 with ODatabaseDocumentInternal

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;
}
Also used : ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 88 with ODatabaseDocumentInternal

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());
        }
    }
}
Also used : OClass(com.orientechnologies.orient.core.metadata.schema.OClass) OClassImpl(com.orientechnologies.orient.core.metadata.schema.OClassImpl) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 89 with ODatabaseDocumentInternal

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();
    }
}
Also used : ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) ORecordId(com.orientechnologies.orient.core.id.ORecordId)

Example 90 with ODatabaseDocumentInternal

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;
}
Also used : OSerializationException(com.orientechnologies.orient.core.exception.OSerializationException) ORID(com.orientechnologies.orient.core.id.ORID) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Aggregations

ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)139 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)42 OStorage (com.orientechnologies.orient.core.storage.OStorage)31 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)26 OStorageProxy (com.orientechnologies.orient.core.storage.OStorageProxy)20 OAutoshardedStorage (com.orientechnologies.orient.core.storage.OAutoshardedStorage)18 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)17 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)16 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)14 ORID (com.orientechnologies.orient.core.id.ORID)13 IOException (java.io.IOException)13 OException (com.orientechnologies.common.exception.OException)12 ORecordId (com.orientechnologies.orient.core.id.ORecordId)11 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)10 OSchemaException (com.orientechnologies.orient.core.exception.OSchemaException)10 ORecord (com.orientechnologies.orient.core.record.ORecord)7 OMetadataInternal (com.orientechnologies.orient.core.metadata.OMetadataInternal)6 OCommandRequestText (com.orientechnologies.orient.core.command.OCommandRequestText)5 ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)5 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)5