本文整理汇总了Java中org.hibernate.exception.JDBCConnectionException类的典型用法代码示例。如果您正苦于以下问题:Java JDBCConnectionException类的具体用法?Java JDBCConnectionException怎么用?Java JDBCConnectionException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JDBCConnectionException类属于org.hibernate.exception包,在下文中一共展示了JDBCConnectionException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: retry
import org.hibernate.exception.JDBCConnectionException; //导入依赖的package包/类
public void retry(Runnable run) {
for (long retry = this.retry; retry > 0; retry--) {
try {
run.run();
retry = -1;
} catch (JDBCConnectionException e) {
clearSessionFactory();
if (retry > 0) {
log.debug("(SecurityTokenManager) JDBCConnectionException for removeExpired, retry left: " + retry);
ThreadUtils.sleep(200);
} else {
log.warn("(SecurityTokenManager) JDBCConnectionException for removeExpired, no more retry", e);
}
}
}
}
示例2: buildSQLExceptionConversionDelegate
import org.hibernate.exception.JDBCConnectionException; //导入依赖的package包/类
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
return new SQLExceptionConversionDelegate() {
@Override
public JDBCException convert(SQLException sqlException, String message, String sql) {
final int errorCode = JdbcExceptionHelper.extractErrorCode(sqlException);
if (errorCode == SQLITE_TOOBIG || errorCode == SQLITE_MISMATCH) {
return new DataException(message, sqlException, sql);
} else if (errorCode == SQLITE_BUSY || errorCode == SQLITE_LOCKED) {
return new LockAcquisitionException(message, sqlException, sql);
} else if ((errorCode >= SQLITE_IOERR && errorCode <= SQLITE_PROTOCOL) || errorCode == SQLITE_NOTADB) {
return new JDBCConnectionException(message, sqlException, sql);
}
// returning null allows other delegates to operate
return null;
}
};
}
示例3: buildSQLExceptionConversionDelegate
import org.hibernate.exception.JDBCConnectionException; //导入依赖的package包/类
@Override
public SQLExceptionConversionDelegate buildSQLExceptionConversionDelegate() {
return new SQLExceptionConversionDelegate() {
@Override
public JDBCException convert(SQLException sqlException, String message, String sql) {
final int errorCode = JdbcExceptionHelper.extractErrorCode(sqlException);
if (errorCode == SQLITE_TOOBIG || errorCode == SQLITE_MISMATCH) {
return new DataException(message, sqlException, sql);
} else if (errorCode == SQLITE_BUSY || errorCode == SQLITE_LOCKED) {
return new LockAcquisitionException(message, sqlException, sql);
} else if ((errorCode >= SQLITE_IOERR && errorCode <= SQLITE_PROTOCOL) || errorCode == SQLITE_NOTADB) {
return new JDBCConnectionException(message, sqlException, sql);
}
return null;
}
};
}
示例4: execQuery
import org.hibernate.exception.JDBCConnectionException; //导入依赖的package包/类
public List execQuery(String queryString) {
List result = null;
Transaction tx = null;
try {
Session session = _factory.getCurrentSession();
tx = session.beginTransaction();
Query query = session.createQuery(queryString);
if (query != null) result = query.list();
}
catch (JDBCConnectionException jce) {
_log.error("Caught Exception: Couldn't connect to datasource - " +
"starting with an empty dataset");
}
catch (HibernateException he) {
_log.error("Caught Exception: Error executing query: " + queryString, he);
if (tx != null) tx.rollback();
}
return result;
}
示例5: execQuery
import org.hibernate.exception.JDBCConnectionException; //导入依赖的package包/类
/**
* executes a Query object based on the hql string passed
* @param queryString - the hibernate query to execute
* @return the List of objects returned, or null if the query has some problem
*/
public List execQuery(String queryString) {
List result = null;
Transaction tx = null;
try {
tx = getOrBeginTransaction();
Query query = getSession().createQuery(queryString);
if (query != null) result = query.list();
}
catch (JDBCConnectionException jce) {
_log.error("Caught Exception: Couldn't connect to datasource - " +
"continuing with an empty dataset");
if (tx != null) tx.rollback();
}
catch (HibernateException he) {
_log.error("Caught Exception: Error executing query: " + queryString, he);
if (tx != null) tx.rollback();
}
return result;
}
示例6: execSQLQuery
import org.hibernate.exception.JDBCConnectionException; //导入依赖的package包/类
/**
* executes a plain SQL Query
* @param queryString - the SQL query to execute
* @return the List of objects returned, or null if the query has some problem
*/
public List execSQLQuery(String queryString) {
List result = null;
Transaction tx = null;
try {
tx = getOrBeginTransaction();
Query query = getSession().createSQLQuery(queryString);
if (query != null) result = query.list();
commit();
}
catch (JDBCConnectionException jce) {
_log.error("Caught Exception: Couldn't connect to datasource - " +
"starting with an empty dataset");
if (tx != null) tx.rollback();
}
catch (HibernateException he) {
_log.error("Caught Exception: Error executing query: " + queryString, he);
rollback();
}
return result;
}
示例7: execUpdate
import org.hibernate.exception.JDBCConnectionException; //导入依赖的package包/类
public int execUpdate(String queryString, boolean commit) {
int result = -1;
Transaction tx = null;
try {
tx = getOrBeginTransaction();
result = getSession().createQuery(queryString).executeUpdate();
if (commit) commit();
}
catch (JDBCConnectionException jce) {
_log.error("Caught Exception: Couldn't connect to datasource - " +
"starting with an empty dataset");
}
catch (HibernateException he) {
_log.error("Caught Exception: Error executing query: " + queryString, he);
if (tx != null) tx.rollback();
}
return result;
}
示例8: execute
import org.hibernate.exception.JDBCConnectionException; //导入依赖的package包/类
public void execute(TransactionalOperation operation) {
JDBCConnectionException last = null;
Transaction tx = null;
for (int retry = 0; retry < TRANSACTIONS_MAX_RETRIES; retry++) {
Session dbSession = this.getSession();
try {
tx = dbSession.beginTransaction();
operation.execute(dbSession);
tx.commit();
if (retry > 0)
LOG.warn("Transacao realizada apos "+String.valueOf(retry+1)+" tentativas.");
return;
} catch (JDBCConnectionException ex) {
last = ex;
if (tx != null)
tx.rollback();
tx = null;
this.closeSession();
}
}
LOG.error("Erro ao tentar executar operação transacional apos "+
String.valueOf(TRANSACTIONS_MAX_RETRIES)+" tentativas.", last);
throw new RuntimeException("Erro no banco de dados.", last);
}
示例9: persist
import org.hibernate.exception.JDBCConnectionException; //导入依赖的package包/类
@Override
public void persist(Serializable entity) {
JDBCConnectionException last = null;
Transaction tx = null;
for (int retry = 0; retry < TRANSACTIONS_MAX_RETRIES; retry++) {
Session dbSession = this.getSession();
try {
tx = dbSession.beginTransaction();
dbSession.persist(entity);
tx.commit();
if (retry > 0)
LOG.warn("Transacao realizada apos "+String.valueOf(retry+1)+" tentativas.");
return;
} catch (JDBCConnectionException ex) {
last = ex;
if (tx != null)
tx.rollback();
tx = null;
this.closeSession();
}
}
LOG.error("Erro ao tentar salvar entidade: "+entity.getClass().getCanonicalName()+" apos "+
String.valueOf(TRANSACTIONS_MAX_RETRIES)+" tentativas.", last);
throw new RuntimeException("Erro no banco de dados.", last);
}
示例10: save
import org.hibernate.exception.JDBCConnectionException; //导入依赖的package包/类
@Override
public Serializable save(Serializable entity) {
JDBCConnectionException last = null;
Transaction tx = null;
for (int retry = 0; retry < TRANSACTIONS_MAX_RETRIES; retry++) {
Session dbSession = this.getSession();
try {
tx = dbSession.beginTransaction();
Serializable id = dbSession.save(entity);
tx.commit();
if (retry > 0)
LOG.warn("Transacao realizada apos "+String.valueOf(retry+1)+" tentativas.");
return id;
} catch (JDBCConnectionException ex) {
last = ex;
if (tx != null)
tx.rollback();
tx = null;
this.closeSession();
}
}
LOG.error("Erro ao tentar salvar entidade: "+entity.getClass().getCanonicalName()+" apos "+
String.valueOf(TRANSACTIONS_MAX_RETRIES)+" tentativas.", last);
throw new RuntimeException("Erro no banco de dados.", last);
}
示例11: update
import org.hibernate.exception.JDBCConnectionException; //导入依赖的package包/类
@Override
public void update(Serializable entity) {
JDBCConnectionException last = null;
Transaction tx = null;
for (int retry = 0; retry < TRANSACTIONS_MAX_RETRIES; retry++) {
Session dbSession = this.getSession();
try {
tx = dbSession.beginTransaction();
dbSession.update(entity);
tx.commit();
if (retry > 0)
LOG.warn("Transacao realizada apos "+String.valueOf(retry+1)+" tentativas.");
return;
} catch (JDBCConnectionException ex) {
last = ex;
if (tx != null)
tx.rollback();
tx = null;
this.closeSession();
}
}
LOG.error("Erro ao tentar atualizar entidade: "+entity.getClass().getCanonicalName()+" apos "+
String.valueOf(TRANSACTIONS_MAX_RETRIES)+" tentativas.", last);
throw new RuntimeException("Erro no banco de dados.", last);
}
示例12: delete
import org.hibernate.exception.JDBCConnectionException; //导入依赖的package包/类
@Override
public void delete(Serializable entity) {
JDBCConnectionException last = null;
Transaction tx = null;
for (int retry = 0; retry < TRANSACTIONS_MAX_RETRIES; retry++) {
Session dbSession = this.getSession();
try {
tx = dbSession.beginTransaction();
dbSession.delete(entity);
tx.commit();
if (retry > 0)
LOG.warn("Transacao realizada apos "+String.valueOf(retry+1)+" tentativas.");
return;
} catch (JDBCConnectionException ex) {
last = ex;
if (tx != null)
tx.rollback();
tx = null;
this.closeSession();
}
}
LOG.error("Erro ao tentar deletar entidade: "+entity.getClass().getCanonicalName()+" apos "+
String.valueOf(TRANSACTIONS_MAX_RETRIES)+" tentativas.", last);
throw new RuntimeException("Erro no banco de dados.", last);
}
示例13: bulkUpdate
import org.hibernate.exception.JDBCConnectionException; //导入依赖的package包/类
@Override
public int bulkUpdate(String sqlStatement) {
JDBCConnectionException last = null;
Transaction tx = null;
for (int retry = 0; retry < TRANSACTIONS_MAX_RETRIES; retry++) {
Session dbSession = this.getSession();
try {
tx = dbSession.beginTransaction();
SQLQuery query = dbSession.createSQLQuery(sqlStatement);
int affected = query.executeUpdate();
tx.commit();
if (retry > 0)
LOG.warn("Transacao realizada apos "+String.valueOf(retry+1)+" tentativas.");
return affected;
} catch (JDBCConnectionException ex) {
last = ex;
if (tx != null)
tx.rollback();
tx = null;
this.closeSession();
}
}
LOG.error("Erro ao tentar atualizar entidade em massa apos "+
String.valueOf(TRANSACTIONS_MAX_RETRIES)+" tentativas.", last);
throw new RuntimeException("Erro no banco de dados.", last);
}
示例14: execute
import org.hibernate.exception.JDBCConnectionException; //导入依赖的package包/类
public void execute(TransactionalOperation operation) {
JDBCConnectionException last = null;
EntityTransaction tx = null;
for (int retry = 0; retry < TRANSACTIONS_MAX_RETRIES; retry++) {
EntityManager dbSession = this.getSession();
try {
tx = dbSession.getTransaction();
operation.execute(dbSession);
tx.commit();
if (retry > 0)
LOG.warn("Transacao realizada apos "+String.valueOf(retry+1)+" tentativas.");
return;
} catch (JDBCConnectionException ex) {
last = ex;
if (tx != null)
tx.rollback();
tx = null;
this.closeSession();
}
}
LOG.error("Erro ao tentar executar operação transacional apos "+
String.valueOf(TRANSACTIONS_MAX_RETRIES)+" tentativas.", last);
throw new RuntimeException("Erro no banco de dados.", last);
}
示例15: persist
import org.hibernate.exception.JDBCConnectionException; //导入依赖的package包/类
@Override
public void persist(Serializable entity) {
JDBCConnectionException last = null;
EntityTransaction tx = null;
for (int retry = 0; retry < TRANSACTIONS_MAX_RETRIES; retry++) {
EntityManager dbSession = this.getSession();
try {
tx = dbSession.getTransaction();
dbSession.persist(entity);
tx.commit();
if (retry > 0)
LOG.warn("Transacao realizada apos "+String.valueOf(retry+1)+" tentativas.");
return;
} catch (JDBCConnectionException ex) {
last = ex;
if (tx != null)
tx.rollback();
tx = null;
this.closeSession();
}
}
LOG.error("Erro ao tentar salvar entidade: "+entity.getClass().getCanonicalName()+" apos "+
String.valueOf(TRANSACTIONS_MAX_RETRIES)+" tentativas.", last);
throw new RuntimeException("Erro no banco de dados.", last);
}