Search in sources :

Example 1 with OContextConfiguration

use of com.orientechnologies.orient.core.config.OContextConfiguration 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 (OStorageExistsException e) {
        status = STATUS.CLOSED;
        owner.set(null);
        throw OException.wrapException(new ODatabaseException("Cannot create database '" + getName() + "'"), e);
    } 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 OContextConfiguration

use of com.orientechnologies.orient.core.config.OContextConfiguration in project orientdb by orientechnologies.

the class OPaginatedCluster method configure.

@Override
public void configure(final OStorage storage, final int id, final String clusterName, final Object... parameters) throws IOException {
    startOperation();
    try {
        acquireExclusiveLock();
        try {
            final OContextConfiguration ctxCfg = storage.getConfiguration().getContextConfiguration();
            final String cfgCompression = ctxCfg.getValueAsString(OGlobalConfiguration.STORAGE_COMPRESSION_METHOD);
            final String cfgEncryption = ctxCfg.getValueAsString(OGlobalConfiguration.STORAGE_ENCRYPTION_METHOD);
            final String cfgEncryptionKey = ctxCfg.getValueAsString(OGlobalConfiguration.STORAGE_ENCRYPTION_KEY);
            config = new OStoragePaginatedClusterConfiguration(storage.getConfiguration(), id, clusterName, null, true, OStoragePaginatedClusterConfiguration.DEFAULT_GROW_FACTOR, OStoragePaginatedClusterConfiguration.DEFAULT_GROW_FACTOR, cfgCompression, cfgEncryption, cfgEncryptionKey, null, OStorageClusterConfiguration.STATUS.ONLINE);
            config.name = clusterName;
            init((OAbstractPaginatedStorage) storage, config);
        } finally {
            releaseExclusiveLock();
        }
    } finally {
        completeOperation();
    }
}
Also used : OContextConfiguration(com.orientechnologies.orient.core.config.OContextConfiguration) OStoragePaginatedClusterConfiguration(com.orientechnologies.orient.core.config.OStoragePaginatedClusterConfiguration)

Example 3 with OContextConfiguration

use of com.orientechnologies.orient.core.config.OContextConfiguration in project orientdb by orientechnologies.

the class OServerNetworkListener method readParameters.

/**
 * Initializes connection parameters by the reading XML configuration. If not specified, get the parameters defined as global
 * configuration.
 *
 * @param iServerConfig
 */
private void readParameters(final OContextConfiguration iServerConfig, final OServerParameterConfiguration[] iParameters) {
    configuration = new OContextConfiguration(iServerConfig);
    // SET PARAMETERS
    if (iParameters != null && iParameters.length > 0) {
        // CONVERT PARAMETERS IN MAP TO INTIALIZE THE CONTEXT-CONFIGURATION
        for (OServerParameterConfiguration param : iParameters) configuration.setValue(param.name, param.value);
    }
    socketBufferSize = configuration.getValueAsInteger(OGlobalConfiguration.NETWORK_SOCKET_BUFFER_SIZE);
}
Also used : OServerParameterConfiguration(com.orientechnologies.orient.server.config.OServerParameterConfiguration) OContextConfiguration(com.orientechnologies.orient.core.config.OContextConfiguration)

Example 4 with OContextConfiguration

use of com.orientechnologies.orient.core.config.OContextConfiguration in project orientdb by orientechnologies.

the class OServer method initFromConfiguration.

protected void initFromConfiguration() {
    final OServerConfiguration cfg = serverCfg.getConfiguration();
    // FILL THE CONTEXT CONFIGURATION WITH SERVER'S PARAMETERS
    contextConfiguration = new OContextConfiguration();
    if (cfg.properties != null)
        for (OServerEntryConfiguration prop : cfg.properties) contextConfiguration.setValue(prop.name, prop.value);
    hookManager = new OConfigurableHooksManager(cfg);
}
Also used : OContextConfiguration(com.orientechnologies.orient.core.config.OContextConfiguration) OConfigurableHooksManager(com.orientechnologies.orient.server.handler.OConfigurableHooksManager)

Aggregations

OContextConfiguration (com.orientechnologies.orient.core.config.OContextConfiguration)4 ONeedRetryException (com.orientechnologies.common.concur.ONeedRetryException)1 OException (com.orientechnologies.common.exception.OException)1 OCommandCacheHook (com.orientechnologies.orient.core.cache.OCommandCacheHook)1 OGlobalConfiguration (com.orientechnologies.orient.core.config.OGlobalConfiguration)1 OStoragePaginatedClusterConfiguration (com.orientechnologies.orient.core.config.OStoragePaginatedClusterConfiguration)1 OMetadataDefault (com.orientechnologies.orient.core.metadata.OMetadataDefault)1 OOfflineClusterException (com.orientechnologies.orient.core.storage.impl.local.paginated.OOfflineClusterException)1 OServerParameterConfiguration (com.orientechnologies.orient.server.config.OServerParameterConfiguration)1 OConfigurableHooksManager (com.orientechnologies.orient.server.handler.OConfigurableHooksManager)1 IOException (java.io.IOException)1