@Override public Response getPropertiesValueById(String keyspaceName, String tableName, String id, String... properties) { long startTime = System.currentTimeMillis(); ProjectLogger.log("Cassandra Service getPropertiesValueById method started at ==" + startTime, LoggerEnum.PERF_LOG); Response response = new Response(); try { String selectQuery = CassandraUtil.getSelectStatement(keyspaceName, tableName, properties); PreparedStatement statement = connectionManager.getSession(keyspaceName).prepare(selectQuery); BoundStatement boundStatement = new BoundStatement(statement); ResultSet results = connectionManager.getSession(keyspaceName).execute(boundStatement.bind(id)); response = CassandraUtil.createResponse(results); } catch (Exception e) { ProjectLogger.log(Constants.EXCEPTION_MSG_FETCH + tableName + " : " + e.getMessage(), e); throw new ProjectCommonException(ResponseCode.SERVER_ERROR.getErrorCode(), ResponseCode.SERVER_ERROR.getErrorMessage(), ResponseCode.SERVER_ERROR.getResponseCode()); } long stopTime = System.currentTimeMillis(); long elapsedTime = stopTime - startTime; ProjectLogger.log("Cassandra Service getPropertiesValueById method end at ==" + stopTime + " ,Total time elapsed = " + elapsedTime, LoggerEnum.PERF_LOG); return response; }
/** * getBoundStatementInsert * @param userid * @param devicetoken * @param authcode * @param accesstoken * @param refreshtoken * @param ttl * @return Insert Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementInsert ( Object userid, Object devicetoken, Object authcode, Object accesstoken, Object refreshtoken, Object ttl) throws Exception { return this.getQuery(kInsertName).getBoundStatement( userid, devicetoken, authcode, accesstoken, refreshtoken, ttl); }
/** * Binds Ignite cache key and value object to {@link PreparedStatement}. * * @param statement statement to which key and value object should be bind. * @param key key object. * @param val value object. * @return statement with bounded key and value. */ public BoundStatement bindKeyValue(PreparedStatement statement, Object key, Object val) { KeyPersistenceSettings keySettings = persistenceSettings.getKeyPersistenceSettings(); Object[] keyValues = getBindingValues(keySettings.getStrategy(), keySettings.getSerializer(), keySettings.getFields(), key); ValuePersistenceSettings valSettings = persistenceSettings.getValuePersistenceSettings(); Object[] valValues = getBindingValues(valSettings.getStrategy(), valSettings.getSerializer(), valSettings.getFields(), val); Object[] values = new Object[keyValues.length + valValues.length]; int i = 0; for (Object keyVal : keyValues) { values[i] = keyVal; i++; } for (Object valVal : valValues) { values[i] = valVal; i++; } return statement.bind(values); }
/** * getBoundStatementInsert * @param airportcode * @param latitude * @param longitude * @param continent * @param continentcode * @param country * @param countrycode * @param city * @param populationinmillions * @param addedyearmonthday * @return Insert Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementInsert ( Object airportcode, Object latitude, Object longitude, Object continent, Object continentcode, Object country, Object countrycode, Object city, Object populationinmillions, Object addedyearmonthday) throws Exception { return this.getQuery(kInsertName).getBoundStatement( airportcode, latitude, longitude, continent, continentcode, country, countrycode, city, populationinmillions, addedyearmonthday); }
/** * getBoundStatementInsert * @param email * @param password * @param userid * @return Insert Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementInsert ( Object email, Object password, Object userid) throws Exception { return this.getQuery(kInsertName).getBoundStatement( email, password, userid); }
/** * getBoundStatementSelectTopSmallerThanOrEqualLimit * @param yearmonthdaycountrycode * @param rank * @return SelectTopSmallerThanOrEqualLimit Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementSelectTopSmallerThanOrEqualLimit ( Object yearmonthdaycountrycode, Object rank) throws Exception { return this.getQuery(kSelectTopSmallerThanOrEqualLimitName).getBoundStatement( yearmonthdaycountrycode, rank); }
/** * getBoundStatementSelectTopSmallerThanOrEqualLimit * @param yearweekgridid * @param rank * @return SelectTopSmallerThanOrEqualLimit Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementSelectTopSmallerThanOrEqualLimit ( Object yearweekgridid, Object rank) throws Exception { return this.getQuery(kSelectTopSmallerThanOrEqualLimitName).getBoundStatement( yearweekgridid, rank); }
/** * getBoundStatementDelete * @param postid * @param userid * @return Delete Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementDelete ( Object postid, Object userid) throws Exception { return this.getQuery(kDeleteName).getBoundStatement( postid, userid); }
@Override public Status insertMulti(List<TsPoint> points) { long costTime = 0L; if (points != null) { Cluster cluster = null; try { // cluster = Cluster.builder().addContactPoint(CASSADRA_URL).build(); // Session session = cluster.connect(KEY_SPACE_NAME); Session session = SessionManager.getSession(); BatchStatement batch = new BatchStatement(); PreparedStatement ps = session.prepare( "INSERT INTO " + TABLE_NAME + "(timestamp,device_code,sensor_code,value) VALUES(?,?,?,?)"); for (TsPoint point : points) { BoundStatement bs = ps.bind(new Date(point.getTimestamp()), point.getDeviceCode(), point.getSensorCode(), Double.parseDouble(point.getValue().toString())); batch.add(bs); } long startTime = System.nanoTime(); session.execute(batch); long endTime = System.nanoTime(); costTime = endTime - startTime; batch.clear(); // session.close(); } catch (Exception e) { e.printStackTrace(); } finally { if (cluster != null) cluster.close(); } } // System.out.println("costTime=" + costTime); return Status.OK(costTime); }
/** * getBoundStatementSelectAfter * @param yearmonthdayhourcontroller * @param logtime * @return SelectAfter Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementSelectAfter ( Object yearmonthdayhourcontroller, Object logtime) throws Exception { return this.getQuery(kSelectAfterName).getBoundStatement( yearmonthdayhourcontroller, logtime); }
/** * Override to change what data from the statement are parsed into the span representing it. By * default, this sets the span name to the lower-camel case type name and tags {@link * CassandraTraceKeys#CASSANDRA_KEYSPACE} and {@link CassandraTraceKeys#CASSANDRA_QUERY} for bound * statements. * * <p>If you only want to change the span name, you can override {@link #spanName(Statement)} * instead. * * @see #spanName(Statement) */ public void request(Statement statement, SpanCustomizer customizer) { customizer.name(spanName(statement)); String keyspace = statement.getKeyspace(); if (keyspace != null) { customizer.tag(CassandraTraceKeys.CASSANDRA_KEYSPACE, statement.getKeyspace()); } if (statement instanceof BoundStatement) { customizer.tag(CassandraTraceKeys.CASSANDRA_QUERY, ((BoundStatement) statement).preparedStatement().getQueryString()); } }
/** * getBoundStatementInsert * @param postid * @param userid * @param commenttime * @return Insert Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementInsert ( Object postid, Object userid, Object commenttime) throws Exception { return this.getQuery(kInsertName).getBoundStatement( postid, userid, commenttime); }
/** * getBoundStatementInsert * @param messageid * @param message * @return Insert Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementInsert ( Object messageid, Object message) throws Exception { return this.getQuery(kInsertName).getBoundStatement( messageid, message); }
/** * getBoundStatementDelete * @param userid * @param devicetoken * @return Delete Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementDelete ( Object userid, Object devicetoken) throws Exception { return this.getQuery(kDeleteName).getBoundStatement( userid, devicetoken); }
void execute(Function<Session, BoundStatement> statement) { try (Cluster cluster = Cluster.builder() .addContactPointsWithPorts(Collections.singleton(cassandra.contactPoint())) .build(); Session session = cluster.connect()) { session.execute(statement.apply(session)); } }
/** * getBoundStatementInsert * @param yearweekgridid * @param rank * @param userid * @return Insert Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementInsert ( Object yearweekgridid, Object rank, Object userid) throws Exception { return this.getQuery(kInsertName).getBoundStatement( yearweekgridid, rank, userid); }
/** * getBoundStatementSelectEqual * @param yearmonthday * @param registrationtime * @return SelectEqual Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementSelectEqual ( Object yearmonthday, Object registrationtime) throws Exception { return this.getQuery(kSelectEqualName).getBoundStatement( yearmonthday, registrationtime); }
@Override public ListenableFuture<Boolean> checkRelation(EntityId from, EntityId to, String relationType, RelationTypeGroup typeGroup) { BoundStatement stmt = getCheckRelationStmt().bind() .setUUID(0, from.getId()) .setString(1, from.getEntityType().name()) .setUUID(2, to.getId()) .setString(3, to.getEntityType().name()) .set(4, typeGroup, relationTypeGroupCodec) .setString(5, relationType); return getFuture(executeAsyncRead(stmt), rs -> rs != null ? rs.one() != null : false); }
/** * getBoundStatementSetLastLocation * @param lastlatitude * @param lastlongitude * @param userid * @return SetLastLocation Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementSetLastLocation ( Object lastlatitude, Object lastlongitude, Object userid) throws Exception { return this.getQuery(kSetLastLocationName).getBoundStatement( lastlatitude, lastlongitude, userid); }
/** * getBoundStatementSelectRecent * @param userid * @param messagetime * @return SelectRecent Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementSelectRecent ( Object userid, Object messagetime) throws Exception { return this.getQuery(kSelectRecentName).getBoundStatement( userid, messagetime); }
private void findAllAsyncSequentiallyWithLimit(final TsKvQueryCursor cursor, final SimpleListenableFuture<List<TsKvEntry>> resultFuture) { if (cursor.isFull() || !cursor.hasNextPartition()) { resultFuture.set(cursor.getData()); } else { PreparedStatement proto = getFetchStmt(Aggregation.NONE); BoundStatement stmt = proto.bind(); stmt.setString(0, cursor.getEntityType()); stmt.setUUID(1, cursor.getEntityId()); stmt.setString(2, cursor.getKey()); stmt.setLong(3, cursor.getNextPartition()); stmt.setLong(4, cursor.getStartTs()); stmt.setLong(5, cursor.getEndTs()); stmt.setInt(6, cursor.getCurrentLimit()); Futures.addCallback(executeAsyncRead(stmt), new FutureCallback<ResultSet>() { @Override public void onSuccess(@Nullable ResultSet result) { cursor.addData(convertResultToTsKvEntryList(result.all())); findAllAsyncSequentiallyWithLimit(cursor, resultFuture); } @Override public void onFailure(Throwable t) { log.error("[{}][{}] Failed to fetch data for query {}-{}", stmt, t); } }, readResultsProcessingExecutor); } }
/** * getBoundStatementUpdateLastActiveDate * @param lastactiveyearmonthday * @param yearmonthday * @param airportcode * @param seqid * @return UpdateLastActiveDate Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementUpdateLastActiveDate ( Object lastactiveyearmonthday, Object yearmonthday, Object airportcode, Object seqid) throws Exception { return this.getQuery(kUpdateLastActiveDateName).getBoundStatement( lastactiveyearmonthday, yearmonthday, airportcode, seqid); }
/** * getBoundStatementSelect * @param postid * @param userid * @return Select Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementSelect ( Object postid, Object userid) throws Exception { return this.getQuery(kSelectName).getBoundStatement( postid, userid); }
/** * getBoundStatementInsert * @param yearmonthday * @param registrationtime * @param userid * @return Insert Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementInsert ( Object yearmonthday, Object registrationtime, Object userid) throws Exception { return this.getQuery(kInsertName).getBoundStatement( yearmonthday, registrationtime, userid); }
/** * getBoundStatementSelectDuring * @param yearmonthdayhourcontroller * @param logtimestart * @param logtimeend * @return SelectDuring Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementSelectDuring ( Object yearmonthdayhourcontroller, Object logtimestart, Object logtimeend) throws Exception { return this.getQuery(kSelectDuringName).getBoundStatement( yearmonthdayhourcontroller, logtimestart, logtimeend); }
/** * getBoundStatementInsert * @param userid * @param followeruserid * @param followertime * @return Insert Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementInsert ( Object userid, Object followeruserid, Object followertime) throws Exception { return this.getQuery(kInsertName).getBoundStatement( userid, followeruserid, followertime); }
/** * getBoundStatementInsert * @param yearmonthdaygridid * @param rank * @param postid * @return Insert Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementInsert ( Object yearmonthdaygridid, Object rank, Object postid) throws Exception { return this.getQuery(kInsertName).getBoundStatement( yearmonthdaygridid, rank, postid); }
/** {@inheritDoc} */ @Override public void fetchAllKeys(String cacheName, Metadata metadata, final IgniteInClosure<Object> action) throws CacheLoaderException { final PersistenceController ctrl = settings.get(cacheName, metadata); CassandraSession ses = session(); try { ses.executeAllRows(new GenericExecutionAssistant<Void>(false, "READ ALL KEYS") { @Override public String getStatement() { return ctrl.getLoadStatement(true, false, false); } @Override public BoundStatement bindStatement(PreparedStatement statement) { return new BoundStatement(statement); } @Override public KeyValuePersistenceSettings getPersistenceSettings() { return ctrl.getPersistenceSettings(); } @Override public Void process(Row row) { action.apply(ctrl.buildKeyObject(row)); return null; } }); } finally { U.closeQuiet(ses); } }
/** * getBoundStatementSelectDuring * @param yearmonthdayuserid * @param logtimestart * @param logtimeend * @return SelectDuring Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementSelectDuring ( Object yearmonthdayuserid, Object logtimestart, Object logtimeend) throws Exception { return this.getQuery(kSelectDuringName).getBoundStatement( yearmonthdayuserid, logtimestart, logtimeend); }
/** * getBoundStatementInsert * @param yearmonthday * @param airportcode * @param seqid * @param postid * @return Insert Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementInsert ( Object yearmonthday, Object airportcode, Object seqid, Object postid) throws Exception { return this.getQuery(kInsertName).getBoundStatement( yearmonthday, airportcode, seqid, postid); }
/** * getBoundStatementSelectAtOrBeforeTimeLimit * @param userid * @param posttime * @return SelectAtOrBeforeTimeLimit Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementSelectAtOrBeforeTimeLimit ( Object userid, Object posttime) throws Exception { return this.getQuery(kSelectAtOrBeforeTimeLimitName).getBoundStatement( userid, posttime); }
/** * getBoundStatementSelectTopSmallerThanOrEqualLimit * @param yearmonthday * @param rank * @return SelectTopSmallerThanOrEqualLimit Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementSelectTopSmallerThanOrEqualLimit ( Object yearmonthday, Object rank) throws Exception { return this.getQuery(kSelectTopSmallerThanOrEqualLimitName).getBoundStatement( yearmonthday, rank); }
/** * getBoundStatementSelectTopSmallerThanLimit * @param yearmonthday * @param rank * @return SelectTopSmallerThanLimit Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementSelectTopSmallerThanLimit ( Object yearmonthday, Object rank) throws Exception { return this.getQuery(kSelectTopSmallerThanLimitName).getBoundStatement( yearmonthday, rank); }
/** * getBoundStatementSelectAtOrBeforeTimeLimit * @param userid * @param followingtime * @return SelectAtOrBeforeTimeLimit Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementSelectAtOrBeforeTimeLimit ( Object userid, Object followingtime) throws Exception { return this.getQuery(kSelectAtOrBeforeTimeLimitName).getBoundStatement( userid, followingtime); }
/** * getBoundStatementIncrementBadRequestResponses * @param runtimemilliseconds * @param yearmonthdayhourcontroller * @return IncrementBadRequestResponses Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementIncrementBadRequestResponses ( Object runtimemilliseconds, Object yearmonthdayhourcontroller) throws Exception { return this.getQuery(kIncrementBadRequestResponsesName).getBoundStatement( runtimemilliseconds, yearmonthdayhourcontroller); }
/** * getBoundStatementSelectBefore * @param yearmonthdayuserid * @param logtime * @return SelectBefore Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementSelectBefore ( Object yearmonthdayuserid, Object logtime) throws Exception { return this.getQuery(kSelectBeforeName).getBoundStatement( yearmonthdayuserid, logtime); }
/** * getBoundStatementIncrementOkResponses * @param runtimemilliseconds * @param yearmonthdayhourcontroller * @return IncrementOkResponses Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementIncrementOkResponses ( Object runtimemilliseconds, Object yearmonthdayhourcontroller) throws Exception { return this.getQuery(kIncrementOkResponsesName).getBoundStatement( runtimemilliseconds, yearmonthdayhourcontroller); }
/** * getBoundStatementInsert * @param pictureid * @param picture * @return Insert Query in the form of * a BoundStatement ready for execution or to be added to * a BatchStatement * @throws Exception */ public BoundStatement getBoundStatementInsert ( Object pictureid, Object picture) throws Exception { return this.getQuery(kInsertName).getBoundStatement( pictureid, picture); }