Package org.apache.derby.iapi.services.context

Examples of org.apache.derby.iapi.services.context.ContextManager


    //REMIND: someone is leaving an incorrect manager on when they
    // are exiting the system in the nested case.
    if (SanityManager.DEBUG)
    {
      if (tr.getCsf() != null) {
        ContextManager cm1 = tr.getCsf().getCurrentContextManager();
        ContextManager cm2 = tr.getContextManager();
        // If the system has been shut down, cm1 can be null.
        // Otherwise, cm1 and cm2 should be identical.
        Util.ASSERT(this, (cm1 == cm2 || cm1 == null),
          "Current Context Manager not the one was expected: " +
           cm1 + " " + cm2);
View Full Code Here


        ts = (TopService) services.get(position);
      }

      // push a new context manager
      ContextManager cm = contextService.newContextManager();
      try {
        // pop the default shutdown context, we are shutting down
        cm.popContext();

        contextService.setCurrentContextManager(cm);


        shutdown(ts.getService());
View Full Code Here

    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 = (TopService) 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);

      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) {
View Full Code Here

  /**
    Get the locale from the ContextManager and then find the bundle
    based upon that locale.
  */
  public ResourceBundle getBundle(String messageId) {
    ContextManager cm;
    try {
      cm = ContextService.getFactory().getCurrentContextManager();
    } catch (ShutdownException se) {
      cm = null;
    }

    if (cm != null) {
      return MessageService.getBundleForLocale(cm.getMessageLocale(), messageId);
    }
    return null;
  }
View Full Code Here

     *
     * @exception StandardException thrown if something goes wrong
     */
    private void resetSavepoints() throws StandardException
    {
        final ContextManager cm = getContextManager();
        final List stmts = cm.getContextStack(org.apache.derby.
                                              iapi.reference.
                                              ContextId.LANG_STATEMENT);
        final int end = stmts.size();
        for (int i = 0; i < end; ++i) {
            ((StatementContext)stmts.get(i)).resetSavePoint();
View Full Code Here

        XAXactId xid_im = new XAXactId(xid);
        XATransactionState tranState = getTransactionState(xid_im);
       
        if (tranState == null) {
            XAResourceManager rm = ra.getXAResourceManager();
            ContextManager inDoubtCM = rm.find(xid);
            // RM also does not know about this xid.
            if (inDoubtCM == null)
                throw new XAException(XAException.XAER_NOTA);
            ContextService csf = ContextService.getFactory();
            csf.setCurrentContextManager(inDoubtCM);
            try {
                rm.commit(inDoubtCM, xid_im, onePhase);
               
                // close the connection/transaction since it can never
                // be used again. DERBY-4856 No extended diagnostic information needed.
                inDoubtCM.cleanupOnError(StandardException.closeException(),
                        false);
                return;
            } catch (StandardException se) {
                // The rm threw an exception, clean it up in the approprate
                // context.  There is no transactionResource to handle the
                // exception for us.
                inDoubtCM.cleanupOnError(se, con.isActive());
                throw wrapInXAException(se);
            } finally {
                csf.resetCurrentContextManager(inDoubtCM);
            }
           
View Full Code Here

        XATransactionState tranState = getTransactionState(xid_im);
       
        if (tranState == null) {
            XAResourceManager rm = ra.getXAResourceManager();
           
            ContextManager inDoubtCM = rm.find(xid);
           
            // RM also does not know about this xid.
            if (inDoubtCM == null)
                throw new XAException(XAException.XAER_NOTA);
           
View Full Code Here

       
        XATransactionState tranState = getTransactionState(xid_im);
        if (tranState == null) {
            XAResourceManager rm = ra.getXAResourceManager();
           
            ContextManager inDoubtCM = rm.find(xid);
           
            // RM also does not know about this xid.
            if (inDoubtCM == null)
                throw new XAException(XAException.XAER_NOTA);
           
            ContextService csf = ContextService.getFactory();
           
            csf.setCurrentContextManager(inDoubtCM);
            try {
                rm.forget(inDoubtCM, xid_im);
               
                // close the connection/transaction since it can never be used again.
                inDoubtCM.cleanupOnError(StandardException.closeException(),
                        false);
                return;
            } catch (StandardException se) {
                // The rm threw an exception, clean it up in the approprate
                // context.  There is no transactionResource to handle the
                // exception for us.
                inDoubtCM.cleanupOnError(se, con.isActive());
                throw wrapInXAException(se);
            } finally {
                csf.resetCurrentContextManager(inDoubtCM);
            }
           
View Full Code Here

        XATransactionState tranState = getTransactionState(xid_im);
       
        if (tranState == null) {
            XAResourceManager rm = ra.getXAResourceManager();
           
            ContextManager inDoubtCM = rm.find(xid);
           
            // RM also does not know about this xid.
            if (inDoubtCM == null)
                throw new XAException(XAException.XAER_NOTA);
           
            ContextService csf = ContextService.getFactory();
           
            csf.setCurrentContextManager(inDoubtCM);
            try {
                rm.rollback(inDoubtCM, xid_im);
               
                // close the connection/transaction since it can never be used again.
                inDoubtCM.cleanupOnError(StandardException.closeException(),
                        false);
                return;
            } catch (StandardException se) {
                // The rm threw an exception, clean it up in the approprate
                // context.  There is no transactionResource to handle the
                // exception for us.
                inDoubtCM.cleanupOnError(se, con.isActive());
                throw wrapInXAException(se);
            } finally {
                csf.resetCurrentContextManager(inDoubtCM);
            }
           
View Full Code Here

    /*
    ** The current connection is the one in the current
    ** connection context, so get the context.
    */
    ContextManager  cm = getCurrentContextManager();

    ConnectionContext localCC = null;

    /*
      cm is null the very first time, and whenever
      we aren't actually nested.
     */
    if (cm != null) {
      localCC = (ConnectionContext)
        (cm.getContext(ConnectionContext.CONTEXT_ID));
    }

    return localCC;
  }
View Full Code Here

TOP

Related Classes of org.apache.derby.iapi.services.context.ContextManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.