Package com.anylogic.engine.database
- Nested Class Summary
- Field Summary
- Constructor Summary
- Method Summary
- Methods inherited from class java.lang.Object
- Field Detail
- CURRENT_VERSION
- DATABASE_DIRECTORY
- DATABASE_DB_PATH
- PUBLIC_SCHEMA_NAME
- DROP_SQL_OBJECT
- LOG_OBJECT_SUFFIX
- ANYLOGIC_IDENTIFIER_PREFIX
- UNIQUE_AUTOINC_COLUMN_NAME
- AL_SELECTED_LOG_OBJECTS
- AL_SELECTED_LOG_OBJECT_NAME
- AL_SELECTED_LOG_OBJECT_TYPE
- SQL_TABLE
- SQL_VIEW
- SQL_FUNCTION
- AL_DB_OBJECTS
- AL_OBJECT_NAME
- AL_OBJECT_TYPE
- AL_OBJECT_USAGE
- AL_OBJECT_USAGE_LOG
- Constructor Detail
- Method Detail
- getCache
- getCachedValue
- createLogSchema
- restoreUsersViews
- restoreUsersViews
- deleteExistingLogObjects
- getCreateTableSQL
- log
- getAgentTypeId
- generateAgentElementId
- generateAgentId
- getEventId
- getStatechartId
- getAgentTypeElementId
- getAgentTypeStateId
- getConnection
- disconnect
- resetBeforeStart
- getDSLConfiguration
- select
- execute
- selectFrom
- importFromExternalDB
- exportToExternalDB
- wrapResultSet
- java.lang.Object
-
- com.anylogic.engine.database.ModelDatabase
public class ModelDatabase
extends java.lang.Object
This class represents the built-in AnyLogic Model Database. Almost all the methods of this class are internal.
The database object may be accessed from
getEngine().getModelDatabase()
and may be used for import /
export with external data sources.- Author:
- AnyLogic North America, LLC https://anylogic.com
static class |
ModelDatabase.DatabaseCacheKey |
This class is internal and shouldn't be called by user.
it may be removed/renamed in future. |
Modifier and Type | Class | Description |
---|
static java.lang.String |
AL_DB_OBJECTS |
|
static java.lang.String |
AL_OBJECT_NAME |
|
static java.lang.String |
AL_OBJECT_TYPE |
|
static java.lang.String |
AL_OBJECT_USAGE |
|
static java.lang.String |
AL_OBJECT_USAGE_LOG |
|
static java.lang.String |
AL_SELECTED_LOG_OBJECT_NAME |
|
static java.lang.String |
AL_SELECTED_LOG_OBJECT_TYPE |
|
static java.lang.String |
AL_SELECTED_LOG_OBJECTS |
|
static java.lang.String |
ANYLOGIC_IDENTIFIER_PREFIX |
|
static java.lang.String |
CURRENT_VERSION |
|
static java.lang.String |
DATABASE_DB_PATH |
|
static java.lang.String |
DATABASE_DIRECTORY |
|
static java.lang.String |
DROP_SQL_OBJECT |
|
static java.lang.String |
LOG_OBJECT_SUFFIX |
|
static java.lang.String |
PUBLIC_SCHEMA_NAME |
|
static java.lang.String |
SQL_FUNCTION |
|
static java.lang.String |
SQL_TABLE |
|
static java.lang.String |
SQL_VIEW |
|
static java.lang.String |
UNIQUE_AUTOINC_COLUMN_NAME |
|
Modifier and Type | Field | Description |
---|
ModelDatabase(Engine engine,
ModelProperties modelProperties,
DatabaseLogProperties logProperties) |
This constructor is internal and shouldn't be called by user.
it may be removed/renamed in future. |
Constructor | Description |
---|
static void |
createLogSchema(java.sql.Connection connection) |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
static void |
deleteExistingLogObjects(java.sql.Connection connection) |
This method deletes all the model log data (if any were turned on) from the model database
|
void |
disconnect() |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
java.sql.ResultSet |
execute(java.lang.String sqlStatement) |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
void |
exportToExternalDB(java.lang.String sourceTableName,
java.sql.Connection targetConnection,
java.lang.String targetTableName,
boolean clearTargetTable,
boolean autoCommit) |
Exports a single table data from this database to an external database.
|
int |
generateAgentElementId() |
This method returns id property of dynamically create model elements
|
int |
generateAgentId() |
Internal method, used to initialize
Agent.getId() property |
int |
getAgentTypeElementId(LoggingType loggingType,
Agent agent,
java.lang.String elementName) |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
int |
getAgentTypeId(Agent agent) |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
<T extends java.lang.Enum<T> & IStatechartState<?,T>> |
getAgentTypeStateId(Agent agent,
Statechart<T> statechart,
T state) |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
LRUCache<ModelDatabase.DatabaseCacheKey,java.lang.Object> |
getCache() |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
<R> java.lang.Object |
getCachedValue(com.querydsl.sql.SQLBindings sqlBindings,
java.lang.String operation,
java.util.function.Supplier<R> f) |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
java.sql.Connection |
getConnection() |
|
static java.lang.String |
getCreateTableSQL(java.lang.String tableName,
java.lang.String tableContent,
boolean cached) |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
com.querydsl.sql.Configuration |
getDSLConfiguration() |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
int |
getEventId(EventOriginator event) |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
int |
getStatechartId(Statechart<?> statechart) |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
void |
importFromExternalDB(java.sql.Connection sourceConnection,
java.lang.String sourceTableName,
java.lang.String targetTableName,
boolean clearTargetTable,
boolean autoCommit) |
Imports a single table data from an external database.
|
void |
log(ILogEntry logEntry) |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
void |
resetBeforeStart() |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
static void |
restoreUsersViews(java.sql.Connection connection) |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
static void |
restoreUsersViews(java.sql.Connection connection,
java.util.Collection<java.lang.String> viewNames) |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
java.sql.ResultSet |
select(java.lang.String sqlQuery) |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
java.sql.ResultSet |
selectFrom(java.lang.String tableName) |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
ResultSet |
wrapResultSet(java.sql.ResultSet results) |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
Modifier and Type | Method | Description |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
@AnyLogicInternalAPI public static final java.lang.String CURRENT_VERSION
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final java.lang.String DATABASE_DIRECTORY
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final java.lang.String DATABASE_DB_PATH
@AnyLogicInternalAPI public static final java.lang.String PUBLIC_SCHEMA_NAME
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final java.lang.String DROP_SQL_OBJECT
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final java.lang.String LOG_OBJECT_SUFFIX
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final java.lang.String ANYLOGIC_IDENTIFIER_PREFIX
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final java.lang.String UNIQUE_AUTOINC_COLUMN_NAME
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final java.lang.String AL_SELECTED_LOG_OBJECTS
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final java.lang.String AL_SELECTED_LOG_OBJECT_NAME
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final java.lang.String AL_SELECTED_LOG_OBJECT_TYPE
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final java.lang.String SQL_TABLE
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final java.lang.String SQL_VIEW
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final java.lang.String SQL_FUNCTION
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final java.lang.String AL_DB_OBJECTS
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final java.lang.String AL_OBJECT_NAME
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final java.lang.String AL_OBJECT_TYPE
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final java.lang.String AL_OBJECT_USAGE
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final java.lang.String AL_OBJECT_USAGE_LOG
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public ModelDatabase(Engine engine, ModelProperties modelProperties, DatabaseLogProperties logProperties)
This constructor is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
@AnyLogicInternalAPI public LRUCache<ModelDatabase.DatabaseCacheKey,java.lang.Object> getCache()
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
@AnyLogicInternalAPI public <R> java.lang.Object getCachedValue(com.querydsl.sql.SQLBindings sqlBindings, java.lang.String operation, java.util.function.Supplier<R> f)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
@AnyLogicInternalAPI public static void createLogSchema(java.sql.Connection connection) throws java.sql.SQLException
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
- Throws:
java.sql.SQLException
@AnyLogicInternalAPI public static void restoreUsersViews(java.sql.Connection connection, java.util.Collection<java.lang.String> viewNames) throws java.sql.SQLException
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
- Throws:
java.sql.SQLException
@AnyLogicInternalAPI public static void restoreUsersViews(java.sql.Connection connection) throws java.sql.SQLException
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
- Throws:
java.sql.SQLException
public static void deleteExistingLogObjects(java.sql.Connection connection) throws java.sql.SQLException
This method deletes all the model log data (if any were turned on) from the model database
- Parameters:
connection
- database connection- Throws:
java.sql.SQLException
@AnyLogicInternalAPI public static java.lang.String getCreateTableSQL(java.lang.String tableName, java.lang.String tableContent, boolean cached)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
@AnyLogicInternalAPI public void log(ILogEntry logEntry)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
@AnyLogicInternalAPI public int getAgentTypeId(Agent agent)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
@AnyLogicInternalAPI public int generateAgentElementId()
This method returns id property of dynamically create model elements
@AnyLogicInternalAPI public int generateAgentId()
Internal method, used to initialize
Agent.getId()
property@AnyLogicInternalAPI public int getEventId(EventOriginator event)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
@AnyLogicInternalAPI public int getStatechartId(Statechart<?> statechart)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
@AnyLogicInternalAPI public int getAgentTypeElementId(LoggingType loggingType, Agent agent, java.lang.String elementName)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
@AnyLogicInternalAPI public <T extends java.lang.Enum<T> & IStatechartState<?,T>> int getAgentTypeStateId(Agent agent, Statechart<T> statechart, T state)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
@AnyLogicInternalAPI public java.sql.Connection getConnection()
@AnyLogicInternalAPI public void disconnect()
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
@AnyLogicInternalAPI public void resetBeforeStart() throws java.lang.Exception
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
- Throws:
java.lang.Exception
@AnyLogicInternalAPI public com.querydsl.sql.Configuration getDSLConfiguration()
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
@AnyLogicInternalAPI public java.sql.ResultSet select(java.lang.String sqlQuery)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
@AnyLogicInternalAPI public java.sql.ResultSet execute(java.lang.String sqlStatement)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
@AnyLogicInternalAPI public java.sql.ResultSet selectFrom(java.lang.String tableName)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
public void importFromExternalDB(java.sql.Connection sourceConnection, java.lang.String sourceTableName, java.lang.String targetTableName, boolean clearTargetTable, boolean autoCommit)
Imports a single table data from an external database. Column types should match or be convertible.
- Parameters:
sourceConnection
- Connection object for external database to copy data fromsourceTableName
- name of the table in external database to copy data fromtargetTableName
- table in this database where the data should be copied toclearTargetTable
- iftrue
the target table will be cleared before data is copiedautoCommit
- if this parameter isfalse
, this action will not open or commit any transaction (which may decrease performance in some cases).
Usage example (performing multiple operations in a single transaction)ModelDatabase modelDB = getEngine().getModelDatabase(); Connection targetConnection = modelDB.getConnection(); targetConnection.setAutoCommit(false); try { modelDB.importFromExternalDB( ... , false); modelDB.importFromExternalDB( ... , false); modelDB.importFromExternalDB( ... , false); targetConnection.commit(); } catch (Exception e) { targetConnection.rollback(); } finally { targetConnection.setAutoCommit(true); }
public void exportToExternalDB(java.lang.String sourceTableName, java.sql.Connection targetConnection, java.lang.String targetTableName, boolean clearTargetTable, boolean autoCommit)
Exports a single table data from this database to an external database. Column types should match or be convertible.
When exporting to
When exporting to
Database#getConnection()
, depending on the external database implementation, the data may be actually saved when
the model is stopped (when Engine will automatically call Database#disconnect()
at the end).
For custom experiment this requires calling engine.stop()
at the end.- Parameters:
sourceTableName
- table in this database to copy data fromtargetConnection
- Connection object for external database to copy data totargetTableName
- table in external database where the data should be copied toclearTargetTable
- iftrue
the target table will be cleared before data is copiedautoCommit
- if this parameter isfalse
, this action will not open or commit any transaction (which may decrease performance in some cases).
Usage example (performing multiple operations in a single transaction)ModelDatabase modelDB = getEngine().getModelDatabase(); Connection targetConnection = targetDB.getConnection(); targetConnection.setAutoCommit(false); try { modelDB.exportToExternalDB( ... , false); modelDB.exportToExternalDB( ... , false); modelDB.exportToExternalDB( ... , false); targetConnection.commit(); } catch (Exception e) { targetConnection.rollback(); } finally { targetConnection.setAutoCommit(true); }
@AnyLogicInternalAPI public ResultSet wrapResultSet(java.sql.ResultSet results)
This method is internal and shouldn't be called by user.
it may be removed/renamed in future.
it may be removed/renamed in future.
-
How can we improve this article?
-