當前位置: 首頁>>代碼示例>>Java>>正文


Java QueryBuilder.batch方法代碼示例

本文整理匯總了Java中com.datastax.driver.core.querybuilder.QueryBuilder.batch方法的典型用法代碼示例。如果您正苦於以下問題:Java QueryBuilder.batch方法的具體用法?Java QueryBuilder.batch怎麽用?Java QueryBuilder.batch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.datastax.driver.core.querybuilder.QueryBuilder的用法示例。


在下文中一共展示了QueryBuilder.batch方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: removeAccessTokenUsingRefreshToken

import com.datastax.driver.core.querybuilder.QueryBuilder; //導入方法依賴的package包/類
@Override
public void removeAccessTokenUsingRefreshToken(OAuth2RefreshToken refreshToken) {
  String tokenValue = refreshToken.getValue();
  // Lookup RefreshTokenToAccessToken table for locating access token
  RefreshTokenToAccessToken refreshTokenToAccessToken = refreshTokenToAccessTokenRepository.findOne(tokenValue);
  if (refreshTokenToAccessToken != null) {
    String accessTokenKey = refreshTokenToAccessToken.getAccessTokenKey();
    AccessToken accessToken = accessTokenRepository.findOne(accessTokenKey);
    String jsonOAuth2AccessToken = accessToken.getoAuth2AccessToken();
    OAuth2AccessToken oAuth2AccessToken = OAuthUtil.deserializeOAuth2AccessToken(jsonOAuth2AccessToken);
    // Delete access token from all related tables
    List<RegularStatement> statementList = prepareRemoveAccessTokenStatements(oAuth2AccessToken);
    // Delete from RefreshTokenToAccessToken table
    Delete refreshTokenToAccessTokenDelete = CassandraTemplate.createDeleteQuery(RefreshTokenToAccessToken.TABLE, refreshTokenToAccessToken, null, cassandraTemplate.getConverter());
    statementList.add(refreshTokenToAccessTokenDelete);
    Batch batch = QueryBuilder.batch(statementList.toArray(new RegularStatement[statementList.size()]));
    cassandraTemplate.execute(batch);
  }
}
 
開發者ID:Mert-Z,項目名稱:spring-oauth2-cassandra-token-store,代碼行數:20,代碼來源:CassandraTokenStore.java

示例2: runBatchInsert

import com.datastax.driver.core.querybuilder.QueryBuilder; //導入方法依賴的package包/類
private void runBatchInsert(List<Insert> insertRequest) {
    try {
        Batch batch;
        if (config.getLoggedBatch()) {
            batch = QueryBuilder.batch(insertRequest
                    .toArray(new RegularStatement[insertRequest.size()]));
        } else {
            batch = QueryBuilder.unloggedBatch(insertRequest
                    .toArray(new RegularStatement[insertRequest.size()]));
        }
        totalCassandraInsertRequest.addAndGet(insertRequest.size());
        ResultSetFuture future = cassandraSession.executeAsync(batch);
        CallBackListener listener = new CallBackListener(future, null);
        future.addListener(listener, pool);
        incrementBatchInsertCounter();
        pendingRequestCounter.incrementAndGet();
    } catch (Throwable ex) {
        LOGGER.error("Error publising metrics in MetricCassandraCollector:" + ex.getMessage());
        cassandraErrorCount.increment();
        registerError(ex);
    } finally {
        insertRequest.clear();
    }
}
 
開發者ID:pulsarIO,項目名稱:realtime-analytics,代碼行數:25,代碼來源:MetricCassandraCollector.java

示例3: runBatchUpdate

import com.datastax.driver.core.querybuilder.QueryBuilder; //導入方法依賴的package包/類
private void runBatchUpdate(List<Update> updateRequest) {
    try {
        Batch batch;

        if (config.getLoggedBatch()) {
            batch = QueryBuilder.batch(updateRequest
                    .toArray(new RegularStatement[updateRequest.size()]));
        } else {
            batch = QueryBuilder.unloggedBatch(updateRequest
                    .toArray(new RegularStatement[updateRequest.size()]));
        }
        totalCassandraUpdateRequest.addAndGet(updateRequest.size());
        ResultSetFuture future = cassandraSession.executeAsync(batch);
        CallBackListener listener = new CallBackListener(future, null);
        future.addListener(listener, pool);
        incrementBatchUpdateCounter();
        pendingRequestCounter.incrementAndGet();
    } catch (Throwable ex) {
        LOGGER.error("Error publising metrics in MetricCassandraCollector:" + ex.getMessage());
        cassandraErrorCount.increment();
        registerError(ex);
    } finally {
        updateRequest.clear();
    }
}
 
開發者ID:pulsarIO,項目名稱:realtime-analytics,代碼行數:26,代碼來源:MetricCassandraCollector.java

示例4: deleteAcls

import com.datastax.driver.core.querybuilder.QueryBuilder; //導入方法依賴的package包/類
public void deleteAcls(List<AclObjectIdentity> objectIdsToDelete) {
	assertAclObjectIdentityList(objectIdsToDelete);

	if (LOG.isDebugEnabled()) {
		LOG.debug("BEGIN deleteAcls: objectIdsToDelete: " + objectIdsToDelete);
	}

	List<String> ids = new ArrayList<String>();
	for (AclObjectIdentity entry : objectIdsToDelete) {
		ids.add(entry.getRowId());
	}
	Batch batch = QueryBuilder.batch();
	batch.add(QueryBuilder.delete().all().from(KEYSPACE, AOI_TABLE).where(QueryBuilder.in("id", ids.toArray())));
	batch.add(QueryBuilder.delete().all().from(KEYSPACE, CHILDREN_TABLE).where(QueryBuilder.in("id", ids.toArray())));
	session.execute(batch);
	
	if (LOG.isDebugEnabled()) {
		LOG.debug("END deleteAcls");
	}
}
 
開發者ID:RigasGrigoropoulos,項目名稱:spring-security-acl-cassandra,代碼行數:21,代碼來源:CassandraAclRepositoryImpl.java

示例5: saveAcl

import com.datastax.driver.core.querybuilder.QueryBuilder; //導入方法依賴的package包/類
public void saveAcl(AclObjectIdentity aoi) throws AclAlreadyExistsException {
	assertAclObjectIdentity(aoi);

	if (LOG.isDebugEnabled()) {
		LOG.debug("BEGIN saveAcl: aclObjectIdentity: " + aoi);
	}

	// Check this object identity hasn't already been persisted
	if (findAclObjectIdentity(aoi) != null) {
		throw new AclAlreadyExistsException("Object identity '" + aoi + "' already exists");
	}
	
	Batch batch = QueryBuilder.batch();
	batch.add(QueryBuilder.insertInto(KEYSPACE, AOI_TABLE).values(AOI_KEYS, new Object[] { aoi.getRowId(), aoi.getId(), aoi.getObjectClass(), aoi.isEntriesInheriting(),
			aoi.getOwnerId(), aoi.isOwnerPrincipal(), aoi.getParentObjectId(), aoi.getParentObjectClass() }));
	
	if (aoi.getParentRowId() != null) {
		batch.add(QueryBuilder.insertInto(KEYSPACE, CHILDREN_TABLE).values(CHILD_KEYS, new Object[] { aoi.getParentRowId(), aoi.getRowId(), aoi.getId(), aoi.getObjectClass() }));
	}
	session.execute(batch);
	
	if (LOG.isDebugEnabled()) {
		LOG.debug("END saveAcl");
	}
}
 
開發者ID:RigasGrigoropoulos,項目名稱:spring-security-acl-cassandra,代碼行數:26,代碼來源:CassandraAclRepositoryImpl.java

示例6: storeRefreshToken

import com.datastax.driver.core.querybuilder.QueryBuilder; //導入方法依賴的package包/類
@Override
public void storeRefreshToken(OAuth2RefreshToken refreshToken, OAuth2Authentication authentication) {
  List<RegularStatement> statementList = new ArrayList<RegularStatement>();

  byte[] serializedRefreshToken = SerializationUtils.serialize(refreshToken);
  ByteBuffer bufferedRefreshToken = ByteBuffer.wrap(serializedRefreshToken);

  byte[] serializedAuthentication = SerializationUtils.serialize(authentication);
  ByteBuffer bufferedAuthentication = ByteBuffer.wrap(serializedAuthentication);

  WriteOptions refreshWriteOptions = new WriteOptions();
  if (refreshToken instanceof ExpiringOAuth2RefreshToken) {
    ExpiringOAuth2RefreshToken expiringRefreshToken = (ExpiringOAuth2RefreshToken) refreshToken;
    Date expiration = expiringRefreshToken.getExpiration();
    if (expiration != null) {
      int seconds = Long.valueOf((expiration.getTime() - System.currentTimeMillis()) / 1000L).intValue();
      refreshWriteOptions.setTtl(seconds);
    }
  }

  // Insert into RefreshToken table
  Insert accessInsert = CassandraTemplate.createInsertQuery(RefreshToken.TABLE, new RefreshToken(refreshToken.getValue(), bufferedRefreshToken), refreshWriteOptions, cassandraTemplate.getConverter());
  statementList.add(accessInsert);

  // Insert into RefreshTokenAuthentication table
  Insert authInsert = CassandraTemplate.createInsertQuery(RefreshTokenAuthentication.TABLE, new RefreshTokenAuthentication(refreshToken.getValue(), bufferedAuthentication), refreshWriteOptions, cassandraTemplate.getConverter());
  statementList.add(authInsert);

  Batch batch = QueryBuilder.batch(statementList.toArray(new RegularStatement[statementList.size()]));
  cassandraTemplate.execute(batch);
}
 
開發者ID:Mert-Z,項目名稱:spring-oauth2-cassandra-token-store,代碼行數:32,代碼來源:CassandraTokenStore.java

示例7: removeRefreshToken

import com.datastax.driver.core.querybuilder.QueryBuilder; //導入方法依賴的package包/類
@Override
public void removeRefreshToken(OAuth2RefreshToken token) {
  String tokenValue = token.getValue();
  List<RegularStatement> statementList = new ArrayList<RegularStatement>();
  // Delete from RefreshToken table
  statementList.add(prepareDeleteByPrimaryKeyRegularStatement(RefreshToken.class, tokenValue));
  // Delete from RefreshTokenAuthentication table
  statementList.add(prepareDeleteByPrimaryKeyRegularStatement(RefreshTokenAuthentication.class, tokenValue));
  // Delete from RefreshTokenToAccessToken table
  statementList.add(prepareDeleteByPrimaryKeyRegularStatement(RefreshTokenToAccessToken.class, tokenValue));
  Batch batch = QueryBuilder.batch(statementList.toArray(new RegularStatement[statementList.size()]));
  cassandraTemplate.execute(batch);
}
 
開發者ID:Mert-Z,項目名稱:spring-oauth2-cassandra-token-store,代碼行數:14,代碼來源:CassandraTokenStore.java

示例8: doCql3SaveToCassandra

import com.datastax.driver.core.querybuilder.QueryBuilder; //導入方法依賴的package包/類
public static <W> void doCql3SaveToCassandra(RDD<W> rdd, ICassandraDeepJobConfig<W> writeConfig,
                                             Function1<W, Tuple2<Cells, Cells>> transformer) {
    if (!writeConfig.getIsWriteConfig()) {
        throw new IllegalArgumentException("Provided configuration object is not suitable for writing");
    }
    Tuple2<Map<String, ByteBuffer>, Map<String, ByteBuffer>> tuple = new Tuple2<>(null, null);

    RDD<Tuple2<Cells, Cells>> mappedRDD = rdd.map(transformer,
            ClassTag$.MODULE$.<Tuple2<Cells, Cells>>apply(tuple.getClass()));

    ((CassandraDeepJobConfig) writeConfig).createOutputTableIfNeeded(mappedRDD.first());

    final int pageSize = writeConfig.getBatchSize();
    int offset = 0;

    List<Tuple2<Cells, Cells>> elements = Arrays.asList((Tuple2<Cells, Cells>[]) mappedRDD.collect());
    List<Tuple2<Cells, Cells>> split;
    do {
        split = elements.subList(pageSize * (offset++), Math.min(pageSize * offset, elements.size()));

        Batch batch = QueryBuilder.batch();

        for (Tuple2<Cells, Cells> t : split) {
            Tuple2<String[], Object[]> bindVars = Utils.prepareTuple4CqlDriver(t);

            Insert insert = QueryBuilder
                    .insertInto(quote(writeConfig.getKeyspace()), quote(writeConfig.getTable()))
                    .values(bindVars._1(), bindVars._2());

            batch.add(insert);
        }
        writeConfig.getSession().execute(batch);

    } while (!split.isEmpty() && split.size() == pageSize);
}
 
開發者ID:Stratio,項目名稱:deep-spark,代碼行數:36,代碼來源:CassandraUtils.java

示例9: prepareBatch

import com.datastax.driver.core.querybuilder.QueryBuilder; //導入方法依賴的package包/類
private Batch prepareBatch(RegularStatement... statement) {
  Batch batch;
  if (batchType != null && batchType.equals(CassandraBatchType.UNLOGGED)) {
    batch = QueryBuilder.unloggedBatch(statement);
  } else {
    batch = QueryBuilder.batch(statement);
  }
  batch.setConsistencyLevel(getWriteConsistencyLevel());
  return batch;
}
 
開發者ID:kaaproject,項目名稱:kaa,代碼行數:11,代碼來源:CassandraLogEventDao.java

示例10: removeAccessToken

import com.datastax.driver.core.querybuilder.QueryBuilder; //導入方法依賴的package包/類
@Override
public void removeAccessToken(OAuth2AccessToken token) {
  List<RegularStatement> statementList = prepareRemoveAccessTokenStatements(token);
  Batch batch = QueryBuilder.batch(statementList.toArray(new RegularStatement[statementList.size()]));
  cassandraTemplate.execute(batch);
}
 
開發者ID:Mert-Z,項目名稱:spring-oauth2-cassandra-token-store,代碼行數:7,代碼來源:CassandraTokenStore.java

示例11: updateAcl

import com.datastax.driver.core.querybuilder.QueryBuilder; //導入方法依賴的package包/類
public void updateAcl(AclObjectIdentity aoi, List<AclEntry> entries) throws AclNotFoundException {
	assertAclObjectIdentity(aoi);

	if (LOG.isDebugEnabled()) {
		LOG.debug("BEGIN updateAcl: aclObjectIdentity: " + aoi + ", entries: " + entries);
	}

	// Check this object identity is already persisted
	AclObjectIdentity persistedAoi = findAclObjectIdentity(aoi);
	if (persistedAoi == null) {
		throw new AclNotFoundException("Object identity '" + aoi + "' does not exist");
	}
	
	// Update AOI & delete existing ACLs
	Batch batch = QueryBuilder.batch();
	batch.add(QueryBuilder.insertInto(KEYSPACE, AOI_TABLE).values(AOI_KEYS, new Object[] { aoi.getRowId(), aoi.getId(), aoi.getObjectClass(), aoi.isEntriesInheriting(),
			aoi.getOwnerId(), aoi.isOwnerPrincipal(), aoi.getParentObjectId(), aoi.getParentObjectClass() }));
	batch.add(QueryBuilder.delete().all().from(KEYSPACE, ACL_TABLE).where(QueryBuilder.eq("id", aoi.getRowId())));

	// Check if parent is different and delete from children table
	boolean parentChanged = false;
	if (!(persistedAoi.getParentRowId() == null ? aoi.getParentRowId() == null : persistedAoi.getParentRowId().equals(aoi.getParentRowId()))) {
		parentChanged = true;
		
		if (persistedAoi.getParentRowId() != null) {
			batch.add(QueryBuilder.delete().all().from(KEYSPACE, CHILDREN_TABLE).where(QueryBuilder.eq("id", persistedAoi.getParentRowId())).and(QueryBuilder.eq("childId", aoi.getRowId())));
		}			
	}
	session.execute(batch);
	
	// Update ACLs & children table	
	batch = QueryBuilder.batch();
	boolean executeBatch = false;
	
	if (entries != null && !entries.isEmpty()) {
		for (AclEntry entry : entries) {
			batch.add(QueryBuilder.insertInto(KEYSPACE, ACL_TABLE).values(ACL_KEYS, new Object[] { aoi.getRowId(), entry.getOrder(), entry.getSid(), entry.getMask(), entry.isSidPrincipal(),
					entry.isGranting(), entry.isAuditSuccess(), entry.isAuditFailure() }));
		}
		executeBatch = true;
	}		
	if (parentChanged) {
		if (aoi.getParentRowId() != null) {
			batch.add(QueryBuilder.insertInto(KEYSPACE, CHILDREN_TABLE).values(CHILD_KEYS, new Object[] { aoi.getParentRowId(), aoi.getRowId(), aoi.getId(), aoi.getObjectClass() }));
		}
		executeBatch = true;
	}
	if (executeBatch) {
		session.execute(batch);
	}		

	if (LOG.isDebugEnabled()) {
		LOG.debug("END updateAcl");
	}
}
 
開發者ID:RigasGrigoropoulos,項目名稱:spring-security-acl-cassandra,代碼行數:56,代碼來源:CassandraAclRepositoryImpl.java


注:本文中的com.datastax.driver.core.querybuilder.QueryBuilder.batch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。