Example #1
0
 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;
 }
Example #2
0
 public String getIndexName(String tableName, List<String> columnNames) {
   return makeName(
       qualifyIndexName() ? tableName + '_' : "",
       StringUtils.join(columnNames, '_'),
       "_IDX",
       getMaxIndexNameSize());
 }
Example #3
0
  /** Extracts document location from a Zope-like URL ie : server/path_or_docId/view_id/tab_id . */
  @Override
  public DocumentView getDocumentViewFromUrl(String url) {
    final Pattern pattern = Pattern.compile(getPrefix() + URLPattern);
    Matcher m = pattern.matcher(url);
    if (m.matches()) {
      if (m.groupCount() >= 4) {

        // for debug
        // for (int i = 1; i < m.groupCount() + 1; i++) {
        // System.err.println(i + ": " + m.group(i));
        // }

        final String server = m.group(1);
        String uuid = m.group(2);
        final DocumentRef docRef = new IdRef(uuid);

        // get other parameters

        Map<String, String> params = new HashMap<String, String>();
        if (m.groupCount() >= 4) {
          String filePropertyPath = m.group(4);
          params.put(FILE_PROPERTY_PATH_KEY, filePropertyPath);
        }

        if (m.groupCount() >= 6) {
          String filename = m.group(6);
          try {
            filename = URLDecoder.decode(filename, "UTF-8");
          } catch (UnsupportedEncodingException e) {
            filename = StringUtils.toAscii(filename);
          }
          int jsessionidIndex = filename.indexOf(";jsessionid");
          if (jsessionidIndex != -1) {
            filename = filename.substring(0, jsessionidIndex);
          }
          params.put(FILENAME_KEY, filename);
        }

        if (m.groupCount() >= 8) {
          String query = m.group(8);
          Map<String, String> requestParams = URIUtils.getRequestParameters(query);
          if (requestParams != null) {
            params.putAll(requestParams);
          }
        }

        final DocumentLocation docLoc = new DocumentLocationImpl(server, docRef);

        return new DocumentViewImpl(docLoc, null, params);
      }
    }

    return null;
  }
Example #4
0
 @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);
 }
 protected String[] retrieveBasicLogin(HttpServletRequest httpRequest) {
   String auth = httpRequest.getHeader("authorization");
   if (auth != null && auth.toLowerCase().startsWith("basic")) {
     int idx = auth.indexOf(' ');
     String b64userpassword = auth.substring(idx + 1);
     byte[] clearUp = Base64.decode(b64userpassword);
     String userpassword = new String(clearUp);
     String[] up = StringUtils.split(userpassword, ':', false);
     if (up.length != 2) {
       return null;
     }
     return up;
   }
   return null;
 }
Example #6
0
 /**
  * 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, ", "));
   }
 }
Example #7
0
 /**
  * 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=?";
 }
Example #8
0
 @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;
 }