/** key used to extract array index if needed */ protected String getSelectColName(Column col, String key) { String colName = getSelectColName(col); if (col.isArray()) { String[] segments = canonicalXPath(key).split("/"); if (segments.length > 1) { // last segment String segment = segments[segments.length - 1]; if (INDEX.matcher(segment).matches() && !segment.startsWith("*")) { int arrayElementIndex = Integer.parseInt(segment); colName = dialect.getArrayElementString(colName, arrayElementIndex); } } } return colName; }
protected void visitExpressionLike(Column column, Operator op, Operand rvalue, String lvalueName, int arrayElementIndex) { if (column.isArray() && arrayElementIndex == -1) { if (lvalueName == null) { throw new AssertionError("Name is required when lvalue is an array"); } boolean positive = (op == Operator.LIKE); String sql = dialect.getArrayLikeSql(column, lvalueName, positive, dataHierTable); buf.append(sql); whereParams.add(getSerializableLiteral((Literal) rvalue)); } else { visitSimpleExpression(column, op, rvalue, null, arrayElementIndex); addLikeEscaping(); } }
protected void visitExpressionEqOrIn(Column column, Operator op, Operand rvalue, String cast, int arrayElementIndex) { if (column.isArray() && arrayElementIndex == -1) { List<Serializable> params; if (rvalue instanceof Literal) { Serializable param = getSerializableLiteral((Literal) rvalue); params = Collections.singletonList(param); } else { params = getSerializableLiterals((LiteralList) rvalue); } boolean positive = op == Operator.EQ || op == Operator.IN; String sql = dialect.getArrayInSql(column, cast, positive, params); buf.append(sql); whereParams.addAll(params); } else { visitSimpleExpression(column, op, rvalue, cast, arrayElementIndex); } }
protected void visitExpressionIlike(Column column, Operator op, Operand rvalue, String lvalueName, int arrayElementIndex) { if (column.isArray() && arrayElementIndex == -1) { if (lvalueName == null) { throw new AssertionError("Name is required when lvalue is an array"); } boolean positive = op == Operator.ILIKE; String sql = dialect.getArrayIlikeSql(column, lvalueName, positive, dataHierTable); buf.append(sql); whereParams.add(getSerializableLiteral((Literal) rvalue)); } else if (dialect.supportsIlike()) { visitSimpleExpression(column, op, rvalue, null, arrayElementIndex); } else { buf.append("LOWER("); visitReference(column, arrayElementIndex); buf.append(") "); if (op == Operator.NOTILIKE) { buf.append("NOT "); } buf.append("LIKE"); buf.append(" LOWER("); rvalue.accept(this); buf.append(")"); addLikeEscaping(); } }
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); } }
boolean skipJoin = !isArrayElement && prop.propertyType.isArray() && !column.isArray(); Column posColumn = null; if (column.isArray() && star) { contextKey = contextStart + segment + contextSuffix; ArraySubQuery arraySubQuery = getArraySubQuery(contextHier, contextKey, column, skipJoin); column.isArray() ? -1 : index, skipJoin, null); column = table.getColumn(prop.fragmentKey); if (star) { return new ColumnInfo(column, posColumn, column.isArray() ? index : -1, isArrayElement, prop.propertyType.isArray());