Get Dataservice, store dataservice in session if session scope.<br>

@param session
@param cls
@return
@throws DataServiceException
359147
Object _getDataService(T session, Class cls) throws DataServiceException {
		String dataServiceClassName = cls.getName();
		DataService dataServiceAnno = (DataService) cls.getAnnotation(DataService.class);
		IDataServiceResolver resolver = getResolver(dataServiceAnno.resolver());
		Scope scope = resolver.getScope(cls);
		Object dataService = null;
		Map<String, Object> sessionBeans = getSessionBeans(session);
		logger.debug("{} : scope : {}", dataServiceClassName, scope);
		if (scope.equals(Scope.SESSION)) {
			dataService = sessionBeans.get(dataServiceClassName);
			logger.debug("{} : scope : session is in session : {}", dataServiceClassName, (dataService != null));
		}
		if (dataService == null) {
			dataService = resolver.resolveDataService(cls);
			if (scope.equals(Scope.SESSION)) {
				logger.debug("Store {} scope session in session", dataServiceClassName);
				sessionBeans.put(dataServiceClassName, dataService);
			}
		}
		return dataService;
	}
1040355
@Override
  public IRxSessionData getAppSessionData(Class<? extends AppSession> clazz, String sessionId) {
    if (clazz.equals(ClientRxSession.class)) {
      ClientRxSessionDataLocalImpl data = new ClientRxSessionDataLocalImpl();
      data.setSessionId(sessionId);
      return data;
    }
    else if (clazz.equals(ServerRxSession.class)) {
      ServerRxSessionDataLocalImpl data = new ServerRxSessionDataLocalImpl();
      data.setSessionId(sessionId);
      return data;
    }
    throw new IllegalArgumentException(clazz.toString());
  }
1361061
public ISLgSessionData getAppSessionData(Class<? extends AppSession> clazz, String sessionId) {
    if (clazz.equals(ClientSLgSession.class)) {
      ClientSLgSessionDataReplicatedImpl data = new ClientSLgSessionDataReplicatedImpl(sessionId, this.mobicentsCluster,
          this.replicatedSessionDataSource.getContainer());
      return data;
    } else if (clazz.equals(ServerSLgSession.class)) {
      ServerSLgSessionDataReplicatedImpl data = new ServerSLgSessionDataReplicatedImpl(sessionId, this.mobicentsCluster,
          this.replicatedSessionDataSource.getContainer());
      return data;
    }
    throw new IllegalArgumentException();
  }
152877
public Session getSession() throws HibernateException
    {
        Session s = threadSession.get();
        if (s == null)
        {
            s = initSession();
        }

        return s;
    }
835270
public void sessionCreated(ISession session) {
        if (com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled() && LoggingUtil.SESSION_LOGGER_CORE.isLoggable(Level.FINE)) {
            LoggingUtil.SESSION_LOGGER_CORE.logp(Level.FINE, methodClassName, "sessionCreated", "sessionObservers.size()=" + _sessionObservers.size());
        }
        if (_sessionObservers == null || _sessionObservers.size() < 1) {
            return;
        }
        ISessionObserver sessionObserver = null;
        for (int i = 0; i < _sessionObservers.size(); i++) {
            sessionObserver = (ISessionObserver) _sessionObservers.get(i);
            sessionObserver.sessionCreated(session);
        }
    }
707349
DataSource getDataSource() {
        if (com.ibm.websphere.ras.TraceComponent.isAnyTracingEnabled() && LoggingUtil.SESSION_LOGGER_WAS.isLoggable(Level.FINER)) {
            LoggingUtil.SESSION_LOGGER_WAS.entering(methodClassName, methodNames[GET_DATA_SOURCE]);
        }

        if (dataSource != null)
            return dataSource;

        try {

            //            Properties p = new Properties();
            //
            //            p.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
            //            InitialContext ic = new javax.naming.InitialContext(p);
            beginDBContext(); // PK06395/d321615
            //            dataSource = (DataSource) ic.lookup(_smc.getJNDIDataSourceName());

            ResourceConfig rc = this.getDatabaseStoreService().getResourceConfigFactory().createResourceConfig("javax.sql.DataSource");
            rc.setResAuthType(ResourceConfig.AUTH_CONTAINER);
            rc.setSharingScope(ResourceConfig.SHARING_SCOPE_SHAREABLE);
            rc.setIsolationLevel(Connection.TRANSACTION_READ_COMMITTED);
            //            ResRef.APPLICATION, // resAuth - org.eclipse.jst.j2ee.common.ResAuthTypeBase.APPLICATION=
            //            ResRef.SHAREABLE, // resSharingScope - org.eclipse.jst.j2ee.common.ResSharingScopeType.SHAREABLE
            //            ResRef.TRANSACTION_READ_COMMITTED); // resIsolationLevel - com.ibm.ejs.models.base.extensions.commonext.IsolationLevelKind.TRANSACTION_READ_COMMITTED
            dataSource = (DataSource) this.getDatabaseStoreService().getDataSourceFactory().createResource(rc);

            //            dataSource = (DataSource)SessionMgrComponentImpl.getDataSourceFactory().createResource(null); // direct JNDI lookup
            endDBContext(); // PK06395/d321615
            return dataSource;

        } catch (Exception e) {
            com.ibm.ws.ffdc.FFDCFilter.processException(e, "com.ibm.ws.session.store.db.DatabaseHashMap.getDataSource", "558", this);
            LoggingUtil.SESSION_LOGGER_WAS.logp(Level.SEVERE, methodClassName, methodNames[GET_DATA_SOURCE], "DatabaseHashMap.dataSrcErr");
            LoggingUtil.SESSION_LOGGER_WAS.logp(Level.SEVERE, methodClassName, methodNames[GET_DATA_SOURCE], "CommonMessage.exception", e);
            dataSource = null;
        }
        return null;
    }
475085
@Override
    public Object getObjectInstance(Object obj, Name name, Context context, @Sensitive Hashtable<?, ?> environment) throws Exception {

        if (!(obj instanceof Reference)) {
            return null;
        }

        Reference ref = (Reference) obj;

        if (!ServiceRefObjectFactory.class.getName().equals(ref.getFactoryClassName())) {
            return null;
        }

        // Retrieve our service-ref metadata from the Reference object.
        WebServiceRefInfo wsrInfo = null;
        WebServiceRefInfoRefAddr wsrInfoRefAddr = (WebServiceRefInfoRefAddr) ref.get(WebServiceRefInfoRefAddr.ADDR_KEY);
        if (wsrInfoRefAddr != null) {
            wsrInfo = (WebServiceRefInfo) wsrInfoRefAddr.getContent();
        }

        // Make sure we found the WebServiceRefInfo object that contains the service-ref metadata.
        if (wsrInfo == null) {
            throw new Exception("Internal Error: Can not found the WebServiceRefInfo.");
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "Service Ref JNDI name: " + wsrInfo.getJndiName());
        }

        // Get the client metadata
        JaxWsClientMetaData declaredClientMetaData = wsrInfo.getClientMetaData();
        //146981
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            Tr.debug(tc, "declaredClientMetaData: " + declaredClientMetaData);
        JaxWsClientMetaData currentClientMetaData = JaxWsMetaDataManager.getJaxWsClientMetaData();
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
            Tr.debug(tc, "currentClientMetaData: " + currentClientMetaData);
        if (declaredClientMetaData == null) {
            declaredClientMetaData = currentClientMetaData;
        }

        // If we didn't find the ClientMetaData, we have a problem.
        if (declaredClientMetaData == null) {
            throw new IllegalStateException("Internal Error: Can not found the JaxWsClientMetaData");
        }

        mergeWebServicesBndInfo(wsrInfo, declaredClientMetaData);

        //1. The Bus from client module which declares the serviceRef is used for locating WSDL or other usage.
        //2. The classLoader from current client module is used for loading service interface or other related stub classes.
        //The scenario is that, different modules could packge the same stub classes in their own classpaths.
        Bus originalThreadBus = BusFactory.getThreadDefaultBus(false);
        try {
            BusFactory.setThreadDefaultBus(declaredClientMetaData.getClientBus());
            // Collect all of our module-specific service-ref metadata.            
            TransientWebServiceRefInfo tInfo = new TransientWebServiceRefInfo(declaredClientMetaData, wsrInfo, declaredClientMetaData.getModuleMetaData().getAppContextClassLoader());
            Object instance = getInstance(tInfo, wsrInfo);
            return instance;
        } finally {
            BusFactory.setThreadDefaultBus(originalThreadBus);
        }
    }
977986
@Override
  public ICCASessionData getAppSessionData(Class<? extends AppSession> clazz, String sessionId) {
    if (clazz.equals(ClientCCASession.class)) {
      ClientCCASessionDataLocalImpl data = new ClientCCASessionDataLocalImpl();
      data.setSessionId(sessionId);
      return data;
    }
    else if (clazz.equals(ServerCCASession.class)) {
      ServerCCASessionDataLocalImpl data = new ServerCCASessionDataLocalImpl();
      data.setSessionId(sessionId);
      return data;
    }
    throw new IllegalArgumentException(clazz.toString());
  }
77525
@Override
  public ICCASessionData getAppSessionData(Class<? extends AppSession> clazz, String sessionId) {
    if (clazz.equals(ClientCCASession.class)) {
      ClientCCASessionDataReplicatedImpl data =
          new ClientCCASessionDataReplicatedImpl(sessionId, this.mobicentsCluster, this.replicatedSessionDataSource.getContainer());
      return data;
    }
    else if (clazz.equals(ServerCCASession.class)) {
      ServerCCASessionDataReplicatedImpl data = new ServerCCASessionDataReplicatedImpl(sessionId, this.mobicentsCluster);
      return data;
    }
    throw new IllegalArgumentException();
  }
423431
public <T> T getServiceClientAsInterface(S adsSession, Class<T> interfaceClass)
      throws ServiceException {
    return adsServiceClientFactory.getServiceClient(adsSession, interfaceClass);
  }
999603
@Override
  public IAccSessionData getAppSessionData(Class<? extends AppSession> clazz, String sessionId) {
    if (clazz.equals(ClientAccSession.class)) {
      ClientAccSessionDataReplicatedImpl data =
          new ClientAccSessionDataReplicatedImpl(sessionId, this.mobicentsCluster, this.replicatedSessionDataSource.getContainer());
      return data;
    }
    else if (clazz.equals(ServerAccSession.class)) {
      ServerAccSessionDataReplicatedImpl data = new ServerAccSessionDataReplicatedImpl(sessionId, this.mobicentsCluster);
      return data;
    }
    throw new IllegalArgumentException();
  }
103916
@Override
    public <Instance> DatastoreType getDatastoreType(Instance instance) {
        InstanceInvocationHandler<DatastoreType> invocationHandler = proxyFactory.getInvocationHandler(instance);
        return invocationHandler.getDatastoreType();
    }
928804
public static Session getSession(final ICommandLine cl) throws Exception {
        JSch jsch = new JSch();
        Session session = null;
        int timeout = DEFAULT_TIMEOUT;
        int port = cl.hasOption("port") ? Integer.parseInt(cl.getOptionValue("port")) : +DEFAULT_PORT;
        String hostname = cl.getOptionValue("hostname");
        String username = cl.getOptionValue("username");
        String password = cl.getOptionValue("password");
        String key = cl.getOptionValue("key");
        if (cl.hasOption("timeout")) {
            try {
                timeout = Integer.parseInt(cl.getOptionValue("timeout"));
            } catch (NumberFormatException e) {
                throw new MetricGatheringException("Invalid numeric value for timeout.", Status.CRITICAL, e);
            }
        }
        session = jsch.getSession(username, hostname, port);
        if (key == null) {
            session.setConfig("StrictHostKeyChecking", "no");
            session.setPassword(password);
        } else {
            jsch.addIdentity(key);
        }
        session.connect(timeout * 1000);
        return session;
    }
518657
@Override
  public IAccSessionData getAppSessionData(Class<? extends AppSession> clazz, String sessionId) {
    if (clazz.equals(ClientAccSession.class)) {
      ClientAccSessionDataLocalImpl data = new ClientAccSessionDataLocalImpl();
      data.setSessionId(sessionId);
      return data;
    }
    else if (clazz.equals(ServerAccSession.class)) {
      ServerAccSessionDataLocalImpl data = new ServerAccSessionDataLocalImpl();
      data.setSessionId(sessionId);
      return data;
    }
    throw new IllegalArgumentException(clazz.toString());
  }
400124
public <T> T getSessionObject(Class<T> type, String name) {

        T value = (T) session.get(name);
        if (logger.isDebugEnabled()) {
            logger.debug("Recovering object [" + name + "] from  session with value [" + value + "]");
        }
        return value;
    }
420158
public <T> T datastoreToJava(Entity entity) {
		try {
			if (entity == null) {
				return null;
			}
			T result = (T) persistentClass.newInstance();
			populate(entity, result);
			return result;
		} catch (InstantiationException e) {
			throw new RuntimeException(e);
		} catch (IllegalAccessException e) {
			throw new RuntimeException(e);
		}
	}
1188038
public static Session toSession(ConnectorTransactionHandle transactionHandle, ConnectorSession session)
    {
        TransactionId transactionId = ((GlobalSystemTransactionHandle) transactionHandle).getTransactionId();
        ConnectorIdentity connectorIdentity = session.getIdentity();
        Identity identity = new Identity(connectorIdentity.getUser(), connectorIdentity.getPrincipal());
        return Session.builder(new SessionPropertyManager(SYSTEM_SESSION_PROPERTIES))
                .setQueryId(new QueryId(session.getQueryId()))
                .setTransactionId(transactionId)
                .setCatalog("catalog")
                .setSchema("schema")
                .setPath(new SqlPath(Optional.of("path")))
                .setIdentity(identity)
                .setTimeZoneKey(session.getTimeZoneKey())
                .setLocale(session.getLocale())
                .setStartTime(session.getStartTime())
                .build();
    }