Search in sources :

Example 1 with ODatabaseDocument

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

Example 2 with ODatabaseDocument

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

Example 3 with ODatabaseDocument

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

Example 4 with ODatabaseDocument

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);
            }
        }
    }
}
Also used : ODatabaseDocument(com.orientechnologies.orient.core.db.document.ODatabaseDocument) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 5 with ODatabaseDocument

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

Aggregations

ODatabaseDocument (com.orientechnologies.orient.core.db.document.ODatabaseDocument)187 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)81 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)68 Test (org.testng.annotations.Test)53 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)47 ORecordId (com.orientechnologies.orient.core.id.ORecordId)23 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)17 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)16 ORecord (com.orientechnologies.orient.core.record.ORecord)14 Test (org.junit.Test)14 OCommandRequestText (com.orientechnologies.orient.core.command.OCommandRequestText)12 ORID (com.orientechnologies.orient.core.id.ORID)11 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)10 ODatabaseException (com.orientechnologies.orient.core.exception.ODatabaseException)9 OValidationException (com.orientechnologies.orient.core.exception.OValidationException)9 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)9 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)9 ArrayList (java.util.ArrayList)9 OMetadataInternal (com.orientechnologies.orient.core.metadata.OMetadataInternal)8 HashSet (java.util.HashSet)8