Package com.datastax.driver.core

Examples of com.datastax.driver.core.PreparedStatement


        session.execute("CREATE TABLE IF NOT EXISTS " + KEYSPACE + ".qp_test (id int PRIMARY KEY, cid int, val text);");

        String insertCQL = "INSERT INTO " + KEYSPACE + ".qp_test (id, cid, val) VALUES (?, ?, ?)";
        String selectCQL = "Select * from " + KEYSPACE + ".qp_test where id = ?";

        PreparedStatement preparedInsert = session.prepare(insertCQL);
        PreparedStatement preparedSelect = session.prepare(selectCQL);

        session.execute(preparedInsert.bind(1, 1, "value"));
        assertEquals(1, session.execute(preparedSelect.bind(1)).all().size());

        cluster.close();

        cluster = Cluster.builder().addContactPoint("127.0.0.1")
                                   .withPort(DatabaseDescriptor.getNativeTransportPort())
                                   .build();
        session = cluster.connect();

        preparedInsert = session.prepare(insertCQL);
        preparedSelect = session.prepare(selectCQL);
        session.execute(preparedInsert.bind(1, 1, "value"));

        assertEquals(1, session.execute(preparedSelect.bind(1)).all().size());
    }
View Full Code Here


   *
   * @param query The query to execute.
   * @return The results of executing the query.
   */
  public ResultSet execute(String query) {
    PreparedStatement preparedStatement = mStatementCache.getPreparedStatement(query);
    return mSession.execute(preparedStatement.bind());
  }
View Full Code Here

   *
   * @param query The query to execute.
   * @return The results of executing the query.
   */
  public ResultSetFuture executeAsync(String query) {
    PreparedStatement preparedStatement = mStatementCache.getPreparedStatement(query);
    return mSession.executeAsync(preparedStatement.bind());
  }
View Full Code Here

        mMetaTableName,
        QUALIFIER_TABLE,
        QUALIFIER_TIME,
        QUALIFIER_LAYOUT,
        QUALIFIER_UPDATE);
    PreparedStatement preparedStatementInsertAll = mAdmin.getPreparedStatement(queryTextInsertAll);

    String queryTextInsertLayout = String.format(
        "INSERT INTO %s (%s, %s, %s) VALUES (?, ?, ?)",
        mMetaTableName,
        QUALIFIER_TABLE,
        QUALIFIER_TIME,
        QUALIFIER_LAYOUT);
    final PreparedStatement insertLayoutStatement =
        mAdmin.getPreparedStatement(queryTextInsertLayout);

    // TODO: Unclear what happens to layout IDs here...
    for (TableLayoutBackupEntry lbe : layoutBackup.getLayouts()) {
      final byte[] layoutBytes = encodeTableLayoutDesc(lbe.getLayout());
      final ByteBuffer layoutByteBuffer = ByteBuffer.wrap(layoutBytes);

      if (lbe.getUpdate() != null) {
        final byte[] updateBytes = encodeTableLayoutDesc(lbe.getUpdate());
        final ByteBuffer updateByteBuffer = ByteBuffer.wrap(updateBytes);
        final long timestamp = lbe.getTimestamp();

        mAdmin.execute(preparedStatementInsertAll.bind(
            tableName,
            new Date(timestamp),
            layoutByteBuffer,
            updateByteBuffer));
      } else {
        mAdmin.execute(insertLayoutStatement.bind(tableName, new Date(), layoutByteBuffer));
      }
    }
    // TODO: Some kind of flush?
  }
View Full Code Here

   * @param query to turn into a prepared statement.
   * @return a prepared statement for the query.
   */
  synchronized PreparedStatement getPreparedStatement(String query) {
    if (!mStatementCache.containsKey(query)) {
      PreparedStatement statement = mSession.prepare(query);
      mStatementCache.put(query, statement);
    }
    return mStatementCache.get(query);
  }
View Full Code Here

    private void onBeginX(String x, MappedSchemaObject<?> entity, Statement statement) {
        String queryString = "";
        String queryKeyspace = "";
        if (statement instanceof BoundStatement) {
            PreparedStatement pstmt = ((BoundStatement) statement).preparedStatement();
            queryKeyspace = pstmt.getQueryKeyspace();
            queryString = pstmt.getQueryString();
        }
        else if (statement instanceof RegularStatement) {
            RegularStatement rstmt = (RegularStatement) statement;
            queryKeyspace = rstmt.getKeyspace();
            queryString = rstmt.getQueryString();
View Full Code Here

        binder.clearSpecial();
    }

    BoundStatement buildModifyInitial(Session session, PersistOption[] persistOptions, PreparedStatements.StatementType statementType,
                                      Binder binder) {
        PreparedStatement pStmt = preparedStatements.statementFor(session, statementType, binder, persistOptions);
        BoundStatement bStmt = pStmt.bind();

        binder.bindColumns(0, bStmt);

        PersistOption.forBoundStatement(persistOptions, bStmt);
        return bStmt;
View Full Code Here

            }
        } catch (Throwable t) {
            throw new RuntimeException("Invalid primary key element "+Arrays.toString(primaryKey), t);
        }

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

        idx = binder.bindColumns(0, bStmt);
View Full Code Here

        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);
View Full Code Here

            return;
        }

        CqlColumn[] readColumns = readColumns(persistOptions);

        PreparedStatement pstmt = preparedStatements.statementFor(queryBinder.session, PreparedStatements.StatementType.SELECT,
            readColumns, queryBinder.conditionFor((Class<? extends T>) type), persistOptions);
        BoundStatement bStmt = pstmt.bind();
        statementOptions.applyRead(bStmt, readConsistencyLevel, persistOptions);
        PersistOption.forBoundStatement(persistOptions, bStmt);
        queryBinder.addStatement((Class<? extends T>) type, bStmt, readColumns);
    }
View Full Code Here

TOP

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

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.