Package com.datastax.driver.core

Examples of com.datastax.driver.core.Session


    public void should_allow_dynamic_schema_update_for_cluster_counter() throws Exception {
        //Given
        Long id = RandomUtils.nextLong(0,Long.MAX_VALUE);
        UUID date = UUIDGen.getTimeUUID();

        final Session session = CassandraEmbeddedServerBuilder
                .withEntities(Arrays.<Class<?>>asList(CompleteBean.class))
                .withKeyspaceName("schema_dynamic_update_counter")
                .cleanDataFilesAtStartup(true)
                .buildNativeSessionOnly();
        session.execute("DROP TABLE IF EXISTS new_counter_field");
        session.execute("CREATE TABLE new_counter_field(id bigint, date timeuuid, existing_counter counter, PRIMARY KEY(id,date))");

        //When
        final PersistenceManagerFactory pmf = PersistenceManagerFactoryBuilder.builder(session.getCluster())
                .withEntities(Arrays.<Class<?>>asList(ClusteredCounterEntityWithNewCounterField.class))
                .enableSchemaUpdate(true)
                .build();

        final PersistenceManager pm = pmf.createPersistenceManager();
        pm.insert(new ClusteredCounterEntityWithNewCounterField(id, date, CounterBuilder.incr(12L)));

        //Then
        assertThat(pm.find(ClusteredCounterEntityWithNewCounterField.class, new ClusteredCounterEntityWithNewCounterField.Compound(id, date))).isNotNull();

        session.close();
    }
View Full Code Here


    }

    @Test(expected = AchillesInvalidTableException.class)
    public void should_fail_bootstrapping_if_schema_update_forbidden_for_entity() throws Exception {
        //Given
        final Session session = CassandraEmbeddedServerBuilder
                .noEntityPackages().withKeyspaceName("schema_dynamic_update_fail")
                .cleanDataFilesAtStartup(true)
                .buildNativeSessionOnly();
        session.execute("DROP TABLE IF EXISTS new_simple_field");
        session.execute("CREATE TABLE new_simple_field(id bigint PRIMARY KEY, existing_field text)");

        //When
        PersistenceManagerFactoryBuilder.builder(session.getCluster())
                .withEntities(Arrays.<Class<?>>asList(EntityWithNewSimpleField.class))
                .withKeyspaceName("schema_dynamic_update_fail")
                .enableSchemaUpdate(true)
                .enableSchemaUpdateForTables(ImmutableMap.of("schema_dynamic_update_fail.new_simple_field", false))
                .build();

        session.close();
    }
View Full Code Here

    }

    @Test(expected = AchillesInvalidTableException.class)
    public void should_fail_bootstrapping_if_index_validation_fails() throws Exception {
        //Given
        final Session session = CassandraEmbeddedServerBuilder
                .noEntityPackages().withKeyspaceName("schema_dynamic_update")
                .cleanDataFilesAtStartup(true)
                .buildNativeSessionOnly();

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

        session.close();
    }
View Full Code Here

    public void should_use_custom_bean_validator_interceptor() throws Exception {
        // Given
        Long id = RandomUtils.nextLong(0,Long.MAX_VALUE);
        boolean exceptionRaised = false;

        Session nativeSession = this.manager.getNativeSession();
        Cluster cluster = nativeSession.getCluster();
        CustomValidationInterceptor interceptor = new CustomValidationInterceptor();

        Map<ConfigurationParameters, Object> configMap = new HashMap<>();
        configMap.put(NATIVE_SESSION, nativeSession);
        configMap.put(ENTITIES_LIST, Arrays.asList(EntityWithGroupConstraint.class));
View Full Code Here

    private Session session = CassandraEmbeddedServerBuilder.noEntityPackages().withKeyspaceName("test_keyspace")
            .buildNativeSessionOnly();

    @Test
    public void should_return_same_native_session() throws Exception {
        Session session = CassandraEmbeddedServerBuilder.noEntityPackages().withKeyspaceName("test_keyspace")
                .buildNativeSessionOnly();

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

      throw new RuntimeException(
          "Cassandra cluster has not yet been initialized!");
    }
    try {
      _log.info("Started connecting to cluster...");
      final Session session = _cluster.connect(_configuration
          .getKeyspace());
      _log.info("Finished connecting to cluster...");
      return new CassandraVirtualDataWindow(session, context);
    } catch (Exception e) {
      _log.error("Error connecting to cluster!");
View Full Code Here

TOP

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

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.