本文整理汇总了Java中org.jooq.exception.DataAccessException类的典型用法代码示例。如果您正苦于以下问题:Java DataAccessException类的具体用法?Java DataAccessException怎么用?Java DataAccessException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DataAccessException类属于org.jooq.exception包,在下文中一共展示了DataAccessException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isUnhealthyIfTransactionFails
import org.jooq.exception.DataAccessException; //导入依赖的package包/类
@Test
public void isUnhealthyIfTransactionFails() throws Exception {
MockDataProvider mockDataProvider = new MockDataProvider() {
@Override
public MockResult[] execute(MockExecuteContext ctx) throws SQLException {
throw new SQLException("BOOM");
}
};
try {
runHealthCheck(mockDataProvider);
assert_().fail();
} catch (DataAccessException e) {
assertThat(e.getMessage()).contains(validationQuery);
assertThat(e.getMessage()).contains("BOOM");
}
}
示例2: update
import org.jooq.exception.DataAccessException; //导入依赖的package包/类
@Override
public void update(SettingsForm form) {
String eMails = join(form.getRecipients());
String features = join(form.getEnabledFeatures());
try {
ctx.update(SETTINGS)
.set(SETTINGS.HEARTBEAT_INTERVAL_IN_SECONDS, toSec(form.getHeartbeat()))
.set(SETTINGS.HOURS_TO_EXPIRE, form.getExpiration())
.set(SETTINGS.MAIL_ENABLED, form.getEnabled())
.set(SETTINGS.MAIL_HOST, form.getHost())
.set(SETTINGS.MAIL_USERNAME, form.getUsername())
.set(SETTINGS.MAIL_PASSWORD, form.getPassword())
.set(SETTINGS.MAIL_FROM, form.getFrom())
.set(SETTINGS.MAIL_PROTOCOL, form.getProtocol())
.set(SETTINGS.MAIL_PORT, form.getPort())
.set(SETTINGS.MAIL_RECIPIENTS, eMails)
.set(SETTINGS.NOTIFICATION_FEATURES, features)
.where(SETTINGS.APP_ID.eq(APP_ID))
.execute();
} catch (DataAccessException e) {
throw new SteveException("FAILED to save the settings", e);
}
}
示例3: addOcppTag
import org.jooq.exception.DataAccessException; //导入依赖的package包/类
@Override
public int addOcppTag(OcppTagForm u) {
try {
return ctx.insertInto(OCPP_TAG)
.set(OCPP_TAG.ID_TAG, u.getIdTag())
.set(OCPP_TAG.PARENT_ID_TAG, u.getParentIdTag())
.set(OCPP_TAG.EXPIRY_DATE, toDateTime(u.getExpiration()))
.set(OCPP_TAG.NOTE, u.getNote())
.set(OCPP_TAG.BLOCKED, false)
.set(OCPP_TAG.IN_TRANSACTION, false)
.returning(OCPP_TAG.OCPP_TAG_PK)
.fetchOne()
.getOcppTagPk();
} catch (DataAccessException e) {
if (e.getCause() instanceof SQLIntegrityConstraintViolationException) {
throw new SteveException("A user with idTag '%s' already exists.", u.getIdTag());
} else {
throw new SteveException("Execution of addOcppTag for idTag '%s' FAILED.", u.getIdTag(), e);
}
}
}
示例4: hasIpv6_falseWhenKnownSQLState
import org.jooq.exception.DataAccessException; //导入依赖的package包/类
@Test
public void hasIpv6_falseWhenKnownSQLState() throws SQLException {
SQLSyntaxErrorException sqlException = new SQLSyntaxErrorException(
"Unknown column 'zipkin_annotations.endpoint_ipv6' in 'field list'",
"42S22", 1054);
DataSource dataSource = mock(DataSource.class);
// cheats to lower mock count: this exception is really thrown during execution of the query
when(dataSource.getConnection()).thenThrow(
new DataAccessException(sqlException.getMessage(), sqlException));
Boolean result = MySQLStorage.builder()
.executor(Runnable::run)
.datasource(dataSource)
.build().hasIpv6.get();
assertThat(result).isFalse();
}
示例5: hasIpv6_falseWhenUnknownSQLState
import org.jooq.exception.DataAccessException; //导入依赖的package包/类
/**
* This returns false instead of failing when the SQLState code doesn't imply the column is
* missing. This is to prevent zipkin from crashing due to scenarios we haven't thought up, yet.
* The root error goes into the log in this case.
*/
@Test
public void hasIpv6_falseWhenUnknownSQLState() throws SQLException {
SQLSyntaxErrorException sqlException = new SQLSyntaxErrorException(
"java.sql.SQLSyntaxErrorException: Table 'zipkin.zipkin_annotations' doesn't exist",
"42S02", 1146);
DataSource dataSource = mock(DataSource.class);
// cheats to lower mock count: this exception is really thrown during execution of the query
when(dataSource.getConnection()).thenThrow(
new DataAccessException(sqlException.getMessage(), sqlException));
Boolean result = MySQLStorage.builder()
.executor(Runnable::run)
.datasource(dataSource)
.build().hasIpv6.get();
assertThat(result).isFalse();
}
示例6: hasDependencies_missing
import org.jooq.exception.DataAccessException; //导入依赖的package包/类
@Test
public void hasDependencies_missing() throws SQLException {
SQLSyntaxErrorException sqlException = new SQLSyntaxErrorException(
"SQL [select count(*) from `zipkin_dependencies`]; Table 'zipkin.zipkin_dependencies' doesn't exist\n"
+ " Query is : select count(*) from `zipkin_dependencies`",
"42S02", 1146);
DataSource dataSource = mock(DataSource.class);
// cheats to lower mock count: this exception is really thrown during execution of the query
when(dataSource.getConnection()).thenThrow(
new DataAccessException(sqlException.getMessage(), sqlException));
Boolean result = MySQLStorage.builder()
.executor(Runnable::run)
.datasource(dataSource)
.build().hasPreAggregatedDependencies.get();
assertThat(result).isFalse();
}
示例7: execute
import org.jooq.exception.DataAccessException; //导入依赖的package包/类
@Override
public MockResult[] execute(MockExecuteContext ctx) throws SQLException {
MockResult[] mock = new MockResult[1];
// The execute context contains SQL string(s), bind values, and other meta-data
String sql = ctx.sql();
// Exceptions are propagated through the JDBC and jOOQ APIs
if (sql.equals("SELECT 1")) {
mock[0] = new MockResult(1, DSL.using(SQLDialect.HSQLDB).newResult());
} else {
throw new DataAccessException("Incorrect validation query");
}
return mock;
}
示例8: add
import org.jooq.exception.DataAccessException; //导入依赖的package包/类
/**
* @param entity to add
* @return the persisted entity
* @throws ActivityTrackerException
*/
@Override
public E add(E entity) throws ActivityTrackerException {
E transformedEntity = null;
try {
R persisted;
persisted = jooq.insertInto(transformer.getTable())
.set(transformer.createRecord(entity))
.returning()
.fetchOne();
transformedEntity = transformer.mapToEntity(persisted);
} catch (DataAccessException e) {
ExceptionHandler.getInstance().convertAndThrowException(e, ExceptionLocation.REPOSITORY, ErrorCode.UNKNOWN, e.getMessage());
}
return transformedEntity;
}
示例9: findAll
import org.jooq.exception.DataAccessException; //导入依赖的package包/类
/**
* @return all the entities currently in the database
* @throws ActivityTrackerException
*/
@Override
public List<E> findAll() throws ActivityTrackerException {
List<E> entries = null;
try {
entries = new ArrayList<>();
List<R> queryResults = jooq.selectFrom(transformer.getTable()).fetchInto(transformer.getRecordClass());
for (R queryResult : queryResults) {
E entry = transformer.mapToEntity(queryResult);
entries.add(entry);
}
} catch (DataAccessException e) {
ExceptionHandler.getInstance().convertAndThrowException(e, ExceptionLocation.REPOSITORY, ErrorCode.UNKNOWN, e.getMessage());
}
return entries;
}
示例10: execute
import org.jooq.exception.DataAccessException; //导入依赖的package包/类
@Override
public CompletableFuture<Boolean> execute(final String query, final Object... params)
{
return CompletableFuture.supplyAsync(() -> {
try (Connection connection = getConnection())
{
try (PreparedStatement stmt = prepareStatement(connection, query))
{
bindValues(stmt, params);
return stmt.execute();
}
}
catch (SQLException e)
{
throw new DataAccessException("SQL-Error while doing an execute-query: " + query, e);
}
});
}
示例11: update
import org.jooq.exception.DataAccessException; //导入依赖的package包/类
@Override
public CompletableFuture<Integer> update(final String query, final Object... params)
{
return CompletableFuture.supplyAsync(() -> {
try (Connection connection = getConnection())
{
try (PreparedStatement stmt = prepareStatement(connection, query))
{
bindValues(stmt, params);
return stmt.executeUpdate();
}
}
catch (SQLException e)
{
throw new DataAccessException("SQL-Error while doing an update-query: " + query, e);
}
}, this.executor);
}
示例12: getRandomString
import org.jooq.exception.DataAccessException; //导入依赖的package包/类
protected String getRandomString(String name, boolean visible, boolean uuid) {
String value = get(name);
if ( value == null ) {
if ( uuid ) {
value = UUID.randomUUID().toString();
} else {
byte[] bytes = new byte[64];
random.nextBytes(bytes);
value = Base64.encodeBase64String(bytes);
}
try {
set(name, value, visible);
} catch (DataAccessException e) {
value = get(name);
if ( value == null ) {
throw e;
}
}
}
return value;
}
示例13: apply
import org.jooq.exception.DataAccessException; //导入依赖的package包/类
protected RuntimeException apply(Client client, String itemName) {
try {
create()
.insertInto(CONFIG_ITEM_STATUS,
CONFIG_ITEM_STATUS.NAME,
CONFIG_ITEM_STATUS.AGENT_ID,
CONFIG_ITEM_STATUS.REQUESTED_VERSION,
CONFIG_ITEM_STATUS.REQUESTED_UPDATED)
.values(
itemName,
new Long(client.getResourceId()),
1L,
new Timestamp(System.currentTimeMillis()))
.execute();
return null;
} catch ( DataAccessException e ) {
return e;
}
}
示例14: register
import org.jooq.exception.DataAccessException; //导入依赖的package包/类
@Override
public void register(String name) {
Task task = getTask(name);
if ( task == null ) {
try {
create()
.insertInto(TASK, TASK.NAME)
.values(name)
.execute();
} catch ( DataAccessException e ) {
if ( getTask(name) == null ) {
throw e;
}
}
}
}
示例15: logsAllUnderlyingCauses
import org.jooq.exception.DataAccessException; //导入依赖的package包/类
@Test
public void logsAllUnderlyingCauses() {
SQLException one = new SQLException("a");
SQLException two = new SQLException("b");
SQLException e = new SQLException("fail");
e.setNextException(one);
e.setNextException(two);
DataAccessException dae = new DataAccessException("moar fail", e);
mapper.logException(0, dae);
verify(logger).error(anyString(), eq(e));
verify(logger).error(anyString(), eq(one));
verify(logger).error(anyString(), eq(two));
}