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 void
commitCurrentTransaction()
Commits current transactionvoid
compactHsql()
DatabaseType
getDatabaseType()
Returns the type of database this data source connected to.org.springframework.jdbc.datasource.DataSourceTransactionManager
getDataSourceTransactionManager()
SQLDialect
getDialect()
Provides with SQL functions.long
getNextId(String tableName, String idColumnName)
org.springframework.transaction.support.TransactionTemplate
getTransactionTemplate()
Provides with a ready to use Spring's transaction template.static boolean
isInsideSpringTransaction()
<T> T
runAndRetry(DBAction<T> action)
Runs the given function in its own transaction.void
runAndRetry(DBActionNoResults action)
Runs the given procedure in its own transaction.void
runDdl(String query, String task)
Performs the specified DDL command.void
runDdls(String[] queries)
Performs the specified DDL commands.void
runDmls(String[] queries)
Performs the specified DML queries (insert, update, delete), and commits the transaction.void
runSql(SQLRunner.NoResultSQLAction r)
void
runSql(SQLRunner.NoResultSQLAction r, boolean ignoreError)
Deprecated.since 9.0: useGenericQuery
<T> T
runSql(SQLRunner.SQLAction<T> r)
void
shutdown()
<T> T
withDB(DBAction<T> action)
Performs the specified function with a database.void
withDB(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:DBFunctionsProvider
Performs the specified procedure with a database.- Specified by:
withDB
in 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:DBFunctionsProvider
Performs the specified function with a database. TheDBFunctionsProvider.getWithDB(DBAction)
is preferred because allows to avoid redundant actions casting to theDBAction
.- Specified by:
withDB
in 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:DBFunctionsProvider
Runs the given procedure in its own transaction.If this procedure became a deadlock victim or when
RetryException
occurred, 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:
runAndRetry
in 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:DBFunctionsProvider
Runs the given function in its own transaction.If this function became a deadlock victim or when
RetryException
occurred, 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:
runAndRetry
in 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:DBFunctionsProvider
Provides with SQL functions.- Specified by:
getDialect
in interfaceDBFunctionsProvider
- Returns:
- an instance of
SQLDialect
object, probably a shared instance.
-
runDdl
public final void runDdl(@NotNull String query, @NotNull String task) throws org.springframework.jdbc.UncategorizedSQLException
Performs the specified DDL command.- Specified by:
runDdl
in 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 DBException
Performs the specified DDL commands.- Specified by:
runDdls
in interfaceSQLRunnerEx
- Parameters:
queries
- DDL commands to perform.- Throws:
DBException
-
runDmls
public final void runDmls(@NotNull String[] queries) throws DBException
Performs the specified DML queries (insert, update, delete), and commits the transaction. Given queries should be without parameters.- Specified by:
runDmls
in interfaceSQLRunnerEx
- Parameters:
queries
- DML queries to perform.- Throws:
DBException
-
runSql
public final <T> T runSql(@NotNull SQLRunner.SQLAction<T> r)
- Specified by:
runSql
in interfaceSQLRunner
- Specified by:
runSql
in interfaceSQLRunnerEx
-
isInsideSpringTransaction
public static boolean isInsideSpringTransaction()
-
getTransactionTemplate
public org.springframework.transaction.support.TransactionTemplate getTransactionTemplate()
Description copied from interface:SQLRunnerEx
Provides 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:
getTransactionTemplate
in interfaceSQLRunnerEx
- Returns:
- a Spring's transaction template.
-
getDataSourceTransactionManager
public org.springframework.jdbc.datasource.DataSourceTransactionManager getDataSourceTransactionManager()
-
getDatabaseType
public DatabaseType getDatabaseType()
Description copied from interface:SQLRunnerEx
Returns 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:
getDatabaseType
in interfaceSQLRunnerEx
- Returns:
- the database type.
-
commitCurrentTransaction
public void commitCurrentTransaction()
Description copied from interface:SQLRunner
Commits current transaction- Specified by:
commitCurrentTransaction
in interfaceSQLRunner
-
-