Ejemplo n.º 1
0
  private Neo4jGraph(final GraphDatabaseService baseGraph) {
    this.configuration.copy(EMPTY_CONFIGURATION);
    this.baseGraph = baseGraph;
    this.transactionManager =
        ((GraphDatabaseAPI) baseGraph)
            .getDependencyResolver()
            .resolveDependency(TransactionManager.class);
    this.cypher = new ExecutionEngine(this.baseGraph);
    this.neo4jGraphVariables = new Neo4jGraphVariables(this);

    ///////////
    final Optional<Boolean> metaProperties =
        this.neo4jGraphVariables.get(Graph.System.system(CONFIG_META_PROPERTIES));
    if (metaProperties.isPresent()) {
      this.supportsMetaProperties = metaProperties.get();
    } else {
      this.supportsMetaProperties = false;
      this.neo4jGraphVariables.set(Graph.System.system(CONFIG_META_PROPERTIES), false);
    }
    final Optional<Boolean> multiProperties =
        this.neo4jGraphVariables.get(Graph.System.system(CONFIG_MULTI_PROPERTIES));
    if (multiProperties.isPresent()) {
      this.supportsMultiProperties = multiProperties.get();
    } else {
      this.supportsMultiProperties = false;
      this.neo4jGraphVariables.set(Graph.System.system(CONFIG_MULTI_PROPERTIES), false);
    }
    if ((this.supportsMetaProperties && !this.supportsMultiProperties)
        || (!this.supportsMetaProperties && this.supportsMultiProperties)) {
      tx().rollback();
      throw new UnsupportedOperationException(
          "Neo4jGraph currently requires either both meta- and multi-properties activated or neither activated");
    }
    tx().commit();
    ///////////
  }
Ejemplo n.º 2
0
 private Neo4jGraph(final Configuration configuration) {
   try {
     this.configuration.copy(EMPTY_CONFIGURATION);
     this.configuration.copy(configuration);
     final String directory = this.configuration.getString(CONFIG_DIRECTORY);
     final Map neo4jSpecificConfig =
         ConfigurationConverter.getMap(this.configuration.subset(CONFIG_CONF));
     final boolean ha = this.configuration.getBoolean(CONFIG_HA, false);
     // if HA is enabled then use the correct factory to instantiate the GraphDatabaseService
     this.baseGraph =
         ha
             ? new HighlyAvailableGraphDatabaseFactory()
                 .newHighlyAvailableDatabaseBuilder(directory)
                 .setConfig(neo4jSpecificConfig)
                 .newGraphDatabase()
             : new GraphDatabaseFactory()
                 .newEmbeddedDatabaseBuilder(directory)
                 .setConfig(neo4jSpecificConfig)
                 .newGraphDatabase();
     this.transactionManager =
         ((GraphDatabaseAPI) this.baseGraph)
             .getDependencyResolver()
             .resolveDependency(TransactionManager.class);
     this.cypher = new ExecutionEngine(this.baseGraph);
     this.neo4jGraphVariables = new Neo4jGraphVariables(this);
     ///////////
     if (!this.neo4jGraphVariables.get(Graph.System.system(CONFIG_META_PROPERTIES)).isPresent())
       this.neo4jGraphVariables.set(
           Graph.System.system(CONFIG_META_PROPERTIES),
           this.configuration.getBoolean(CONFIG_META_PROPERTIES, false));
     // TODO: Logger saying the configuration properties are ignored if already in Graph.Variables
     if (!this.neo4jGraphVariables.get(Graph.System.system(CONFIG_MULTI_PROPERTIES)).isPresent())
       this.neo4jGraphVariables.set(
           Graph.System.system(CONFIG_MULTI_PROPERTIES),
           this.configuration.getBoolean(CONFIG_MULTI_PROPERTIES, false));
     // TODO: Logger saying the configuration properties are ignored if already in Graph.Variables
     this.supportsMetaProperties =
         this.neo4jGraphVariables.<Boolean>get(Graph.System.system(CONFIG_META_PROPERTIES)).get();
     this.supportsMultiProperties =
         this.neo4jGraphVariables.<Boolean>get(Graph.System.system(CONFIG_MULTI_PROPERTIES)).get();
     if ((this.supportsMetaProperties && !this.supportsMultiProperties)
         || (!this.supportsMetaProperties && this.supportsMultiProperties)) {
       tx().rollback();
       throw new UnsupportedOperationException(
           "Neo4jGraph currently requires either both meta- and multi-properties activated or neither activated");
     }
     tx().commit();
     ///////////
   } catch (Exception e) {
     if (this.baseGraph != null) this.baseGraph.shutdown();
     throw new RuntimeException(e.getMessage(), e);
   }
 }