Package com.datastax.driver.core

Examples of com.datastax.driver.core.PreparedStatement


  @Override
  public void ingest(String cql, RowIterator rowIterator, WriteOptions options) {

    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


      @Override
      public Object doInSession(Session s) throws DataAccessException {

        String cql = "insert into book (isbn, title, author, pages) values (?, ?, ?, ?)";

        PreparedStatement ps = s.prepare(cql);
        BoundStatement bs = ps.bind(isbn, title, author, pages);

        s.execute(bs);

        return null;
View Full Code Here

    final String queryString = QueryStringBuilder.createSelectQueryString(
        _context, lookupContext, _table);
    _log.debug("Created query {}", queryString);
    CassandraVirtualDataWindowLookup result = null;
    synchronized (_session) {
      final PreparedStatement statement = _session.prepare(queryString);
      result = new CassandraVirtualDataWindowLookup(_session,
          lookupContext, statement, _context);
    }
    return result;
  }
View Full Code Here

    // Insert events into window
    if (oldData == null) {
      _log.debug("Starting insert...");
      final String query = QueryStringBuilder.createInsertQuery(_context);
      PreparedStatement _insertStatement = _session.prepare(query);
      final Object[] values = new Object[propertyNames.length];
      for (EventBean insertBean : newData) {
        for (int i = 0; i < propertyNames.length; ++i) {
          values[i] = insertBean.get(propertyNames[i]);
        }
        BoundStatement boundStatement = null;
        synchronized (_insertStatement) {
          boundStatement = _insertStatement.bind(values);
        }
        synchronized (_session) {
          _session.execute(boundStatement);
        }
      }

      _log.debug("Finished insert...");
    }
    // Delete events from window
    else if (newData == null) {

    }
    // Update events in window
    else {
      if (newData.length > 0) {
        _log.debug("Starting update...");
        EventBean newDataFirst = newData[0];
        List<String> propertiesToUpdateList = new ArrayList<String>();
        for (String propertyName : propertyNames) {
          if (newDataFirst.get(propertyName) != null) {
            propertiesToUpdateList.add(propertyName);
          }
        }

        String propertiesToUpdate[] = propertiesToUpdateList
            .toArray(new String[propertiesToUpdateList.size()]);
        final String query = QueryStringBuilder.createUpdateQuery(
            _context, propertiesToUpdate);
        PreparedStatement _updateStatement = _session.prepare(query);
        Object primaryKeyValue = null;
        for (EventBean updateBean : newData) {
          final List<Object> values = new ArrayList<Object>();
          for (int i = 0; i < propertiesToUpdate.length; ++i) {
            if (QueryStringBuilder.TABLE_ID
                .equals(propertiesToUpdate[i])) {
              primaryKeyValue = updateBean
                  .get(propertiesToUpdate[i]);
            } else {
              values.add(updateBean.get(propertiesToUpdate[i]));
            }
          }
          values.add(primaryKeyValue);
          BoundStatement boundStatement = null;
          synchronized (_updateStatement) {
            boundStatement = _updateStatement
                .bind(values.toArray());
          }
          synchronized (_session) {
            _session.execute(boundStatement);
          }
View Full Code Here

    final String queryString = QueryStringBuilder.createQueryString(
        _context, lookupContext, _table);
    _log.debug("Created query {}", queryString);
    CassandraVirtualDataWindowLookup result = null;
    synchronized (_session) {
      final PreparedStatement statement = _session.prepare(queryString);
      result = new CassandraVirtualDataWindowLookup(_session,
          lookupContext, statement, _context);
    }
    return result;
  }
View Full Code Here

            }

            if (!markAsUnused) {
                // store content as used
                String stmt = "INSERT INTO modeshape.binary (cid, payload, usage) VALUES (?,?,1)";
                PreparedStatement preparedStatement = session.prepare(stmt);
                BoundStatement statement = new BoundStatement(preparedStatement);
                session.execute(statement.bind(key.toString(), buffer(stream)));
            } else {
                // store content as un-used
                String stmt = "INSERT INTO modeshape.binary (cid, usage_time, payload, usage) VALUES (?,?,?,0)";
                PreparedStatement preparedStatement = session.prepare(stmt);
                BoundStatement statement = new BoundStatement(preparedStatement);
                session.execute(statement.bind(key.toString(), new Date(), buffer(stream)));
            }
            return new StoredBinaryValue(this, key, temp.getSize());
        } catch (BinaryStoreException e) {
View Full Code Here

        }
    }

    @Override
    public void markAsUnused( Iterable<BinaryKey> keys ) throws BinaryStoreException {
        PreparedStatement preparedStatement = session.prepare("UPDATE modeshape.binary SET usage = ?, usage_time = ? WHERE cid = ?");
        try {
            for (BinaryKey key : keys) {
                BoundStatement statement = new BoundStatement(preparedStatement);
                session.execute(statement.bind(0, new Date(), key.toString()));
            }
View Full Code Here

        Class<?> entityClass = context.getEntityClass();
        EntityMeta entityMeta = context.getEntityMeta();
        Set<String> clusteredFields = pm.forCache().extractClusteredFieldsIfNecessary();
        StatementCacheKey cacheKey = new StatementCacheKey(CacheType.SELECT_FIELD, clusteredFields, entityClass, noOptions());
        PreparedStatement ps = dynamicPSCache.getIfPresent(cacheKey);
        if (ps == null) {
            ps = generator.prepareSelectField(session, entityMeta, pm);
            dynamicPSCache.put(cacheKey, ps);
            displayCacheStatistics(dynamicPSCache);
        }
View Full Code Here

        Class<?> entityClass = context.getEntityClass();
        EntityMeta entityMeta = context.getEntityMeta();
        Set<String> fields = new HashSet<>(transform(pms, propertyExtractor));
        StatementCacheKey cacheKey = new StatementCacheKey(CacheType.INSERT, fields, entityClass, context.getOptions());
        PreparedStatement ps = dynamicPSCache.getIfPresent(cacheKey);
        if (ps == null) {
            ps = generator.prepareInsert(session, entityMeta, pms, context.getOptions());
            dynamicPSCache.put(cacheKey, ps);
            displayCacheStatistics(dynamicPSCache);
        }
View Full Code Here

        Class<?> entityClass = context.getEntityClass();
        EntityMeta entityMeta = context.getEntityMeta();
        Set<String> fields = new HashSet<>(transform(pms, propertyExtractor));
        StatementCacheKey cacheKey = new StatementCacheKey(CacheType.UPDATE_FIELDS, fields, entityClass, context.getOptions());
        PreparedStatement ps = dynamicPSCache.getIfPresent(cacheKey);
        if (ps == null) {
            ps = generator.prepareUpdateFields(session, entityMeta, pms, context.getOptions());
            dynamicPSCache.put(cacheKey, ps);
            displayCacheStatistics(dynamicPSCache);
        }
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.