Search in sources :

Example 1 with OMetadataDefault

use of com.orientechnologies.orient.core.metadata.OMetadataDefault in project orientdb by orientechnologies.

the class ODatabaseDocumentTx method create.

/**
   * {@inheritDoc}
   */
@Override
public <DB extends ODatabase> DB create(String incrementalBackupPath) {
    create();
    final OStorage storage = getStorage();
    storage.restoreFromIncrementalBackup(incrementalBackupPath);
    metadata = new OMetadataDefault(this);
    metadata.load();
    return (DB) this;
}
Also used : OMetadataDefault(com.orientechnologies.orient.core.metadata.OMetadataDefault)

Example 2 with OMetadataDefault

use of com.orientechnologies.orient.core.metadata.OMetadataDefault in project orientdb by orientechnologies.

the class ODatabaseDocumentTx method create.

@Override
public <DB extends ODatabase> DB create(final Map<OGlobalConfiguration, Object> iInitialSettings) {
    setupThreadOwner();
    activateOnCurrentThread();
    try {
        if (status == STATUS.OPEN)
            throw new IllegalStateException("Database " + getName() + " is already open");
        if (storage == null)
            storage = Orient.instance().loadStorage(url);
        final OContextConfiguration ctxCfg = storage.getConfiguration().getContextConfiguration();
        if (iInitialSettings != null && !iInitialSettings.isEmpty()) {
            // SETUP INITIAL SETTINGS
            for (Map.Entry<OGlobalConfiguration, Object> e : iInitialSettings.entrySet()) {
                ctxCfg.setValue(e.getKey(), e.getValue());
            }
            storage.getConfiguration().update();
        }
        storage.create(properties);
        status = STATUS.OPEN;
        componentsFactory = getStorage().getComponentsFactory();
        localCache.startup();
        getStorage().getConfiguration().setRecordSerializer(getSerializer().toString());
        getStorage().getConfiguration().setRecordSerializerVersion(getSerializer().getCurrentVersion());
        // since 2.1 newly created databases use strict SQL validation by default
        getStorage().getConfiguration().setProperty(OStatement.CUSTOM_STRICT_SQL, "true");
        getStorage().getConfiguration().update();
        // THIS IF SHOULDN'T BE NEEDED, CREATE HAPPEN ONLY IN EMBEDDED
        if (!(getStorage() instanceof OStorageProxy))
            installHooksEmbedded();
        // CREATE THE DEFAULT SCHEMA WITH DEFAULT USER
        metadata = new OMetadataDefault(this);
        metadata.create();
        if (!(getStorage() instanceof OStorageProxy))
            registerHook(new OCommandCacheHook(this), ORecordHook.HOOK_POSITION.REGULAR);
        registerHook(new OSecurityTrackerHook(metadata.getSecurity(), this), ORecordHook.HOOK_POSITION.LAST);
        final OUser usr = getMetadata().getSecurity().getUser(OUser.ADMIN);
        if (usr == null)
            user = null;
        else
            user = new OImmutableUser(getMetadata().getSecurity().getVersion(), usr);
        // WAKE UP DB LIFECYCLE LISTENER
        for (Iterator<ODatabaseLifecycleListener> it = Orient.instance().getDbLifecycleListeners(); it.hasNext(); ) it.next().onCreate(getDatabaseOwner());
        // WAKE UP LISTENERS
        for (ODatabaseListener listener : browseListeners()) try {
            listener.onCreate(this);
        } catch (Throwable ignore) {
        }
    } catch (Exception e) {
        // REMOVE THE (PARTIAL) DATABASE
        try {
            drop();
        } catch (Exception ex) {
        // IGNORE IT
        }
        // DELETE THE STORAGE TOO
        try {
            if (storage == null)
                storage = Orient.instance().loadStorage(url);
            storage.delete();
        } catch (Exception ex) {
        // IGNORE IT
        }
        status = STATUS.CLOSED;
        owner.set(null);
        throw OException.wrapException(new ODatabaseException("Cannot create database '" + getName() + "'"), e);
    }
    return (DB) this;
}
Also used : OGlobalConfiguration(com.orientechnologies.orient.core.config.OGlobalConfiguration) OException(com.orientechnologies.common.exception.OException) ONeedRetryException(com.orientechnologies.common.concur.ONeedRetryException) OOfflineClusterException(com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException) IOException(java.io.IOException) OCommandCacheHook(com.orientechnologies.orient.core.cache.OCommandCacheHook) OMetadataDefault(com.orientechnologies.orient.core.metadata.OMetadataDefault) OContextConfiguration(com.orientechnologies.orient.core.config.OContextConfiguration)

Example 3 with OMetadataDefault

use of com.orientechnologies.orient.core.metadata.OMetadataDefault in project orientdb by orientechnologies.

the class ODatabaseDocumentTx method copy.

/**
   * Returns a copy of current database if it's open. The returned instance can be used by another thread without affecting current
   * instance. The database copy is not set in thread local.
   */
public ODatabaseDocumentTx copy() {
    ODatabaseDocumentInternal dbInThreadLocal = ODatabaseRecordThreadLocal.INSTANCE.getIfDefined();
    if (this.isClosed())
        throw new ODatabaseException("Cannot copy a closed db");
    final ODatabaseDocumentTx db = new ODatabaseDocumentTx(this.url);
    db.setupThreadOwner();
    db.user = this.user;
    db.properties.putAll(this.properties);
    db.serializer = this.serializer;
    db.componentsFactory = this.componentsFactory;
    db.metadata = new OMetadataDefault(db);
    db.initialized = true;
    if (storage instanceof OStorageProxy) {
        db.storage = ((OStorageProxy) storage).copy(this, db);
        ((OStorageProxy) db.storage).addUser();
    } else {
        db.storage = storage;
    }
    db.setStatus(STATUS.OPEN);
    db.metadata.load();
    if (!(db.getStorage() instanceof OStorageProxy))
        db.installHooksEmbedded();
    else
        db.installHooksRemote();
    db.initialized = true;
    if (dbInThreadLocal != null) {
        dbInThreadLocal.activateOnCurrentThread();
    } else {
        if (ODatabaseRecordThreadLocal.INSTANCE.isDefined()) {
            ODatabaseRecordThreadLocal.INSTANCE.remove();
        }
    }
    return db;
}
Also used : OMetadataDefault(com.orientechnologies.orient.core.metadata.OMetadataDefault)

Example 4 with OMetadataDefault

use of com.orientechnologies.orient.core.metadata.OMetadataDefault in project orientdb by orientechnologies.

the class ODatabaseDocumentTx method initAtFirstOpen.

private void initAtFirstOpen(String iUserName, String iUserPassword) {
    if (initialized)
        return;
    ORecordSerializerFactory serializerFactory = ORecordSerializerFactory.instance();
    String serializeName = getStorage().getConfiguration().getRecordSerializer();
    if (serializeName == null) {
        throw new ODatabaseException("Database created with orientdb version not supported anymore, use export+import to migrate the database");
    }
    serializer = serializerFactory.getFormat(serializeName);
    if (serializer == null)
        throw new ODatabaseException("RecordSerializer with name '" + serializeName + "' not found ");
    if (getStorage().getConfiguration().getRecordSerializerVersion() > serializer.getMinSupportedVersion())
        throw new ODatabaseException("Persistent record serializer version is not support by the current implementation");
    componentsFactory = getStorage().getComponentsFactory();
    localCache.startup();
    user = null;
    metadata = new OMetadataDefault(this);
    metadata.load();
    recordFormat = DEF_RECORD_FORMAT;
    if (!(getStorage() instanceof OStorageProxy)) {
        if (metadata.getIndexManager().autoRecreateIndexesAfterCrash()) {
            metadata.getIndexManager().recreateIndexes();
            activateOnCurrentThread();
            user = null;
        }
        installHooksEmbedded();
        registerHook(new OCommandCacheHook(this), ORecordHook.HOOK_POSITION.REGULAR);
        registerHook(new OSecurityTrackerHook(metadata.getSecurity(), this), ORecordHook.HOOK_POSITION.LAST);
        user = null;
    } else if (iUserName != null && iUserPassword != null) {
        user = new OImmutableUser(-1, new OUser(iUserName, OUser.encryptPassword(iUserPassword)).addRole(new ORole("passthrough", null, ORole.ALLOW_MODES.ALLOW_ALL_BUT)));
        installHooksRemote();
    }
    initialized = true;
}
Also used : ORecordSerializerFactory(com.orientechnologies.orient.core.serialization.serializer.record.ORecordSerializerFactory) OMetadataDefault(com.orientechnologies.orient.core.metadata.OMetadataDefault) OCommandCacheHook(com.orientechnologies.orient.core.cache.OCommandCacheHook)

Aggregations

OMetadataDefault (com.orientechnologies.orient.core.metadata.OMetadataDefault)4 OCommandCacheHook (com.orientechnologies.orient.core.cache.OCommandCacheHook)2 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)1 OException (com.orientechnologies.common.exception.OException)1 OContextConfiguration (com.orientechnologies.orient.core.config.OContextConfiguration)1 OGlobalConfiguration (com.orientechnologies.orient.core.config.OGlobalConfiguration)1 ORecordSerializerFactory (com.orientechnologies.orient.core.serialization.serializer.record.ORecordSerializerFactory)1 OOfflineClusterException (com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException)1 IOException (java.io.IOException)1