@Override
 public void index(Document document) {
   if (log.isTraceEnabled()) {
     log.trace(
         "Indexing "
             + sql
             + " id="
             + JdbcIndexDefinition.this.identifier
             + ", key = "
             + JdbcIndexDefinition.this.key);
   }
   String id = getIdentifier();
   if (id != null) {
     document.add(
         new Field(
             "builder",
             "VIRTUAL BUILDER",
             Field.Store.YES,
             Field.Index.NOT_ANALYZED)); // keyword
     document.add(
         new Field(
             "number", getIdentifier(), Field.Store.YES, Field.Index.NOT_ANALYZED)); // keyword
   }
   try {
     for (int i = 1; i <= meta.getColumnCount(); i++) {
       String value = org.mmbase.util.Casting.toString(results.getString(i));
       if (log.isTraceEnabled()) {
         log.trace(
             "Indexing " + value + " for " + meta.getColumnName(i) + " on " + getIdentifier());
       }
       String fieldName = meta.getColumnName(i);
       if (keyWords.contains(fieldName)) {
         Indexer.addField(
             document,
             new Field(fieldName, value, Field.Store.YES, Field.Index.NOT_ANALYZED),
             nonDefaultMultiples.get(fieldName)); // keyword
       } else {
         Field field = new Field(fieldName, value, Field.Store.YES, Field.Index.ANALYZED);
         Float boost = boosts.get(fieldName);
         if (boost != null) {
           field.setBoost(boost);
         }
         Indexer.addField(document, field, nonDefaultMultiples.get(fieldName));
         Field fullText = new Field("fulltext", value, Field.Store.YES, Field.Index.ANALYZED);
         if (boost != null) {
           fullText.setBoost(boost);
         }
         document.add(fullText);
       }
     }
   } catch (SQLException sqe) {
     log.error(sqe.getMessage(), sqe);
   }
 }
 @Override
 public String getKey() {
   if (JdbcIndexDefinition.this.key != null && !JdbcIndexDefinition.this.key.equals("")) {
     try {
       return results.getString(JdbcIndexDefinition.this.key);
     } catch (SQLException sqe) {
       log.error(sqe.getMessage(), sqe);
       return "";
     }
   } else {
     return null;
   }
 }
 @Override
 public String getIdentifier() {
   if (JdbcIndexDefinition.this.identifier != null
       && !JdbcIndexDefinition.this.identifier.equals("")) {
     try {
       return results.getString(JdbcIndexDefinition.this.identifier);
     } catch (SQLException sqe) {
       log.error(meta + " " + sqe.getMessage(), sqe);
       return "";
     }
   } else {
     return null;
   }
 }
 /**
  * Jdbc connection pooling of MMBase would kill the statement if too duratious. This produces a
  * 'direct connection' in that case, to circumvent that problem (Indexing queries _may_ take a
  * while).
  */
 protected Connection getDirectConnection() throws SQLException {
   directConnections++;
   try {
     if (dataSource instanceof GenericDataSource) {
       return ((GenericDataSource) dataSource).getDirectConnection();
     } else {
       return dataSource.getConnection();
     }
   } catch (SQLException sqe) {
     log.error("With direct connection #" + directConnections + ": " + sqe.getMessage());
     throw sqe;
   } catch (Throwable t) {
     throw new RuntimeException("direct connection #" + directConnections, t);
   }
 }
Exemple #5
0
 protected boolean executeOnlyIf(Connection con, String q) throws SQLException {
   if (q == null) return true;
   Statement stmt = null;
   try {
     stmt = con.createStatement();
     q = q.replace("$PREFIX", getPrefix());
     LOG.debug(" Executing query " + q);
     ResultSet rs = stmt.executeQuery(q);
     rs.next();
     boolean res = rs.getBoolean(1);
     LOG.debug("Result: " + res);
     return res;
   } catch (SQLException sqe) {
     LOG.error(sqe.getMessage() + " from " + q);
     throw sqe;
   } finally {
     try {
       if (stmt != null) {
         stmt.close();
       }
     } catch (Exception g) {
     }
   }
 }