Package com.datastax.driver.core

Examples of com.datastax.driver.core.Session$State


    }

    private void createKeyspaceIfNeeded(Cluster cluster, String keyspaceName, Boolean keyspaceDurableWrite) {
        LOGGER.debug("Creating keyspace {} if neeeded", keyspaceName);

        final Session session = cluster.connect("system");
        final Row row = session.execute(
                "SELECT count(1) FROM schema_keyspaces WHERE keyspace_name='" + keyspaceName + "'").one();
        if (row.getLong(0) != 1) {
            StringBuilder createKeyspaceStatement = new StringBuilder("CREATE keyspace IF NOT EXISTS ");
            createKeyspaceStatement.append(keyspaceName);
            createKeyspaceStatement.append(" WITH REPLICATION = {'class':'SimpleStrategy', 'replication_factor':1}");
            if (!keyspaceDurableWrite) {
                createKeyspaceStatement.append(" AND DURABLE_WRITES=false");
            }
            session.execute(createKeyspaceStatement.toString());
        }
        session.close();
    }
View Full Code Here


        ConfigMap params = new ConfigMap();
        params.put(KEYSPACE_NAME, "achilles");

        when(cluster.connect("achilles")).thenReturn(session);

        Session actual = extractor.initSession(cluster, params);

        assertThat(actual).isSameAs(session);
    }
View Full Code Here

    @Test
    public void should_init_session_without_keyspace() throws Exception {
        ConfigMap params = new ConfigMap();
        when(cluster.connect()).thenReturn(session);

        Session actual = extractor.initSession(cluster, params);

        assertThat(actual).isSameAs(session);
    }
View Full Code Here

    public void should_get_native_session_from_parameter() throws Exception {
        ConfigMap params = new ConfigMap();
        params.put(KEYSPACE_NAME, "achilles");
        params.put(NATIVE_SESSION, session);

        Session actual = extractor.initSession(cluster, params);

        assertThat(actual).isSameAs(session);
    }
View Full Code Here

        return Optional.fromNullable(configurationMap.<String>getTyped(KEYSPACE_NAME));
    }
    public Session initSession(Cluster cluster, ConfigMap configurationMap) {
        log.trace("Extract or init Session from configuration map");

        Session nativeSession = configurationMap.getTyped(NATIVE_SESSION);
        if (nativeSession == null) {
            final Optional<String> keyspaceNameO = initKeyspaceName(configurationMap);
            if (keyspaceNameO.isPresent()) {
                nativeSession = cluster.connect(keyspaceNameO.get());
            } else {
View Full Code Here

        final String keyspaceName = configurationMap.getTyped(KEYSPACE_NAME);

        log.info("Bootstrapping Achilles PersistenceManagerFactory for keyspace {}", keyspaceName);

        configContext = argumentExtractor.initConfigContext(configurationMap);
        Session session = argumentExtractor.initSession(cluster, configurationMap);
        final ClassLoader classLoader = argumentExtractor.initOSGIClassLoader(configurationMap);
        List<Interceptor<?>> interceptors = argumentExtractor.initInterceptors(configurationMap);
        List<Class<?>> candidateClasses = argumentExtractor.initEntities(configurationMap, classLoader);

        ParsingResult parsingResult = parseEntities(candidateClasses);
View Full Code Here

    }

    @Override
    public void deleteByColumn(String schemaName, String tableName, String columnName, Object columnValue)
    {
        Session session = factory.getConnection();
        String rowKeyName = null;
        CQLTranslator translator = new CQLTranslator();
        try
        {
            List<ColumnMetadata> primaryKeys = session.getCluster().getMetadata().getKeyspace("\"" + schemaName + "\"")
                    .getTable("\"" + tableName + "\"").getPrimaryKey();
            rowKeyName = primaryKeys.get(0).getName();
        }
        finally
        {
View Full Code Here

    @Override
    protected <T> T execute(final String query, Object connection)
    {

        Session session = factory.getConnection();
        ;
        try
        {
            Statement queryStmt = new SimpleStatement(query);
            KunderaCoreUtils.printQuery(query, showQuery);
            queryStmt.setConsistencyLevel(ConsistencyLevel.valueOf(this.consistencyLevel.name()));
            return (T) session.execute(queryStmt);
        }
        catch (Exception e)
        {
            log.error("Error while executing query {}.", query);
            throw new KunderaException(e);
View Full Code Here

        }
    }

    public int executeUpdateDeleteQuery(String cqlQuery)
    {
        Session session = null;
        try
        {
            if (log.isInfoEnabled())
            {
                log.info("Executing cql query {}.", cqlQuery);
            }
            session = factory.getConnection();
            KunderaCoreUtils.printQuery(cqlQuery, showQuery);
            session.execute(cqlQuery);
        }
        finally
        {
            // factory.releaseConnection(session);
        }
View Full Code Here

    @Test
    public void should_allow_dynamic_schema_update() throws Exception {
        //Given
        Long id = RandomUtils.nextLong(0,Long.MAX_VALUE);
        final Session session = CassandraEmbeddedServerBuilder
                .noEntityPackages().withKeyspaceName("schema_dynamic_update")
                .cleanDataFilesAtStartup(true)
                .buildNativeSessionOnly();
        session.execute("DROP TABLE IF EXISTS new_simple_field");
        session.execute("DROP INDEX IF EXISTS field_index");
        session.execute("CREATE TABLE new_simple_field(id bigint PRIMARY KEY, existing_field text)");
        session.execute("CREATE INDEX field_index ON schema_dynamic_update.new_simple_field(existing_field)");

        //When
        final PersistenceManagerFactory pmf = PersistenceManagerFactoryBuilder.builder(session.getCluster())
                .withNativeSession(session)
                .withEntities(Arrays.<Class<?>>asList(EntityWithNewSimpleField.class))
                .enableSchemaUpdate(false)
                .enableSchemaUpdateForTables(ImmutableMap.of("schema_dynamic_update.new_simple_field", true))
                .relaxIndexValidation(true)
                .build();

        final PersistenceManager pm = pmf.createPersistenceManager();
        pm.insert(new EntityWithNewSimpleField(id, "existing", "new"));

        //Then
        final EntityWithNewSimpleField found = pm.find(EntityWithNewSimpleField.class, id);

        assertThat(found).isNotNull();
        assertThat(found.getUnmappedField()).isEqualTo("UNMAPPED");

        assertThat(pm.getProxy(EntityWithNewSimpleField.class, id).getUnmappedField()).isEqualTo("UNMAPPED");

        session.close();
    }
View Full Code Here

TOP

Related Classes of com.datastax.driver.core.Session$State

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.