@Override public String getQuotedName() { return dialect.openQuote() + alias + dialect.closeQuote(); }
@Override public String getColumnName(String name) { // ignore suffixed "_" when checking for reservedness String n = name.replaceAll("_+$", ""); for (String reserved : RESERVED_COLUMN_NAMES) { if (n.equals(reserved)) { // reserved, add one more suffix "_" name += "_"; break; } } return super.getColumnName(name); }
deleteSQL = "DELETE FROM " + tableName + " WHERE " + keyColName + " = ?"; deleteIfLongSQL = deleteSQL + " AND " + longColName + " = ?"; deleteIfStringSQL = deleteSQL + " AND " + dialect.getQuotedNameForExpression(stringCol) + " = ?"; deleteIfBytesSQL = deleteSQL + " AND " + bytesColName + " = ?"; expireSQL = "DELETE FROM " + tableName + " WHERE " + ttlColName + " < ?"; keyStreamSQL = "SELECT " + keyColName + " FROM " + tableName; keyStreamPrefixSQL = keyStreamSQL + " WHERE " + keyColName + " LIKE ?"; String esc = dialect.getLikeEscaping(); if (esc != null) { keyStreamPrefixSQL += esc;
/** * Creates a new column with the given name and type. * * @param table the column's table * @param physicalName the column physical name * @param type the column's type * @param key the associated field name */ public Column(Table table, String physicalName, ColumnType type, String key) { this.table = table; dialect = table.getDialect(); this.physicalName = physicalName; this.type = type; JDBCInfo jdbcInfo = dialect.getJDBCTypeAndString(type); jdbcType = jdbcInfo.jdbcType; jdbcTypeString = jdbcInfo.string; jdbcBaseType = jdbcInfo.jdbcBaseType; jdbcBaseTypeString = jdbcInfo.jdbcBaseTypeString; this.key = key; quotedName = dialect.openQuote() + physicalName + dialect.closeQuote(); freeVariableSetter = dialect.getFreeVariableSetterForType(type); }
protected void postAddColumn(Column column, List<String> sqls, Model model) { if (column.isPrimary() && !(column.isIdentity() && dialect.isIdentityAlreadyPrimary())) { StringBuilder buf = new StringBuilder(); String constraintName = dialect.openQuote() + dialect.getPrimaryKeyConstraintName(key) + dialect.closeQuote(); buf.append("ALTER TABLE "); buf.append(getQuotedName()); buf.append(dialect.getAddPrimaryKeyConstraintString(constraintName)); buf.append('('); buf.append(column.getQuotedName()); sqls.addAll(dialect.getPostCreateIdentityColumnSql(column)); String constraintName = dialect.openQuote() + dialect.getForeignKeyConstraintName(key, column.getPhysicalName(), ft.getPhysicalName()) + dialect.closeQuote(); StringBuilder buf = new StringBuilder(); buf.append("ALTER TABLE "); buf.append(getQuotedName()); buf.append(dialect.getAddForeignKeyConstraintString(constraintName, new String[] { column.getQuotedName() }, ft.getQuotedName(), new String[] { fc.getQuotedName() }, true)); if (dialect.supportsCircularCascadeDeleteConstraints() || (Model.MAIN_KEY.equals(fc.getPhysicalName()) && Model.MAIN_KEY.equals(column.getPhysicalName()))) { String createIndexSql = dialect.getCreateIndexSql(indexName, indexType, this, cols, model); sqls.add(createIndexSql);
String operator; boolean substring = fulltext != null && fulltext.contains(columnName); if ("".equals(value) && dialect.hasNullEmptyString() && !substring) { if (dialect.supportsIlike()) { operator = " ILIKE "; // postgresql rules } else { for (Iterator<Map.Entry<String, String>> it = orderBy.entrySet().iterator(); it.hasNext();) { Entry<String, String> entry = it.next(); orderby.append(dialect.openQuote()) .append(entry.getKey()) .append(dialect.closeQuote()) .append(' ') .append(entry.getValue()); offset = 0; if (dialect.supportsPaging()) { query = dialect.addPagingClause(query, limit, offset); manualLimitOffset = false; } else {
orderBy.append(", "); orderBy.append(dialect.openQuote()); orderBy.append(ob.reference.name); orderBy.append(dialect.closeQuote()); if (ob.isDescending) { orderBy.append(" DESC"); if (!dialect.supportsPaging()) { throw new QueryParseException("Cannot use limit/offset, not supported by database"); query = dialect.addPagingClause(query, limit, offset);
alias = dialect.openQuote() + COL_ALIAS_PREFIX + (i + 1) + dialect.closeQuote(); whatName = getSelectColName(col, key); if (col.getTable().getRealTable() == hier && col.getKey().equals(Model.MAIN_KEY)) { Serializable principals = queryFilter.getPrincipals(); Serializable permissions = queryFilter.getPermissions(); if (!dialect.supportsArrays()) { principals = StringUtils.join((String[]) principals, Dialect.ARRAY_SEP); permissions = StringUtils.join((String[]) permissions, Dialect.ARRAY_SEP); String id = dialect.supportsWith() ? mainAlias : hierId; if (dialect.supportsReadAcl()) { String racl = dialect.openQuote() + READ_ACL_ALIAS + dialect.closeQuote(); String aclrum = dialect.openQuote() + READ_ACL_USER_MAP_ALIAS + dialect.closeQuote(); securityJoins.add(new Join(Join.INNER, Model.HIER_READ_ACL_TABLE_NAME, READ_ACL_ALIAS, null, id, racl + '.' + Model.HIER_READ_ACL_ID)); securityJoins.add(new Join(Join.INNER, Model.ACLR_USER_MAP_TABLE_NAME, READ_ACL_USER_MAP_ALIAS, null, racl + '.' + Model.HIER_READ_ACL_ACL_ID, aclrum + '.' + Model.ACLR_USER_MAP_ACL_ID)); securityClause = dialect.getReadAclsCheckSql(aclrum + '.' + Model.ACLR_USER_MAP_USER_ID); securityParams.add(principals); } else { securityClause = dialect.getSecurityCheckSql(id); securityParams.add(principals); securityParams.add(permissions); if (dialect.supportsWith()) { String withTable = dialect.openQuote() + WITH_ALIAS_PREFIX + (statements.size() + 1)
/** * Gets a CREATE INDEX statement for an index. * * @param indexName the index name (for fulltext) * @param indexType the index type * @param table the table * @param columns the columns to index * @param model the model */ public String getCreateIndexSql(String indexName, Table.IndexType indexType, Table table, List<Column> columns, Model model) { List<String> qcols = new ArrayList<>(columns.size()); List<String> pcols = new ArrayList<>(columns.size()); for (Column col : columns) { qcols.add(col.getQuotedName()); pcols.add(col.getPhysicalName()); } String quotedIndexName = openQuote() + getIndexName(table.getKey(), pcols) + closeQuote(); if (indexType == Table.IndexType.FULLTEXT) { return getCreateFulltextIndexSql(indexName, quotedIndexName, table, columns, model); } else { String unique = indexType == Table.IndexType.UNIQUE ? "UNIQUE " : ""; return String.format("CREATE %sINDEX %s ON %s (%s)", unique, quotedIndexName, table.getQuotedName(), String.join(", ", qcols)); } }
@Override protected void fixSelect(Select select) { if (type == COUNT_SOURCE) { // add a GROUP BY on first col String name; if (dialect.needsOriginalColumnInGroupBy()) { name = firstSelectedColumn.getFullQuotedName(); } else { name = dialect.openQuote() + COL_ALIAS_PREFIX + "1" + dialect.closeQuote(); } select.setGroupBy(name); } }
protected <T> PartialList<T> queryProjection(String query, String queryType, QueryFilter queryFilter, long countUpTo, BiFunctionSQLException<SQLInfoSelect, ResultSet, T> extractor, Object... params) { if (dialect.needsPrepareUserReadAcls()) { prepareUserReadAcls(queryFilter); if (countUpTo == 0 && limit > 0 && dialect.supportsPaging()) { sql = dialect.addPagingClause(sql, limit, offset); limit = 0; offset = 0; } else if (countUpTo > 0 && dialect.supportsPaging()) { sql = dialect.addPagingClause(sql, Math.max(countUpTo + 1, limit + offset), 0);
dialect = Dialect.createDialect(connection, repositoryDescriptor); } catch (SQLException cause) { throw new NuxeoException("Cannot get connection from datasource: " + dataSourceName, cause); modelSetup.materializeFulltextSyntheticColumn = dialect.getMaterializeFulltextSyntheticColumn(); modelSetup.supportsArrayColumns = dialect.supportsArrayColumns(); switch (dialect.getIdType()) { case VARCHAR: case UUID: break; default: throw new AssertionError(dialect.getIdType().toString());
fulltextQuery = dialect.getDialectFulltextQuery(fulltextQuery); ftJoinNumber++; Column mainColumn = dataHierTable.getColumn(Model.MAIN_KEY); FulltextMatchInfo info = dialect.getFulltextScoredMatchInfo(fulltextQuery, name, ftJoinNumber, mainColumn, model, database); ftMatchInfo = info; if (dialect.supportsIlike()) { visitReference(ref); buf.append(" ILIKE ");
setToPreparedStatement(updateReturningSql, ps, psColumns, psValues); if (useReturnResultSet) { dialect.registerReturnParameter(ps, 3, longCol.getJdbcType()); ResultSet rs; if (useReturnResultSet) { rs = dialect.getReturnResultSet(ps); } else { rs = ps.executeQuery(); return delta; } catch (SQLException e) { if (!dialect.isConcurrentUpdateException(e)) { throw e;
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(); } }
List<Column> psColumns = new ArrayList<>(); List<Serializable> psValues = new ArrayList<>(); String sql = dialect.getUpsertSql(Arrays.asList(keyCol, longCol, stringCol, bytesCol, ttlCol), Arrays.asList(key, longValue, stringValue, bytesValue, ttlValue), psColumns, psValues); for (int retry = 0; retry < MAX_RETRY; retry++) { if (!dialect.isConcurrentUpdateException(e)) { throw e;
/** * Checks the SQL error we got and determine if a concurrent update happened. Throws if that's the case. * * @param e the exception * @since 7.10-HF04, 8.2 */ protected void checkConcurrentUpdate(Throwable e) throws ConcurrentUpdateException { if (dialect.isConcurrentUpdateException(e)) { throw new ConcurrentUpdateException(e); } }
public Table addTable(String name) throws IllegalArgumentException { String physicalName = dialect.getTableName(name); if (!physicalTables.add(physicalName)) { throw new IllegalArgumentException("Duplicate table name: " + physicalName); } Table table = new TableImpl(dialect, physicalName, name); tables.put(name, table); return table; }
set = true; } catch (SQLException e) { if (!dialect.isConcurrentUpdateException(e)) { throw e; + " = ? WHERE " + keyColName + " = ? AND " + dialect.getQuotedNameForExpression(expectedCol) + " = ?"; try (PreparedStatement ps = connection.prepareStatement(sql)) {
protected void addLikeEscaping() { String escape = dialect.getLikeEscaping(); if (escape != null) { buf.append(escape); } }