Example usage for org.apache.ibatis.exceptions PersistenceException PersistenceException

List of usage examples for org.apache.ibatis.exceptions PersistenceException PersistenceException

Introduction

In this page you can find the example usage for org.apache.ibatis.exceptions PersistenceException PersistenceException.

Prototype

public PersistenceException(Throwable cause) 

Source Link

Usage

From source file:cern.c2mon.server.history.logger.ServerLifecycleLoggerTest.java

License:Open Source License

/**
 * Test the start log is repeated if logging fails.
 * Expect at least 3 tries in 5s. Also checks stop returns.
 * @throws InterruptedException/*from   w  w w .  ja v a 2 s  .  c om*/
 */
@Test
public void testRepeatStartLog() throws InterruptedException {
    lifecycleMapper.logEvent(EasyMock.isA(ServerLifecycleEvent.class));
    CountDownLatch latch = new CountDownLatch(3);
    EasyMock.expectLastCall().andAnswer(() -> {
        latch.countDown();
        throw new PersistenceException("");
    }).times(3, 10);
    control.replay();
    serverLifecycleLogger.start();
    latch.await();
    serverLifecycleLogger.stop();
    control.verify();
}

From source file:cn.chenlichao.web.ssm.service.impl.BaseServiceImpl.java

License:Apache License

@Override
public PK save(E entity) {
    if (entity == null) {
        throw new IllegalArgumentException("?null");
    }//from  w ww  .j a v  a2  s  .  co m
    int result = baseMapper.insert(entity);
    if (result != 1) {
        throw new PersistenceException("??");
    }
    LOGGER.trace("???, ID: [{}]", entity.getId());
    return entity.getId();
}

From source file:cn.chenlichao.web.ssm.service.impl.BaseServiceImpl.java

License:Apache License

@Override
public PK saveWithNull(E entity) {
    if (entity == null) {
        throw new IllegalArgumentException("?null");
    }//from w  ww  . ja v  a 2  s .  c  o m
    int result = baseMapper.insertWithNull(entity);
    if (result != 1) {
        throw new PersistenceException("??");
    }
    LOGGER.trace("???, ID: [{}]", entity.getId());
    return entity.getId();
}

From source file:edu.eci.pdsw.posgrado.dao.mybatis.mybatisMateriaDAO.java

/**
 * //w  w w . j  a  v  a2 s.  c  o  m
 * @param sigla
 * @param nombre
 * @param creditos
 * @param asignatura_nombre
 * @param descripcion 
 */
@Override
public void addMateria(String sigla, String nombre, int creditos, String asignatura_nombre,
        String descripcion) {
    try {
        materiaMapper.registrarMateria(sigla, nombre, creditos, asignatura_nombre, descripcion);
    } catch (PersistenceException e) {
        throw new PersistenceException("Error al Insertar materia" + e);
    }
}

From source file:org.mybatis.guice.generictypehandler.GenericCustomObjectTypeHandler.java

License:Apache License

private E createResult(String name) {
    try {//from www  . j a  v  a 2s  . com
        E customObject = type.newInstance();
        customObject.setName(name);
        return customObject;
    } catch (InstantiationException e) {
        throw new PersistenceException(e);
    } catch (IllegalAccessException e) {
        throw new PersistenceException(e);
    }
}

From source file:org.mybatis.guice.transactional.MultiTransactionManager.java

License:Apache License

public void commit(boolean force) {
    boolean errors = false;
    for (Map.Entry<String, DbSessionManager> entry : managerMap.entrySet()) {
        final DbSessionManager man = entry.getValue();
        if (man.isManagedSessionStarted()) {
            log.debug("Committing transaction [environment: {}]", entry.getKey());
            try {
                man.commit(force);/*from  w  w  w  .  j  a va 2s .c om*/
            } catch (Exception e) {
                errors = true;
                log.error("Failed to commit transaction for [environment: {}]", entry.getKey(), e);
            }
        }
    }
    if (errors) {
        throw new PersistenceException("One or more environments failed to commit. See log for details");
    }
}

From source file:org.mybatis.guice.transactional.MultiTransactionManager.java

License:Apache License

public void rollback(boolean force) {
    boolean errors = false;
    for (Map.Entry<String, DbSessionManager> entry : managerMap.entrySet()) {
        final DbSessionManager man = entry.getValue();
        if (man.isManagedSessionStarted()) {
            log.debug("Rolling back transaction [environment: {}]", entry.getKey());
            try {
                man.rollback(force);//from w  w  w  .  j  a v  a 2s  .  co m
            } catch (Exception e) {
                errors = true;
                log.error("Failed to rollback transaction for [environment: {}]", entry.getKey(), e);
            }
        }
    }
    if (errors) {
        throw new PersistenceException("One or more environments failed to roll back. See log for details");
    }

}

From source file:org.mybatis.guice.transactional.MultiTransactionManager.java

License:Apache License

public void close() {
    boolean errors = false;
    for (Map.Entry<String, DbSessionManager> entry : managerMap.entrySet()) {
        final DbSessionManager man = entry.getValue();
        if (man.isManagedSessionStarted()) {
            log.debug("Closing session [environment: {}]", entry.getKey());
            try {
                man.close();//from  w w  w. ja va 2  s.co  m
            } catch (Exception e) {
                errors = true;
                log.error("Failed to close session for [environment: {}]", entry.getKey(), e);
            }
        }
    }

    // Ensure thread local cleanup on finishing
    stopTransactionalContext();

    if (errors) {
        throw new PersistenceException("One or more environments failed to close. See log for details");
    }
}

From source file:org.restcomm.sbc.rest.NetworkPointsEndpoint.java

License:Open Source License

private void validate(final MultivaluedMap<String, String> data) {
    if (!data.containsKey("Id")) {
        throw new NullPointerException("Id can not be null.");
    }//from   w  w w. j a v a 2s.  c  om
    if (!data.containsKey("Tag")) {
        throw new NullPointerException("Tag can not be null.");
    }
    String id = data.getFirst("Id");
    if (!NetworkManager.exists(id)) {
        throw new NullPointerException("Real ID does not exist.");

    }

    final NetworkPointsDao dao = daos.getNetworkPointDao();
    if (dao.getNetworkPoint(id) != null) {
        throw new PersistenceException("Id is yet taged");
    }
    ;

}

From source file:org.sonar.server.setting.ThreadLocalSettingsTest.java

License:Open Source License

@Test
public void getProperties_return_empty_if_DB_error_on_first_call_ever_out_of_thread_cache() {
    SettingLoader settingLoaderMock = mock(SettingLoader.class);
    PersistenceException toBeThrown = new PersistenceException("Faking an error connecting to DB");
    doThrow(toBeThrown).when(settingLoaderMock).loadAll();
    underTest = new ThreadLocalSettings(new PropertyDefinitions(), new Properties(), settingLoaderMock);

    assertThat(underTest.getProperties()).isEmpty();
}