當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。