public ColumnInfo(Column column, Column posColumn, int arrayElementIndex, boolean isArrayElement, boolean isArray) { this.column = column; this.posColumn = posColumn; this.arrayElementIndex = arrayElementIndex; this.isArrayElement = isArrayElement; this.needsSubSelect = !isArrayElement && isArray && !column.getType().isArray(); } }
protected Serializable getFromResultSetString(ResultSet rs, int index, Column column) throws SQLException { String string = rs.getString(index); if (string == null) { return null; } ColumnType type = column.getType(); if (type == ColumnType.SYSNAMEARRAY) { // implementation when arrays aren't supported // an initial separator is expected if (string.startsWith(ARRAY_SEP)) { string = string.substring(ARRAY_SEP.length()); } // the final separator is dropped as split does not return final // empty strings return string.split(Pattern.quote(ARRAY_SEP)); } else { return string; } }
protected void setToPreparedStatementString(PreparedStatement ps, int index, Serializable value, Column column) throws SQLException { String v; ColumnType type = column.getType(); if (type == ColumnType.SYSNAMEARRAY) { // implementation when arrays aren't supported String[] strings = (String[]) value; if (strings == null) { v = null; } else { // use initial and final separator as terminator StringBuilder buf = new StringBuilder(ARRAY_SEP); for (String string : strings) { buf.append(string); buf.append(ARRAY_SEP); } v = buf.toString(); } } else { v = (String) value; } ps.setString(index, v); }
/** * Tables created for directories don't need a clustered column automatically defined. */ protected boolean needsClusteredColumn(Table table) { if (idType == DialectIdType.SEQUENCE) { // good enough for a clustered index // no need to add another column return false; } for (Column col : table.getColumns()) { if (col.getType().isId()) { return true; } } return false; }
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; }
@Override public Column getSubQueryIdColumn() { Column column = fakeSubqueryTableAlias.getColumn(Model.MAIN_KEY); return new ArraySubQueryPostgreSQLColumn(column.getPhysicalName(), column.getType()); }
public String getClause(Dialect dialect) { if (on1 == null && on2 == null) { on1 = column1.getFullQuotedName(); on2 = column2.getFullQuotedName(); boolean isid1 = column1.getType().isId(); boolean isid2 = column2.getType().isId(); if (dialect != null && isid1 != isid2) { // temporary fix cast uuid to varchar because relation table // has varchar source and target field if (isid1) { on1 = dialect.castIdToVarchar(on1); } else { on2 = dialect.castIdToVarchar(on2); } } } return on1 + " = " + on2; }
protected void visitSimpleExpression(Column column, Operator op, Operand rvalue, String cast, int arrayElementIndex) { visitReference(column, cast, arrayElementIndex); op.accept(this); boolean oldVisitingId = visitingId; visitingId = column.getType().isId(); rvalue.accept(this); visitingId = oldVisitingId; }
protected void visitReference(Column column, String cast, int arrayElementIndex) { if (DATE_CAST.equals(cast) && column.getType() != ColumnType.TIMESTAMP) { throw new QueryParseException("Cannot cast to " + cast + ": " + column); } String qname = column.getFullQuotedName(); if (arrayElementIndex != -1) { if (column.isArray()) { qname = dialect.getArrayElementString(qname, arrayElementIndex); } else { throw new QueryParseException( "Cannot use array index " + arrayElementIndex + " for non-array column " + column); } } // some databases (Derby) can't do comparisons on CLOB if (column.getJdbcType() == Types.CLOB) { String colFmt = dialect.getClobCast(inOrderBy); if (colFmt != null) { qname = String.format(colFmt, qname, Integer.valueOf(255)); } } if (cast != null) { // only DATE cast for now String fmt = dialect.getDateCast(); buf.append(String.format(fmt, qname)); } else { buf.append(qname); } }
@Override public void visitFunction(Function node) { String func = node.name.toUpperCase(); Reference ref = (Reference) node.args.get(0); ref.accept(this); // whatColumns / whatKeys for column // replace column info with aggregate Column col = whatColumns.removeLast(); String key = whatKeys.removeLast(); final String aggFQN = func + "(" + col.getFullQuotedName() + ")"; final ColumnType aggType = getAggregateType(func, col.getType()); final int aggJdbcType = dialect.getJDBCTypeAndString(aggType).jdbcType; Column cc = new Column(col, col.getTable()) { private static final long serialVersionUID = 1L; @Override public String getFullQuotedName() { return aggFQN; } @Override public ColumnType getType() { return aggType; } @Override public int getJdbcType() { return aggJdbcType; } }; whatColumns.add(cc); whatKeys.add(func + "(" + key + ")"); }
protected void visitExpression(Column column, Operator op, Operand rvalue) { visitColumn(column); if (op == Operator.EQ || op == Operator.NOTEQ) { if (column.getType().spec == ColumnSpec.BOOLEAN) { rvalue = getBooleanLiteral(rvalue); } if (directory.getDialect().hasNullEmptyString() && rvalue instanceof StringLiteral && ((StringLiteral) rvalue).value.isEmpty()) { // see NXP-6172, empty values are Null in Oracle op = op == Operator.EQ ? Operator.ISNULL : Operator.ISNOTNULL; rvalue = null; } } op.accept(this); if (rvalue != null) { rvalue.accept(this); } }
if (info.column.getType() == ColumnType.BOOLEAN) { rvalue = getBooleanLiteral(rvalue);