/** {@inheritDoc} */ @Override Object getProperty(SqlProcessContext ctx, Object obj, String item) { String prefix = null; String suffix = null; String name = null; int ix = item.indexOf("?"); if (ix >= 0) { prefix = item.substring(0, ix); suffix = item.substring(ix + 1); name = prefix + suffix; } else { ix = item.indexOf("@"); if (ix >= 0) { prefix = item.substring(0, ix); suffix = SqlProcessContext.getFeature(item.substring(ix + 1)); name = prefix + suffix; } else { name = item; } } Object result = (BeanUtils.checkProperty(obj, name)) ? BeanUtils.getProperty(obj, name) : null; if (result != null || prefix == null || suffix == null) return result; suffix = SqlUtils.firstLowerCase(suffix); Object o = (BeanUtils.checkProperty(obj, suffix)) ? BeanUtils.getProperty(obj, suffix) : null; if (o == null || !(o instanceof Map)) { suffix = SqlProcessContext.getFeature(SqlFeature.OPERATOR_ATTRIBUTE_IN_MAP); o = (BeanUtils.checkProperty(obj, suffix)) ? BeanUtils.getProperty(obj, suffix) : null; if (o == null || !(o instanceof Map)) { return null; } } Map map = (Map) o; return map.get(prefix); }
/** * 按条件查询多条数据 * * @param dbManager DB管理器 * @param conditions 查询条件 * @param pageNo 页号 * @param rowsPerPage 每页的行数 * @return PageRecord 查询的一页的结果 * @throws Exception */ public PageRecord findByConditions( DBManager dbManager, String conditions, int pageNo, int rowsPerPage) throws Exception { DBLwTownProrateAppend dbLwTownProrateAppend = new DBLwTownProrateAppend(dbManager); Collection collection = new ArrayList(); if (conditions.trim().length() == 0) { conditions = "1=1"; } int count = dbLwTownProrateAppend.getCount(SqlUtils.getWherePartForGetCount(conditions)); collection = dbLwTownProrateAppend.findByConditions(conditions, pageNo, rowsPerPage); PageRecord pageRecord = new PageRecord(count, pageNo, 1, rowsPerPage, collection); return pageRecord; }
@Override public void load(LoadConfiguration loadConfiguration, RuntimeContext context) { String prefix = UUID.randomUUID().toString().replaceAll("-", "_"); // setup jdbc operations JdbcCommands operations = new JdbcCommands(jdbcTemplate); String sqlCreateTable = SqlUtils.createExternalReadableTable( loadConfiguration, prefix, context != null ? context.getLocations() : null); String sqlDropTable = SqlUtils.dropExternalReadableTable(loadConfiguration, prefix); String sqlInsert = SqlUtils.load(loadConfiguration, prefix); operations.setPrepareSql(sqlCreateTable); operations.setCleanSql(sqlDropTable); operations.setRunSql(sqlInsert); operations.setBeforeSqls(loadConfiguration.getSqlBefore()); operations.setAfterSqls(loadConfiguration.getSqlAfter()); if (!operations.execute() && operations.getLastException() != null) { throw operations.getLastException(); } }
/* constructor which (re)creates the aggregate */ public GeotaggedTweetAggregate( Connection c, String schema, String table, String override_name, String label, String point_column, int axisToSplit, long chunkSize, Object[][] newRange) throws SQLException { AggregateAxis x_axis = null; AggregateAxis y_axis = null; DbType type = SqlUtils.dbType(c); if (type == DbType.MONETDB) { this.checkMonetDbGis(c, schema, table, point_column); } if (type == DbType.MONETDB) { x_axis = new MetricAxis(point_column + "_x", "double", "" + DFLT_BASEBOXSIZE, DFLT_N); y_axis = new MetricAxis(point_column + "_y", "double", "" + DFLT_BASEBOXSIZE, DFLT_N); } else if (type == DbType.POSTGRES) { x_axis = new MetricAxis("ST_X(" + point_column + ")", "double", "" + DFLT_BASEBOXSIZE, DFLT_N); y_axis = new MetricAxis("ST_Y(" + point_column + ")", "double", "" + DFLT_BASEBOXSIZE, DFLT_N); } else { throw new UnsupportedOperationException("Database type " + type + " not yet supported!"); } AggregateAxis axis[] = {x_axis, y_axis}; createPreAggregate( c, schema, table, override_name, label, axis, "len", "bigint", AGGR_ALL, axisToSplit, chunkSize, newRange); }
private void visitValues(StringBuilder sql, List<Object> insertArgsBuilder) { sql.append("VALUES "); for (List<Object> valuesList : valuesToInsert) { if (valuesList.isEmpty()) { continue; } sql.append("("); for (Object value : valuesList) { SqlUtils.addToSqlString(sql, insertArgsBuilder, value); sql.append(","); } sql.deleteCharAt(sql.length() - 1); sql.append("),"); } sql.deleteCharAt(sql.length() - 1); }
private List getNextSequenceImpl(TypeDescriptor typeDescriptor, Session session) { Field[] pkFields = typeDescriptor.getPkFields(); Assert.condition( 1 == pkFields.length, "Automatic PK values are only supported for types with a single PK field."); String createPKStmt = dbDescriptor.getCreatePKStatement( sqlUtils.getSchemaName(), typeDescriptor.getPkSequence(), this.sequenceBatchSize); Field field = pkFields[0]; if (session.isUsingPreparedStatements(typeDescriptor.getType())) { PreparedStatement pkStatement = null; try { Connection connection = session.getConnection(); PreparedStatement result; try { result = connection.prepareStatement(createPKStmt); } catch (SQLException x) { throw new InternalException(x); } pkStatement = result; ResultSet pkQuery = pkStatement.executeQuery(); List newIds = new LinkedList(); while (pkQuery.next()) { newIds.add( DmlManager.getJavaValue( field.getType(), typeDescriptor.getPersistentField(field).getLength(), pkQuery, 1, true, false)); } return newIds; } catch (SQLException e) { throw new InternalException(e); } finally { QueryUtils.closeStatement(pkStatement); } } else { Statement pkStmt = null; try { Connection connection = session.getConnection(); pkStmt = connection.createStatement(); ResultSet pkQuery = pkStmt.executeQuery(createPKStmt); List newIds = new LinkedList(); while (pkQuery.next()) { newIds.add( DmlManager.getJavaValue( field.getType(), typeDescriptor.getPersistentField(field).getLength(), pkQuery, 1, true, false)); } return newIds; } catch (SQLException e) { throw new InternalException(e); } finally { QueryUtils.closeStatement(pkStmt); } } }