Package com.anylogic.engine.database
- java.lang.Object
- com.anylogic.engine.database.ModelDBConnectivity
- com.anylogic.engine.database.ModelDatabase
public class ModelDatabase extends ModelDBConnectivity
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
AL_DB_OBJECTS, AL_ID_COLUMN_NAME, AL_LOG_TYPE_TABLE, AL_LOG_TYPE_VIEW, AL_OBJECT_NAME, AL_OBJECT_TYPE, AL_OBJECT_USAGE, AL_OBJECT_USAGE_LOG, AL_SELECTED_LOG_OBJECT_NAME, AL_SELECTED_LOG_OBJECT_TYPE, AL_SELECTED_LOG_OBJECTS, AL_VIEW_DEFINITION, AL_VIEW_NAME, AL_VIEWS_TABLE_NAME, CREATE_VIEW_SQL, CURRENT_VERSION, DATABASE_DB_PATH, DATABASE_DIRECTORY, DROP_SQL_OBJECT, LOG_OBJECT_SUFFIX, PUBLIC_SCHEMA_NAME, SQL_FUNCTION, 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 |
---|---|---|
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.
|
void | importFromExternalDB |
Imports a single table data from an external database.
|
ModelDBConfiguration | initConfiguration() |
This method is internal and shouldn't be called by user.
it may be removed/renamed in future. |
boolean | isLoggingOn | |
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. |
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 ModelDatabase(Engine engine, ModelProperties modelProperties, DatabaseLogState logState)
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 ModelDBConfiguration initConfiguration()
Description copied from class:
ModelDBConnectivity
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.
- Overrides:
initConfiguration
in classModelDBConnectivity
- Returns:
- default implementation does nothing and returns
null
- See Also:
@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
public boolean isLoggingOn(LoggingType loggingType)
@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 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.