Search in sources :

Example 41 with BoundStatement

use of com.datastax.driver.core.BoundStatement in project pinpoint by naver.

the class CassandraStatementExecuteQueryInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    SpanEventRecorder recorder = trace.traceBlockBegin();
    try {
        DatabaseInfo databaseInfo = (target instanceof DatabaseInfoAccessor) ? ((DatabaseInfoAccessor) target)._$PINPOINT$_getDatabaseInfo() : null;
        if (databaseInfo == null) {
            databaseInfo = UnKnownDatabaseInfo.INSTANCE;
        }
        recorder.recordServiceType(databaseInfo.getExecuteQueryType());
        recorder.recordEndPoint(databaseInfo.getMultipleHost());
        recorder.recordDestinationId(databaseInfo.getDatabaseId());
        String sql;
        if (args[0] instanceof BoundStatement) {
            sql = ((BoundStatement) args[0]).preparedStatement().getQueryString();
        } else if (args[0] instanceof RegularStatement) {
            sql = ((RegularStatement) args[0]).getQueryString();
        } else {
            // we have string
            sql = (String) args[0];
        }
        ParsingResult parsingResult = traceContext.parseSql(sql);
        if (parsingResult != null) {
            ((ParsingResultAccessor) target)._$PINPOINT$_setParsingResult(parsingResult);
        } else {
            if (logger.isErrorEnabled()) {
                logger.error("sqlParsing fail. parsingResult is null sql:{}", sql);
            }
        }
        Map<Integer, String> bindValue = ((BindValueAccessor) target)._$PINPOINT$_getBindValue();
        // Extracting bind variables from already-serialized is too risky
        if (bindValue != null && !bindValue.isEmpty()) {
            String bindString = toBindVariable(bindValue);
            recorder.recordSqlParsingResult(parsingResult, bindString);
        } else {
            recorder.recordSqlParsingResult(parsingResult);
        }
        recorder.recordApi(descriptor);
        clean(target);
    } catch (Exception e) {
        if (logger.isWarnEnabled()) {
            logger.warn(e.getMessage(), e);
        }
    }
}
Also used : UnKnownDatabaseInfo(com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo) DatabaseInfo(com.navercorp.pinpoint.bootstrap.context.DatabaseInfo) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) DatabaseInfoAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor) BindValueAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor) ParsingResultAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor) RegularStatement(com.datastax.driver.core.RegularStatement) Trace(com.navercorp.pinpoint.bootstrap.context.Trace) ParsingResult(com.navercorp.pinpoint.bootstrap.context.ParsingResult) BoundStatement(com.datastax.driver.core.BoundStatement)

Example 42 with BoundStatement

use of com.datastax.driver.core.BoundStatement in project cas by apereo.

the class DefaultCassandraRepository method bind.

private static BoundStatement bind(final PreparedStatement statement, final Object... params) {
    final BoundStatement boundStatement = statement.bind(params);
    LOGGER.debug("CQL: {} with parameters [{}]", statement.getQueryString(), StringUtils.join(params, ", "));
    return boundStatement;
}
Also used : BoundStatement(com.datastax.driver.core.BoundStatement)

Example 43 with BoundStatement

use of com.datastax.driver.core.BoundStatement in project apex-malhar by apache.

the class CassandraPOJOOutputOperator method setStatementParameters.

@Override
@SuppressWarnings("unchecked")
protected Statement setStatementParameters(PreparedStatement updateCommand, Object tuple) throws DriverException {
    final BoundStatement boundStmnt = new BoundStatement(updateCommand);
    final int size = columnDataTypes.size();
    for (int i = 0; i < size; i++) {
        final DataType type = columnDataTypes.get(i);
        switch(type.getName()) {
            case UUID:
                final UUID id = ((Getter<Object, UUID>) getters.get(i)).get(tuple);
                boundStmnt.setUUID(i, id);
                break;
            case ASCII:
            case VARCHAR:
            case TEXT:
                final String ascii = ((Getter<Object, String>) getters.get(i)).get(tuple);
                boundStmnt.setString(i, ascii);
                break;
            case BOOLEAN:
                final boolean bool = ((GetterBoolean<Object>) getters.get(i)).get(tuple);
                boundStmnt.setBool(i, bool);
                break;
            case INT:
                final int intValue = ((GetterInt<Object>) getters.get(i)).get(tuple);
                boundStmnt.setInt(i, intValue);
                break;
            case BIGINT:
            case COUNTER:
                final long longValue = ((GetterLong<Object>) getters.get(i)).get(tuple);
                boundStmnt.setLong(i, longValue);
                break;
            case FLOAT:
                final float floatValue = ((GetterFloat<Object>) getters.get(i)).get(tuple);
                boundStmnt.setFloat(i, floatValue);
                break;
            case DOUBLE:
                final double doubleValue = ((GetterDouble<Object>) getters.get(i)).get(tuple);
                boundStmnt.setDouble(i, doubleValue);
                break;
            case DECIMAL:
                final BigDecimal decimal = ((Getter<Object, BigDecimal>) getters.get(i)).get(tuple);
                boundStmnt.setDecimal(i, decimal);
                break;
            case SET:
                Set<?> set = ((Getter<Object, Set<?>>) getters.get(i)).get(tuple);
                boundStmnt.setSet(i, set);
                break;
            case MAP:
                final Map<?, ?> map = ((Getter<Object, Map<?, ?>>) getters.get(i)).get(tuple);
                boundStmnt.setMap(i, map);
                break;
            case LIST:
                final List<?> list = ((Getter<Object, List<?>>) getters.get(i)).get(tuple);
                boundStmnt.setList(i, list);
                break;
            case TIMESTAMP:
                final Date date = ((Getter<Object, Date>) getters.get(i)).get(tuple);
                boundStmnt.setDate(i, LocalDate.fromMillisSinceEpoch(date.getTime()));
                break;
            default:
                throw new RuntimeException("unsupported data type " + type.getName());
        }
    }
    return boundStmnt;
}
Also used : Getter(org.apache.apex.malhar.lib.util.PojoUtils.Getter) GetterFloat(org.apache.apex.malhar.lib.util.PojoUtils.GetterFloat) BigDecimal(java.math.BigDecimal) Date(java.util.Date) LocalDate(com.datastax.driver.core.LocalDate) GetterBoolean(org.apache.apex.malhar.lib.util.PojoUtils.GetterBoolean) DataType(com.datastax.driver.core.DataType) GetterLong(org.apache.apex.malhar.lib.util.PojoUtils.GetterLong) UUID(java.util.UUID) BoundStatement(com.datastax.driver.core.BoundStatement) GetterInt(org.apache.apex.malhar.lib.util.PojoUtils.GetterInt) GetterDouble(org.apache.apex.malhar.lib.util.PojoUtils.GetterDouble)

Example 44 with BoundStatement

use of com.datastax.driver.core.BoundStatement in project apex-malhar by apache.

the class CassandraTransactionalStore method getCommittedWindowId.

@Override
public long getCommittedWindowId(String appId, int operatorId) {
    try {
        BoundStatement boundStatement = new BoundStatement(lastWindowFetchCommand);
        lastWindowFetchStatement = boundStatement.bind(appId, operatorId);
        long lastWindow = -1;
        ResultSet resultSet = session.execute(lastWindowFetchStatement);
        if (!resultSet.isExhausted()) {
            lastWindow = resultSet.one().getLong(0);
        }
        lastWindowFetchCommand.disableTracing();
        return lastWindow;
    } catch (DriverException ex) {
        throw new RuntimeException(ex);
    }
}
Also used : ResultSet(com.datastax.driver.core.ResultSet) DriverException(com.datastax.driver.core.exceptions.DriverException) BoundStatement(com.datastax.driver.core.BoundStatement)

Example 45 with BoundStatement

use of com.datastax.driver.core.BoundStatement in project apex-malhar by apache.

the class CassandraTransactionalStore method removeCommittedWindowId.

@Override
public void removeCommittedWindowId(String appId, int operatorId) {
    try {
        BoundStatement boundStatement = new BoundStatement(lastWindowDeleteCommand);
        lastWindowDeleteStatement = boundStatement.bind(appId, operatorId);
        session.execute(lastWindowDeleteStatement);
        lastWindowDeleteCommand.disableTracing();
    } catch (DriverException e) {
        throw new RuntimeException(e);
    }
}
Also used : DriverException(com.datastax.driver.core.exceptions.DriverException) BoundStatement(com.datastax.driver.core.BoundStatement)

Aggregations

BoundStatement (com.datastax.driver.core.BoundStatement)48 ResultSet (com.datastax.driver.core.ResultSet)9 PreparedStatement (com.datastax.driver.core.PreparedStatement)6 ResultSetFuture (com.datastax.driver.core.ResultSetFuture)5 Row (com.datastax.driver.core.Row)5 Test (org.junit.Test)5 ArrayList (java.util.ArrayList)4 RegularStatement (com.datastax.driver.core.RegularStatement)3 Session (com.datastax.driver.core.Session)3 DriverException (com.datastax.driver.core.exceptions.DriverException)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)3 List (java.util.List)3 Map (java.util.Map)3 UUID (java.util.UUID)3 MetricRegistry (com.codahale.metrics.MetricRegistry)2 DataType (com.datastax.driver.core.DataType)2 Statement (com.datastax.driver.core.Statement)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Futures.allAsList (com.google.common.util.concurrent.Futures.allAsList)2