Package com.arcadedb.database
Class EmbeddedDatabase
- java.lang.Object
-
- com.arcadedb.utility.RWLockContext
-
- com.arcadedb.database.EmbeddedDatabase
-
- All Implemented Interfaces:
Database
,DatabaseInternal
,AutoCloseable
public class EmbeddedDatabase extends RWLockContext implements DatabaseInternal
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.arcadedb.database.Database
Database.TransactionScope
-
Nested classes/interfaces inherited from interface com.arcadedb.database.DatabaseInternal
DatabaseInternal.CALLBACK_EVENT
-
-
Field Summary
Fields Modifier and Type Field Description protected DatabaseAsyncExecutorImpl
async
protected Lock
asyncLock
protected boolean
autoTransaction
protected ContextConfiguration
configuration
protected String
databasePath
static int
EDGE_LIST_INITIAL_CHUNK_SIZE
protected FileManager
fileManager
protected GraphEngine
graphEngine
AtomicLong
indexCompactions
protected DocumentIndexer
indexer
static int
MAX_RECOMMENDED_EDGE_LIST_CHUNK_SIZE
protected PaginatedFile.MODE
mode
protected String
name
protected boolean
open
protected PageManager
pageManager
protected QueryEngineManager
queryEngineManager
protected RecordFactory
recordFactory
protected EmbeddedSchema
schema
protected BinarySerializer
serializer
protected DatabaseStats
stats
protected TransactionManager
transactionManager
protected WALFileFactory
walFactory
-
Constructor Summary
Constructors Modifier Constructor Description protected
EmbeddedDatabase(String path, PaginatedFile.MODE mode, ContextConfiguration configuration, Map<DatabaseInternal.CALLBACK_EVENT,List<Callable<Void>>> callbacks)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DatabaseAsyncExecutorImpl
async()
void
begin()
Begins a new transaction.protected void
checkDatabaseIsOpen()
boolean
checkTransactionIsActive(boolean createTx)
void
close()
ResultSet
command(String language, String query, Object... parameters)
ResultSet
command(String language, String query, Map<String,Object> parameters)
void
commit()
Commits the current transaction.long
countBucket(String bucketName)
long
countType(String typeName, boolean polymorphic)
protected void
create()
void
createRecord(MutableDocument record)
void
createRecord(Record record, String bucketName)
void
createRecordNoLock(Record record, String bucketName)
void
deleteRecord(Record record)
void
drop()
boolean
equals(Object o)
Returns true if two databases are the same.ResultSet
execute(String language, String script, Object... args)
ResultSet
execute(String language, String script, Map<Object,Object> params)
void
executeCallbacks(DatabaseInternal.CALLBACK_EVENT event)
<RET> RET
executeInReadLock(Callable<RET> callable)
Executes a callback in a shared lock.<RET> RET
executeInWriteLock(Callable<RET> callable)
Executes a callback in an exclusive lock.ContextConfiguration
getConfiguration()
DatabaseContext.DatabaseContextTL
getContext()
String
getDatabasePath()
int
getEdgeListSize(int previousSize)
DatabaseInternal
getEmbedded()
ExecutionPlanCache
getExecutionPlanCache()
FileManager
getFileManager()
GraphEngine
getGraphEngine()
DocumentIndexer
getIndexer()
PaginatedFile.MODE
getMode()
String
getName()
PageManager
getPageManager()
RecordFactory
getRecordFactory()
Schema
getSchema()
BinarySerializer
getSerializer()
StatementCache
getStatementCache()
Map<String,Object>
getStats()
TransactionContext
getTransaction()
TransactionManager
getTransactionManager()
WALFileFactory
getWALFileFactory()
DatabaseInternal
getWrappedDatabaseInstance()
int
hashCode()
void
incrementStatsTxCommits()
boolean
isAutoTransaction()
boolean
isOpen()
boolean
isReadYourWrites()
boolean
isTransactionActive()
Iterator<Record>
iterateBucket(String bucketName)
Iterator<Record>
iterateType(String typeName, boolean polymorphic)
void
kill()
Test only API.IndexCursor
lookupByKey(String type, String[] keyNames, Object[] keyValues)
IndexCursor
lookupByKey(String type, String keyName, Object keyValue)
Record
lookupByRID(RID rid, boolean loadContent)
MutableDocument
newDocument(String typeName)
Edge
newEdgeByKeys(Vertex sourceVertex, String destinationVertexType, String[] destinationVertexKeyNames, Object[] destinationVertexKeyValues, boolean createVertexIfNotExist, String edgeType, boolean bidirectional, Object... properties)
Edge
newEdgeByKeys(String sourceVertexType, String[] sourceVertexKeyNames, Object[] sourceVertexKeyValues, String destinationVertexType, String[] destinationVertexKeyNames, Object[] destinationVertexKeyValues, boolean createVertexIfNotExist, String edgeType, boolean bidirectional, Object... properties)
MutableEmbeddedDocument
newEmbeddedDocument(EmbeddedModifier modifier, String typeName)
MutableVertex
newVertex(String typeName)
protected void
open()
ResultSet
query(String language, String query, Object... parameters)
ResultSet
query(String language, String query, Map<String,Object> parameters)
void
registerCallback(DatabaseInternal.CALLBACK_EVENT event, Callable<Void> callback)
void
rollback()
Rolls back the current transaction.void
rollbackAllNested()
Rolls back all the nested transactions if any.void
scanBucket(String bucketName, RecordCallback callback)
void
scanType(String typeName, boolean polymorphic, DocumentCallback callback)
void
setAutoTransaction(boolean autoTransaction)
void
setEdgeListSize(int size)
void
setReadYourWrites(boolean readYourWrites)
void
setWrappedDatabaseInstance(DatabaseInternal wrappedDatabaseInstance)
String
toString()
void
transaction(Database.TransactionScope txBlock)
Executes a lambda in the transaction scope.boolean
transaction(Database.TransactionScope txBlock, boolean joinCurrentTx)
Executes a lambda in the transaction scope.boolean
transaction(Database.TransactionScope txBlock, boolean joinCurrentTx, int retries)
Executes a lambda in the transaction scope.boolean
transaction(Database.TransactionScope txBlock, boolean joinCurrentTx, int retries, OkCallback ok, ErrorCallback error)
Executes a lambda in the transaction scope.void
unregisterCallback(DatabaseInternal.CALLBACK_EVENT event, Callable<Void> callback)
void
updateRecord(Record record)
void
updateRecordNoLock(Record record)
-
Methods inherited from class com.arcadedb.utility.RWLockContext
readLock, readUnlock, writeLock, writeUnlock
-
-
-
-
Field Detail
-
EDGE_LIST_INITIAL_CHUNK_SIZE
public static final int EDGE_LIST_INITIAL_CHUNK_SIZE
- See Also:
- Constant Field Values
-
MAX_RECOMMENDED_EDGE_LIST_CHUNK_SIZE
public static final int MAX_RECOMMENDED_EDGE_LIST_CHUNK_SIZE
- See Also:
- Constant Field Values
-
indexCompactions
public final AtomicLong indexCompactions
-
name
protected final String name
-
mode
protected final PaginatedFile.MODE mode
-
configuration
protected final ContextConfiguration configuration
-
databasePath
protected final String databasePath
-
serializer
protected final BinarySerializer serializer
-
recordFactory
protected final RecordFactory recordFactory
-
graphEngine
protected final GraphEngine graphEngine
-
walFactory
protected final WALFileFactory walFactory
-
indexer
protected final DocumentIndexer indexer
-
queryEngineManager
protected final QueryEngineManager queryEngineManager
-
stats
protected final DatabaseStats stats
-
fileManager
protected FileManager fileManager
-
pageManager
protected PageManager pageManager
-
schema
protected EmbeddedSchema schema
-
transactionManager
protected TransactionManager transactionManager
-
async
protected volatile DatabaseAsyncExecutorImpl async
-
asyncLock
protected Lock asyncLock
-
autoTransaction
protected boolean autoTransaction
-
open
protected volatile boolean open
-
-
Constructor Detail
-
EmbeddedDatabase
protected EmbeddedDatabase(String path, PaginatedFile.MODE mode, ContextConfiguration configuration, Map<DatabaseInternal.CALLBACK_EVENT,List<Callable<Void>>> callbacks)
-
-
Method Detail
-
open
protected void open()
-
create
protected void create()
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceDatabase
-
async
public DatabaseAsyncExecutorImpl async()
-
getStats
public Map<String,Object> getStats()
- Specified by:
getStats
in interfaceDatabaseInternal
-
getDatabasePath
public String getDatabasePath()
- Specified by:
getDatabasePath
in interfaceDatabase
-
getTransaction
public TransactionContext getTransaction()
- Specified by:
getTransaction
in interfaceDatabase
- Specified by:
getTransaction
in interfaceDatabaseInternal
-
begin
public void begin()
Description copied from interface:Database
Begins a new transaction. If a transaction is already begun, the current transaction is parked and a new sub-transaction is begun. The new sub-transaction does not access to the content of the previous transaction. Sub transactions are totally isolated.
-
incrementStatsTxCommits
public void incrementStatsTxCommits()
-
commit
public void commit()
Description copied from interface:Database
Commits the current transaction. If it was a sub-transaction, then the previous in the stack becomes active again.
-
rollback
public void rollback()
Description copied from interface:Database
Rolls back the current transaction. If it was a sub-transaction, then the previous in the stack becomes active again.
-
rollbackAllNested
public void rollbackAllNested()
Description copied from interface:Database
Rolls back all the nested transactions if any.- Specified by:
rollbackAllNested
in interfaceDatabase
-
countBucket
public long countBucket(String bucketName)
- Specified by:
countBucket
in interfaceDatabase
-
countType
public long countType(String typeName, boolean polymorphic)
-
scanType
public void scanType(String typeName, boolean polymorphic, DocumentCallback callback)
-
scanBucket
public void scanBucket(String bucketName, RecordCallback callback)
- Specified by:
scanBucket
in interfaceDatabase
-
iterateType
public Iterator<Record> iterateType(String typeName, boolean polymorphic)
- Specified by:
iterateType
in interfaceDatabase
-
iterateBucket
public Iterator<Record> iterateBucket(String bucketName)
- Specified by:
iterateBucket
in interfaceDatabase
-
lookupByRID
public Record lookupByRID(RID rid, boolean loadContent)
- Specified by:
lookupByRID
in interfaceDatabase
-
lookupByKey
public IndexCursor lookupByKey(String type, String keyName, Object keyValue)
- Specified by:
lookupByKey
in interfaceDatabase
-
lookupByKey
public IndexCursor lookupByKey(String type, String[] keyNames, Object[] keyValues)
- Specified by:
lookupByKey
in interfaceDatabase
-
registerCallback
public void registerCallback(DatabaseInternal.CALLBACK_EVENT event, Callable<Void> callback)
- Specified by:
registerCallback
in interfaceDatabaseInternal
-
unregisterCallback
public void unregisterCallback(DatabaseInternal.CALLBACK_EVENT event, Callable<Void> callback)
- Specified by:
unregisterCallback
in interfaceDatabaseInternal
-
getGraphEngine
public GraphEngine getGraphEngine()
- Specified by:
getGraphEngine
in interfaceDatabaseInternal
-
getTransactionManager
public TransactionManager getTransactionManager()
- Specified by:
getTransactionManager
in interfaceDatabaseInternal
-
isReadYourWrites
public boolean isReadYourWrites()
- Specified by:
isReadYourWrites
in interfaceDatabase
-
setReadYourWrites
public void setReadYourWrites(boolean readYourWrites)
- Specified by:
setReadYourWrites
in interfaceDatabase
-
createRecord
public void createRecord(MutableDocument record)
- Specified by:
createRecord
in interfaceDatabaseInternal
-
createRecord
public void createRecord(Record record, String bucketName)
- Specified by:
createRecord
in interfaceDatabaseInternal
-
createRecordNoLock
public void createRecordNoLock(Record record, String bucketName)
- Specified by:
createRecordNoLock
in interfaceDatabaseInternal
-
updateRecord
public void updateRecord(Record record)
- Specified by:
updateRecord
in interfaceDatabaseInternal
-
updateRecordNoLock
public void updateRecordNoLock(Record record)
- Specified by:
updateRecordNoLock
in interfaceDatabaseInternal
-
deleteRecord
public void deleteRecord(Record record)
- Specified by:
deleteRecord
in interfaceDatabase
-
isTransactionActive
public boolean isTransactionActive()
- Specified by:
isTransactionActive
in interfaceDatabase
-
transaction
public void transaction(Database.TransactionScope txBlock)
Description copied from interface:Database
Executes a lambda in the transaction scope. If there is an active transaction, then the current transaction is parked and a new sub-transaction is begun.- Specified by:
transaction
in interfaceDatabase
- Parameters:
txBlock
- Transaction lambda to execute
-
transaction
public boolean transaction(Database.TransactionScope txBlock, boolean joinCurrentTx)
Description copied from interface:Database
Executes a lambda in the transaction scope. If there is an active transaction, then the current transaction is parked and a new sub-transaction is begun if joinCurrentTx is true, otherwise the current active transaction is joined.- Specified by:
transaction
in interfaceDatabase
- Parameters:
txBlock
- Transaction lambda to executejoinCurrentTx
- if active joins the current transaction, otherwise always create a new one- Returns:
- true if a new transaction has been created or false if an existent transaction has been joined
-
transaction
public boolean transaction(Database.TransactionScope txBlock, boolean joinCurrentTx, int retries)
Description copied from interface:Database
Executes a lambda in the transaction scope. If there is an active transaction, then the current transaction is parked and a new sub-transaction is begun if joinCurrentTx is true, otherwise the current active transaction is joined. The difference with the methodDatabase.transaction(TransactionScope)
is that in case the NeedRetryException exception is thrown, the transaction is re-executed for a number of retries.- Specified by:
transaction
in interfaceDatabase
- Parameters:
txBlock
- Transaction lambda to executejoinCurrentTx
- if active joins the current transaction, otherwise always create a new oneretries
- number of retries in case the NeedRetryException exception is thrown- Returns:
- true if a new transaction has been created or false if an existent transaction has been joined
-
transaction
public boolean transaction(Database.TransactionScope txBlock, boolean joinCurrentTx, int retries, OkCallback ok, ErrorCallback error)
Description copied from interface:Database
Executes a lambda in the transaction scope. If there is an active transaction, then the current transaction is parked and a new sub-transaction is begun if joinCurrentTx is true, otherwise the current active transaction is joined. The difference with the methodDatabase.transaction(TransactionScope)
is that in case the NeedRetryException exception is thrown, the transaction is re-executed for a number of retries.- Specified by:
transaction
in interfaceDatabase
- Parameters:
txBlock
- Transaction lambda to executejoinCurrentTx
- if active joins the current transaction, otherwise always create a new oneretries
- number of retries in case the NeedRetryException exception is thrownok
- callback invoked if the transaction completes the commiterror
- callback invoked if the transaction cannot complete the commit, after the rollback- Returns:
- true if a new transaction has been created or false if an existent transaction has been joined
-
getRecordFactory
public RecordFactory getRecordFactory()
- Specified by:
getRecordFactory
in interfaceDatabaseInternal
-
getSerializer
public BinarySerializer getSerializer()
- Specified by:
getSerializer
in interfaceDatabaseInternal
-
getPageManager
public PageManager getPageManager()
- Specified by:
getPageManager
in interfaceDatabaseInternal
-
newDocument
public MutableDocument newDocument(String typeName)
- Specified by:
newDocument
in interfaceDatabase
-
newEmbeddedDocument
public MutableEmbeddedDocument newEmbeddedDocument(EmbeddedModifier modifier, String typeName)
- Specified by:
newEmbeddedDocument
in interfaceDatabaseInternal
-
newVertex
public MutableVertex newVertex(String typeName)
-
newEdgeByKeys
public Edge newEdgeByKeys(String sourceVertexType, String[] sourceVertexKeyNames, Object[] sourceVertexKeyValues, String destinationVertexType, String[] destinationVertexKeyNames, Object[] destinationVertexKeyValues, boolean createVertexIfNotExist, String edgeType, boolean bidirectional, Object... properties)
- Specified by:
newEdgeByKeys
in interfaceDatabase
-
newEdgeByKeys
public Edge newEdgeByKeys(Vertex sourceVertex, String destinationVertexType, String[] destinationVertexKeyNames, Object[] destinationVertexKeyValues, boolean createVertexIfNotExist, String edgeType, boolean bidirectional, Object... properties)
- Specified by:
newEdgeByKeys
in interfaceDatabase
-
isAutoTransaction
public boolean isAutoTransaction()
- Specified by:
isAutoTransaction
in interfaceDatabase
-
setAutoTransaction
public void setAutoTransaction(boolean autoTransaction)
- Specified by:
setAutoTransaction
in interfaceDatabase
-
getFileManager
public FileManager getFileManager()
- Specified by:
getFileManager
in interfaceDatabaseInternal
-
getMode
public PaginatedFile.MODE getMode()
-
checkTransactionIsActive
public boolean checkTransactionIsActive(boolean createTx)
- Specified by:
checkTransactionIsActive
in interfaceDatabase
-
kill
public void kill()
Test only API.- Specified by:
kill
in interfaceDatabaseInternal
-
getIndexer
public DocumentIndexer getIndexer()
- Specified by:
getIndexer
in interfaceDatabaseInternal
-
equals
public boolean equals(Object o)
Returns true if two databases are the same.
-
getContext
public DatabaseContext.DatabaseContextTL getContext()
- Specified by:
getContext
in interfaceDatabaseInternal
-
executeInReadLock
public <RET> RET executeInReadLock(Callable<RET> callable)
Executes a callback in a shared lock.- Specified by:
executeInReadLock
in interfaceDatabase
- Overrides:
executeInReadLock
in classRWLockContext
-
executeInWriteLock
public <RET> RET executeInWriteLock(Callable<RET> callable)
Executes a callback in an exclusive lock.- Specified by:
executeInWriteLock
in interfaceDatabase
- Overrides:
executeInWriteLock
in classRWLockContext
-
getStatementCache
public StatementCache getStatementCache()
- Specified by:
getStatementCache
in interfaceDatabaseInternal
-
getExecutionPlanCache
public ExecutionPlanCache getExecutionPlanCache()
- Specified by:
getExecutionPlanCache
in interfaceDatabaseInternal
-
getWALFileFactory
public WALFileFactory getWALFileFactory()
- Specified by:
getWALFileFactory
in interfaceDatabaseInternal
-
executeCallbacks
public void executeCallbacks(DatabaseInternal.CALLBACK_EVENT event) throws IOException
- Specified by:
executeCallbacks
in interfaceDatabaseInternal
- Throws:
IOException
-
getEmbedded
public DatabaseInternal getEmbedded()
- Specified by:
getEmbedded
in interfaceDatabaseInternal
-
getConfiguration
public ContextConfiguration getConfiguration()
- Specified by:
getConfiguration
in interfaceDatabase
-
getWrappedDatabaseInstance
public DatabaseInternal getWrappedDatabaseInstance()
- Specified by:
getWrappedDatabaseInstance
in interfaceDatabaseInternal
-
setWrappedDatabaseInstance
public void setWrappedDatabaseInstance(DatabaseInternal wrappedDatabaseInstance)
-
setEdgeListSize
public void setEdgeListSize(int size)
- Specified by:
setEdgeListSize
in interfaceDatabase
-
getEdgeListSize
public int getEdgeListSize(int previousSize)
- Specified by:
getEdgeListSize
in interfaceDatabaseInternal
-
checkDatabaseIsOpen
protected void checkDatabaseIsOpen()
-
-