Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.tinkerpop.blueprints.impls.orient;
  
  
  
 public class OrientGraphFactory extends OrientConfigurableGraph {
   protected final String                      url;
   protected final String                      user;
   protected final String                      password;
   protected volatile OPartitionedDatabasePool pool;
   protected OIntent                           intent;
   protected AtomicBoolean                     used = new AtomicBoolean(false);

  
Creates a factory that use default admin credentials.

Parameters:
iURL to the database
 
   public OrientGraphFactory(final String iURL) {
     this(iURL..);
   }

  
Creates a factory with given credentials.

Parameters:
iURL to the database
iUser name of the user
iPassword of the user
 
   public OrientGraphFactory(final String iURLfinal String iUserfinal String iPassword) {
      = iURL;
      = iUser;
      = iPassword;
   }

  
Closes all pooled databases and clear the pool.
 
   public void close() {
 		if ( != null)
 
      = null;
   }

  
Drops current database if such one exists.
 
   public void drop() {
     getDatabase(falsetrue).drop();
   }

  
Gets transactional graph with the database from pool if pool is configured. Otherwise creates a graph with new db instance. The Graph instance inherits the factory's configuration.

Returns:
transactional graph
 
   public OrientGraph getTx() {
     final OrientGraph g;
     if ( == null) {
       g = new OrientGraph(getDatabase(), );
     } else {
       // USE THE POOL
       g = new OrientGraph();
     }
 
     initGraph(g);
     return g;
   }

  
Gets non transactional graph with the database from pool if pool is configured. Otherwise creates a graph with new db instance. The Graph instance inherits the factory's configuration.

Returns:
non transactional graph
 
   public OrientGraphNoTx getNoTx() {
     final OrientGraphNoTx g;
     if ( == null) {
       g = new OrientGraphNoTx(getDatabase(), );
     } else {
       // USE THE POOL
       g = new OrientGraphNoTx();
     }
 
     initGraph(g);
     return g;
   }

  
Gives new connection to database. If current factory configured to use pool (see setupPool(int,int) method), retrieves connection from pool. Otherwise creates new connection each time. Automatically creates database if database with given URL does not exist Shortcut for getDatabase(true)

Returns:
database.
    return getDatabase(truetrue);
  }

  
Gives new connection to database. If current factory configured to use pool (see setupPool(int,int) method), retrieves connection from pool. Otherwise creates new connection each time.

Parameters:
iCreate if true automatically creates database if database with given URL does not exist
iOpen if true automatically opens the database
Returns:
database
  public ODatabaseDocumentTx getDatabase(final boolean iCreatefinal boolean iOpen) {
    final ODatabaseDocumentTx db = new ODatabaseDocumentTx();
    if (!db.getURL().startsWith("remote:") && !db.exists()) {
      if (iCreate)
        db.create();
      else if (iOpen)
        throw new ODatabaseException("Database '" +  + "' not found");
    } else if (iOpen)
      db.open();
    return db;
  }

  
Check if the database with path given to the factory exists.

Returns:
true if database is exists
  public boolean exists() {
    final ODatabaseDocumentTx db = getDatabase(falsefalse);
    try {
      return db.exists();
    } finally {
      db.close();
    }
  }

  
Setting up the factory to use database pool instead of creation a new instance of database connection each time.

Parameters:
iMin minimum size of pool
iMax maximum size of pool
Returns:
this
  public OrientGraphFactory setupPool(final int iMinfinal int iMax) {
     = new OPartitionedDatabasePool(iMax);
    return this;
  }

  
Returns the number of available instances in the pool.
  public int getAvailableInstancesInPool() {
    if ( != null)
      return .getAvailableConnections();
    return 0;
  }

  
Returns the total number of instances created in the pool.
  public int getCreatedInstancesInPool() {
    if ( != null)
      return .getCreatedInstances();
    return 0;
  }
  public void declareIntent(final OIntent iIntent) {
     = iIntent;
  }
  protected void initGraph(final OrientBaseGraph g) {
    if (.compareAndSet(falsetrue)) {
      // EXECUTE ONLY ONCE
      final ODatabaseDocumentTx db = g.getRawGraph();
      boolean txActive = db.getTransaction().isActive();
      if (txActive)
        // COMMIT TX BEFORE ANY SCHEMA CHANGES
        db.commit();
      g.checkForGraphSchema(db);
      if (txActive)
        // REOPEN IT AGAIN
        db.begin();
    }
    if ( != null)
      g.declareIntent(.copy());
  }
  protected void finalize() throws Throwable {
    close();
    super.finalize();
  }
New to GrepCode? Check out our FAQ X