本文整理汇总了Java中org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException类的典型用法代码示例。如果您正苦于以下问题:Java UnableToExecuteStatementException类的具体用法?Java UnableToExecuteStatementException怎么用?Java UnableToExecuteStatementException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnableToExecuteStatementException类属于org.skife.jdbi.v2.exceptions包,在下文中一共展示了UnableToExecuteStatementException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: unableToExecuteStatement
import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; //导入依赖的package包/类
@ExceptionHandler(value = UnableToExecuteStatementException.class)
public ResponseEntity<Object> unableToExecuteStatement(UnableToExecuteStatementException exception) {
logger.error(exception.getMessage(), exception);
Optional<Throwable> cause = Optional.ofNullable(Throwables.getRootCause(exception))
.filter(c -> c != exception);
Optional<String> exceptionName = cause.map(c -> c.getClass().getName());
Optional<String> message = cause.map(Throwable::getMessage);
if (exceptionName.isPresent() && exceptionName.get().contains(PSQLException.class.getName())
&& message.isPresent() && message.get().contains(UNIQUE_CONSTRAINT_MESSAGE)) {
return new ResponseEntity<>(message.get(), HttpStatus.CONFLICT);
}
return new ResponseEntity<>("Internal server error", new HttpHeaders(), HttpStatus.INTERNAL_SERVER_ERROR);
}
示例2: saveClaimShouldReturnConflictForDuplicateClaimFailures
import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; //导入依赖的package包/类
@Test
public void saveClaimShouldReturnConflictForDuplicateClaimFailures() throws Exception {
String claimantId = "1";
Exception duplicateKeyError = new UnableToExecuteStatementException(new PSQLException(
"ERROR: duplicate key value violates unique constraint \"external_id_unique\"", null), null);
given(userService.getUserDetails(anyString())).willReturn(SampleUserDetails.builder()
.withUserId(claimantId)
.withMail("[email protected]")
.build());
given(claimRepository.saveRepresented(anyString(), anyString(), any(LocalDate.class),
any(LocalDate.class), anyString(), anyString()))
.willThrow(duplicateKeyError);
webClient
.perform(post("/claims/" + claimantId)
.header(HttpHeaders.CONTENT_TYPE, "application/json")
.header(HttpHeaders.AUTHORIZATION, "token")
.content(jsonMapper.toJson(SampleClaimData.validDefaults()))
)
.andExpect(status().isConflict());
}
示例3: toolsIdVersionsPost
import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; //导入依赖的package包/类
@Transaction
@Override
public Response toolsIdVersionsPost(String id, ToolVersion body, SecurityContext securityContext) throws NotFoundException {
// refresh the release on github
//gitHubBuilder.createBranchAndRelease(, , body.getName());
String[] split = id.split("/");
LOG.info("Creating branch...");
String organization = split[0];
String repo = split[1];
String version = body.getName();
gitHubBuilder.createBranchAndRelease(organization, repo, version);
try {
int insert = toolVersionDAO.insert(id, version);
if (insert != 1) {
LOG.info("Tool version already exists in database");
return Response.notModified().build();
}
} catch (UnableToExecuteStatementException e) {
LOG.info("Tool version already exists in database");
}
ToolVersion byId = toolVersionDAO.findByToolVersion(id, version);
if (byId == null) {
return Response.notModified().build();
}
return Response.ok().entity(byId).build();
}
示例4: toolsIdVersionsVersionIdTypeDescriptorPost
import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; //导入依赖的package包/类
@Transaction
@Override
public Response toolsIdVersionsVersionIdTypeDescriptorPost(String type, String id, String versionId, ToolDescriptor body,
SecurityContext securityContext) throws NotFoundException {
String[] split = id.split("/");
String organization = split[0];
String repo = split[1];
String path = body.getUrl();
String url = generateUrl(id, versionId, body.getUrl());
ToolDescriptor byId = toolDescriptorDAO.findByPath(id, versionId, path);
if (byId == null) {
try {
toolDescriptorDAO.insert(body.getDescriptor(), id, versionId, path);
} catch (UnableToExecuteStatementException e) {
LOG.debug("Descriptor already exists in database");
}
}
gitHubBuilder.stashFile(organization, repo, body.getUrl(), body.getDescriptor(), versionId);
// TODO: improve this, this looks slow and awkward
body.setUrl(url);
toolDescriptorDAO.update(body, id, versionId, path);
byId = toolDescriptorDAO.findByPath(id, versionId, path);
return Response.ok().entity(byId).build();
}
示例5: toolsPost
import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; //导入依赖的package包/类
@Transaction
@Override
public Response toolsPost(Tool body, SecurityContext securityContext) throws NotFoundException {
// try creating a repo on github for this, this should probably be made into a transaction
if (!gitHubBuilder.repoExists(body.getOrganization(), body.getToolname())) {
LOG.info("Repo does not exist");
boolean repo = gitHubBuilder.createRepo(body.getOrganization(), body.getToolname());
if (!repo) {
return Response.notModified("Could not create github repo").build();
}
}
try {
toolDAO.insert(body.getId());
} catch (UnableToExecuteStatementException e) {
LOG.info("Tool already exists in database");
}
String gitUrl = gitHubBuilder.getGitUrl(body.getOrganization(), body.getToolname());
body.setUrl(gitUrl);
toolDAO.update(body);
Tool byId = toolDAO.findById(body.getId());
if (byId != null) {
return Response.ok().entity(byId).build();
}
return Response.notModified().build();
}
示例6: insert
import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; //导入依赖的package包/类
public Position insert(Position p) {
p.setCreatedAt(DateTime.now());
p.setUpdatedAt(p.getCreatedAt());
//prevent code conflicts
if (p.getCode() != null && p.getCode().trim().length() == 0) { p.setCode(null); }
try {
GeneratedKeys<Map<String,Object>> keys = dbHandle.createStatement(
"/* positionInsert */ INSERT INTO positions (name, code, type, "
+ "status, organizationId, locationId, createdAt, updatedAt) "
+ "VALUES (:name, :code, :type, :status, :organizationId, :locationId, :createdAt, :updatedAt)")
.bindFromProperties(p)
.bind("type", DaoUtils.getEnumId(p.getType()))
.bind("organizationId", DaoUtils.getId(p.getOrganization()))
.bind("status", DaoUtils.getEnumId(p.getStatus()))
.bind("locationId", DaoUtils.getId(p.getLocation()))
.executeAndReturnGeneratedKeys();
p.setId(DaoUtils.getGeneratedId(keys));
//Specifically don't set currentPersonId here because we'll handle that later in setPersonInPosition();
} catch (UnableToExecuteStatementException e) {
checkForUniqueCodeViolation(e);
throw e;
}
return p;
}
示例7: update
import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; //导入依赖的package包/类
public int update(Position p) {
p.setUpdatedAt(DateTime.now());
//prevent code conflicts
if (p.getCode() != null && p.getCode().trim().length() == 0) { p.setCode(null); }
try {
return dbHandle.createStatement("/* positionUpdate */ UPDATE positions SET name = :name, "
+ "code = :code, organizationId = :organizationId, type = :type, status = :status, "
+ "locationId = :locationId, updatedAt = :updatedAt WHERE id = :id")
.bindFromProperties(p)
.bind("type", DaoUtils.getEnumId(p.getType()))
.bind("organizationId", DaoUtils.getId(p.getOrganization()))
.bind("status", DaoUtils.getEnumId(p.getStatus()))
.bind("locationId", DaoUtils.getId(p.getLocation()))
.execute();
} catch (UnableToExecuteStatementException e) {
checkForUniqueCodeViolation(e);
throw e;
}
}
示例8: testExternalBatches
import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; //导入依赖的package包/类
@Test
public void testExternalBatches()
{
assertFalse(dao.externalBatchExists("foo"));
assertFalse(dao.externalBatchExists("bar"));
dao.insertExternalBatch("foo");
assertTrue(dao.externalBatchExists("foo"));
assertFalse(dao.externalBatchExists("bar"));
try {
dao.insertExternalBatch("foo");
fail("expected exception");
}
catch (UnableToExecuteStatementException e) {
assertInstanceOf(e.getCause(), SQLException.class);
assertTrue(((SQLException) e.getCause()).getSQLState().startsWith("23"));
}
}
示例9: catchConflict
import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; //导入依赖的package包/类
public <T> T catchConflict(NewResourceAction<T> function,
String messageFormat, Object... messageParameters)
throws ResourceConflictException
{
try {
return function.call();
}
catch (UnableToExecuteStatementException ex) {
if (ex.getCause() instanceof SQLException) {
SQLException sqlEx = (SQLException) ex.getCause();
if (isConflictException(sqlEx)) {
throw new ResourceConflictException("Resource already exists: " + String.format(messageFormat, messageParameters));
}
}
throw ex;
}
}
示例10: catchForeignKeyNotFound
import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; //导入依赖的package包/类
public <T> T catchForeignKeyNotFound(NewResourceAction<T> function,
String messageFormat, Object... messageParameters)
throws ResourceNotFoundException, ResourceConflictException
{
try {
return function.call();
}
catch (UnableToExecuteStatementException ex) {
if (ex.getCause() instanceof SQLException) {
SQLException sqlEx = (SQLException) ex.getCause();
if (isForeignKeyException(sqlEx)) {
throw new ResourceNotFoundException("Resource not found: " + String.format(messageFormat, messageParameters));
}
}
throw ex;
}
}
示例11: save
import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; //导入依赖的package包/类
public void save(String project, ABTestingReport report) {
if (report.id != -1) {
throw new RakamException("Report already has an id.", HttpResponseStatus.BAD_REQUEST);
}
try (Handle handle = dbi.open()) {
handle.createStatement("INSERT INTO ab_testing (project, name, variants, collection_name, connector_field, goals, options)" +
" VALUES (:project, :name, :variants, :collection_name, :goals, :options)")
.bind("project", project)
.bind("name", report.name)
.bind("collection_name", report.collectionName)
.bind("variants", JsonHelper.encode(report.variants))
.bind("goals", JsonHelper.encode(ImmutableList.of(report.goal)))
.bind("options", JsonHelper.encode(report.options, false))
.execute();
} catch (UnableToExecuteStatementException e) {
if (e.getCause() instanceof SQLException && ((SQLException) e.getCause()).getSQLState().equals("23505")) {
// TODO: replace
throw new RakamException("Report already exists", HttpResponseStatus.BAD_REQUEST);
}
}
}
示例12: save
import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; //导入依赖的package包/类
public void save(String project, RealTimeReport report) {
try (Handle handle = dbi.open()) {
handle.createStatement("INSERT INTO realtime_reports (project, name, table_name, collections, dimensions, filter, measures) " +
"VALUES (:project, :name, :table_name, :collections, :dimensions, :filter, :measures)")
.bind("project", project)
.bind("name", report.name)
.bind("table_name", report.table_name)
.bind("collections", JsonHelper.encode(report.collections))
.bind("dimensions", JsonHelper.encode(report.dimensions))
.bind("filter", report.filter)
.bind("measures", JsonHelper.encode(report.measures))
.execute();
} catch (UnableToExecuteStatementException e) {
try {
list(project).stream().anyMatch(re -> re.table_name.equals(report.table_name));
} catch (NotExistsException ex) {
throw e;
}
throw new AlreadyExistsException(String.format("Report '%s'", report.table_name), BAD_REQUEST);
}
}
示例13: save
import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; //导入依赖的package包/类
public void save(Integer userId, int project, Report report) {
try (Handle handle = dbi.open()) {
handle.createStatement("INSERT INTO reports (project_id, slug, category, name, query, options, user_id, query_options) VALUES (:project, :slug, :category, :name, :query, :options, :user, :query_options)")
.bind("project", project)
.bind("name", report.name)
.bind("query", report.query)
.bind("slug", report.slug)
.bind("user", userId)
.bind("category", report.category)
.bind("query_options", JsonHelper.encode(report.queryOptions))
.bind("shared", report.shared)
.bind("options", JsonHelper.encode(report.options))
.execute();
} catch (UnableToExecuteStatementException e) {
try {
get(null, project, report.slug);
} catch (NotExistsException ex) {
throw e;
}
throw new AlreadyExistsException(String.format("Report '%s'", report.slug), BAD_REQUEST);
}
}
示例14: createUser_noSuchRole
import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; //导入依赖的package包/类
@Test(expected = UnableToExecuteStatementException.class)
public void createUser_noSuchRole() // throws SQLException;
{
DefaultUserImpl u = harness.getUserDAO().findUser("FOO");
if (u != null)
{
harness.getUserDAO().deleteUser(u.getId());
}
ISecurityRole r = new DefaultRoleImpl("fakey", Collections.singleton("blah"));
u = new DefaultUserImpl(null, "FOO", "PASSWORD", Collections.singleton(r));
// THIS should fail in DBs that support FK constraints.
Long newId = harness.getUserDAO().createUser(u);
assertNotNull("UserId assigned during creation.", newId);
assertEquals(newId, u.getId());
LOG.info("Freshly minted user: {}", u);
DefaultUserImpl fromDb = harness.getUserDAO().findUser("FOO");
assertEquals("UserId and username match.", u, fromDb);
// IN other DBs it fails here. Oops
assertEquals("Roles correctly persisted to DB.", u.getRoles(), fromDb.getRoles());
harness.getUserDAO().deleteUser(newId);
}
示例15: createUser_valueTooLongForColumn
import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; //导入依赖的package包/类
/**
* Not sure why we'd ever do this...
*/
@Test(expected = UnableToExecuteStatementException.class)
public void createUser_valueTooLongForColumn() // throws SQLException;
{
DefaultUserImpl u = harness.getUserDAO().findUser("FOO");
if (u != null) {
harness.getUserDAO().deleteUser(u.getId());
}
ISecurityRole r = new DefaultRoleImpl("user", Collections.singleton("bar"));
u = new DefaultUserImpl(null, "FOO",
"A_TOO_LONG_PASSWORD"
+ "_0123456789_0123456789_0123456789_0123456789_0123456789"
+ "_0123456789_0123456789_0123456789_0123456789_0123456789"
+ "_0123456789_0123456789_0123456789_0123456789_0123456789"
+ "_0123456789_0123456789_0123456789_0123456789_0123456789"
+ "_0123456789_0123456789_0123456789_0123456789_0123456789"
+ "_0123456789_0123456789_0123456789_0123456789_0123456789"
, Collections.singleton(r));
// Should throw...
Long newId = harness.getUserDAO().createUser(u);
// clean-up incase this test-case fails (e.g., db silently truncates)
assertNotNull(newId);
harness.getUserDAO().deleteUser(newId);
}