Package com.anylogic.engine.database
- Nested Class Summary
- Field Summary
- Constructor Summary
- Method Summary
- Field Details
- 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 Details
- Method Details
- 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 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
Modifier and Type | Class | Description |
---|---|---|
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 | Field | Description |
---|---|---|
static final String | AL_DB_OBJECTS | |
static final String | AL_OBJECT_NAME | |
static final String | AL_OBJECT_TYPE | |
static final String | AL_OBJECT_USAGE | |
static final String | AL_OBJECT_USAGE_LOG | |
static final String | AL_SELECTED_LOG_OBJECT_NAME | |
static final String | AL_SELECTED_LOG_OBJECT_TYPE | |
static final String | AL_SELECTED_LOG_OBJECTS | |
static final String | ANYLOGIC_IDENTIFIER_PREFIX | |
static final String | CURRENT_VERSION | |
static final String | DATABASE_DB_PATH | |
static final String | DATABASE_DIRECTORY | |
static final String | DROP_SQL_OBJECT | |
static final String | LOG_OBJECT_SUFFIX | |
static final String | PUBLIC_SCHEMA_NAME | |
static final String | SQL_FUNCTION | |
static final String | SQL_TABLE | |
static final String | SQL_VIEW | |
static final String | UNIQUE_AUTOINC_COLUMN_NAME |
Constructor | Description |
---|---|
ModelDatabase |
This constructor is internal and shouldn't be called by user.
it may be removed/renamed in future. |
Modifier and Type | Method | Description |
---|---|---|
static void | createLogSchema |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
static void | deleteExistingLogObjects |
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. |
ResultSet | execute |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
void | exportToExternalDB |
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 |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
int | getAgentTypeId |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
<T extends Enum<T> & IStatechartState<?, | getAgentTypeStateId |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
LRUCache<ModelDatabase.DatabaseCacheKey, | getCache() |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
<R> Object | getCachedValue |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
Connection | getConnection() | |
static String | getCreateTableSQL |
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 |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
int | getStatechartId |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
void | importFromExternalDB |
Imports a single table data from an external database.
|
void | log |
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 |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
static void | restoreUsersViews |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
ResultSet | select |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
ResultSet | selectFrom |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
ResultSet | wrapResultSet |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
@AnyLogicInternalAPI public static final String CURRENT_VERSION
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final String DATABASE_DIRECTORY
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final String DATABASE_DB_PATH
@AnyLogicInternalAPI public static final String PUBLIC_SCHEMA_NAME
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final String DROP_SQL_OBJECT
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final String LOG_OBJECT_SUFFIX
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final String ANYLOGIC_IDENTIFIER_PREFIX
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final String UNIQUE_AUTOINC_COLUMN_NAME
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final String AL_SELECTED_LOG_OBJECTS
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final String AL_SELECTED_LOG_OBJECT_NAME
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final String AL_SELECTED_LOG_OBJECT_TYPE
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final String SQL_TABLE
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final String SQL_VIEW
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final String SQL_FUNCTION
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final String AL_DB_OBJECTS
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final String AL_OBJECT_NAME
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final String AL_OBJECT_TYPE
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final String AL_OBJECT_USAGE
- See Also:
- Constant Field Values
@AnyLogicInternalAPI public static final 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,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> Object getCachedValue(com.querydsl.sql.SQLBindings sqlBindings, String operation, 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(Connection connection) throws 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:
SQLException
@AnyLogicInternalAPI public static void restoreUsersViews(Connection connection, Collection<String> viewNames) throws 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:
SQLException
@AnyLogicInternalAPI public static void restoreUsersViews(Connection connection) throws 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:
SQLException
public static void deleteExistingLogObjects(Connection connection) throws SQLException
This method deletes all the model log data (if any were turned on) from the model database
- Parameters:
connection
- database connection- Throws:
SQLException
@AnyLogicInternalAPI public static String getCreateTableSQL(String tableName, 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, 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 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 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 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:
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 ResultSet select(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 ResultSet execute(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 ResultSet selectFrom(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(Connection sourceConnection, String sourceTableName, 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(String sourceTableName, Connection targetConnection, 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(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.