Package com.datastax.driver.core

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


        return comp;
    }

    @Test
    public void userTypeMeta() throws InterruptedException {
        Session session = cluster.connect();
        try {
            session.execute("CREATE TYPE udttest.phone ( cntry varchar, city varchar, num varchar )");
            session.execute("CREATE TYPE udttest.address ( street varchar, city varchar, country varchar, ph_num phone )");

            Thread.sleep(500L);

            KeyspaceMetadata ksm = cluster.getMetadata().getKeyspace("udttest");
            Collection<UserType> uts = ksm.getUserTypes();

            Assert.assertTrue(uts.size() >= 2);

            UserType utPhone = ksm.getUserType("phone");
            UserType utAddress = ksm.getUserType("address");

            Assert.assertNotNull(utPhone);
            Assert.assertNotNull(utAddress);
        } finally {session.close();}
    }
View Full Code Here


            for (int i = 0; ; i++) {
                System.out.println("Building Cluster instance...");
                cluster = builder.build();

                try {
                    Session ignored = cluster.connect();
                    ignored.close();
                    break;
                } catch (Exception e) {
                    try {
                        cluster.close();
                    } catch (Throwable ignore) {
View Full Code Here

    }

    @SuppressWarnings({"BusyWait", "CallToPrintStackTrace"}) protected static void recreateKeyspace(String keyspaceName) {
        System.out.println("Creating keyspace " + keyspaceName + " ...");
        for (int i = 0; ; i++) {
            Session session = null;
            try {
                session = cluster.connect();

                if (keyspaceExists(session, keyspaceName)) {
                    System.out.println("Dropping keyspace " + keyspaceName);
                    session.execute("DROP KEYSPACE " + keyspaceName).one();
                    for (int j = 0; j < 100; j++) {
                        if (!keyspaceExists(session, keyspaceName)) {
                            break;
                        }
                        try {
                            Thread.sleep(100);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                    if (keyspaceExists(session, keyspaceName)) {
                        Assert.fail("could not drop keyspace " + keyspaceName);
                    }
                }

                System.out.println("Creating keyspace " + keyspaceName);
                session
                    .execute("CREATE KEYSPACE " + keyspaceName + " WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 2 }")
                    .one();
                for (int j = 0; j < 100; j++) {
                    if (keyspaceExists(session, keyspaceName)) {
                        break;
                    }
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                if (!keyspaceExists(session, keyspaceName)) {
                    Assert.fail("could not drop keyspace " + keyspaceName);
                }
                return;
            } catch (NoHostAvailableException noHost) {
                try {
                    Thread.sleep(250L);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                if (i == 5) {
                    throw noHost;
                }
            } finally { if (session!=null) session.close(); }
        }
    }
View Full Code Here

        }
        MapEntity<?, ?> instance = (MapEntity) raw;

        persistOptions = withTTL(persistOptions);

        Session session = persistenceSession.driverSession();

        BatchStatement batch = new BatchStatement();

        //TODO adding a DELETE...WHERE partitionKey=? in front of INSERTs for the same partition key results in no insert at all *SICK*
        //Binder binder = new Binder(null, true, partitionKeyColumns, PersistMode.DELETE);
View Full Code Here

        }
        MapEntity<?, ?> instance = (MapEntity) raw;

        persistOptions = withTTL(persistOptions);

        Session session = persistenceSession.driverSession();

        BatchStatement batch = new BatchStatement();

        Set removed = instance.getRemoved();
        if (!removed.isEmpty()) {
View Full Code Here

        // WHERE row_specification
        // ( IF ( EXISTS | (column_name = literal ) ) AND ( column_name = literal ) . . . )

        persistOptions = withTTL(persistOptions);

        Session session = persistenceSession.driverSession();

        Binder binder = new Binder(null, true, partitionKeyColumns, PersistMode.DELETE, true);
        buildModifyBindColumns(instance, binder, partitionAttributes);
        BoundStatement bStmt = buildModifyInitial(session, persistOptions, PreparedStatements.StatementType.DELETE, binder);
View Full Code Here

        Binder binder = new Binder(loadColumns, false, primaryKeyColumns, null, true);

        buildModifyBindColumns(container, binder);

        Session session = persistenceSession.driverSession();

        PreparedStatement pstmt = preparedStatements
            .statementFor(session, PreparedStatements.StatementType.SELECT, binder, persistOptions);
        BoundStatement bStmt = pstmt.bind();
        statementOptions.applyRead(bStmt, readConsistencyLevel, persistOptions);
        PersistOption.forBoundStatement(persistOptions, bStmt);

        int idx = binder.bindColumns(0, bStmt);

        PersistOption.LimitOption.apply(bStmt, persistOptions, idx);

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Lazy load of {} attributes for {}", attrs.length, type);
        }

        ResultSet resultSet = session.execute(bStmt);
        Row row = resultSet.one();
        if (row != null) {
            Retriever retriever = new GettableRetriever(persistenceSession.persistenceManager.protocolVersion, row, loadColumns);
            for (MappedAttribute attr : attrs) {
                Object instance = resolveParentInstance(container, attr);
View Full Code Here

        Binder binder = new Binder(loadColumns, false, primaryKeyColumns, null, true);

        buildModifyBindColumns(container, binder);

        Session session = persistenceSession.driverSession();

        PreparedStatement pstmt = preparedStatements
            .statementFor(session, PreparedStatements.StatementType.SELECT, binder, persistOptions);
        BoundStatement bStmt = pstmt.bind();
        statementOptions.applyRead(bStmt, readConsistencyLevel, persistOptions);
        PersistOption.forBoundStatement(persistOptions, bStmt);

        int idx = binder.bindColumns(0, bStmt);

        PersistOption.LimitOption.apply(bStmt, persistOptions, idx);

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Lazy load of {} attributes for {}", attrs.length, type);
        }

        ResultSet resultSet = session.execute(bStmt);
        Row row = resultSet.one();
        if (row != null) {
            Retriever retriever = new GettableRetriever(persistenceSession.persistenceManager.protocolVersion, row, loadColumns);
            for (MappedAttribute attr : attrs) {
                Object instance = resolveParentInstance(container, attr);
View Full Code Here

    }

    @Override public BatchFuture submitBatchAsync() {
        submitted = true;
        persistenceSession.statementOptions.applyWrite(batchStatement, null, null);
        Session session = persistenceSession.driverSession();
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("Submitting batch bound statement {}", batchStatement);
        }

        for (BatchPartFutureImpl future : futures) {
            Interceptors preModify = future.mode == PersistMode.DELETE ? future.entity.preDelete : future.entity.prePersist;
            if (preModify != null) {
                preModify.invoke(future.instance, future.entity, future.mode);
            }
        }

        BatchFutureImpl future = new BatchFutureImpl(session.executeAsync(batchStatement));
        return future;
    }
View Full Code Here

    CachedPreparedStatementCreator cpsc = new CachedPreparedStatementCreator(cql);

    PreparedStatement preparedStatement = cpsc.createPreparedStatement(getSession());
    addPreparedStatementOptions(preparedStatement, options);

    Session s = getSession();
    while (rowIterator.hasNext()) {
      s.executeAsync(preparedStatement.bind(rowIterator.next()));
    }
  }
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.