Opens this connection resource and enlisted this resource in the
transaction.

@throws EFapsException if the resource is already opened or this
resource could not be enlisted
195188
protected void open()
        throws EFapsException
    {
        AbstractResource.LOG.debug("open resource:{}", this);
        if (this.opened) {
            AbstractResource.LOG.error("resource already opened");
            throw new EFapsException(AbstractResource.class, "open.AlreadyOpened");
        }
        try {
            final Context context = Context.getThreadContext();
            context.getTransaction().enlistResource(this);
        } catch (final RollbackException e) {
            AbstractResource.LOG.error("exception occurs while delisting in transaction, " + "commit not possible", e);
            throw new EFapsException(AbstractResource.class, "open.RollbackException", e);
        } catch (final SystemException e) {
            AbstractResource.LOG.error("exception occurs while delisting in transaction, " + "commit not possible", e);
            throw new EFapsException(AbstractResource.class, "open.SystemException", e);
        }
        this.opened = true;
    }
405504
public static void initialize()
        throws EFapsException
    {
        Quartz.QUARTZ = new Quartz();
        try {
            //Kernel-Configuration
            final SystemConfiguration config = EFapsSystemConfiguration.get();
            final Properties props = config.getAttributeValueAsProperties(KernelSettings.QUARTZPROPS);

            final StdSchedulerFactory schedFact = new StdSchedulerFactory();
            javax.naming.Context envCtx = null;
            String lookup = "java:global/";
            try {
                final InitialContext initCtx = new InitialContext();
                envCtx = (javax.naming.Context) initCtx.lookup(lookup);
            } catch (final NamingException e) {
                Quartz.LOG.info("Catched NamingException on evaluation for Quartz");
            }
            // for a build the context might be different, try this before surrender
            if (envCtx == null) {
                try {
                    lookup = "java:comp/env";
                    final InitialContext initCtx = new InitialContext();
                    envCtx = (javax.naming.Context) initCtx.lookup(lookup);
                } catch (final NamingException e) {
                    Quartz.LOG.info("Catched NamingException on evaluation for Quartz");
                }
            }
            try {
                final DelegatingUserTransaction trans = (DelegatingUserTransaction) envCtx
                                .lookup(INamingBinds.RESOURCE_USERTRANSACTION);
                // QuartzTrigger
                trans.setUserName(Person.get(UUID.fromString("df2f02a7-c556-49ad-b019-e13db66e1cbf")).getName());
            } catch (final NamingException e) {
                Quartz.LOG.info("Catched NamingException on evaluation for Quartz");
            }

            props.put(StdSchedulerFactory.PROP_SCHED_USER_TX_URL, lookup + "/" + INamingBinds.RESOURCE_USERTRANSACTION);
            props.put(StdSchedulerFactory.PROP_SCHED_WRAP_JOB_IN_USER_TX, "true");
            props.put(StdSchedulerFactory.PROP_THREAD_POOL_CLASS, "org.quartz.simpl.SimpleThreadPool");
            props.put(StdSchedulerFactory.PROP_SCHED_JOB_FACTORY_CLASS, SimpleJobFactory.class.getName());
            props.put("org.quartz.plugin.jobInitializer.class", "org.efaps.admin.common.QuartzSchedulerPlugin");

            if (!props.containsKey(StdSchedulerFactory.PROP_SCHED_MAKE_SCHEDULER_THREAD_DAEMON)) {
                props.put(StdSchedulerFactory.PROP_SCHED_MAKE_SCHEDULER_THREAD_DAEMON, "true");
            }
            if (!props.containsKey(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME)) {
                props.put(StdSchedulerFactory.PROP_SCHED_INSTANCE_NAME, "eFapsScheduler");
            }
            if (!props.containsKey("org.quartz.threadPool.threadCount")) {
                props.put("org.quartz.threadPool.threadCount", "2");
            }

            if (!props.containsKey("org.quartz.plugin.triggHistory.class")) {
                props.put("org.quartz.plugin.triggHistory.class",
                                "org.quartz.plugins.history.LoggingTriggerHistoryPlugin");
                props.put("org.quartz.plugin.triggHistory.triggerFiredMessage",
                            "Trigger {1}.{0} fired job {6}.{5} at: {4, date, HH:mm:ss MM/dd/yyyy}");
                props.put("org.quartz.plugin.triggHistory.triggerCompleteMessage",
                            "Trigger {1}.{0} completed firing job {6}.{5} at {4, date, HH:mm:ss MM/dd/yyyy}.");
            }
            Quartz.LOG.info("Sheduling Quartz with properties {}", props);

            schedFact.initialize(props);
            Quartz.QUARTZ.scheduler = schedFact.getScheduler("eFapsScheduler");
            if (Quartz.QUARTZ.scheduler != null) {
                Quartz.QUARTZ.scheduler.shutdown();
            }
            Quartz.QUARTZ.scheduler =  schedFact.getScheduler();

            if (config.getAttributeValueAsBoolean(KernelSettings.MSGTRIGGERACTIVE)) {
                final int interval = config.getAttributeValueAsInteger(KernelSettings.MSGTRIGGERINTERVAL);
                final Trigger trigger = TriggerBuilder.newTrigger()
                                .withIdentity("SystemMessageTrigger")
                                .withSchedule(SimpleScheduleBuilder.repeatMinutelyForever(interval > 0 ? interval : 1))
                                .build();

                JobDetail jobDetail = Quartz.QUARTZ.scheduler.getJobDetail(new JobKey("SystemMessage",
                                Quartz.QUARTZGROUP));
                if (jobDetail == null) {
                    jobDetail = JobBuilder.newJob(MessageStatusHolder.class)
                                    .withIdentity("SystemMessage", Quartz.QUARTZGROUP).build();
                    Quartz.QUARTZ.scheduler.scheduleJob(jobDetail, trigger);
                } else {
                    Quartz.QUARTZ.scheduler.rescheduleJob(new TriggerKey("SystemMessageTrigger", Quartz.QUARTZGROUP),
                                    trigger);
                }
            }
            Quartz.QUARTZ.scheduler.start();
        } catch (final SchedulerException e) {
            throw new EFapsException(Quartz.class, "Quartz.SchedulerException", e);
        }
    }
421126
@Override
    public synchronized void beginTransaction() throws DatabaseEngineRuntimeException {
        /*
         * It makes sense trying to reconnect since it's the beginning of a transaction.
         */
        try {
            getConnection();
            if (!conn.getAutoCommit()) { //I.E. Manual control
                logger.debug("There's already one transaction active");
                return;
            }

            conn.setAutoCommit(false);
        } catch (final Exception ex) {
            throw new DatabaseEngineRuntimeException("Error occurred while starting transaction", ex);
        }
    }
667476
@Override
    public void enlist() throws ResourceException {

        final boolean isTracingEnabled = TraceComponent.isAnyTracingEnabled();

        if (isTracingEnabled && tc.isEntryEnabled())
            Tr.entry(this, tc, "enlist", mcWrapper.getUOWCoordinator());

        if (this.hasRollbackOccured) {
            ResourceException x = new ResourceException("Attempt to continue working after transaction rolledback !");
            if (isTracingEnabled && tc.isEntryEnabled())
                Tr.exit(tc, "enlist", "It is NOT valid to continue working under a transaction that has already rolledback");
            throw x;
        }
        if (enlisted == true) {

            if (isTracingEnabled && tc.isEntryEnabled()) {
                Tr.exit(this, tc, "enlist", "already enlisted");
            }

            return; // Already enlisted, no-op.

        }

        try {
            int branchCoupling = mcWrapper.getCm().getResourceRefInfo().getBranchCoupling();
            int startFlag = XAResource.TMNOFLAGS;
            if (branchCoupling != ResourceRefInfo.BRANCH_COUPLING_UNSET) {
                startFlag = mcWrapper.getCm().supportsBranchCoupling(branchCoupling, mcWrapper.get_managedConnectionFactory());
                if (startFlag == -1)
                    throw new ResourceException("Branch coupling attribute not implemented for this resource");
            }
            int recoveryToken = mcWrapper.getRecoveryToken();
            EmbeddableWebSphereTransactionManager tranMgr = mcWrapper.pm.connectorSvc.transactionManager;
            if (tranMgr.enlist(mcWrapper.getUOWCoordinator(), this, recoveryToken, startFlag) != true) {
                Tr.error(tc, "BAD_RETURN_VALUE_FROM_ENLIST_J2CA0087", this, mcWrapper.gConfigProps.cfName);
                ResourceException x = new ResourceException("Error on enlist");
                if (isTracingEnabled && tc.isEntryEnabled())
                    Tr.exit(this, tc, "enlist", x);
                throw x;
            }
        } catch (ResourceException e) {
            com.ibm.ws.ffdc.FFDCFilter.processException(
                                                        e,
                                                        "com.ibm.ejs.j2c.XATransactionWrapper.enlist",
                                                        "535",
                                                        this);

            Tr.error(tc, "ENLIST_RESOURCE_EXCP_J2CA0030", "enlist", e, "ResourceException", mcWrapper.gConfigProps.cfName);

            mcWrapper.markTransactionError();
            try {
                EmbeddableWebSphereTransactionManager tranMgr = mcWrapper.pm.connectorSvc.transactionManager;
                tranMgr.getTransaction().setRollbackOnly();
            } catch (Exception ex) {

                com.ibm.ws.ffdc.FFDCFilter.processException(ex, "com.ibm.ejs.j2c.XATransactionWrapper.enlist",
                                                            "630", this);
                if (isTracingEnabled && tc.isEventEnabled()) {
                    Tr.event(this, tc, "Caught Exception while trying to mark transaction RollbackOnly - Exception:" + ex);
                }

            }

            if (isTracingEnabled && tc.isEntryEnabled())
                Tr.exit(this, tc, "enlist", e);
            throw e;
        } catch (Exception e) {

            com.ibm.ws.ffdc.FFDCFilter.processException(
                                                        e,
                                                        "com.ibm.ejs.j2c.XATransactionWrapper.enlist",
                                                        "546",
                                                        this);

            String pmiName = null;
            if (mcWrapper != null) {
                pmiName = mcWrapper.gConfigProps.cfName;
            }
            Object[] parms = new Object[] { "enlist", e, "ResourceException", pmiName };
            Tr.error(tc, "ENLIST_RESOURCE_EXCP_J2CA0030", parms);

            mcWrapper.markTransactionError();
            try {
                EmbeddableWebSphereTransactionManager tranMgr = mcWrapper.pm.connectorSvc.transactionManager;
                tranMgr.getTransaction().setRollbackOnly();
            } catch (Exception ex) {
                com.ibm.ws.ffdc.FFDCFilter.processException(ex, "com.ibm.ejs.j2c.XATransactionWrapper.enlist",
                                                            "663", this);
                if (isTracingEnabled && tc.isEventEnabled()) {
                    Tr.event(this, tc, "Caught Exception while trying to mark transaction RollbackOnly - Exception:" + ex);
                }

            }

            ResourceException re = new ResourceException("enlist: caught Exception");
            re.initCause(e);
            if (isTracingEnabled && tc.isEntryEnabled())
                Tr.exit(this, tc, "enlist", e);
            throw re;

        }

        enlisted = true;

        if (isTracingEnabled && tc.isEntryEnabled())
            Tr.exit(this, tc, "enlist");
    }
594835
@SuppressWarnings("unchecked")
   private ManagedConnection open(Subject s) throws ResourceException
   {
      log.debugf("Open managed connection (%s)", s);

      if (recoverMC == null)
         recoverMC = mcf.createManagedConnection(s, null);

      if (plugin == null)
      {
         try
         {
            ValidatingManagedConnectionFactory vmcf = (ValidatingManagedConnectionFactory)mcf;

            Set connectionSet = new HashSet(1);
            connectionSet.add(recoverMC);

            Set invalid = vmcf.getInvalidConnections(connectionSet);

            if (invalid != null && !invalid.isEmpty())
            {
               log.debugf("Invalid managed connection: %s", recoverMC);

               close(recoverMC);
               recoverMC = mcf.createManagedConnection(s, null);
            }
         }
         catch (ResourceException re)
         {
            log.debugf("Exception during invalid check", re);

            close(recoverMC);
            recoverMC = mcf.createManagedConnection(s, null);
         }
      }

      return recoverMC;
   }
580200
public void execute(final OutputStream _out)
        throws EFapsException
    {
        final boolean hasAccess = super.getInstance().getType().hasAccess(super.getInstance(),
                                                                          AccessTypeEnums.CHECKOUT.getAccessType());
        if (!hasAccess) {
            throw new EFapsException(this.getClass(), "execute.NoAccess");
        }
        this.executeWithoutAccessCheck(_out);
    }
1226255
public void beginTransaction() throws SQLException {
		final Connection conn = getConnection();
		checkTransactionSupported(conn);
		conn.setAutoCommit(false);
	}
1128230
public void begin() throws ResourceException {
        if (tc.isEntryEnabled())
            Tr.entry(this, tc, "begin", ivMC);

        // if the MC marked Stale, it means the user requested a purge pool with an immediate option
        // so don't allow any work on the mc
        if (ivMC._mcStale) {
            if (tc.isDebugEnabled())
                Tr.debug(this, tc, "MC is stale");
            throw new DataStoreAdapterException("INVALID_CONNECTION", AdapterUtil.staleX(), WSRdbSpiLocalTransactionImpl.class);
        }

        if (dsConfig.get().enableMultithreadedAccessDetection) 
            ivMC.detectMultithreadedAccess(); 

        if (!ivMC.isTransactional()) { // do nothing if no enlistment
            if (tc.isEntryEnabled())
                Tr.exit(this, tc, "begin", "no-op.  Enlistment disabled");
            return;
        }

        if (tc.isDebugEnabled()) {
            String cId = null;
            try {
                cId = ivMC.mcf.getCorrelator(ivMC); 
            } catch (SQLException x) {
                // will just log the exception here and ignore it since its in trace
                Tr.debug(
                         tc,
                         "got an exception trying to get the correlator, exception is: ",
                         x);
            }

            if (cId != null) {
                StringBuffer stbuf = new StringBuffer(200);
                stbuf.append("Correlator: DB2, ID: ");
                stbuf.append(cId);
                stbuf.append(" Transaction : ");
                stbuf.append(this);
                stbuf.append(" BEGIN");

                Tr.debug(this, tc, stbuf.toString());
            }
        }

        ResourceException re;

        // Remove synchronization. 

        re = ivStateManager.isValid(WSStateManager.LT_BEGIN);

        if (re == null) {
            //Note the MC handles all notification of connection error event and such on setAutoCommit
            // also, it sets it only when necessary

            try {
                if (ivMC.getAutoCommit())
                    ivMC.setAutoCommit(false);
            } catch (SQLException sqle) {
                FFDCFilter.processException(
                                            sqle,
                                            currClass.getName() + ".begin",
                                            "126",
                                            this);

                throw new DataStoreAdapterException(
                                "DSA_ERROR",
                                sqle,
                                currClass);
            }

            //Note this exception is not caught - This is because
            //  1)  it is of type ResourceException so it can be thrown from the method
            //  2)  if isValid is okay, this should never fail.  If isValid is not okay
            //     an exception is thrown from there
            // We already validated the state in this sync block, so just set it. 
            ivStateManager.transtate = WSStateManager.LOCAL_TRANSACTION_ACTIVE;
        } else 
        {
            // state change was not valid         

            LocalTransactionException local_tran_excep =
                            new LocalTransactionException(re.getMessage());

            DataStoreAdapterException dsae = new DataStoreAdapterException(
                                            "WS_INTERNAL_ERROR",
                                            local_tran_excep,
                                            currClass,
                                            "Cannot start SPI local transaction.",
                                            "",
                                            local_tran_excep.getMessage());

            // Use FFDC to log the possible components list. 
            FFDCFilter.processException(
                                        dsae,
                                        "com.ibm.ws.rsadapter.spi.WSRdbSpiLocalTransactionImpl.begin",
                                        "127",
                                        this,
                                        new Object[] { "Possible components: WebSphere J2C Implementation" });
            if (tc.isEntryEnabled())
                Tr.exit(this, tc, "begin", "Exception"); 
            throw dsae;
        }

        if (tc.isEventEnabled())
            Tr.event(
                     tc,
                     "SpiLocalTransaction started.  ManagedConnection state is "
                                     + ivMC.getTransactionStateAsString());

        if (tc.isEntryEnabled())
            Tr.exit(this, tc, "begin");
    }
893383
public static void initialize()
        throws EFapsException
    {
        try {
            final SystemConfiguration config = EFapsSystemConfiguration.get();
            if (config != null) {
                final int timeout = config.getAttributeValueAsInteger(KernelSettings.JMS_TIMEOOUT);
                if (timeout > 0) {
                    JmsSession.setSessionTimeout(timeout);
                }
            }

            //JMS-Configuration
            final SystemConfiguration configJms = SystemConfiguration.get(
                            UUID.fromString("65b6a1a8-c979-4471-b175-774593f1acd7"));
            final boolean active = configJms != null && configJms.getAttributeValueAsBoolean(JmsHandler.ACTIVEJMS);

            if (active) {
            // this check is necessary for first install and update
                if (CIAdminCommon.JmsAbstract.getType() != null) {
                    // remove any existing
                    JmsHandler.stop();
                    final Context ctx = new InitialContext();
                    final QueryBuilder queryBldr = new QueryBuilder(CIAdminCommon.JmsAbstract);
                    final MultiPrintQuery multi = queryBldr.getPrint();
                    multi.addAttribute(CIAdminCommon.JmsAbstract.Type,
                                    CIAdminCommon.JmsAbstract.Name,
                                    CIAdminCommon.JmsAbstract.ConnectionFactoryJNDI,
                                    CIAdminCommon.JmsAbstract.DestinationJNDI);
                    final SelectBuilder sel = new SelectBuilder().linkto(CIAdminCommon.JmsAbstract.ESJPLink)
                                    .file().label();
                    multi.addSelect(sel);
                    if (multi.executeWithoutAccessCheck()) {
                        //TODO add scanning
                    }
                    while (multi.next()) {
                        final Type type = multi.<Type>getAttribute(CIAdminCommon.JmsAbstract.Type);
                        final String connectionFactoryJNDI = multi
                                        .<String>getAttribute(CIAdminCommon.JmsAbstract.ConnectionFactoryJNDI);
                        final String destinationJNDI = multi
                                        .<String>getAttribute(CIAdminCommon.JmsAbstract.DestinationJNDI);
                        final String name = multi.<String>getAttribute(CIAdminCommon.JmsAbstract.Name);
                        final String esjp = multi.<String>getSelect(sel);

                        final Session session;
                        if (type.isKindOf(CIAdminCommon.JmsQueueAbstract.getType())) {
                            final QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) ctx
                                            .lookup(connectionFactoryJNDI);
                            final QueueConnection queueConnection;
                            if (JmsHandler.QUEUE2QUECONN.containsKey(connectionFactoryJNDI)) {
                                queueConnection = JmsHandler.QUEUE2QUECONN.get(connectionFactoryJNDI);
                            } else {
                                queueConnection = queueConnectionFactory.createQueueConnection();
                            }
                            JmsHandler.QUEUE2QUECONN.put(connectionFactoryJNDI, queueConnection);
                            session = queueConnection.createQueueSession(false,
                                            Session.AUTO_ACKNOWLEDGE);
                            queueConnection.start();
                        } else {
                            final TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) ctx
                                            .lookup(connectionFactoryJNDI);
                            final TopicConnection topicConn;
                            if (JmsHandler.TOPIC2QUECONN.containsKey(connectionFactoryJNDI)) {
                                topicConn = JmsHandler.TOPIC2QUECONN.get(connectionFactoryJNDI);
                            } else {
                                topicConn = topicConnectionFactory.createTopicConnection();
                            }
                            JmsHandler.TOPIC2QUECONN.put(connectionFactoryJNDI, topicConn);
                            if (type.isKindOf(CIAdminCommon.JmsTopicDurableConsumer.getType())) {
                                topicConn.setClientID(org.efaps.db.Context.getThreadContext().getPath() + ":" + name);
                            }
                            session = topicConn.createTopicSession(true, Session.AUTO_ACKNOWLEDGE);
                            topicConn.start();
                        }
                        final Destination dest = (Destination) ctx.lookup(destinationJNDI);

                        if (type.isKindOf(CIAdminCommon.JmsQueueProducer.getType())
                                        || type.isKindOf(CIAdminCommon.JmsTopicProducer.getType())) {
                            final MessageProducer producer;
                            if (type.isKindOf(CIAdminCommon.JmsQueueProducer.getType())) {
                                producer = session.createProducer(dest);
                            } else {
                                producer = ((TopicSession) session).createPublisher((Topic) dest);
                            }
                            producer.setDeliveryMode(DeliveryMode.PERSISTENT);
                            JmsHandler.NAME2DEF.put(name, new JmsDefinition(name, producer, session));
                        } else {
                            final MessageConsumer consumer;
                            if (type.isKindOf(CIAdminCommon.JmsQueueConsumer.getType())) {
                                consumer = session.createConsumer(dest);
                            } else if (type.isKindOf(CIAdminCommon.JmsTopicDurableConsumer.getType())) {
                                consumer = session.createDurableSubscriber((Topic) dest, name);
                            } else {
                                consumer = ((TopicSession) session).createSubscriber((Topic) dest);
                            }
                            @SuppressWarnings("unchecked")
                            final Class<? extends MessageListener> clazz = (Class<? extends MessageListener>) Class
                                            .forName(esjp.trim(), false, EFapsClassLoader.getInstance());
                            final MessageListener myListener = clazz.newInstance();
                            consumer.setMessageListener(myListener);
                        }

                    }
                }
            }
        } catch (final NamingException e) {
            // this means that a definition cannot be found.
            JmsHandler.LOG.warn("Naming exception for JMS", e);
        } catch (final JMSException e) {
            // this means normally that e.g. no jms server was found
            JmsHandler.LOG.error("JMS not working!!!!!!!", e);
        } catch (final ClassNotFoundException e) {
            throw new EFapsException("ClassNotFoundException", e);
        } catch (final InstantiationException e) {
            throw new EFapsException("InstantiationException", e);
        } catch (final IllegalAccessException e) {
            throw new EFapsException("IllegalAccessException", e);
        }
    }
733359
private void beginTransaction() {

		if (currentTransaction == null) {

			try {
				currentTransaction = StructrApp.getInstance(securityContext).tx(true, false, false);

			} catch (FrameworkException fex) {

				// transaction can fail here (theoretically...)
				logger.warn("Unable to begin transaction.", fex);
			}
		}
	}
887531
final void activate() throws SQLException {
      for(ConnectionPoolConnection conn : connections) {
         conn.forceRealClose();
         conn.realOpen();
         conn.logicalClose(true); //Tests the connection
      }

      if(closeQueue != null) {
         closeQueue.clear();
      }

      availableQueue.clear();
      reopenExecutor.getQueue().clear();

      List<ConnectionPoolConnection> connections = Lists.newArrayListWithCapacity(this.connections.length);
      for(ConnectionPoolConnection connection : this.connections) {
         connections.add(connection);
         connection.state.set(ConnectionPoolConnection.STATE_AVAILABLE);
      }

      isActive = true;
      stats.activate();
      availableQueue.addAll(connections);
   }
148538
public function beginTransaction()
    {
        if ($this->isTransactionEnabled() === false) {
            throw new ServiceException(sprintf(
                'The repository for %s doesn\'t support Transactions',
                $this->getEntityServiceName()
            ));
        }

        $this->getRepository()->beginTransaction();
    }
820858
public synchronized void open() throws SFException, SnowflakeSQLException
  {
    performSanityCheckOnProperties();

    Boolean insecureMode = (Boolean) connectionPropertiesMap.get(
        SFSessionProperty.INSECURE_MODE);

    HttpUtil.configureCustomProxyProperties(connectionPropertiesMap);

    HttpUtil.initHttpClient(insecureMode != null ? insecureMode : false, null);

    logger.debug(
        "input: server={}, account={}, user={}, password={}, role={}, " +
        "database={}, schema={}, warehouse={}, authenticator={}, insecure_mode={}, " +
        "passcode_in_passward={}, passcode={}, private_key={}, " +
        "use_proxy={}, proxy_host={}, proxy_port={}, proxy_user={}, proxy_password={}, disable_socks_proxy={}, " +
        "application={}, app_id={}, app_version={}, " +
        "login_timeout={}, network_timeout={}, query_timeout={}, tracing={}",
        connectionPropertiesMap.get(SFSessionProperty.SERVER_URL),
        connectionPropertiesMap.get(SFSessionProperty.ACCOUNT),
        connectionPropertiesMap.get(SFSessionProperty.USER),
        !Strings.isNullOrEmpty((String) connectionPropertiesMap.get(SFSessionProperty.PASSWORD)) ? "***" : "(empty)",
        connectionPropertiesMap.get(SFSessionProperty.ROLE),
        connectionPropertiesMap.get(SFSessionProperty.DATABASE),
        connectionPropertiesMap.get(SFSessionProperty.SCHEMA),
        connectionPropertiesMap.get(SFSessionProperty.WAREHOUSE),
        connectionPropertiesMap.get(SFSessionProperty.AUTHENTICATOR),

        connectionPropertiesMap.get(SFSessionProperty.INSECURE_MODE),
        connectionPropertiesMap.get(SFSessionProperty.PASSCODE_IN_PASSWORD),
        !Strings.isNullOrEmpty((String) connectionPropertiesMap.get(SFSessionProperty.PASSCODE)) ? "***" : "(empty)",

        connectionPropertiesMap.get(SFSessionProperty.PRIVATE_KEY) != null ? "(not null)" : "(null)",

        connectionPropertiesMap.get(SFSessionProperty.USE_PROXY),
        connectionPropertiesMap.get(SFSessionProperty.PROXY_HOST),
        connectionPropertiesMap.get(SFSessionProperty.PROXY_PORT),
        connectionPropertiesMap.get(SFSessionProperty.PROXY_USER),
        !Strings.isNullOrEmpty((String) connectionPropertiesMap.get(SFSessionProperty.PROXY_PASSWORD)) ? "***" :
        "(empty)",
        connectionPropertiesMap.get(SFSessionProperty.DISABLE_SOCKS_PROXY),

        connectionPropertiesMap.get(SFSessionProperty.APPLICATION),
        connectionPropertiesMap.get(SFSessionProperty.APP_ID),
        connectionPropertiesMap.get(SFSessionProperty.APP_VERSION),

        connectionPropertiesMap.get(SFSessionProperty.LOGIN_TIMEOUT),
        connectionPropertiesMap.get(SFSessionProperty.NETWORK_TIMEOUT),
        connectionPropertiesMap.get(SFSessionProperty.QUERY_TIMEOUT),
        connectionPropertiesMap.get(SFSessionProperty.TRACING)
    );
    SessionUtil.LoginInput loginInput = new SessionUtil.LoginInput();
    loginInput.setServerUrl(
        (String) connectionPropertiesMap.get(SFSessionProperty.SERVER_URL))
        .setDatabaseName(
            (String) connectionPropertiesMap.get(SFSessionProperty.DATABASE))
        .setSchemaName(
            (String) connectionPropertiesMap.get(SFSessionProperty.SCHEMA))
        .setWarehouse(
            (String) connectionPropertiesMap.get(SFSessionProperty.WAREHOUSE))
        .setRole((String) connectionPropertiesMap.get(SFSessionProperty.ROLE))
        .setAuthenticator(
            (String) connectionPropertiesMap.get(SFSessionProperty.AUTHENTICATOR))
        .setAccountName(
            (String) connectionPropertiesMap.get(SFSessionProperty.ACCOUNT))
        .setLoginTimeout(loginTimeout)
        .setUserName(
            (String) connectionPropertiesMap.get(SFSessionProperty.USER))
        .setPassword(
            (String) connectionPropertiesMap.get(SFSessionProperty.PASSWORD))
        .setToken(
            (String) connectionPropertiesMap.get(SFSessionProperty.TOKEN))
        .setIdToken(
            (String) connectionPropertiesMap.get(SFSessionProperty.ID_TOKEN))
        .setClientInfo(this.getClientInfo())
        .setPasscodeInPassword(passcodeInPassword)
        .setPasscode(
            (String) connectionPropertiesMap.get(SFSessionProperty.PASSCODE))
        .setConnectionTimeout(httpClientConnectionTimeout)
        .setSocketTimeout(httpClientSocketTimeout)
        .setAppId((String) connectionPropertiesMap.get(SFSessionProperty.APP_ID))
        .setAppVersion(
            (String) connectionPropertiesMap.get(SFSessionProperty.APP_VERSION))
        .setSessionParameters(sessionParametersMap)
        .setPrivateKey((PrivateKey) connectionPropertiesMap.get(
            SFSessionProperty.PRIVATE_KEY))
        .setApplication((String) connectionPropertiesMap.get(
            SFSessionProperty.APPLICATION))
        .setServiceName(this.getServiceName());

    SessionUtil.LoginOutput loginOutput = SessionUtil.openSession(loginInput);
    isClosed = false;

    if (loginOutput.isUpdatedByTokenRequest())
    {
      setCurrentObjects(loginInput, loginOutput);
    }

    sessionToken = loginOutput.getSessionToken();
    masterToken = loginOutput.getMasterToken();
    idToken = loginOutput.getIdToken();
    databaseVersion = loginOutput.getDatabaseVersion();
    databaseMajorVersion = loginOutput.getDatabaseMajorVersion();
    databaseMinorVersion = loginOutput.getDatabaseMinorVersion();
    httpClientSocketTimeout = loginOutput.getHttpClientSocketTimeout();
    masterTokenValidityInSeconds = loginOutput.getMasterTokenValidityInSeconds();
    database = loginOutput.getSessionDatabase();
    schema = loginOutput.getSessionSchema();
    role = loginOutput.getSessionRole();
    warehouse = loginOutput.getSessionWarehouse();

    // Update common parameter values for this session
    SessionUtil.updateSfDriverParamValues(loginOutput.getCommonParams(), this);

    String loginDatabaseName = (String) connectionPropertiesMap.get(
        SFSessionProperty.DATABASE);
    String loginSchemaName = (String) connectionPropertiesMap.get(
        SFSessionProperty.SCHEMA);
    String loginRole = (String) connectionPropertiesMap.get(
        SFSessionProperty.ROLE);
    String loginWarehouse = (String) connectionPropertiesMap.get(
        SFSessionProperty.WAREHOUSE);

    if (loginDatabaseName != null && !loginDatabaseName
        .equalsIgnoreCase(database))
    {
      sqlWarnings.add(new SFException(ErrorCode
                                          .CONNECTION_ESTABLISHED_WITH_DIFFERENT_PROP,
                                      "Database", loginDatabaseName, database));
    }

    if (loginSchemaName != null && !loginSchemaName
        .equalsIgnoreCase(schema))
    {
      sqlWarnings.add(new SFException(ErrorCode.
                                          CONNECTION_ESTABLISHED_WITH_DIFFERENT_PROP,
                                      "Schema", loginSchemaName, schema));
    }

    if (loginRole != null && !loginRole
        .equalsIgnoreCase(role))
    {
      sqlWarnings.add(new SFException(ErrorCode.
                                          CONNECTION_ESTABLISHED_WITH_DIFFERENT_PROP,
                                      "Role", loginRole, role));
    }

    if (loginWarehouse != null && !loginWarehouse
        .equalsIgnoreCase(warehouse))
    {
      sqlWarnings.add(new SFException(ErrorCode.
                                          CONNECTION_ESTABLISHED_WITH_DIFFERENT_PROP,
                                      "Warehouse", loginWarehouse, warehouse));
    }

    // start heartbeat for this session so that the master token will not expire
    startHeartbeatForThisSession();
  }
287169
@Override
    public void enlist() throws ResourceException {

        if (tc.isEntryEnabled()) {
            Tr.entry(this, tc, "enlist", mcWrapper.getUOWCoordinator());
        }

        if (this.hasRollbackOccured) {
            if (tc.isEntryEnabled())
                Tr.exit(this, tc, "enlist", "It is NOT valid to continue working under a transaction that has already rolledback");
            throw new ResourceException("Attempt to continue working after transaction rolledback !");
        }
        if (enlisted == true) {

            if (tc.isEntryEnabled()) {
                Tr.exit(this, tc, "enlist", "already enlisted");
            }
            return; // Already enlisted, no-op.

        } // end enlisted == true

        UOWCoordinator uowCoord = mcWrapper.getUOWCoordinator();
        if (uowCoord != null) {
            if (uowCoord.isGlobal()) {
                // Global Transaction
                EmbeddableWebSphereTransactionManager tranMgr = mcWrapper.pm.connectorSvc.transactionManager;
                try {
                    if (_rrsTransactional) {
                        int branchCoupling = mcWrapper.getCm().getResourceRefInfo().getBranchCoupling();
                        int startFlag = XAResource.TMNOFLAGS;
                        if (branchCoupling != ResourceRefInfo.BRANCH_COUPLING_UNSET) {
                            startFlag = mcWrapper.getCm().supportsBranchCoupling(branchCoupling, mcWrapper.get_managedConnectionFactory());
                            if (startFlag == -1)
                                throw new ResourceException("Branch coupling attribute not implemented for this resource");
                        }

                        mcWrapper.enlistRRSXAResource(mcWrapper.getRecoveryToken(), startFlag);
                    }

                    // Use the following enlist call since this is a One Phase resource.
                    boolean rc = false;
                    rc = tranMgr.enlistOnePhase(uowCoord, this);
                    if (rc != true) {
                        Tr.error(tc, "BAD_RETURN_VALUE_FROM_ENLIST_J2CA0087", this, mcWrapper.gConfigProps.cfName);
                        ResourceException x = new ResourceException("Error on enlistOnePhase");
                        if (tc.isEntryEnabled())
                            Tr.exit(this, tc, "enlist", x);
                        throw x;
                    }
                    mcWrapper.markLocalTransactionWrapperInUse();
                    enlisted = true;
                } catch (ResourceException e) {
                    com.ibm.ws.ffdc.FFDCFilter.processException(
                                                                e,
                                                                "com.ibm.ejs.j2c.LocalTransactionWrapper.enlist",
                                                                "344",
                                                                this);
                    Tr.error(tc, "ENLIST_RESOURCE_EXCP_J2CA0030", "enlist", e, "Exception", mcWrapper.gConfigProps.cfName);

                    // Error recovery from enlist has been moved here.  The transaction team has
                    //  asked us to setRollbackOnly() for all the failed enlist() calls.  Doing
                    //  this causes them (for release 5.0. They may change it next release) to
                    //  flow the rollback sequence to all the other resources in the tran.  This
                    //  connection failed to enlist and so won't be called to roll back.  This
                    //  connection is, however registered for afterCompletion calls which they will
                    //  also drive.  Its important that we mark this connection stale prior to
                    //  calling setRollbackOnly() because our afterCompletion code will return it
                    //  to the freePool if we don't.  We want the connection destroyed since it
                    //  is potentially corrupt.
                    mcWrapper.markTransactionError();
                    try {
                        tranMgr.getTransaction().setRollbackOnly();
                    } catch (Exception ex) {
                        com.ibm.ws.ffdc.FFDCFilter.processException(ex, "com.ibm.ejs.j2c.LocalTransactionWrapper.enlist",
                                                                    "445", this);
                        if (tc.isEventEnabled()) {
                            Tr.event(this, tc,
                                     "Caught Exception while trying to mark transaction RollbackOnly - Exception:"
                                               + ex);
                        }
                    }

                    if (tc.isEntryEnabled())
                        Tr.exit(this, tc, "enlist", e);
                    throw e;
                } catch (Exception e) {
                    com.ibm.ws.ffdc.FFDCFilter.processException(
                                                                e,
                                                                "com.ibm.ejs.j2c.LocalTransactionWrapper.enlist",
                                                                "459",
                                                                this,
                                                                new Object[] { mcWrapper }); //LI3162-5
                    Tr.error(tc, "ENLIST_RESOURCE_EXCP_J2CA0030", "enlist", e, "Exception", mcWrapper.gConfigProps.cfName);

                    // Error recovery from enlist has been moved here.  The transaction team has
                    //  asked us to setRollbackOnly() for all the failed enlist() calls.  Doing
                    //  this causes them (for release 5.0. They may change it next release) to
                    //  flow the rollback sequence to all the other resources in the tran.  This
                    //  connection failed to enlist and so won't be called to roll back.  This
                    //  connection is, however registered for afterCompletion calls which they will
                    //  also drive.  Its important that we mark this connection stale prior to
                    //  calling setRollbackOnly() because our afterCompletion code will return it
                    //  to the freePool if we don't.  We want the connection destroyed since it
                    //  is potentially corrupt.
                    mcWrapper.markTransactionError();
                    try {
                        tranMgr.getTransaction().setRollbackOnly();
                    } catch (Exception ex) {
                        com.ibm.ws.ffdc.FFDCFilter.processException(ex, "com.ibm.ejs.j2c.LocalTransactionWrapper.enlist",
                                                                    "477", this);
                        if (tc.isEventEnabled()) {
                            Tr.event(this, tc,
                                     "Caught Exception while trying to mark transaction RollbackOnly - Exception:"
                                               + ex);
                        }
                    }

                    ResourceException re = new ResourceException("enlist: caught Exception");
                    re.initCause(e);
                    if (tc.isEntryEnabled())
                        Tr.exit(this, tc, "enlist", re);
                    throw re;
                }
                if (tc.isEntryEnabled()) {
                    Tr.exit(this, tc, "enlist");
                }
                return;
            } // end Global Transaction
            else {
                // Local Transaction
                try {
                    if (_rrsTransactional) {
                        int dummyInt = -1;
                        rrsXAResource = mcWrapper.enlistRRSXAResource(dummyInt, dummyInt);
                    }

                    // If the resolution is CONTAINER_AT_BOUNDARY then do a straight enlist.
                    // The transaction service will manage begin/end of this transaction.
                    if (((LocalTransactionCoordinator) uowCoord).isContainerResolved()) {
                        ((LocalTransactionCoordinator) uowCoord).enlist(this);
                    } else {
                        // If resolution is NOT CONTAINER_AT_BOUNDARY, we assume it is APPLICATION,
                        //  (which is the only other choice and also the default) then do an
                        //  enistForCleanup.  Here the application is expected to commit/rollback
                        //  the local transaction.  If it does, we will get an event in our
                        //  connectionEventListener and it will drive delist() on this object,
                        //  which in turn will call delistFromCleanup. If the user doesn't
                        //  commit/rollback the transaction service will clean things up.
                        ((LocalTransactionCoordinator) uowCoord).enlistForCleanup(this);
                    }
                    mcWrapper.markLocalTransactionWrapperInUse();
                    enlisted = true;
                } catch (Exception e) {
                    com.ibm.ws.ffdc.FFDCFilter.processException(
                                                                e,
                                                                "com.ibm.ejs.j2c.LocalTransactionWrapper.enlist",
                                                                "405",
                                                                this);
                    mcWrapper.markTransactionError();
                    mcWrapper.releaseToPoolManager();
                    Tr.error(tc, "ENLIST_RESOURCE_EXCP_J2CA0030", "enlist", e, "Exception", mcWrapper.gConfigProps.cfName);
                    ResourceException re = new ResourceException("enlist: caught Exception");
                    re.initCause(e);
                    if (tc.isEntryEnabled())
                        Tr.exit(this, tc, "enlist", e);
                    throw re;
                }
                if (tc.isEntryEnabled()) {
                    Tr.exit(this, tc, "enlist", "Local Tran");
                }
                return;
            } // end Local Transaction
        } else {
            // No transaction context.  Should never happen.
            Tr.error(tc, "NO_VALID_TRANSACTION_CONTEXT_J2CA0040", "enlist", null, mcWrapper.gConfigProps.cfName);
            ResourceException x = new ResourceException("INTERNAL ERROR: No valid transaction context present");
            if (tc.isEntryEnabled())
                Tr.exit(this, tc, "enlist", x);
            throw x;
        }

    }
408353
public function open()
    {
        if (is_resource($this->stream)) {
            throw new ResourceException(
                'The temporary file is already open.'
            );
        }

        $this->stream = fopen($this->lock_filename, 'w+b');
    }
534910
public void open() throws IOException {
        mConnection.connect();
        mContentType = mConnection.getContentType();
        mResponseCode = mConnection.getResponseCode();
        mContentEncoding = mConnection.getContentEncoding();
    }
1278086
public Instance execute()
        throws EFapsException
    {
        this.update = new Insert((IInsertStatement) getEQLStmt());
        StmtRunner.get().execute(this.update);
        return this.update.getInstance();
    }