Class DBFacade
- java.lang.Object
-
- jetbrains.buildServer.serverSide.db.DBFacade
-
- All Implemented Interfaces:
DBFunctionsProvider,SQLRunnerEx,SQLRunner
public class DBFacade extends Object implements SQLRunnerEx
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jetbrains.buildServer.serverSide.SQLRunner
SQLRunner.NoResultSQLAction, SQLRunner.SQLAction<T>
-
-
Constructor Summary
Constructors Constructor Description DBFacade(TeamCityDatabaseManager dbManager)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidcommitCurrentTransaction()Commits current transactionvoidcompactHsql()DatabaseTypegetDatabaseType()Returns the type of database this data source connected to.org.springframework.jdbc.datasource.DataSourceTransactionManagergetDataSourceTransactionManager()SQLDialectgetDialect()Provides with SQL functions.longgetNextId(String tableName, String idColumnName)org.springframework.transaction.support.TransactionTemplategetTransactionTemplate()Provides with a ready to use Spring's transaction template.static booleanisInsideSpringTransaction()<T> TrunAndRetry(DBAction<T> action)Runs the given function in its own transaction.voidrunAndRetry(DBActionNoResults action)Runs the given procedure in its own transaction.voidrunDdl(String query, String task)Performs the specified DDL command.voidrunDdls(String[] queries)Performs the specified DDL commands.voidrunDmls(String[] queries)Performs the specified DML queries (insert, update, delete), and commits the transaction.voidrunSql(SQLRunner.NoResultSQLAction r)voidrunSql(SQLRunner.NoResultSQLAction r, boolean ignoreError)Deprecated.since 9.0: useGenericQuery<T> TrunSql(SQLRunner.SQLAction<T> r)voidshutdown()<T> TwithDB(DBAction<T> action)Performs the specified function with a database.voidwithDB(DBActionNoResults action)Performs the specified procedure with a database.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jetbrains.buildServer.serverSide.db.DBFunctionsProvider
getWithDB
-
-
-
-
Constructor Detail
-
DBFacade
public DBFacade(@NotNull TeamCityDatabaseManager dbManager)
-
-
Method Detail
-
shutdown
public void shutdown()
-
compactHsql
public void compactHsql()
-
runSql
public final void runSql(@NotNull SQLRunner.NoResultSQLAction r)
-
runSql
@Deprecated public final void runSql(@NotNull SQLRunner.NoResultSQLAction r, boolean ignoreError)
Deprecated.since 9.0: useGenericQuery
-
withDB
public final void withDB(@NotNull DBActionNoResults action)Description copied from interface:DBFunctionsProviderPerforms the specified procedure with a database.- Specified by:
withDBin interfaceDBFunctionsProvider- Parameters:
action- action (class that implements procedureDBActionNoResults.run(jetbrains.buildServer.serverSide.db.DBFunctions)) to perform.- See Also:
DBFunctionsProvider.withDB(DBAction),DBFunctionsProvider.runAndRetry(DBActionNoResults)
-
withDB
public final <T> T withDB(@NotNull DBAction<T> action)Description copied from interface:DBFunctionsProviderPerforms the specified function with a database. TheDBFunctionsProvider.getWithDB(DBAction)is preferred because allows to avoid redundant actions casting to theDBAction.- Specified by:
withDBin interfaceDBFunctionsProvider- Type Parameters:
T- type of returning value.- Parameters:
action- action (class that implement functionDBAction.run(jetbrains.buildServer.serverSide.db.DBFunctions)) to perform.- Returns:
- value returned by action.
DBAction.run(jetbrains.buildServer.serverSide.db.DBFunctions). - See Also:
DBFunctionsProvider.withDB(DBActionNoResults),DBFunctionsProvider.runAndRetry(DBAction)
-
runAndRetry
public final void runAndRetry(@NotNull DBActionNoResults action)Description copied from interface:DBFunctionsProviderRuns the given procedure in its own transaction.If this procedure became a deadlock victim or when
RetryExceptionoccurred, it rolls the transaction back and re-runs the procedure (may be several times). Then, when success, commits the transaction.If an exception (not deadlock) occurred during the execution, the transaction will be rolled back the the occurred exception is thrown.
Warning! - there must be only database works with the given DBF instance inside the transaction. Using other database connections or performing file system operations inside this transaction can cause strange exceptions or even fall the system into stuck. Remember, that the commands inside can be performed several times.
- Specified by:
runAndRetryin interfaceDBFunctionsProvider- Parameters:
action- action (class that implements procedureDBActionNoResults.run(jetbrains.buildServer.serverSide.db.DBFunctions)) to perform.- See Also:
DBFunctionsProvider.runAndRetry(DBAction),DBFunctionsProvider.withDB(DBActionNoResults),RetryException
-
runAndRetry
public final <T> T runAndRetry(@NotNull DBAction<T> action)Description copied from interface:DBFunctionsProviderRuns the given function in its own transaction.If this function became a deadlock victim or when
RetryExceptionoccurred, it rolls the transaction back and re-runs the function (may be several times). Then, when success, commits the transaction.If an exception (not deadlock) occurred during the execution, the transaction will be rolled back the the occurred exception is thrown.
Warning! - there must be only database works with the given DBF instance inside the transaction. Using other database connections or performing file system operations inside this transaction can cause strange exceptions or even fall the system into stuck. Remember, that the commands inside can be performed several times.
- Specified by:
runAndRetryin interfaceDBFunctionsProvider- Type Parameters:
T- type of returning value.- Parameters:
action- action (class that implement functionDBAction.run(jetbrains.buildServer.serverSide.db.DBFunctions)) to perform.- Returns:
- value returned by the function
DBAction.run(jetbrains.buildServer.serverSide.db.DBFunctions). - See Also:
DBFunctionsProvider.runAndRetry(DBActionNoResults),DBFunctionsProvider.withDB(DBAction),RetryException
-
getDialect
@NotNull public SQLDialect getDialect()
Description copied from interface:DBFunctionsProviderProvides with SQL functions.- Specified by:
getDialectin interfaceDBFunctionsProvider- Returns:
- an instance of
SQLDialectobject, probably a shared instance.
-
runDdl
public final void runDdl(@NotNull String query, @NotNull String task) throws org.springframework.jdbc.UncategorizedSQLExceptionPerforms the specified DDL command.- Specified by:
runDdlin interfaceSQLRunnerEx- Parameters:
query- DDL command to perform.task- performing task (for passing to exceptions on problem).- Throws:
org.springframework.jdbc.UncategorizedSQLException
-
runDdls
public final void runDdls(@NotNull String[] queries) throws DBExceptionPerforms the specified DDL commands.- Specified by:
runDdlsin interfaceSQLRunnerEx- Parameters:
queries- DDL commands to perform.- Throws:
DBException
-
runDmls
public final void runDmls(@NotNull String[] queries) throws DBExceptionPerforms the specified DML queries (insert, update, delete), and commits the transaction. Given queries should be without parameters.- Specified by:
runDmlsin interfaceSQLRunnerEx- Parameters:
queries- DML queries to perform.- Throws:
DBException
-
runSql
public final <T> T runSql(@NotNull SQLRunner.SQLAction<T> r)- Specified by:
runSqlin interfaceSQLRunner- Specified by:
runSqlin interfaceSQLRunnerEx
-
isInsideSpringTransaction
public static boolean isInsideSpringTransaction()
-
getTransactionTemplate
public org.springframework.transaction.support.TransactionTemplate getTransactionTemplate()
Description copied from interface:SQLRunnerExProvides with a ready to use Spring's transaction template.This template may be invalidated on some database maintenance operations (such as cleanup, backup, etc.), so don't persist this reference in your classes.
- Specified by:
getTransactionTemplatein interfaceSQLRunnerEx- Returns:
- a Spring's transaction template.
-
getDataSourceTransactionManager
public org.springframework.jdbc.datasource.DataSourceTransactionManager getDataSourceTransactionManager()
-
getDatabaseType
public DatabaseType getDatabaseType()
Description copied from interface:SQLRunnerExReturns the type of database this data source connected to. This method is fast because it just returns the type value, doesn't perfrom any request and doesn't interact with database server ot jdbc driver.- Specified by:
getDatabaseTypein interfaceSQLRunnerEx- Returns:
- the database type.
-
commitCurrentTransaction
public void commitCurrentTransaction()
Description copied from interface:SQLRunnerCommits current transaction- Specified by:
commitCurrentTransactionin interfaceSQLRunner
-
-