Search in sources :

Example 1 with OCommandCacheHook

use of com.orientechnologies.orient.core.cache.OCommandCacheHook 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 2 with OCommandCacheHook

use of com.orientechnologies.orient.core.cache.OCommandCacheHook 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

OCommandCacheHook (com.orientechnologies.orient.core.cache.OCommandCacheHook)2 OMetadataDefault (com.orientechnologies.orient.core.metadata.OMetadataDefault)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