コード例 #1
0
ファイル: StartupDemo.java プロジェクト: roshanl/databus
  public static void createAggregation(String aggName, String schemaName, String... urls) {
    StreamAggregation s = NoSql.em().find(StreamAggregation.class, aggName);
    if (s == null) {
      s = new StreamAggregation();
    } else {
      if (!s.getSchema().getName().equals(schemaName))
        throw new RuntimeException(
            "Aggregation name=" + aggName + " is already in use under group=" + schemaName);
    }

    SecureSchema schema = SecureSchema.findByName(NoSql.em(), schemaName);

    s.setName(aggName);
    List<String> streamUrls = s.getUrls();
    streamUrls.clear();

    for (String url : urls) {
      streamUrls.add(url);
    }

    s.setSchema(schema);
    NoSql.em().put(s);
    NoSql.em().put(schema);
    NoSql.em().flush();
  }
コード例 #2
0
ファイル: SearchUtils.java プロジェクト: hopcroft/databus
  public static void indexAggregation(StreamAggregation aggregation, SecureSchema owningSchema)
      throws IOException, SAXException, ParserConfigurationException, SolrServerException {
    // Solr server instance
    SolrServer solrServer = Search.getSolrServer();
    // Add this new table to the meta index...
    createCoreIfNeeded("databusmeta", "databusmeta", solrServer);
    SolrInputDocument doc = new SolrInputDocument();

    // Add special fields to track the type of record an the primary key.
    doc.addField("id", aggregation.getName());
    doc.addField("type", "aggregation");
    // aggregations don't store their creator.  Add something like this later
    // doc.addField("creator_texts", aggregation.getCreator().getUsername());

    doc.addField("description_texts", aggregation.getUrls());

    // There is a bug in the 2 way relationship between aggs and schemas, right now it's possible
    // for a
    // schema to have an aggregation in it's 'getAggregations()' list, but the aggregation DOES NOT
    // HAVE
    // that schema set as it's .getSchema().  It's possible to pass in the owning schema to account
    // for this.
    if (aggregation.getSchema() != null) {
      doc.addField("database_texts", aggregation.getSchema().getSchemaName());
      doc.addField("databaseDescription_texts", aggregation.getSchema().getDescription());
    } else if (owningSchema != null) {
      doc.addField("database_texts", owningSchema.getSchemaName());
      doc.addField("databaseDescription_texts", owningSchema.getDescription());
    }

    Set<String> allTermsSet = new HashSet<String>();

    allTermsSet.add((String) doc.getField("id").getValue());
    allTermsSet.add((String) doc.getField("type").getValue());
    allTermsSet.addAll(aggregation.getUrls());

    if (aggregation.getSchema() != null && owningSchema != null) {
      allTermsSet.add((String) doc.getField("database_texts").getValue());
      allTermsSet.add((String) doc.getField("databaseDescription_texts").getValue());
    }

    doc.addField("allTerms_texts", allTermsSet);

    UpdateRequest request = new UpdateRequest();
    request.setAction(AbstractUpdateRequest.ACTION.COMMIT, false, false);
    request.add(doc);
    request.process(Search.getSolrCore("databusmeta"));
  }