当前位置: 首页>>代码示例>>Java>>正文


Java SQLIntegrityConstraintViolationException类代码示例

本文整理汇总了Java中java.sql.SQLIntegrityConstraintViolationException的典型用法代码示例。如果您正苦于以下问题:Java SQLIntegrityConstraintViolationException类的具体用法?Java SQLIntegrityConstraintViolationException怎么用?Java SQLIntegrityConstraintViolationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SQLIntegrityConstraintViolationException类属于java.sql包,在下文中一共展示了SQLIntegrityConstraintViolationException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: whenAlreadyExists

import java.sql.SQLIntegrityConstraintViolationException; //导入依赖的package包/类
@Test
public void whenAlreadyExists() throws Exception {

    // given
    FixtureScript fs = new EmployeeTearDown();
    fixtureScripts.runFixtureScript(fs, null);
    transactionService.nextTransaction();
    wrap(menu).create("Faz", "123", null);
    transactionService.nextTransaction();

    // then
    expectedExceptions.expectCause(causalChainContains(SQLIntegrityConstraintViolationException.class));

    // when
    wrap(menu).create("Faz", "123", null);
    transactionService.nextTransaction();
}
 
开发者ID:bibryam,项目名称:rotabuilder,代码行数:18,代码来源:EmployeeMenu_IntegTest.java

示例2: test11

import java.sql.SQLIntegrityConstraintViolationException; //导入依赖的package包/类
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using for-each loop
 */
@Test
public void test11() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException("Exception 1", t1);
    SQLIntegrityConstraintViolationException ex1 =
            new SQLIntegrityConstraintViolationException("Exception 2");
    SQLIntegrityConstraintViolationException ex2 =
            new SQLIntegrityConstraintViolationException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    for (Throwable e : ex) {
        assertTrue(msgs[num++].equals(e.getMessage()));
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:SQLIntegrityConstraintViolationExceptionTests.java

示例3: test12

import java.sql.SQLIntegrityConstraintViolationException; //导入依赖的package包/类
/**
 * Validate that the ordering of the returned Exceptions is correct
 * using traditional while loop
 */
@Test
public void test12() {
    SQLIntegrityConstraintViolationException ex =
            new SQLIntegrityConstraintViolationException("Exception 1", t1);
    SQLIntegrityConstraintViolationException ex1 =
            new SQLIntegrityConstraintViolationException("Exception 2");
    SQLIntegrityConstraintViolationException ex2 =
            new SQLIntegrityConstraintViolationException("Exception 3", t2);
    ex.setNextException(ex1);
    ex.setNextException(ex2);
    int num = 0;
    SQLException sqe = ex;
    while (sqe != null) {
        assertTrue(msgs[num++].equals(sqe.getMessage()));
        Throwable c = sqe.getCause();
        while (c != null) {
            assertTrue(msgs[num++].equals(c.getMessage()));
            c = c.getCause();
        }
        sqe = sqe.getNextException();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:27,代码来源:SQLIntegrityConstraintViolationExceptionTests.java

示例4: toResponse

import java.sql.SQLIntegrityConstraintViolationException; //导入依赖的package包/类
@Override 
public Response toResponse(Exception ex) {
    if (Options.RETURN_EXCEPTION_BODY) {
        if (ex instanceof PersistenceException) {
            Throwable cause = ex.getCause();
            if (cause != null) { // The type of this exception is determined at runtime
                cause = cause.getCause();
                if (cause instanceof SQLIntegrityConstraintViolationException) {
                    return new RestErrorBuilder(cause).createResponse();
                }
            }
        }
    }
    
    ExceptionMapper exceptionMapper = providers.getExceptionMapper(ex.getClass());
    if (exceptionMapper == null || exceptionMapper == this) {
        return Response.serverError().build();
    }
    else {
        return exceptionMapper.toResponse(ex);
    }
}
 
开发者ID:codebulb,项目名称:crudlet,代码行数:23,代码来源:RestfulExceptionMapper.java

示例5: addOcppTag

import java.sql.SQLIntegrityConstraintViolationException; //导入依赖的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);
        }
    }
}
 
开发者ID:RWTH-i5-IDSG,项目名称:steve-plugsurfing,代码行数:23,代码来源:OcppTagRepositoryImpl.java

示例6: whenAlreadyExists

import java.sql.SQLIntegrityConstraintViolationException; //导入依赖的package包/类
@Test
public void whenAlreadyExists() throws Exception {

    // given
    FixtureScript fs = new SimpleObjectsTearDown();
    fixtureScripts.runFixtureScript(fs, null);
    transactionService.nextTransaction();
    wrap(menu).create("Faz");
    transactionService.nextTransaction();

    // then
    expectedExceptions.expectCause(causalChainContains(SQLIntegrityConstraintViolationException.class));

    // when
    wrap(menu).create("Faz");
    transactionService.nextTransaction();
}
 
开发者ID:Stephen-Cameron-Data-Services,项目名称:isis-agri,代码行数:18,代码来源:SimpleObjectMenu_IntegTest.java

示例7: whenAlreadyExists

import java.sql.SQLIntegrityConstraintViolationException; //导入依赖的package包/类
@Test
public void whenAlreadyExists() throws Exception {

    // given
    FixtureScript fs = new QuickObjectsTearDown();
    fixtureScripts.runFixtureScript(fs, null);
    nextTransaction();
    wrap(quickObjectMenu).create("Faz");
    nextTransaction();

    // then
    expectedExceptions.expectCause(causalChainContains(SQLIntegrityConstraintViolationException.class));

    // when
    wrap(quickObjectMenu).create("Faz");
    nextTransaction();
}
 
开发者ID:isisaddons-legacy,项目名称:isis-app-quickstart,代码行数:18,代码来源:QuickObjectMenuIntegTest.java

示例8: whenAlreadyExists

import java.sql.SQLIntegrityConstraintViolationException; //导入依赖的package包/类
@Test
public void whenAlreadyExists() throws Exception {

    // given
    FixtureScript fs = new SimpleObjectsTearDown();
    fixtureScripts.runFixtureScript(fs, null);
    nextTransaction();
    wrap(simpleObjects).create("Faz");
    nextTransaction();

    // then
    expectedExceptions.expectCause(causalChainContains(SQLIntegrityConstraintViolationException.class));

    // when
    wrap(simpleObjects).create("Faz");
    nextTransaction();
}
 
开发者ID:isisaddons,项目名称:isis-app-simpledsl,代码行数:18,代码来源:SimpleObjectsIntegTest.java

示例9: whenAlreadyExists

import java.sql.SQLIntegrityConstraintViolationException; //导入依赖的package包/类
@Test
public void whenAlreadyExists() throws Exception {

    // given
    fixtureScript = new OwnersFixture();
    fixtureScripts.runFixtureScript(fixtureScript, null);
    nextTransaction();

    final Owner owner = fixtureScript.lookup("owners-fixture/owner-for-bill/item-1", Owner.class);
    assertThat(owner, is(notNullValue()));

    wrap(pets).create("Bonzo", PetSpecies.Dog, owner);
    nextTransaction();

    // then
    expectedException.expectCause(causalChainContains(SQLIntegrityConstraintViolationException.class));

    // when
    wrap(pets).create("Bonzo", PetSpecies.Dog, owner);
    nextTransaction();
}
 
开发者ID:danhaywood,项目名称:isis-app-petclinic,代码行数:22,代码来源:PetsTest.java

示例10: whenAlreadyExists

import java.sql.SQLIntegrityConstraintViolationException; //导入依赖的package包/类
@Test
public void whenAlreadyExists() throws Exception {

    // given
    fixtureScript = new PetClinicAppTearDownFixture();
    fixtureScripts.runFixtureScript(fixtureScript, null);
    nextTransaction();

    wrap(owners).create("Bill");
    nextTransaction();

    // then
    expectedException.expectCause(causalChainContains(SQLIntegrityConstraintViolationException.class));

    // when
    wrap(owners).create("Bill");
    nextTransaction();
}
 
开发者ID:danhaywood,项目名称:isis-app-petclinic,代码行数:19,代码来源:OwnersTest.java

示例11: getMessageFromCause

import java.sql.SQLIntegrityConstraintViolationException; //导入依赖的package包/类
protected static String getMessageFromCause(Throwable cause) {
    String message = "Persistence error";
    if (cause instanceof ConstraintViolationException) {
        Set<ConstraintViolation<?>> violations = ((ConstraintViolationException) cause).getConstraintViolations();
        message = "";
        for (ConstraintViolation violation : violations) {
            message += (String.format("Field %s %s\n", violation.getPropertyPath(), violation.getMessage()));
        }
    } else if (cause instanceof JDODataStoreException) {
        for (Throwable exception : ((JDODataStoreException) cause).getNestedExceptions()) {
            if (exception instanceof SQLIntegrityConstraintViolationException) {
                message = exception.getMessage();
                break;
            }
        }
    }
    return message;
}
 
开发者ID:motech,项目名称:motech,代码行数:19,代码来源:ObjectException.java

示例12: test_Constructor_LString

import java.sql.SQLIntegrityConstraintViolationException; //导入依赖的package包/类
/**
 * @test java.sql.SQLIntegrityConstraintViolationException(String)
 */
public void test_Constructor_LString() {
    SQLIntegrityConstraintViolationException sQLIntegrityConstraintViolationException = new SQLIntegrityConstraintViolationException(
            "MYTESTSTRING");
    assertNotNull(sQLIntegrityConstraintViolationException);
    assertNull(
            "The SQLState of SQLIntegrityConstraintViolationException should be null",
            sQLIntegrityConstraintViolationException.getSQLState());
    assertEquals(
            "The reason of SQLIntegrityConstraintViolationException set and get should be equivalent",
            "MYTESTSTRING", sQLIntegrityConstraintViolationException
                    .getMessage());
    assertEquals(
            "The error code of SQLIntegrityConstraintViolationException should be 0",
            sQLIntegrityConstraintViolationException.getErrorCode(), 0);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:19,代码来源:SQLIntegrityConstraintViolationExceptionTest.java

示例13: test_Constructor_LStringLString

import java.sql.SQLIntegrityConstraintViolationException; //导入依赖的package包/类
/**
 * @test java.sql.SQLIntegrityConstraintViolationException(String, String)
 */
public void test_Constructor_LStringLString() {
    SQLIntegrityConstraintViolationException sQLIntegrityConstraintViolationException = new SQLIntegrityConstraintViolationException(
            "MYTESTSTRING1", "MYTESTSTRING2");
    assertNotNull(sQLIntegrityConstraintViolationException);
    assertEquals(
            "The SQLState of SQLIntegrityConstraintViolationException set and get should be equivalent",
            "MYTESTSTRING2", sQLIntegrityConstraintViolationException
                    .getSQLState());
    assertEquals(
            "The reason of SQLIntegrityConstraintViolationException set and get should be equivalent",
            "MYTESTSTRING1", sQLIntegrityConstraintViolationException
                    .getMessage());
    assertEquals(
            "The error code of SQLIntegrityConstraintViolationException should be 0",
            sQLIntegrityConstraintViolationException.getErrorCode(), 0);

}
 
开发者ID:shannah,项目名称:cn1,代码行数:21,代码来源:SQLIntegrityConstraintViolationExceptionTest.java

示例14: test_Constructor_LStringLString_1

import java.sql.SQLIntegrityConstraintViolationException; //导入依赖的package包/类
/**
 * @test java.sql.SQLIntegrityConstraintViolationException(String, String)
 */
public void test_Constructor_LStringLString_1() {
    SQLIntegrityConstraintViolationException sQLIntegrityConstraintViolationException = new SQLIntegrityConstraintViolationException(
            "MYTESTSTRING", (String) null);
    assertNotNull(sQLIntegrityConstraintViolationException);
    assertNull(
            "The SQLState of SQLIntegrityConstraintViolationException should be null",
            sQLIntegrityConstraintViolationException.getSQLState());
    assertEquals(
            "The reason of SQLIntegrityConstraintViolationException set and get should be equivalent",
            "MYTESTSTRING", sQLIntegrityConstraintViolationException
                    .getMessage());
    assertEquals(
            "The error code of SQLIntegrityConstraintViolationException should be 0",
            sQLIntegrityConstraintViolationException.getErrorCode(), 0);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:19,代码来源:SQLIntegrityConstraintViolationExceptionTest.java

示例15: test_Constructor_LStringLString_2

import java.sql.SQLIntegrityConstraintViolationException; //导入依赖的package包/类
/**
 * @test java.sql.SQLIntegrityConstraintViolationException(String, String)
 */
public void test_Constructor_LStringLString_2() {
    SQLIntegrityConstraintViolationException sQLIntegrityConstraintViolationException = new SQLIntegrityConstraintViolationException(
            null, "MYTESTSTRING");
    assertNotNull(sQLIntegrityConstraintViolationException);
    assertEquals(
            "The SQLState of SQLIntegrityConstraintViolationException set and get should be equivalent",
            "MYTESTSTRING", sQLIntegrityConstraintViolationException
                    .getSQLState());
    assertNull(
            "The reason of SQLIntegrityConstraintViolationException should be null",
            sQLIntegrityConstraintViolationException.getMessage());
    assertEquals(
            "The error code of SQLIntegrityConstraintViolationException should be 0",
            sQLIntegrityConstraintViolationException.getErrorCode(), 0);
}
 
开发者ID:shannah,项目名称:cn1,代码行数:19,代码来源:SQLIntegrityConstraintViolationExceptionTest.java


注:本文中的java.sql.SQLIntegrityConstraintViolationException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。