Search in sources :

Example 1 with Context

use of org.apache.derby.iapi.services.context.Context in project derby by apache.

the class GenericLanguageConnectionContext method resetSavepoints.

/**
 * Reset all statement savepoints. Traverses the StatementContext
 * stack from bottom to top, calling resetSavePoint()
 * on each element.
 *
 * @exception StandardException thrown if something goes wrong
 */
private void resetSavepoints() throws StandardException {
    final ContextManager cm = getContextManager();
    final List<Context> stmts = cm.getContextStack(ContextId.LANG_STATEMENT);
    for (Context c : stmts) {
        ((StatementContext) c).resetSavePoint();
    }
}
Also used : StatementContext(org.apache.derby.iapi.sql.conn.StatementContext) CompilerContext(org.apache.derby.iapi.sql.compile.CompilerContext) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) Context(org.apache.derby.iapi.services.context.Context) SQLSessionContext(org.apache.derby.iapi.sql.conn.SQLSessionContext) TriggerExecutionContext(org.apache.derby.iapi.db.TriggerExecutionContext) ContextManager(org.apache.derby.iapi.services.context.ContextManager) StatementContext(org.apache.derby.iapi.sql.conn.StatementContext)

Example 2 with Context

use of org.apache.derby.iapi.services.context.Context in project derby by apache.

the class BaseMonitor method bootService.

/**
 *		Boot (start or create) a service (persistent or non-persistent).
 */
protected Object bootService(PersistentService provider, String factoryInterface, String serviceName, Properties properties, boolean create) throws StandardException {
    // after we got service name.(like in case of restoring from backup).
    if (provider != null)
        serviceName = provider.getCanonicalServiceName(serviceName);
    ProtocolKey serviceKey = ProtocolKey.create(factoryInterface, serviceName);
    if (SanityManager.DEBUG && reportOn) {
        report("Booting service " + serviceKey + " create = " + create);
    }
    ContextManager previousCM = contextService.getCurrentContextManager();
    ContextManager cm = previousCM;
    Object instance;
    TopService ts = null;
    Context sb = null;
    try {
        synchronized (this) {
            if (inShutdown) {
                throw StandardException.newException(SQLState.CLOUDSCAPE_SYSTEM_SHUTDOWN);
            }
            for (int i = 1; i < services.size(); i++) {
                TopService ts2 = services.get(i);
                if (ts2.isPotentialService(serviceKey)) {
                    // if the service already exists then  just return null
                    return null;
                }
            }
            Locale serviceLocale = null;
            if (create) {
                // always wrap the property set in an outer set.
                // this ensures that any random attributes from
                // a JDBC URL are not written into the service.properties
                // file (e.g. like user and password :-)
                properties = new Properties(properties);
                serviceLocale = setLocale(properties);
                properties.put(Property.SERVICE_PROTOCOL, factoryInterface);
                serviceName = provider.createServiceRoot(serviceName, Boolean.valueOf(properties.getProperty(Property.DELETE_ON_CREATE)).booleanValue());
                serviceKey = ProtocolKey.create(factoryInterface, serviceName);
            } else if (properties != null) {
                String serverLocaleDescription = properties.getProperty(Property.SERVICE_LOCALE);
                if (serverLocaleDescription != null)
                    serviceLocale = staticGetLocaleFromString(serverLocaleDescription);
            }
            ts = new TopService(this, serviceKey, provider, serviceLocale);
            services.add(ts);
        }
        if (SanityManager.DEBUG) {
            if (provider != null) {
                SanityManager.ASSERT(provider.getCanonicalServiceName(serviceName).equals(serviceName), "mismatched canonical names " + provider.getCanonicalServiceName(serviceName) + " != " + serviceName);
                SanityManager.ASSERT(serviceName.equals(serviceKey.getIdentifier()), "mismatched names " + serviceName + " != " + serviceKey.getIdentifier());
            }
        }
        if (properties != null) {
            // these properties must not be stored in the persistent properties,
            // otherwise moving databases from one directory to another
            // will not work. Thus they all have a fixed prefix
            // the root of the data
            properties.put(PersistentService.ROOT, serviceName);
            // the type of the service
            properties.put(PersistentService.TYPE, provider.getType());
        }
        if (SanityManager.DEBUG && reportOn) {
            dumpProperties("Service Properties: " + serviceKey.toString(), properties);
        }
        // push a new context manager
        if (previousCM == null) {
            cm = contextService.newContextManager();
            contextService.setCurrentContextManager(cm);
        }
        sb = new ServiceBootContext(cm);
        UpdateServiceProperties usProperties;
        Properties serviceProperties;
        // while doing restore from backup, we don't want service properties to be
        // updated until all the files are copied from backup.
        boolean inRestore = (properties != null ? properties.getProperty(Property.IN_RESTORE_FROM_BACKUP) != null : false);
        if ((provider != null) && (properties != null)) {
            // we need to track to see if the properties have
            // been updated or not. If the database is not created yet, we don't create the
            // services.properties file yet. We let the following if (create) statement do
            // that at the end of the database creation. After that, the changes in
            // services.properties file will be tracked by UpdateServiceProperties.
            usProperties = new UpdateServiceProperties(provider, serviceName, properties, !(create || inRestore));
            serviceProperties = usProperties;
        } else {
            usProperties = null;
            serviceProperties = properties;
        }
        instance = ts.bootModule(create, null, serviceKey, serviceProperties);
        // touch or remove any of the files there
        if (create) {
            provider.createDataWarningFile(usProperties.getStorageFactory());
        }
        if (create || inRestore) {
            // remove all the in-memory properties
            provider.saveServiceProperties(serviceName, usProperties.getStorageFactory(), BaseMonitor.removeRuntimeProperties(properties), false);
            usProperties.setServiceBooted();
        }
        if (cm != previousCM) {
            // Assume database is not active. DERBY-4856 thread dump
            cm.cleanupOnError(StandardException.closeException(), false);
        }
    } catch (Throwable t) {
        StandardException se;
        // ensure that the severity will shutdown the service
        if ((t instanceof StandardException) && (((StandardException) t).getSeverity() == ExceptionSeverity.DATABASE_SEVERITY))
            se = (StandardException) t;
        else
            se = Monitor.exceptionStartingModule(t);
        if (cm != previousCM) {
            // Assume database is not active. DERBY-4856 thread dump
            cm.cleanupOnError(se, false);
        }
        if (ts != null) {
            ts.shutdown();
            synchronized (this) {
                services.remove(ts);
            }
            // Service root will only have been created if
            // ts is non-null.
            boolean deleteOnError = (properties != null ? properties.getProperty(Property.DELETE_ROOT_ON_ERROR) != null : false);
            if (create || deleteOnError)
                provider.removeServiceRoot(serviceName);
        }
        Throwable nested = se.getCause();
        // never hide ThreadDeath
        if (nested instanceof ThreadDeath)
            throw (ThreadDeath) nested;
        throw se;
    } finally {
        if ((previousCM == cm) && (sb != null))
            sb.popMe();
        if (previousCM == null)
            contextService.resetCurrentContextManager(cm);
    }
    // from this point onwards the service is open for business
    ts.setTopModule(instance);
    // 
    // The following yield allows our background threads to
    // execute their run methods. This is needed due to
    // bug 4081540 on Solaris. When the bug is fixed we can
    // remove this yield.
    Thread.yield();
    return instance;
}
Also used : Context(org.apache.derby.iapi.services.context.Context) Locale(java.util.Locale) Properties(java.util.Properties) StandardException(org.apache.derby.shared.common.error.StandardException) ContextManager(org.apache.derby.iapi.services.context.ContextManager)

Aggregations

Context (org.apache.derby.iapi.services.context.Context)2 ContextManager (org.apache.derby.iapi.services.context.ContextManager)2 Locale (java.util.Locale)1 Properties (java.util.Properties)1 TriggerExecutionContext (org.apache.derby.iapi.db.TriggerExecutionContext)1 CompilerContext (org.apache.derby.iapi.sql.compile.CompilerContext)1 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)1 SQLSessionContext (org.apache.derby.iapi.sql.conn.SQLSessionContext)1 StatementContext (org.apache.derby.iapi.sql.conn.StatementContext)1 StandardException (org.apache.derby.shared.common.error.StandardException)1