| Constructor and Description |
|---|
DatabaseImpl(Connection connection,
Options options) |
DatabaseImpl(DatabaseMock mock,
Flavor flavor) |
DatabaseImpl(DatabaseMock mock,
Options options) |
| Modifier and Type | Method and Description |
|---|---|
void |
assertTimeSynchronized()
Convenience method, same as
Database.assertTimeSynchronized(long, long)
with millisToWarn=10000 and millisToError=30000. |
void |
assertTimeSynchronized(long millisToWarn,
long millisToError)
Check the JVM time (and timezone) against the database and log a warning
or throw an error if they are too far apart.
|
void |
commitNow()
Cause the underlying connection to commit its transaction immediately.
|
Ddl |
ddl(String sql)
Create a DDL (schema modifying) statement for further manipulation and execution.
|
void |
dropSequenceQuietly(String sequenceName)
Convenience method to deal with mutually incompatible syntax for this.
|
void |
dropTableQuietly(String tableName)
Convenience method to deal with dropping tables that may or may not exist.
|
Flavor |
flavor()
Access information about what kind of database we are dealing with.
|
DatabaseImpl |
get() |
Long |
nextSequenceValue(String sequenceName)
Read the next value from a sequence.
|
Date |
nowPerApp()
Get the value that would be used if you specify an argNowPerApp() parameter.
|
Options |
options() |
void |
rollbackNow()
Cause the underlying connection to roll back its transaction immediately.
|
SqlUpdate |
toDelete(Sql sql) |
SqlUpdate |
toDelete(String sql)
Create a SQL "delete" statement for further manipulation and execution.
|
SqlInsert |
toInsert(Sql sql) |
SqlInsert |
toInsert(String sql)
Create a SQL "insert" statement for further manipulation and execution.
|
SqlSelect |
toSelect(Sql sql) |
SqlSelect |
toSelect(String sql)
Create a SQL "select" statement for further manipulation and execution.
|
SqlUpdate |
toUpdate(Sql sql) |
SqlUpdate |
toUpdate(String sql)
Create a SQL "update" statement for further manipulation and execution.
|
Connection |
underlyingConnection()
Obtain direct access to the connection being used by this instance.
|
When |
when()
A little syntax sugar to make it easier to customize your SQL based on the
specific database.
|
public DatabaseImpl(@Nonnull Connection connection, @Nonnull Options options)
public DatabaseImpl(@Nonnull DatabaseMock mock, Flavor flavor)
public DatabaseImpl(@Nonnull DatabaseMock mock, @Nonnull Options options)
@Nonnull public DatabaseImpl get()
get in interface java.util.function.Supplier<Database>get in interface javax.inject.Provider<Database>@Nonnull public SqlInsert toInsert(@Nonnull String sql)
DatabasetoInsert in interface Databasesql - the SQL to execute, optionally containing indexed ("?") or
named (":foo") parameters. To include the characters '?' or ':'
in the SQL you must escape them with two ("??" or "::"). You
MUST be careful not to pass untrusted strings in as SQL, since
this will be executed in the database.@Nonnull public SqlSelect toSelect(@Nonnull String sql)
DatabasetoSelect in interface Databasesql - the SQL to execute, optionally containing indexed ("?") or
named (":foo") parameters. To include the characters '?' or ':'
in the SQL you must escape them with two ("??" or "::"). You
MUST be careful not to pass untrusted strings in as SQL, since
this will be executed in the database.@Nonnull public SqlUpdate toUpdate(@Nonnull String sql)
DatabasetoUpdate in interface Databasesql - the SQL to execute, optionally containing indexed ("?") or
named (":foo") parameters. To include the characters '?' or ':'
in the SQL you must escape them with two ("??" or "::"). You
MUST be careful not to pass untrusted strings in as SQL, since
this will be executed in the database.@Nonnull public SqlUpdate toDelete(@Nonnull String sql)
DatabasetoDelete in interface Databasesql - the SQL to execute, optionally containing indexed ("?") or
named (":foo") parameters. To include the characters '?' or ':'
in the SQL you must escape them with two ("??" or "::"). You
MUST be careful not to pass untrusted strings in as SQL, since
this will be executed in the database.@Nonnull public Ddl ddl(@Nonnull String sql)
Databaseddl in interface Databasesql - the SQL to execute, optionally containing indexed ("?") or
named (":foo") parameters. To include the characters '?' or ':'
in the SQL you must escape them with two ("??" or "::"). You
MUST be careful not to pass untrusted strings in as SQL, since
this will be executed in the database.public Long nextSequenceValue(@Nonnull String sequenceName)
DatabasenextSequenceValue in interface Databasepublic Date nowPerApp()
Databasepublic void commitNow()
DatabaseOptions,
or it will throw a DatabaseException.public void rollbackNow()
DatabaseOptions,
or it will throw a DatabaseException.rollbackNow in interface Database@Nonnull public Connection underlyingConnection()
DatabaseObtain direct access to the connection being used by this instance. Be very careful as this is highly likely to be unsafe and cause you great pain and suffering. This method is included to help ease into the library in large codebases where some parts still rely on direct JDBC access.
By default this method will throw a DatabaseException. If you want
to use this method you must explicitly enable it via
Options.allowConnectionAccess()
underlyingConnection in interface Database@Nonnull public Flavor flavor()
Database@Nonnull public When when()
DatabaseA little syntax sugar to make it easier to customize your SQL based on the specific database. For example:
"select 1" + db.when().oracle(" from dual")
"select " + db.when().postgres("date_trunc('day',").other("trunc(") + ") ..."public void dropSequenceQuietly(@Nonnull String sequenceName)
DatabaseOracle: 'drop sequence x'
Derby: 'drop sequence x restrict'
"dropSequenceQuietly in interface Databasepublic void dropTableQuietly(@Nonnull String tableName)
DatabasedropTableQuietly in interface DatabasetableName - the table to be droppedpublic void assertTimeSynchronized(long millisToWarn,
long millisToError)
DatabaseassertTimeSynchronized in interface DatabasemillisToWarn - if the clocks disagree by more than this and less than
millisToError, a warning will be dropped in the logmillisToError - if the clocks disagree by more than this a
DatabaseEception will be thrownpublic void assertTimeSynchronized()
DatabaseDatabase.assertTimeSynchronized(long, long)
with millisToWarn=10000 and millisToError=30000.assertTimeSynchronized in interface DatabaseCopyright © 2016. All rights reserved.