Search in sources :

Example 6 with OStorageProxy

use of com.orientechnologies.orient.core.storage.OStorageProxy in project orientdb by orientechnologies.

the class OSchemaShared method doCreateClass.

private OClass doCreateClass(final String className, final int clusters, final int retry, OClass... superClasses) {
    OClass result;
    final ODatabaseDocumentInternal db = getDatabase();
    final OStorage storage = db.getStorage();
    StringBuilder cmd = null;
    getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_CREATE);
    if (superClasses != null)
        OClassImpl.checkParametersConflict(Arrays.asList(superClasses));
    acquireSchemaWriteLock();
    try {
        final String key = className.toLowerCase();
        if (classes.containsKey(key) && retry == 0)
            throw new OSchemaException("Class '" + className + "' already exists in current database");
        cmd = new StringBuilder("create class ");
        // if (getDatabase().getStorage().getConfiguration().isStrictSql())
        // cmd.append('`');
        cmd.append(className);
        // if (getDatabase().getStorage().getConfiguration().isStrictSql())
        // cmd.append('`');
        List<OClass> superClassesList = new ArrayList<OClass>();
        if (superClasses != null && superClasses.length > 0) {
            boolean first = true;
            for (OClass superClass : superClasses) {
                // Filtering for null
                if (superClass != null) {
                    if (first)
                        cmd.append(" extends ");
                    else
                        cmd.append(", ");
                    cmd.append(superClass.getName());
                    first = false;
                    superClassesList.add(superClass);
                }
            }
        }
        if (clusters == 0)
            cmd.append(" abstract");
        else {
            cmd.append(" clusters ");
            cmd.append(clusters);
        }
        if (executeThroughDistributedStorage()) {
            final int[] clusterIds = createClusters(className, clusters);
            createClassInternal(className, clusterIds, superClassesList);
            final OAutoshardedStorage autoshardedStorage = (OAutoshardedStorage) storage;
            OCommandSQL commandSQL = new OCommandSQL(cmd.toString());
            commandSQL.addExcludedNode(autoshardedStorage.getNodeId());
            final Object res = db.command(commandSQL).execute();
        } else if (storage instanceof OStorageProxy) {
            db.command(new OCommandSQL(cmd.toString())).execute();
            reload();
        } else {
            final int[] clusterIds = createClusters(className, clusters);
            createClassInternal(className, clusterIds, superClassesList);
        }
        result = classes.get(className.toLowerCase());
        // WAKE UP DB LIFECYCLE LISTENER
        for (Iterator<ODatabaseLifecycleListener> it = Orient.instance().getDbLifecycleListeners(); it.hasNext(); ) it.next().onCreateClass(getDatabase(), result);
    } catch (ClusterIdsAreEmptyException e) {
        throw OException.wrapException(new OSchemaException("Cannot create class '" + className + "'"), e);
    } finally {
        releaseSchemaWriteLock();
    }
    return result;
}
Also used : OStorageProxy(com.orientechnologies.orient.core.storage.OStorageProxy) OStorage(com.orientechnologies.orient.core.storage.OStorage) OSchemaException(com.orientechnologies.orient.core.exception.OSchemaException) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OAutoshardedStorage(com.orientechnologies.orient.core.storage.OAutoshardedStorage) ODatabaseLifecycleListener(com.orientechnologies.orient.core.db.ODatabaseLifecycleListener)

Example 7 with OStorageProxy

use of com.orientechnologies.orient.core.storage.OStorageProxy in project orientdb by orientechnologies.

the class OSecurityShared method authenticate.

public OUser authenticate(final String iUserName, final String iUserPassword) {
    final String dbName = getDatabase().getName();
    final OUser user = getUser(iUserName);
    if (user == null)
        throw new OSecurityAccessException(dbName, "User or password not valid for database: '" + dbName + "'");
    if (user.getAccountStatus() != OSecurityUser.STATUSES.ACTIVE)
        throw new OSecurityAccessException(dbName, "User '" + iUserName + "' is not active");
    if (!(getDatabase().getStorage() instanceof OStorageProxy)) {
        // CHECK USER & PASSWORD
        if (!user.checkPassword(iUserPassword)) {
            // WAIT A BIT TO AVOID BRUTE FORCE
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
            }
            throw new OSecurityAccessException(dbName, "User or password not valid for database: '" + dbName + "'");
        }
    }
    return user;
}
Also used : OSecurityAccessException(com.orientechnologies.orient.core.exception.OSecurityAccessException) OStorageProxy(com.orientechnologies.orient.core.storage.OStorageProxy)

Example 8 with OStorageProxy

use of com.orientechnologies.orient.core.storage.OStorageProxy in project orientdb by orientechnologies.

the class OSBTreeRidBag method serialize.

@Override
public int serialize(byte[] stream, int offset, UUID ownerUuid) {
    for (Map.Entry<OIdentifiable, OModifiableInteger> entry : newEntries.entrySet()) {
        OIdentifiable identifiable = entry.getKey();
        assert identifiable instanceof ORecord;
        Change c = changes.get(identifiable);
        final int delta = entry.getValue().intValue();
        if (c == null)
            changes.put(identifiable, new DiffChange(delta));
        else
            c.applyDiff(delta);
    }
    newEntries.clear();
    final ORecordSerializationContext context;
    boolean remoteMode = ODatabaseRecordThreadLocal.INSTANCE.get().getStorage() instanceof OStorageProxy;
    if (remoteMode) {
        context = null;
    } else
        context = ORecordSerializationContext.getContext();
    // make sure that we really save underlying record.
    if (collectionPointer == null) {
        if (context != null) {
            final int clusterId = getHighLevelDocClusterId();
            assert clusterId > -1;
            collectionPointer = ODatabaseRecordThreadLocal.INSTANCE.get().getSbTreeCollectionManager().createSBTree(clusterId, ownerUuid);
        }
    }
    OBonsaiCollectionPointer collectionPointer;
    if (this.collectionPointer != null)
        collectionPointer = this.collectionPointer;
    else {
        collectionPointer = OBonsaiCollectionPointer.INVALID;
    }
    OLongSerializer.INSTANCE.serializeLiteral(collectionPointer.getFileId(), stream, offset);
    offset += OLongSerializer.LONG_SIZE;
    OBonsaiBucketPointer rootPointer = collectionPointer.getRootPointer();
    OLongSerializer.INSTANCE.serializeLiteral(rootPointer.getPageIndex(), stream, offset);
    offset += OLongSerializer.LONG_SIZE;
    OIntegerSerializer.INSTANCE.serializeLiteral(rootPointer.getPageOffset(), stream, offset);
    offset += OIntegerSerializer.INT_SIZE;
    // Keep this section for binary compatibility with versions older then 1.7.5
    OIntegerSerializer.INSTANCE.serializeLiteral(size, stream, offset);
    offset += OIntegerSerializer.INT_SIZE;
    if (context == null) {
        ChangeSerializationHelper.INSTANCE.serializeChanges(changes, OLinkSerializer.INSTANCE, stream, offset);
    } else {
        ODatabaseDocumentInternal db = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
        for (Entry<OIdentifiable, Change> change : this.changes.entrySet()) {
            OIdentifiable key = change.getKey();
            if (db != null && db.getTransaction().isActive()) {
                if (!key.getIdentity().isPersistent()) {
                    OIdentifiable newKey = db.getTransaction().getRecord(key.getIdentity());
                    if (newKey != null) {
                        changes.remove(key);
                        changes.put(newKey, change.getValue());
                    }
                }
            }
        }
        this.collectionPointer = collectionPointer;
        context.push(new ORidBagUpdateSerializationOperation(changes, collectionPointer));
        // 0-length serialized list of changes
        OIntegerSerializer.INSTANCE.serializeLiteral(0, stream, offset);
        offset += OIntegerSerializer.INT_SIZE;
    }
    return offset;
}
Also used : OStorageProxy(com.orientechnologies.orient.core.storage.OStorageProxy) OModifiableInteger(com.orientechnologies.common.types.OModifiableInteger) ORecordSerializationContext(com.orientechnologies.orient.core.storage.impl.local.paginated.ORecordSerializationContext) Change(com.orientechnologies.orient.core.db.record.ridbag.sbtree.OSBTreeRidBag.Change) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal) OBonsaiBucketPointer(com.orientechnologies.orient.core.index.sbtreebonsai.local.OBonsaiBucketPointer) ORidBagUpdateSerializationOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.ORidBagUpdateSerializationOperation) ORecord(com.orientechnologies.orient.core.record.ORecord) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Example 9 with OStorageProxy

use of com.orientechnologies.orient.core.storage.OStorageProxy in project orientdb by orientechnologies.

the class OPropertyImpl method setName.

public OProperty setName(final String name) {
    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 property %s name %s", getFullNameQuoted(), quoteString(name));
            database.command(new OCommandSQL(cmd)).execute();
        } else if (isDistributedCommand()) {
            final String cmd = String.format("alter property %s name %s", getFullNameQuoted(), quoteString(name));
            final OCommandSQL commandSQL = new OCommandSQL(cmd);
            commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
            database.command(commandSQL).execute();
            setNameInternal(name);
        } else
            setNameInternal(name);
    } finally {
        releaseSchemaWriteLock();
    }
    return this;
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OAutoshardedStorage(com.orientechnologies.orient.core.storage.OAutoshardedStorage) OStorageProxy(com.orientechnologies.orient.core.storage.OStorageProxy) OStorage(com.orientechnologies.orient.core.storage.OStorage) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Example 10 with OStorageProxy

use of com.orientechnologies.orient.core.storage.OStorageProxy in project orientdb by orientechnologies.

the class OPropertyImpl method setLinkedClass.

public OPropertyImpl setLinkedClass(final OClass linkedClass) {
    getDatabase().checkSecurity(ORule.ResourceGeneric.SCHEMA, ORole.PERMISSION_UPDATE);
    checkSupportLinkedClass(getType());
    acquireSchemaWriteLock();
    try {
        final ODatabaseDocumentInternal database = getDatabase();
        final OStorage storage = database.getStorage();
        if (storage instanceof OStorageProxy) {
            final String cmd = String.format("alter property %s linkedclass `%s`", getFullNameQuoted(), linkedClass);
            database.command(new OCommandSQL(cmd)).execute();
        } else if (isDistributedCommand()) {
            final String cmd = String.format("alter property %s linkedclass `%s`", getFullNameQuoted(), linkedClass);
            final OCommandSQL commandSQL = new OCommandSQL(cmd);
            commandSQL.addExcludedNode(((OAutoshardedStorage) storage).getNodeId());
            database.command(commandSQL).execute();
            setLinkedClassInternal(linkedClass);
        } else
            setLinkedClassInternal(linkedClass);
    } finally {
        releaseSchemaWriteLock();
    }
    return this;
}
Also used : OCommandSQL(com.orientechnologies.orient.core.sql.OCommandSQL) OAutoshardedStorage(com.orientechnologies.orient.core.storage.OAutoshardedStorage) OStorageProxy(com.orientechnologies.orient.core.storage.OStorageProxy) OStorage(com.orientechnologies.orient.core.storage.OStorage) ODatabaseDocumentInternal(com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)

Aggregations

OStorageProxy (com.orientechnologies.orient.core.storage.OStorageProxy)43 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)20 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)18 OAutoshardedStorage (com.orientechnologies.orient.core.storage.OAutoshardedStorage)18 OStorage (com.orientechnologies.orient.core.storage.OStorage)18 DatabaseAbstractTest (com.orientechnologies.DatabaseAbstractTest)9 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)9 OrientTest (com.orientechnologies.orient.test.database.base.OrientTest)9 Profile (com.orientechnologies.orient.test.domain.whiz.Profile)9 Test (org.testng.annotations.Test)9 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)7 OServerAdmin (com.orientechnologies.orient.client.remote.OServerAdmin)6 ORID (com.orientechnologies.orient.core.id.ORID)6 ODatabaseDocumentTx (com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx)4 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)4 OSchemaException (com.orientechnologies.orient.core.exception.OSchemaException)3 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)3 OSchema (com.orientechnologies.orient.core.metadata.schema.OSchema)3 ORecord (com.orientechnologies.orient.core.record.ORecord)3 ODatabaseLifecycleListener (com.orientechnologies.orient.core.db.ODatabaseLifecycleListener)2