当前位置: 首页>>代码示例>>Java>>正文


Java PrepareSqlRequest类代码示例

本文整理汇总了Java中org.apache.kylin.rest.request.PrepareSqlRequest的典型用法代码示例。如果您正苦于以下问题:Java PrepareSqlRequest类的具体用法?Java PrepareSqlRequest怎么用?Java PrepareSqlRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


PrepareSqlRequest类属于org.apache.kylin.rest.request包,在下文中一共展示了PrepareSqlRequest类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: prepareQuery

import org.apache.kylin.rest.request.PrepareSqlRequest; //导入依赖的package包/类
@RequestMapping(value = "/query/prestate", method = RequestMethod.POST, produces = "application/json")
@ResponseBody
@Timed(name = "query")
public SQLResponse prepareQuery(@RequestBody PrepareSqlRequest sqlRequest) {
    long startTimestamp = System.currentTimeMillis();

    SQLResponse response = doQuery(sqlRequest);
    response.setDuration(System.currentTimeMillis() - startTimestamp);

    queryService.logQuery(sqlRequest, response, new Date(startTimestamp), new Date(System.currentTimeMillis()));

    if (response.getIsException()) {
        String errorMsg = response.getExceptionMessage();
        throw new InternalErrorException(QueryUtil.makeErrorMsgUserFriendly(errorMsg));
    }

    return response;
}
 
开发者ID:KylinOLAP,项目名称:Kylin,代码行数:19,代码来源:QueryController.java

示例2: testQueryException

import org.apache.kylin.rest.request.PrepareSqlRequest; //导入依赖的package包/类
@Test(expected = Exception.class)
public void testQueryException() throws Exception {
    PrepareSqlRequest sqlRequest = new PrepareSqlRequest();
    sqlRequest.setSql("select * from not_exist_table");
    sqlRequest.setProject("default");
    SQLResponse response1 = queryController.query(sqlRequest);
    Assert.assertEquals(false, response1.getIsException());

    SQLResponse response2 = queryController.query(sqlRequest);
    Assert.assertEquals(false, response2.getIsException());
}
 
开发者ID:apache,项目名称:kylin,代码行数:12,代码来源:QueryControllerTest.java

示例3: prepareQuery

import org.apache.kylin.rest.request.PrepareSqlRequest; //导入依赖的package包/类
@RequestMapping(value = "/query/prestate", method = RequestMethod.POST, produces = "application/json")
@ResponseBody
public SQLResponse prepareQuery(@RequestBody PrepareSqlRequest sqlRequest) {
    Map<String, String> newToggles = Maps.newHashMap();
    if (sqlRequest.getBackdoorToggles() != null)
        newToggles.putAll(sqlRequest.getBackdoorToggles());
    newToggles.put(BackdoorToggles.DEBUG_TOGGLE_PREPARE_ONLY, "true");
    sqlRequest.setBackdoorToggles(newToggles);

    return queryService.doQueryWithCache(sqlRequest);
}
 
开发者ID:apache,项目名称:kylin,代码行数:12,代码来源:QueryController.java

示例4: query

import org.apache.kylin.rest.request.PrepareSqlRequest; //导入依赖的package包/类
@RequestMapping(value = "/query", method = RequestMethod.POST, produces = { "application/json" })
@ResponseBody
public SQLResponse query(@RequestBody PrepareSqlRequest sqlRequest) {
    return queryService.doQueryWithCache(sqlRequest);
}
 
开发者ID:apache,项目名称:kylin,代码行数:6,代码来源:QueryController.java

示例5: isPrepareStatementWithParams

import org.apache.kylin.rest.request.PrepareSqlRequest; //导入依赖的package包/类
private boolean isPrepareStatementWithParams(SQLRequest sqlRequest) {
    if (sqlRequest instanceof PrepareSqlRequest && ((PrepareSqlRequest) sqlRequest).getParams() != null
            && ((PrepareSqlRequest) sqlRequest).getParams().length > 0)
        return true;
    return false;
}
 
开发者ID:apache,项目名称:kylin,代码行数:7,代码来源:QueryService.java

示例6: setParam

import org.apache.kylin.rest.request.PrepareSqlRequest; //导入依赖的package包/类
/**
 * @param preparedState
 * @param param
 * @throws SQLException
 */
private void setParam(PreparedStatement preparedState, int index, PrepareSqlRequest.StateParam param)
        throws SQLException {
    boolean isNull = (null == param.getValue());

    Class<?> clazz;
    try {
        clazz = Class.forName(param.getClassName());
    } catch (ClassNotFoundException e) {
        throw new InternalErrorException(e);
    }

    Rep rep = Rep.of(clazz);

    switch (rep) {
    case PRIMITIVE_CHAR:
    case CHARACTER:
    case STRING:
        preparedState.setString(index, isNull ? null : String.valueOf(param.getValue()));
        break;
    case PRIMITIVE_INT:
    case INTEGER:
        preparedState.setInt(index, isNull ? 0 : Integer.valueOf(param.getValue()));
        break;
    case PRIMITIVE_SHORT:
    case SHORT:
        preparedState.setShort(index, isNull ? 0 : Short.valueOf(param.getValue()));
        break;
    case PRIMITIVE_LONG:
    case LONG:
        preparedState.setLong(index, isNull ? 0 : Long.valueOf(param.getValue()));
        break;
    case PRIMITIVE_FLOAT:
    case FLOAT:
        preparedState.setFloat(index, isNull ? 0 : Float.valueOf(param.getValue()));
        break;
    case PRIMITIVE_DOUBLE:
    case DOUBLE:
        preparedState.setDouble(index, isNull ? 0 : Double.valueOf(param.getValue()));
        break;
    case PRIMITIVE_BOOLEAN:
    case BOOLEAN:
        preparedState.setBoolean(index, !isNull && Boolean.parseBoolean(param.getValue()));
        break;
    case PRIMITIVE_BYTE:
    case BYTE:
        preparedState.setByte(index, isNull ? 0 : Byte.valueOf(param.getValue()));
        break;
    case JAVA_UTIL_DATE:
    case JAVA_SQL_DATE:
        preparedState.setDate(index, isNull ? null : java.sql.Date.valueOf(param.getValue()));
        break;
    case JAVA_SQL_TIME:
        preparedState.setTime(index, isNull ? null : Time.valueOf(param.getValue()));
        break;
    case JAVA_SQL_TIMESTAMP:
        preparedState.setTimestamp(index, isNull ? null : Timestamp.valueOf(param.getValue()));
        break;
    default:
        preparedState.setObject(index, isNull ? null : param.getValue());
    }
}
 
开发者ID:apache,项目名称:kylin,代码行数:67,代码来源:QueryService.java

示例7: execute

import org.apache.kylin.rest.request.PrepareSqlRequest; //导入依赖的package包/类
/**
 * @param sql
 * @param sqlRequest
 * @return
 * @throws Exception
 */
private SQLResponse execute(String sql, SQLRequest sqlRequest) throws Exception {
    Connection conn = null;
    Statement stat = null;
    ResultSet resultSet = null;
    List<List<String>> results = new LinkedList<List<String>>();
    List<SelectedColumnMeta> columnMetas = new LinkedList<SelectedColumnMeta>();

    try {
        conn = getOLAPDataSource(sqlRequest.getProject()).getConnection();

        if (sqlRequest instanceof PrepareSqlRequest) {
            PreparedStatement preparedState = conn.prepareStatement(sql);

            for (int i = 0; i < ((PrepareSqlRequest) sqlRequest).getParams().length; i++) {
                setParam(preparedState, i + 1, ((PrepareSqlRequest) sqlRequest).getParams()[i]);
            }

            resultSet = preparedState.executeQuery();
        } else {
            stat = conn.createStatement();
            resultSet = stat.executeQuery(sql);
        }

        ResultSetMetaData metaData = resultSet.getMetaData();
        int columnCount = metaData.getColumnCount();

        // Fill in selected column meta
        for (int i = 1; i <= columnCount; ++i) {
            columnMetas.add(new SelectedColumnMeta(metaData.isAutoIncrement(i), metaData.isCaseSensitive(i), metaData.isSearchable(i), metaData.isCurrency(i), metaData.isNullable(i), metaData.isSigned(i), metaData.getColumnDisplaySize(i), metaData.getColumnLabel(i), metaData.getColumnName(i), metaData.getSchemaName(i), metaData.getCatalogName(i), metaData.getTableName(i), metaData.getPrecision(i), metaData.getScale(i), metaData.getColumnType(i), metaData.getColumnTypeName(i), metaData.isReadOnly(i), metaData.isWritable(i), metaData.isDefinitelyWritable(i)));
        }

        List<String> oneRow = new LinkedList<String>();

        // fill in results
        while (resultSet.next()) {
            for (int i = 0; i < columnCount; i++) {
                oneRow.add((resultSet.getString(i + 1)));
            }

            results.add(new LinkedList<String>(oneRow));
            oneRow.clear();
        }
    } finally {
        close(resultSet, stat, conn);
    }

    boolean isPartialResult = false;
    String cube = "";
    long totalScanCount = 0;
    if (OLAPContext.getThreadLocalContexts() != null) { // contexts can be null in case of 'explain plan for'
        for (OLAPContext ctx : OLAPContext.getThreadLocalContexts()) {
            isPartialResult |= ctx.storageContext.isPartialResultReturned();
            cube = ctx.realization.getName();
            totalScanCount += ctx.storageContext.getTotalScanCount();
        }
    }

    SQLResponse response = new SQLResponse(columnMetas, results, cube, 0, false, null, isPartialResult);
    response.setTotalScanCount(totalScanCount);

    return response;
}
 
开发者ID:KylinOLAP,项目名称:Kylin,代码行数:69,代码来源:QueryService.java

示例8: setParam

import org.apache.kylin.rest.request.PrepareSqlRequest; //导入依赖的package包/类
/**
 * @param preparedState
 * @param param
 * @throws SQLException
 */
private void setParam(PreparedStatement preparedState, int index, PrepareSqlRequest.StateParam param) throws SQLException {
    boolean isNull = (null == param.getValue());

    Class<?> clazz;
    try {
        clazz = Class.forName(param.getClassName());
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e.getMessage(), e);
    }

    Rep rep = Rep.of(clazz);

    switch (rep) {
    case PRIMITIVE_CHAR:
    case CHARACTER:
    case STRING:
        preparedState.setString(index, isNull ? null : String.valueOf(param.getValue()));
        break;
    case PRIMITIVE_INT:
    case INTEGER:
        preparedState.setInt(index, isNull ? 0 : Integer.valueOf(param.getValue()));
        break;
    case PRIMITIVE_SHORT:
    case SHORT:
        preparedState.setShort(index, isNull ? 0 : Short.valueOf(param.getValue()));
        break;
    case PRIMITIVE_LONG:
    case LONG:
        preparedState.setLong(index, isNull ? 0 : Long.valueOf(param.getValue()));
        break;
    case PRIMITIVE_FLOAT:
    case FLOAT:
        preparedState.setFloat(index, isNull ? 0 : Float.valueOf(param.getValue()));
        break;
    case PRIMITIVE_DOUBLE:
    case DOUBLE:
        preparedState.setDouble(index, isNull ? 0 : Double.valueOf(param.getValue()));
        break;
    case PRIMITIVE_BOOLEAN:
    case BOOLEAN:
        preparedState.setBoolean(index, !isNull && Boolean.parseBoolean(param.getValue()));
        break;
    case PRIMITIVE_BYTE:
    case BYTE:
        preparedState.setByte(index, isNull ? 0 : Byte.valueOf(param.getValue()));
        break;
    case JAVA_UTIL_DATE:
    case JAVA_SQL_DATE:
        preparedState.setDate(index, isNull ? null : java.sql.Date.valueOf(param.getValue()));
        break;
    case JAVA_SQL_TIME:
        preparedState.setTime(index, isNull ? null : Time.valueOf(param.getValue()));
        break;
    case JAVA_SQL_TIMESTAMP:
        preparedState.setTimestamp(index, isNull ? null : Timestamp.valueOf(param.getValue()));
        break;
    default:
        preparedState.setObject(index, isNull ? null : param.getValue());
    }
}
 
开发者ID:KylinOLAP,项目名称:Kylin,代码行数:66,代码来源:QueryService.java


注:本文中的org.apache.kylin.rest.request.PrepareSqlRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。