public String getAddForeignKeyConstraintString( String constraintName, String[] foreignKeys, String referencedTable, String[] primaryKeys, boolean referencesPrimaryKey) { String sql = String.format( " ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s", constraintName, StringUtils.join(foreignKeys, ", "), referencedTable); if (!referencesPrimaryKey) { sql += " (" + StringUtils.join(primaryKeys, ", ") + ')'; } return sql; }
public String getIndexName(String tableName, List<String> columnNames) { return makeName( qualifyIndexName() ? tableName + '_' : "", StringUtils.join(columnNames, '_'), "_IDX", getMaxIndexNameSize()); }
@Override public String getBinaryFulltextSql(List<String> columns) { if (compatibilityFulltextTable) { // extract tokens from tsvector List<String> columnsAs = new ArrayList<String>(columns.size()); for (String col : columns) { columnsAs.add("regexp_replace(" + col + "::text, $$'|'\\:[^']*'?$$, ' ', 'g')"); } return "SELECT " + StringUtils.join(columnsAs, ", ") + " FROM fulltext WHERE id=?"; } return super.getBinaryFulltextSql(columns); }
/** * 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<String>(columns.size()); List<String> pcols = new ArrayList<String>(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 { return String.format( "CREATE INDEX %s ON %s (%s)", quotedIndexName, table.getQuotedName(), StringUtils.join(qcols, ", ")); } }
/** * Return the SQL to get the columns fulltext fields * * @param columns * @since 5.9.3 */ public String getBinaryFulltextSql(List<String> columns) { return "SELECT " + StringUtils.join(columns, ", ") + " FROM fulltext WHERE id=?"; }
@Override public Map<String, Serializable> getSQLStatementsProperties(Model model, Database database) { Map<String, Serializable> properties = new HashMap<String, Serializable>(); switch (idType) { case VARCHAR: properties.put("idType", "varchar(36)"); properties.put("idTypeParam", "varchar"); properties.put("idNotPresent", "'-'"); properties.put("sequenceEnabled", Boolean.FALSE); break; case UUID: properties.put("idType", "uuid"); properties.put("idTypeParam", "uuid"); properties.put("idNotPresent", "'00000000-FFFF-FFFF-FFFF-FFFF00000000'"); properties.put("sequenceEnabled", Boolean.FALSE); break; case SEQUENCE: properties.put("idType", "int8"); properties.put("idTypeParam", "int8"); properties.put("idNotPresent", "-1"); properties.put("sequenceEnabled", Boolean.TRUE); properties.put("idSequenceName", idSequenceName); } properties.put("aclOptimizationsEnabled", Boolean.valueOf(aclOptimizationsEnabled)); properties.put("pathOptimizationsEnabled", Boolean.valueOf(pathOptimizationsEnabled)); properties.put("fulltextAnalyzer", fulltextAnalyzer); properties.put("fulltextEnabled", Boolean.valueOf(!fulltextSearchDisabled)); properties.put("clusteringEnabled", Boolean.valueOf(clusteringEnabled)); properties.put("proxiesEnabled", Boolean.valueOf(proxiesEnabled)); properties.put("softDeleteEnabled", Boolean.valueOf(softDeleteEnabled)); if (!fulltextDisabled) { Table ft = database.getTable(model.FULLTEXT_TABLE_NAME); properties.put("fulltextTable", ft.getQuotedName()); FulltextConfiguration fti = model.getFulltextConfiguration(); List<String> lines = new ArrayList<String>(fti.indexNames.size()); for (String indexName : fti.indexNames) { String suffix = model.getFulltextIndexSuffix(indexName); Column ftft = ft.getColumn(model.FULLTEXT_FULLTEXT_KEY + suffix); Column ftst = ft.getColumn(model.FULLTEXT_SIMPLETEXT_KEY + suffix); Column ftbt = ft.getColumn(model.FULLTEXT_BINARYTEXT_KEY + suffix); String concat; if (compatibilityFulltextTable) { // tsvector concat = " NEW.%s := COALESCE(NEW.%s, ''::TSVECTOR) || COALESCE(NEW.%s, ''::TSVECTOR);"; } else { // text with space at beginning and end concat = " NEW.%s := ' ' || COALESCE(NEW.%s, '') || ' ' || COALESCE(NEW.%s, '') || ' ';"; } String line = String.format(concat, ftft.getQuotedName(), ftst.getQuotedName(), ftbt.getQuotedName()); lines.add(line); } properties.put("fulltextTriggerStatements", StringUtils.join(lines, "\n")); } String[] permissions = NXCore.getSecurityService().getPermissionsToCheck(SecurityConstants.BROWSE); List<String> permsList = new LinkedList<String>(); for (String perm : permissions) { permsList.add("('" + perm + "')"); } properties.put("readPermissions", StringUtils.join(permsList, ", ")); properties.put("usersSeparator", getUsersSeparator()); properties.put("everyone", SecurityConstants.EVERYONE); properties.put("readAclMaxSize", Integer.toString(readAclMaxSize)); properties.put("unlogged", unloggedKeyword); return properties; }