@Override public Serializable getCurrentFromResultSet(ResultSet rs, List<Column> columns, Model model, Serializable[] returnId, int[] returnPos) throws SQLException { Serializable id = null; Serializable value = null; int i = 0; for (Column column : columns) { i++; String key = column.getKey(); Serializable v = column.getFromResultSet(rs, i); if (key.equals(model.MAIN_KEY)) { id = v; } else if (key.equals(model.COLL_TABLE_POS_KEY)) { // (the pos column is ignored, results are already ordered by id // then pos) } else if (key.equals(model.COLL_TABLE_VALUE_KEY)) { value = v; } else { throw new RuntimeException(key); } } Serializable prevId = returnId[0]; returnId[0] = id; int pos = (id != null && !id.equals(prevId)) ? 0 : returnPos[0] + 1; returnPos[0] = pos; return value; }
protected void postProcessDelete() { Delete delete = new Delete(table); String wheres = table.getColumns() .stream() .filter(col -> Model.MAIN_KEY.equals(col.getKey())) .map(col -> col.getQuotedName() + " = ?") .collect(Collectors.joining(" AND ")); delete.setWhere(wheres); deleteSqlMap.put(tableName, delete.getStatement()); }
public void logResultSet(ResultSet rs, List<Column> columns) throws SQLException { List<String> res = new LinkedList<>(); int i = 0; for (Column column : columns) { i++; Serializable v = column.getFromResultSet(rs, i); res.add(column.getKey() + "=" + loggedValue(v)); } log(" -> " + String.join(", ", res)); }
@Override protected String getSelectColName(Column col) { String name = super.getSelectColName(col); if (firstSelectedColumn == null) { firstSelectedColumn = col; } if (type == COUNT_SOURCE && col.getTable().getKey().equals(SCHEMA_RELATION) && col.getKey().equals(PROPERTY_SOURCE)) { name = String.format("COUNT(DISTINCT %s)", name); } return name; }
if (col.getKey().equals(upgrade.columnName)) { doUpgrade = true; break;
public void logSQL(String sql, List<Column> columns, Row row, List<Column> whereColumns, Map<String, Serializable> conditions) { List<Serializable> values = new ArrayList<>(); for (Column column : columns) { String key = column.getKey(); Serializable value = row.get(key); if (value instanceof Delta) { Delta delta = (Delta) value; if (delta.getBase() != null) { value = delta.getDeltaValue(); } } values.add(value); } for (Column column : whereColumns) { String key = column.getKey(); Serializable value; if (column.getKey().equals(Model.MAIN_KEY)) { value = row.get(key); } else { value = conditions.get(key); } values.add(value); } logSQL(sql, values); }
int i = 1; for (Column column : columns) { String key = column.getKey(); Serializable value = column.getFromResultSet(rs, i++); if (key.equals(Model.MAIN_KEY)) {
protected void fillPreparedStatementFields(Map<String, Object> filterMap, List<Column> orderedColumns, PreparedStatement ps) { int index = 1; for (Column column : orderedColumns) { Object value = filterMap.get(column.getKey()); if (value instanceof SQLComplexFilter) { index = ((SQLComplexFilter) value).setFieldValue(ps, index, column); } else { setFieldValue(ps, index, column, value); index++; } } addFilterValues(ps, index); }
/** * Alternative to {@link #setNewValues} * * @param columns the columns * @param deltas which of the columns are delta updates */ public void setUpdatedColumns(List<Column> columns, Set<String> deltas) { List<String> updatedColumns = new LinkedList<>(); for (Column column : columns) { if (column.isIdentity()) { // identity column is never inserted continue; } String col = column.getQuotedName(); String fvs = column.getFreeVariableSetter(); String update; if (deltas.contains(column.getKey())) { update = col + " = " + col + " + " + fvs; } else { update = col + " = " + fvs; } updatedColumns.add(update); } newValues = StringUtils.join(updatedColumns, ", "); }
protected Column addColumn(String columnName, ColumnType type) { String colPhysicalName = dialect.getColumnName(columnName); Column column = new Column(table, colPhysicalName, type, columnName); return table.addColumn(column.getKey(), column); }
String where = null; for (Column column : table.getColumns()) { if (column.getKey().equals(Model.MAIN_KEY)) { StringBuilder buf = new StringBuilder(); buf.append(column.getQuotedName());
protected Serializable fieldValueForWrite(Object value, Column column) { ColumnSpec spec = column.getType().spec; if (value instanceof String) { if (spec == ColumnSpec.LONG || spec == ColumnSpec.AUTOINC) { // allow storing string into integer/long key return Long.valueOf((String) value); } if (column.getKey().equals(getPasswordField())) { // hash password if not already hashed String password = (String) value; if (!PasswordHelper.isHashed(password)) { password = PasswordHelper.hashPassword(password, passwordHashAlgorithm); } return password; } } else if (value instanceof Number) { if (spec == ColumnSpec.LONG || spec == ColumnSpec.AUTOINC) { // canonicalize to Long if (value instanceof Integer) { return Long.valueOf(((Integer) value).longValue()); } } else if (spec == ColumnSpec.STRING) { // allow storing number in string field return value.toString(); } } return (Serializable) value; }
String key = column.getKey(); Serializable v; if (key.equals(Model.HIER_PARENT_KEY)) {
for (Column column : columns) { i++; String key = column.getKey(); Serializable v; if (key.equals(Model.MAIN_KEY)) {
int i = 1; for (Column column : columns) { String key = column.getKey(); Serializable value = column.getFromResultSet(rs, i++); if (key.equals(Model.MAIN_KEY)) {
if (column.isOpaque()) { opaqueColumns.add(column); } else if (skipColumns == null || !skipColumns.contains(column.getKey())) { whatColumns.add(column); whats.add(column.getQuotedName());
for (Column column : table.getColumns()) { String qname = fullQuotedName ? column.getFullQuotedName() : column.getQuotedName(); if (freeColumnsList.contains(column.getKey())) { whereColumns.add(column); wheres.add(qname + " = ?");
String key = column.getKey(); if (key.equals(Model.MAIN_KEY) //
protected void postProcessRootIdSelect() { String what = null; String where = null; for (Column column : table.getColumns()) { String key = column.getKey(); String qname = column.getQuotedName(); if (key.equals(Model.MAIN_KEY)) { what = qname; selectRootIdWhatColumn = column; } else if (key.equals(Model.REPOINFO_REPONAME_KEY)) { where = qname + " = ?"; } else { throw new RuntimeException(column.toString()); } } Select select = new Select(table); select.setWhat(what); select.setFrom(table.getQuotedName()); select.setWhere(where); selectRootIdSql = select.getStatement(); }
column.setToPreparedStatement(ps, i++, row.get(column.getKey()));