/*
(non-Javadoc)

@see org.finra.jtaf.ewd.session.SessionFactory
421741
@Override
    public ExtWebDriver createNewSession(Map<String, String> options, WebDriver wd) {
        DefaultExtWebDriver selenium = new DefaultExtWebDriver();
        selenium.setWrappedDriver(wd);

        // Get client properties file
        ClientProperties properties = new ClientProperties(options);

        // Set client properties (specific to our factory/implementation)
        selenium.setClientProperties(properties);

        // Set timeout value
        selenium.setMaxRequestTimeout(properties.getMaxRequestTimeoutString());

        // Highlighting
                selenium.setHighlightColors(properties.getHighlightColorMap());
                selenium.setIsHighlight(properties.isHighlight());

        return selenium;
    }
80994
public static SqlSession getSession() throws IOException {
		SqlSession session = (SqlSession) THREAD_SESSION.get();  
	    try {  
	        if (session == null) {  
	        	session = getSessionFactory().getSession();
	        	THREAD_SESSION.set(session);  
	        }  
	    } catch (Exception e) {  
	        throw new IOException(e);  
	    }  
	    return session;  
	}
743599
public void session(String name, Object value){
        RequestContext.getHttpRequest().getSession().getAttribute(name);
    }
894665
@Override
    public SessionFactory buildSessionFactory() throws HibernateException {

        // set the class loader to load Groovy classes

        // work around for HHH-2624
        SessionFactory sessionFactory;

        Object classLoaderObject = getProperties().get(AvailableSettings.CLASSLOADERS);
        ClassLoader appClassLoader;

        if(classLoaderObject instanceof ClassLoader) {
            appClassLoader = (ClassLoader) classLoaderObject;
        }
        else {
            appClassLoader = getClass().getClassLoader();
        }

        ConfigurationHelper.resolvePlaceHolders(getProperties());

        final GrailsDomainBinder domainBinder = new GrailsDomainBinder(
                dataSourceName,
                sessionFactoryBeanName,
                hibernateMappingContext
        );

        List<Class> annotatedClasses = new ArrayList<>();
        for (PersistentEntity persistentEntity : hibernateMappingContext.getPersistentEntities()) {
            Class javaClass = persistentEntity.getJavaClass();
            if(javaClass.isAnnotationPresent(Entity.class)) {
                annotatedClasses.add(javaClass);
            }
        }

        if(!additionalClasses.isEmpty()) {
            for (Class additionalClass : additionalClasses) {
                if(GormEntity.class.isAssignableFrom(additionalClass)) {
                    hibernateMappingContext.addPersistentEntity(additionalClass);
                }
            }
        }

        addAnnotatedClasses( annotatedClasses.toArray(new Class[annotatedClasses.size()]));

        ClassLoaderService classLoaderService = new ClassLoaderServiceImpl(appClassLoader) {
            @Override
            public <S> Collection<S> loadJavaServices(Class<S> serviceContract) {
                if(MetadataContributor.class.isAssignableFrom(serviceContract)) {
                    if(metadataContributor != null) {
                        return (Collection<S>) Arrays.asList(domainBinder, metadataContributor);
                    }
                    else {
                        return Collections.singletonList((S) domainBinder);
                    }
                }
                else {
                    return super.loadJavaServices(serviceContract);
                }
            }
        };
        EventListenerIntegrator eventListenerIntegrator = new EventListenerIntegrator(hibernateEventListeners, eventListeners);
        BootstrapServiceRegistry bootstrapServiceRegistry = createBootstrapServiceRegistryBuilder()
                                                                    .applyIntegrator(eventListenerIntegrator)
                                                                    .applyIntegrator(new MetadataIntegrator())
                                                                    .applyClassLoaderService(classLoaderService)
                                                                    .build();
        StrategySelector strategySelector = bootstrapServiceRegistry.getService(StrategySelector.class);

        strategySelector.registerStrategyImplementor(
                PropertyAccessStrategy.class, "traitProperty", TraitPropertyAccessStrategy.class
        );

        setSessionFactoryObserver(new SessionFactoryObserver() {
            private static final long serialVersionUID = 1;
            public void sessionFactoryCreated(SessionFactory factory) {}
            public void sessionFactoryClosed(SessionFactory factory) {
                if (serviceRegistry != null) {
                    ((ServiceRegistryImplementor)serviceRegistry).destroy();
                }
            }
        });

        StandardServiceRegistryBuilder standardServiceRegistryBuilder = createStandardServiceRegistryBuilder(bootstrapServiceRegistry)
                                                                                    .applySettings(getProperties());

        StandardServiceRegistry serviceRegistry = standardServiceRegistryBuilder.build();
        sessionFactory = super.buildSessionFactory(serviceRegistry);
        this.serviceRegistry = serviceRegistry;

        return sessionFactory;
    }
954826
public JmsPoolConnectionFactory createPooledConnectionFactory(
			ConnectionFactory connectionFactory) {
		JmsPoolConnectionFactory pooledConnectionFactory = new JmsPoolConnectionFactory();
		pooledConnectionFactory.setConnectionFactory(connectionFactory);

		pooledConnectionFactory
				.setBlockIfSessionPoolIsFull(this.properties.isBlockIfFull());
		if (this.properties.getBlockIfFullTimeout() != null) {
			pooledConnectionFactory.setBlockIfSessionPoolIsFullTimeout(
					this.properties.getBlockIfFullTimeout().toMillis());
		}
		if (this.properties.getIdleTimeout() != null) {
			pooledConnectionFactory.setConnectionIdleTimeout(
					(int) this.properties.getIdleTimeout().toMillis());
		}
		pooledConnectionFactory.setMaxConnections(this.properties.getMaxConnections());
		pooledConnectionFactory.setMaxSessionsPerConnection(
				this.properties.getMaxSessionsPerConnection());
		if (this.properties.getTimeBetweenExpirationCheck() != null) {
			pooledConnectionFactory.setConnectionCheckInterval(
					this.properties.getTimeBetweenExpirationCheck().toMillis());
		}
		pooledConnectionFactory
				.setUseAnonymousProducers(this.properties.isUseAnonymousProducers());
		return pooledConnectionFactory;
	}
1168261
@Override
  public AppSession getNewSession(String sessionId, Class<? extends AppSession> aClass, ApplicationId applicationId, Object[] args) {
    AppSession appSession = null;

    if (aClass == ServerS6aSession.class) {
      if (sessionId == null) {
        if (args != null && args.length > 0 && args[0] instanceof Request) {
          Request request = (Request) args[0];
          sessionId = request.getSessionId();
        }
        else {
          sessionId = this.sessionFactory.getSessionId();
        }
      }
      IServerS6aSessionData sessionData = (IServerS6aSessionData) this.sessionDataFactory.getAppSessionData(ServerS6aSession.class, sessionId);
      sessionData.setApplicationId(applicationId);
      S6aServerSessionImpl serverSession = new S6aServerSessionImpl(sessionData, getMessageFactory(), sessionFactory, this.getServerSessionListener());

      iss.addSession(serverSession);
      serverSession.getSessions().get(0).setRequestListener(serverSession);
      appSession = serverSession;
    }
    else if (aClass == ClientS6aSession.class) {
      if (sessionId == null) {
        if (args != null && args.length > 0 && args[0] instanceof Request) {
          Request request = (Request) args[0];
          sessionId = request.getSessionId();
        }
        else {
          sessionId = this.sessionFactory.getSessionId();
        }
      }
      IClientS6aSessionData sessionData = (IClientS6aSessionData) this.sessionDataFactory.getAppSessionData(ClientS6aSession.class, sessionId);
      sessionData.setApplicationId(applicationId);
      S6aClientSessionImpl clientSession = new S6aClientSessionImpl(sessionData, getMessageFactory(), sessionFactory, this.getClientSessionListener());

      iss.addSession(clientSession);
      clientSession.getSessions().get(0).setRequestListener(clientSession);
      appSession = clientSession;
    }
    else {
      throw new IllegalArgumentException("Wrong session class: " + aClass + ". Supported[" + ServerS6aSession.class + "]");
    }

    return appSession;
  }
500823
private JcrSession openSession() throws ResourceException {
        try {
            Repository repo = mcf.getRepository();
            Session s = repo.login(cri.getCredentials(), cri.getWorkspace());
            return (JcrSession) s;
        } catch (RepositoryException e) {
            throw new ResourceException("Failed to create session: " + e.getMessage(), e);
        }
    }
303157
private void initSessions() throws FileNotFoundException, ClassNotFoundException, IOException,
        ResourceNotExistingException, TTException {
        Map<String, String> filelisteners = getFilelisteners();
        mSessions = new HashMap<String, ISession>();
        mTrx = new HashMap<String, IFilelistenerWriteTrx>();

        if (filelisteners.isEmpty()) {
            return;
        }

        for (Entry<String, String> e : filelisteners.entrySet()) {
            mSessions.put(e.getKey(), StorageManager.getSession(e.getKey()));
            mTrx.put(e.getKey(), new FilelistenerWriteTrx(mSessions.get(e.getKey()).beginBucketWtx(),
                mSessions.get(e.getKey())));
            mSubDirectories.put(e.getValue(), new ArrayList<String>());
            mExecutorMap.put(e.getValue(), Executors.newSingleThreadExecutor());

            List<String> subDirs = mSubDirectories.get(e.getValue());

            for (String s : mTrx.get(e.getKey()).getFilePaths()) {
                String fullFilePath =
                    new StringBuilder().append(e.getValue()).append(File.separator).append(s).toString();
                subDirs.add(fullFilePath);

                Path p = Paths.get(fullFilePath);

                watchParents(p, e.getValue());
            }
        }
    }
707512
@Override
  public <T> ConnectionFactory<T> getConnectionFactory(final Identifier connFactoryId) {
    final ConnectionFactory<T> connFactory = connFactoryMap.get(connFactoryId.toString());
    if (connFactory == null) {
      throw new RuntimeException("Cannot find ConnectionFactory of " + connFactoryId + ".");
    }
    return connFactory;
  }
737788
@SuppressWarnings("unchecked")
    protected void bindManyToOne(Association property, ManyToOne manyToOne,
                                 String path, InFlightMetadataCollector mappings, String sessionFactoryBeanName) {

        NamingStrategy namingStrategy = getNamingStrategy(sessionFactoryBeanName);

        bindManyToOneValues(property, manyToOne);
        PersistentEntity refDomainClass = property instanceof ManyToMany ? property.getOwner() : property.getAssociatedEntity();
        Mapping mapping = getMapping(refDomainClass);
        boolean isComposite = hasCompositeIdentifier(mapping);
        if (isComposite) {
            CompositeIdentity ci = (CompositeIdentity) mapping.getIdentity();
            bindCompositeIdentifierToManyToOne(property, manyToOne, ci, refDomainClass, path, sessionFactoryBeanName);
        }
        else {
            if (property.isCircular() && (property instanceof ManyToMany)) {
                PropertyConfig pc = getPropertyConfig(property);

                if (pc.getColumns().isEmpty()) {
                    mapping.getColumns().put(property.getName(), pc);
                }
                if (!hasJoinKeyMapping(pc) ) {
                    JoinTable jt = new JoinTable();
                    final ColumnConfig columnConfig = new ColumnConfig();
                    columnConfig.setName(namingStrategy.propertyToColumnName(property.getName()) +
                            UNDERSCORE + FOREIGN_KEY_SUFFIX);
                    jt.setKey(columnConfig);
                    pc.setJoinTable(jt);
                }
                bindSimpleValue(property, manyToOne, path, pc, sessionFactoryBeanName);
            }
            else {
                // bind column
                bindSimpleValue(property, null, manyToOne, path, mappings, sessionFactoryBeanName);
            }
        }

        PropertyConfig config = getPropertyConfig(property);
        if ((property instanceof org.grails.datastore.mapping.model.types.OneToOne) && !isComposite) {
            manyToOne.setAlternateUniqueKey(true);
            Column c = getColumnForSimpleValue(manyToOne);
            if (config != null && !config.isUniqueWithinGroup()) {
                c.setUnique(config.isUnique());
            }
            else if (property.isBidirectional() && isHasOne(property.getInverseSide())) {
                c.setUnique(true);
            }
        }
    }
1246659
public HttpSession getSelectedSession() {
		final int selectedRow = this.sessionsTable.getSelectedRow();
		if (selectedRow == -1) {
			// No row selected
			return null;
		}
		final int rowIndex = sessionsTable.convertRowIndexToModel(selectedRow);
		return this.sessionsModel.getHttpSessionAt(rowIndex);
	}
886888
@Override
  public void removeSession(String sessionId) {
    logger.debug("removeSession({}) in Local DataSource", sessionId);

    if (this.localDataSource.exists(sessionId)) {
      this.localDataSource.removeSession(sessionId);
    }
    else if (!this.localMode && this.existReplicated(sessionId)) {
      // FIXME: remove node.
    }
  }
711283
protected Object getSession(String id, int version, boolean isSessionAccess, boolean forceSessionRetrieval, Object xdCorrelator) {
        if (isSessionAccess) {
            if (version == -1) {
                _store.refreshSession(id, xdCorrelator);
            } else {
                _store.refreshSession(id, version, xdCorrelator);
            }
        }

        ISession iSession = getSessionFromStore(id, version, isSessionAccess, forceSessionRetrieval, xdCorrelator);
        if (iSession != null) {
            if (isSessionAccess) {
                boolean stillValid = _store.checkSessionStillValid(iSession, iSession.getLastAccessedTime());
                if (stillValid) {
                    iSession.incrementRefCount();
                    _sessionEventDispatcher.sessionAccessed(iSession);
                } else {
                    iSession = null;
                }
            }
        } else {
            if (isSessionAccess) {
                _sessionEventDispatcher.sessionAccessUnknownKey(id);
            }
        }
        return iSession;
    }
1272945
@Override
  public IRfSessionData getAppSessionData(Class<? extends AppSession> clazz, String sessionId) {
    if (clazz.equals(ClientRfSession.class)) {
      ClientRfSessionDataReplicatedImpl data =
          new ClientRfSessionDataReplicatedImpl(sessionId, this.mobicentsCluster, this.replicatedSessionDataSource.getContainer());
      return data;
    }
    else if (clazz.equals(ServerRfSession.class)) {
      ServerRfSessionDataReplicatedImpl data = new ServerRfSessionDataReplicatedImpl(sessionId, this.mobicentsCluster);
      return data;
    }
    throw new IllegalArgumentException();
  }
857136
public synchronized static Session getSession() {
        if(session == null){
            Properties properties = IOUtil.loadProperties("jdbc.properties");
            session = getSession(properties);
        }

        return session;
    }
985536
@Override
    final public void dissociateConnections() throws ResourceException {

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.entry(TRACE, "dissociateConnections");
        }

        // Dissociate sessions

        for (final Iterator iterator = _sessions.iterator(); iterator.hasNext();) {
            final Object object = iterator.next();
            if (object instanceof JmsJcaSessionImpl) {
                ((JmsJcaSessionImpl) object).dissociate();
                iterator.remove();
            }
        }

        if (TraceComponent.isAnyTracingEnabled() && TRACE.isEntryEnabled()) {
            SibTr.exit(this, TRACE, "dissociateConnections");
        }

    }
152877
public Session getSession() throws HibernateException
    {
        Session s = threadSession.get();
        if (s == null)
        {
            s = initSession();
        }

        return s;
    }