Create session

@param keyspace Default keyspace

@return Session instance
326433
private Session getOrCreateSession(@NotNull String keyspace) {
        Timer timer = getMetricsFactory().getTimer("cassandraClient.getOrCreateSession");

        Session currentSession = sessionsByKeyspace.computeIfAbsent(keyspace, key -> {
            LOGGER.debug("Create session for [{}]", keyspace);

            Session session = getCluster().connect(key);
            session.init();

            return session;
        });

        timer.stop();

        return currentSession;
    }
657248
private CmsUgcSession createSession(CmsObject cms, CmsUgcConfiguration config) throws CmsUgcException {

        if (getQueue(config).waitForSlot()) {
            try {
                return new CmsUgcSession(m_adminCms, cms, config);
            } catch (CmsException e) {
                LOG.error(e.getLocalizedMessage(), e);
                throw new CmsUgcException(e);
            }
        } else {
            String message = Messages.get().container(Messages.ERR_WAIT_QUEUE_EXCEEDED_0).key(
                cms.getRequestContext().getLocale());
            throw new CmsUgcException(CmsUgcConstants.ErrorCode.errMaxQueueLengthExceeded, message);
        }
    }
119866
protected SessionFactory createSessionFactory() {
        // Set up a service registry.
        StandardServiceRegistryBuilder b = new StandardServiceRegistryBuilder();

        // configures settings from hibernate.cfg.xml
        ServiceRegistry registry = b.configure().build();

        // Build the session factory.
        return new MetadataSources(registry)
                .buildMetadata()
                .buildSessionFactory();
    }
924591
private DBConn createAndConnectConn(String keyspace) throws DBNotAvailableException, RuntimeException {
        DBConn dbConn = new DBConn(this, keyspace);
        connectDBConn(dbConn);
        return dbConn;
    }
628597
@Override
	public final Session createSession(boolean transacted, int acknowledgeMode) throws JMSException
    {
    	return createSession(idProvider.createID(), transacted, acknowledgeMode);
    }
895359
def createSessionForKey(self, key, user):
        
        PersistentSession(
            store=self.store,
            sessionKey=key,
            authenticatedAs=user)
697873
private void createKeyspace() throws Exception
    {
        if (cql_version != null && cql_version.equals(CassandraConstants.CQL_VERSION_3_0))
        {
            onCql3CreateKeyspace();
        }
        else
        {
            Map<String, String> strategy_options = new HashMap<String, String>();
            List<CfDef> cfDefs = new ArrayList<CfDef>();
            KsDef ksDef = new KsDef(databaseName, csmd.getPlacement_strategy(databaseName), cfDefs);
            setProperties(ksDef, strategy_options);
            ksDef.setStrategy_options(strategy_options);
            cassandra_client.system_add_keyspace(ksDef);
        }
    }
994974
@NonNull
  public static CreateTableStart createTable(@Nullable String keyspace, @NonNull String tableName) {
    return createTable(
        keyspace == null ? null : CqlIdentifier.fromCql(keyspace),
        CqlIdentifier.fromCql(tableName));
  }
616271
@NonNull
  public static CreateFunctionStart createFunction(
      @Nullable CqlIdentifier keyspace, @NonNull CqlIdentifier functionName) {
    return new DefaultCreateFunction(keyspace, functionName);
  }
220887
@NonNull
  public static CreateMaterializedViewStart createMaterializedView(
      @Nullable String keyspace, @NonNull String viewName) {
    return createMaterializedView(
        keyspace == null ? null : CqlIdentifier.fromCql(keyspace), CqlIdentifier.fromCql(viewName));
  }
423406
@Override
	public void createResource() throws Exception {
		cluster = builder.getCluster();
		session = cluster.connect();

		session.execute(String.format("CREATE KEYSPACE IF NOT EXISTS %s with replication={'class':'SimpleStrategy', 'replication_factor':1};", keySpace));
		session.execute(String.format("CREATE TABLE IF NOT EXISTS %s.%s (sink_id text, sub_id int, checkpoint_id bigint, PRIMARY KEY (sink_id, sub_id));", keySpace, table));

		try {
			session.close();
		} catch (Exception e) {
			LOG.error("Error while closing session.", e);
		}
		try {
			cluster.close();
		} catch (Exception e) {
			LOG.error("Error while closing cluster.", e);
		}
	}
893529
def set_keyspace(self, keyspace):
    
    self._seqid += 1
    d = self._reqs[self._seqid] = defer.Deferred()
    self.send_set_keyspace(keyspace)
    return d
195334
protected Session createSession(Connection connection) throws JMSException {
        if (connection instanceof QueueConnection) {
            return ((QueueConnection) connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        }
        return connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    }
383111
private KsDef setKeySpaceOptions(String keyspace) {
        KsDef ksDef = new KsDef();
        ksDef.setName(keyspace);
        Map<String, Object> ksDefs = m_service.getParamMap("ks_defaults");
        if (ksDefs != null) {
            for (String name : ksDefs.keySet()) {
                Object value = ksDefs.get(name);
                try {
                    KsDef._Fields field = KsDef._Fields.findByName(name);
                    if (field == null) {
                        m_logger.warn("Unknown KeySpace option: {} -- ignoring", name);
                    } else {
                        ksDef.setFieldValue(field, value);
                    }
                } catch (Exception e) {
                    m_logger.warn("Error setting Keyspace option '" + name + "' to '" + value + "' -- ignoring", e);
                }
            }
        }

        // Legacy support: ReplicationFactor -> replication_factor
        if (m_service.getParam("ReplicationFactor") != null) {
            Map<String, String> stratOpts = new HashMap<>();
            stratOpts.put("replication_factor", m_service.getParamString("ReplicationFactor"));
            ksDef.setStrategy_options(stratOpts);
        }
        
        // required: strategy_class, strategy_options, replication_factor, cf_defs, durable_writes
        if (!ksDef.isSetStrategy_class()) {
            ksDef.setStrategy_class(DEFAULT_KS_STRATEGY_CLASS);
        }
        if (!ksDef.isSetStrategy_options()) {
            Map<String, String> stratOpts = new HashMap<>();
            stratOpts.put("replication_factor", DEFAULT_KS_REPLICATION_FACTOR);
            ksDef.setStrategy_options(stratOpts);
        }
        if (!ksDef.isSetCf_defs()) {
            ksDef.setCf_defs(DEFAULT_KS_CF_DEFS);
        }
        if (!ksDef.isSetDurable_writes()) {
            ksDef.setDurable_writes(DEFAULT_KS_DURABLE_WRITES);
        }
        return ksDef;
    }
468036
@Override
    public Namespace createNamespace(Namespace namespace) {
        requireNotDisposed();
        requireArgument(namespace != null, "null namespace cannot be created.");
        
        if (!_validateQualifier(namespace.getQualifier())) {
            throw new SystemException(new IllegalArgumentException(
                    "Illegal characters found while generating namespace. Cannot generate a namespace with this qualifier."));
        }
        
        if (Namespace.findByQualifier(emf.get(), namespace.getQualifier()) != null) {
            throw new SystemException(new IllegalArgumentException("Namespace already exists. Please try a different namespace."));
        }
        
        namespace = updateNamespace(namespace);
        _logger.debug("Generated namespace {}.", namespace);
        return namespace;
    }
1131873
@NonNull
  public static Drop dropKeyspace(@NonNull String keyspaceName) {
    return dropKeyspace(CqlIdentifier.fromCql(keyspaceName));
  }
940334
public EntityManager createDefaultEntityManager(String namespace) {
    ConnectionParameters parameters = new ConnectionParameters();
    parameters.setNamespace(namespace);
    return createEntityManager(parameters);
  }