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, SecurityManager security, Map<DatabaseInternal.CALLBACK_EVENT,List<Callable<Void>>> callbacks)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Map<String,Object>
alignToReplicas()
DatabaseAsyncExecutorImpl
async()
void
begin()
Begins a new transaction.protected void
checkDatabaseIsOpen()
void
checkPermissionsOnDatabase(SecurityDatabaseUser.DATABASE_ACCESS access)
void
checkPermissionsOnFile(int fileId, SecurityDatabaseUser.ACCESS access)
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<String,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()
File
getConfigurationFile()
DatabaseContext.DatabaseContextTL
getContext()
String
getCurrentUserName()
Return the current username if the database supports security.String
getDatabasePath()
int
getEdgeListSize(int previousSize)
DatabaseInternal
getEmbedded()
RecordEvents
getEvents()
ExecutionPlanCache
getExecutionPlanCache()
FileManager
getFileManager()
GraphEngine
getGraphEngine()
DocumentIndexer
getIndexer()
PaginatedFile.MODE
getMode()
String
getName()
PageManager
getPageManager()
QueryEngineManager
getQueryEngineManager()
long
getReadTimeout()
RecordFactory
getRecordFactory()
long
getResultSetLimit()
Schema
getSchema()
SecurityManager
getSecurity()
BinarySerializer
getSerializer()
StatementCache
getStatementCache()
Map<String,Object>
getStats()
TransactionContext
getTransaction()
TransactionManager
getTransactionManager()
WALFileFactory
getWALFileFactory()
DatabaseInternal
getWrappedDatabaseInstance()
Map<String,Object>
getWrappers()
int
hashCode()
void
incrementStatsTxCommits()
boolean
isAsyncFlush()
boolean
isAutoTransaction()
Returns true if a transaction is started automatically for all non-idempotent operation in the database.boolean
isOpen()
boolean
isReadYourWrites()
boolean
isTransactionActive()
Returns true if there is a transaction active.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)
<RET> RET
recordFileChanges(Callable<Object> callback)
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
saveConfiguration()
void
scanBucket(String bucketName, RecordCallback callback)
void
scanBucket(String bucketName, RecordCallback callback, ErrorRecordCallback errorRecordCallback)
void
scanType(String typeName, boolean polymorphic, DocumentCallback callback)
void
scanType(String typeName, boolean polymorphic, DocumentCallback callback, ErrorRecordCallback errorRecordCallback)
EmbeddedDatabase
setAsyncFlush(boolean value)
void
setAutoTransaction(boolean autoTransaction)
void
setEdgeListSize(int size)
void
setReadYourWrites(boolean readYourWrites)
EmbeddedDatabase
setUseWAL(boolean useWAL)
EmbeddedDatabase
setWALFlush(WALFile.FLUSH_TYPE flush)
void
setWrappedDatabaseInstance(DatabaseInternal wrappedDatabaseInstance)
void
setWrapper(String name, Object instance)
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 attempts, 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, SecurityManager security, 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
-
kill
public void kill()
Test only API. Simulates a forced kill of the JVM leaving the database with the .lck file on the file system.- Specified by:
kill
in interfaceDatabaseInternal
-
async
public DatabaseAsyncExecutorImpl async()
-
getStats
public Map<String,Object> getStats()
- Specified by:
getStats
in interfaceDatabaseInternal
-
getDatabasePath
public String getDatabasePath()
- Specified by:
getDatabasePath
in interfaceDatabase
-
getCurrentUserName
public String getCurrentUserName()
Description copied from interface:Database
Return the current username if the database supports security. If used embedded, ArcadeDB does not provide a security model. If you want to use database security, use ArcadeDB server.- Specified by:
getCurrentUserName
in interfaceDatabase
-
getTransaction
public TransactionContext getTransaction()
- 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)
-
scanType
public void scanType(String typeName, boolean polymorphic, DocumentCallback callback, ErrorRecordCallback errorRecordCallback)
-
scanBucket
public void scanBucket(String bucketName, RecordCallback callback)
- Specified by:
scanBucket
in interfaceDatabase
-
scanBucket
public void scanBucket(String bucketName, RecordCallback callback, ErrorRecordCallback errorRecordCallback)
- 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
-
checkPermissionsOnDatabase
public void checkPermissionsOnDatabase(SecurityDatabaseUser.DATABASE_ACCESS access)
- Specified by:
checkPermissionsOnDatabase
in interfaceDatabaseInternal
-
checkPermissionsOnFile
public void checkPermissionsOnFile(int fileId, SecurityDatabaseUser.ACCESS access)
- Specified by:
checkPermissionsOnFile
in interfaceDatabaseInternal
-
getResultSetLimit
public long getResultSetLimit()
- Specified by:
getResultSetLimit
in interfaceDatabaseInternal
-
getReadTimeout
public long getReadTimeout()
- Specified by:
getReadTimeout
in interfaceDatabaseInternal
-
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
-
setUseWAL
public EmbeddedDatabase setUseWAL(boolean useWAL)
-
setWALFlush
public EmbeddedDatabase setWALFlush(WALFile.FLUSH_TYPE flush)
- Specified by:
setWALFlush
in interfaceDatabase
-
isAsyncFlush
public boolean isAsyncFlush()
- Specified by:
isAsyncFlush
in interfaceDatabase
-
setAsyncFlush
public EmbeddedDatabase setAsyncFlush(boolean value)
- Specified by:
setAsyncFlush
in interfaceDatabase
-
createRecord
public void createRecord(MutableDocument record)
- Specified by:
createRecord
in interfaceDatabaseInternal
-
getEvents
public RecordEvents getEvents()
-
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()
Description copied from interface:Database
Returns true if there is a transaction active. A transaction is active if it is in the following states: `{BEGUN, COMMIT_1ST_PHASE, COMMIT_2ND_PHASE}`.- 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 attempts, 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 oneattempts
- number of attempts 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()
Description copied from interface:Database
Returns true if a transaction is started automatically for all non-idempotent operation in the database.- 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 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
-
getSecurity
public SecurityManager getSecurity()
-
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
-
recordFileChanges
public <RET> RET recordFileChanges(Callable<Object> callback)
- Specified by:
recordFileChanges
in interfaceDatabaseInternal
-
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
-
getConfigurationFile
public File getConfigurationFile()
-
getEmbedded
public DatabaseInternal getEmbedded()
- Specified by:
getEmbedded
in interfaceDatabaseInternal
-
getConfiguration
public ContextConfiguration getConfiguration()
- Specified by:
getConfiguration
in interfaceDatabase
-
alignToReplicas
public Map<String,Object> alignToReplicas()
- Specified by:
alignToReplicas
in interfaceDatabaseInternal
-
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
-
getWrappers
public Map<String,Object> getWrappers()
- Specified by:
getWrappers
in interfaceDatabaseInternal
-
setWrapper
public void setWrapper(String name, Object instance)
- Specified by:
setWrapper
in interfaceDatabaseInternal
-
getQueryEngineManager
public QueryEngineManager getQueryEngineManager()
-
saveConfiguration
public void saveConfiguration() throws IOException
- Specified by:
saveConfiguration
in interfaceDatabaseInternal
- Throws:
IOException
-
checkDatabaseIsOpen
protected void checkDatabaseIsOpen()
-
-