Class OCachedDatabasePoolFactoryImpl

java.lang.Object
com.orientechnologies.orient.core.db.OCachedDatabasePoolFactoryImpl
All Implemented Interfaces:
OCachedDatabasePoolFactory

public class OCachedDatabasePoolFactoryImpl extends Object implements OCachedDatabasePoolFactory
Default implementation of OCachedDatabasePoolFactory

Used in OrientDBEmbedded by default

Works like LRU cache

How it works: 1. Pool cache capacity is 100 2. We have 100 pools in cache 3. We want get 101 pool 4. First we will remove pool which used long time ago from pool cache 5. Then we add new pool from point 3 to pool cache

Author:
Vitalii Honchar (weaxme@gmail.com)
  • Constructor Details

    • OCachedDatabasePoolFactoryImpl

      public OCachedDatabasePoolFactoryImpl(OrientDBInternal orientDB, int capacity, long timeout)
      Parameters:
      orientDB - instance of OrientDB which will be used for create new database pools ODatabasePoolInternal
      capacity - capacity of pool cache, by default is 100
      timeout - timeout in milliseconds which means that every timeout will be executed task for clean up cache from closed pools
  • Method Details

    • scheduleCleanUpCache

      protected void scheduleCleanUpCache(TimerTask task)
    • get

      public ODatabasePoolInternal get(String database, String username, String password, OrientDBConfig parentConfig)
      Get or create database pool instance for given user

      Get or create database pool: 1. Create string database + username + password 2. Create key by hashing this string using SHA-256 3. Try to get pool from cache 4. If pool is in cache and pool is not closed, so return this pool 5. If pool is not in cache or pool is closed, so create new pool and put it in cache

      Specified by:
      get in interface OCachedDatabasePoolFactory
      Parameters:
      database - name of database
      username - name of user which need access to database
      password - user password
      Returns:
      ODatabasePoolInternal which is new instance of pool or instance from pool storage
    • reset

      Close all open pools and clear pool storage
      Specified by:
      reset in interface OCachedDatabasePoolFactory
      Returns:
      this instance
    • close

      public void close()
      Close all open pools and clear pool storage. Set flag closed to true, so this instance can't be used again. Need create new instance of OCachedDatabasePoolFactory after close one of factories.
      Specified by:
      close in interface OCachedDatabasePoolFactory
    • isClosed

      public boolean isClosed()
      Description copied from interface: OCachedDatabasePoolFactory
      Check if factory is closed
      Specified by:
      isClosed in interface OCachedDatabasePoolFactory
      Returns:
      true if factory is closed
    • getMaxPoolSize

      public int getMaxPoolSize()
      Returns:
      max pool size. Default is 64
    • setMaxPoolSize

      public OCachedDatabasePoolFactory setMaxPoolSize(int maxPoolSize)
      Set max pool connections size which will be used for create new ODatabasePool
      Parameters:
      maxPoolSize - max pool connections size
      Returns:
      this instance