本文整理汇总了Java中org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException类的典型用法代码示例。如果您正苦于以下问题:Java UnableToExecuteStatementException类的具体用法?Java UnableToExecuteStatementException怎么用?Java UnableToExecuteStatementException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UnableToExecuteStatementException类属于org.skife.jdbi.v2.exceptions包,在下文中一共展示了UnableToExecuteStatementException类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:hmcts,项目名称:cmc-claim-store,代码行数:18,代码来源:ResourceExceptionHandler.java
示例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());
}
开发者ID:hmcts,项目名称:cmc-claim-store,代码行数:25,代码来源:EndpointErrorsTest.java
示例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();
}
开发者ID:dockstore,项目名称:write_api_service,代码行数:27,代码来源:ToolsApiServiceImpl.java
示例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();
}
开发者ID:dockstore,项目名称:write_api_service,代码行数:26,代码来源:ToolsApiServiceImpl.java
示例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();
}
开发者ID:dockstore,项目名称:write_api_service,代码行数:26,代码来源:ToolsApiServiceImpl.java
示例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;
}
开发者ID:deptofdefense,项目名称:anet,代码行数:27,代码来源:PositionDao.java
示例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;
}
}
开发者ID:deptofdefense,项目名称:anet,代码行数:21,代码来源:PositionDao.java
示例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"));
}
}
开发者ID:y-lan,项目名称:presto,代码行数:21,代码来源:TestShardManagerDao.java
示例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;
}
}
开发者ID:treasure-data,项目名称:digdag,代码行数:18,代码来源:BasicDatabaseStoreManager.java
示例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;
}
}
开发者ID:treasure-data,项目名称:digdag,代码行数:18,代码来源:BasicDatabaseStoreManager.java
示例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);
}
}
}
开发者ID:rakam-io,项目名称:rakam,代码行数:22,代码来源:ABTestingMetastore.java
示例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);
}
}
开发者ID:rakam-io,项目名称:rakam,代码行数:23,代码来源:RealtimeMetadataService.java
示例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);
}
}
开发者ID:rakam-io,项目名称:rakam,代码行数:24,代码来源:JDBCReportMetadata.java
示例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);
}
开发者ID:Multifarious,项目名称:shiro-jdbi-realm,代码行数:27,代码来源:TestUserDAO.java
示例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);
}
开发者ID:Multifarious,项目名称:shiro-jdbi-realm,代码行数:27,代码来源:TestUserDAO.java
示例16: open
import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; //导入依赖的package包/类
@Override
public LogFile open(String rollingCohort, String pathPattern, DateTime startTime) {
int attempt = 1;
while(true) {
Timestamp stamp = now();
int serial = dao.determineNextSerial(rollingCohort) + 1;
Path originPath = Paths.get(String.format(pathPattern, serial));
try {
dao.claimIndex(rollingCohort, serial, new Timestamp(startTime.getMillis()), originPath.toUri().toString(), localUri.toString(), stamp);
return new LogFile(rollingCohort, serial, startTime, originPath, null, null, null, null, WRITING, localUri, null, new DateTime(stamp.getTime()), null);
} catch (UnableToExecuteStatementException e) {
if (attempt < 100) {
LOG.debug("Another instance claimed {} serial {}. Will retry.", rollingCohort, serial);
} else {
//Something very wrong; only expect to ever go through this loop a couple times.
throw e;
}
}
attempt++;
}
}
开发者ID:Multifarious,项目名称:skid-road,代码行数:22,代码来源:JDBILogFileTracker.java
示例17: toolsIdVersionsVersionIdDockerfilePost
import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; //导入依赖的package包/类
@Transaction
@Override
public Response toolsIdVersionsVersionIdDockerfilePost(String id, String versionId, ToolDockerfile dockerfile,
SecurityContext securityContext) throws NotFoundException {
String[] split = id.split("/");
String organization = split[0];
String repo = split[1];
gitHubBuilder.stashFile(organization, repo, dockerfile.getUrl(), dockerfile.getDockerfile(), versionId);
gitHubBuilder.createBranchAndRelease(organization, repo, versionId);
if (!quayIoBuilder.repoExists(organization, repo)) {
quayIoBuilder.createRepo(organization, repo, repo);
LOG.info("Created quay.io repository.");
}
quayIoBuilder.triggerBuild(organization, organization, repo, repo, versionId, true);
String url = generateUrl(id, versionId, dockerfile.getUrl());
dockerfile.setUrl(url);
ToolDockerfile findById = toolDockerfileDAO.findById(id, versionId);
if (findById == null) {
try {
toolDockerfileDAO.insert(id, versionId, dockerfile.getDockerfile());
toolDockerfileDAO.update(dockerfile, id, versionId);
} catch (UnableToExecuteStatementException e) {
LOG.info("Dockerfile already exists in database");
}
}
toolDockerfileDAO.update(dockerfile, id, versionId);
ToolDockerfile created = toolDockerfileDAO.findById(id, versionId);
if (created != null) {
created.setUrl(quayIoBuilder.getQuayUrl(organization, repo));
return Response.ok().entity(created).build();
}
return Response.serverError().build();
}
开发者ID:dockstore,项目名称:write_api_service,代码行数:35,代码来源:ToolsApiServiceImpl.java
示例18: checkForUniqueCodeViolation
import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; //导入依赖的package包/类
public void checkForUniqueCodeViolation(UnableToExecuteStatementException e) {
if (e.getCause() != null && e.getCause() instanceof SQLException) {
SQLException cause = (SQLException) e.getCause();
if (cause.getErrorCode() == 2601) { // Unique Key Violation constant for SQL Server
if (cause.getMessage().contains("UniquePositionCodes")) {
throw new WebApplicationException("Another position is already using this "
+ "code and each position must have its own code. "
+ "Please double check that you entered the right code. ", Status.CONFLICT);
}
}
}
}
开发者ID:deptofdefense,项目名称:anet,代码行数:13,代码来源:PositionDao.java
示例19: toResponse
import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; //导入依赖的package包/类
@Override
public Response toResponse(Throwable exception) {
long id = logException(exception);
int status = Response.Status.INTERNAL_SERVER_ERROR.getStatusCode();
String errorDetails = exception.getMessage();
// change error details if the exception is a known DB constraint violation
if (exception instanceof UnableToExecuteStatementException) {
SQLException se = (SQLException) exception.getCause();
if (se.getErrorCode() == ErrorCode.DUPLICATE_KEY_1 &&
se.getMessage().contains("_" + DB_UNIQUE_NAME_CONSTRAINT_NAME_SUFFIX)) {
errorDetails = "Duplicate name.";
} else if (se.getErrorCode() == ErrorCode.CHECK_CONSTRAINT_VIOLATED_1) {
if (se.getMessage().contains("_" + DB_PROPERTY_NAME_CONSTRAINT_NAME_SUFFIX)) {
errorDetails = "Property name can not be same as preserved names and can only contain letter, digit," +
" $ and _ characters, beginning with letter, _ or $.";
} else if (se.getMessage().contains("_" + DB_USERNAME_CONSTRAINT_NAME_SUFFIX)) {
errorDetails = "Please enter a valid username: 3+ characters long, characters \"A-Za-z0-9_\".";
}
}
}
ErrorMessage errorMessage = new ErrorMessage(status, formatErrorMessage(id, exception), errorDetails);
return Response.status(status)
.type(MediaType.APPLICATION_JSON_TYPE)
.entity(errorMessage)
.build();
}
开发者ID:zheng-wang,项目名称:irontest,代码行数:29,代码来源:IronTestLoggingExceptionMapper.java
示例20: createIndexIfNotExists
import org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException; //导入依赖的package包/类
private void createIndexIfNotExists() {
try (Handle handle = dbi.open()) {
handle.createStatement("CREATE INDEX report_type_idx ON custom_reports(report_type, project)")
.execute();
} catch (UnableToExecuteStatementException e) {
// IF NOT EXIST feature is not supported by majority of RDBMSs.
// Since this INDEX is optional, swallow exception
// since the exception is probably about duplicate indexes.
}
}
开发者ID:rakam-io,项目名称:rakam,代码行数:11,代码来源:JDBCCustomReportMetadata.java
注:本文中的org.skife.jdbi.v2.exceptions.UnableToExecuteStatementException类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论