use of org.hibernate.HibernateException in project hibernate-orm by hibernate.
the class IlikeExpression method toSqlString.
@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {
final Dialect dialect = criteriaQuery.getFactory().getDialect();
final String[] columns = criteriaQuery.findColumns(propertyName, criteria);
if (columns.length != 1) {
throw new HibernateException("ilike may only be used with single-column properties");
}
if (dialect instanceof PostgreSQLDialect || dialect instanceof PostgreSQL81Dialect) {
return columns[0] + " ilike ?";
} else {
return dialect.getLowercaseFunction() + '(' + columns[0] + ") like ?";
}
}
use of org.hibernate.HibernateException in project hibernate-orm by hibernate.
the class DriverManagerConnectionProviderImpl method buildCreator.
private ConnectionCreator buildCreator(Map configurationValues) {
final ConnectionCreatorBuilder connectionCreatorBuilder = new ConnectionCreatorBuilder(serviceRegistry);
final String driverClassName = (String) configurationValues.get(AvailableSettings.DRIVER);
connectionCreatorBuilder.setDriver(loadDriverIfPossible(driverClassName));
final String url = (String) configurationValues.get(AvailableSettings.URL);
if (url == null) {
final String msg = log.jdbcUrlNotSpecified(AvailableSettings.URL);
log.error(msg);
throw new HibernateException(msg);
}
connectionCreatorBuilder.setUrl(url);
log.usingDriver(driverClassName, url);
final Properties connectionProps = ConnectionProviderInitiator.getConnectionProperties(configurationValues);
// if debug level is enabled, then log the password, otherwise mask it
if (log.isDebugEnabled()) {
log.connectionProperties(connectionProps);
} else {
log.connectionProperties(ConfigurationHelper.maskOut(connectionProps, "password"));
}
connectionCreatorBuilder.setConnectionProps(connectionProps);
final boolean autoCommit = ConfigurationHelper.getBoolean(AvailableSettings.AUTOCOMMIT, configurationValues, false);
log.autoCommitMode(autoCommit);
connectionCreatorBuilder.setAutoCommit(autoCommit);
final Integer isolation = ConnectionProviderInitiator.extractIsolation(configurationValues);
if (isolation != null) {
log.jdbcIsolationLevel(ConnectionProviderInitiator.toIsolationNiceName(isolation));
}
connectionCreatorBuilder.setIsolation(isolation);
return connectionCreatorBuilder.build();
}
use of org.hibernate.HibernateException in project hibernate-orm by hibernate.
the class PooledConnections method poll.
public Connection poll() throws SQLException {
Connection conn = availableConnections.poll();
if (conn == null) {
synchronized (allConnections) {
if (allConnections.size() < maxSize) {
addConnections(1);
return poll();
}
}
throw new HibernateException("The internal connection pool has reached its maximum size and no connection is currently available!");
}
conn.setAutoCommit(autoCommit);
return conn;
}
use of org.hibernate.HibernateException in project hibernate-orm by hibernate.
the class PessimisticForceIncrementLockingStrategy method lock.
@Override
public void lock(Serializable id, Object version, Object object, int timeout, SharedSessionContractImplementor session) {
if (!lockable.isVersioned()) {
throw new HibernateException("[" + lockMode + "] not supported for non-versioned entities [" + lockable.getEntityName() + "]");
}
final EntityEntry entry = session.getPersistenceContext().getEntry(object);
final EntityPersister persister = entry.getPersister();
final Object nextVersion = persister.forceVersionIncrement(entry.getId(), entry.getVersion(), session);
entry.forceLocked(object, nextVersion);
}
use of org.hibernate.HibernateException in project hibernate-orm by hibernate.
the class PessimisticReadUpdateLockingStrategy method lock.
@Override
public void lock(Serializable id, Object version, Object object, int timeout, SharedSessionContractImplementor session) {
if (!lockable.isVersioned()) {
throw new HibernateException("write locks via update not supported for non-versioned entities [" + lockable.getEntityName() + "]");
}
final SessionFactoryImplementor factory = session.getFactory();
try {
try {
final PreparedStatement st = session.getJdbcCoordinator().getStatementPreparer().prepareStatement(sql);
try {
lockable.getVersionType().nullSafeSet(st, version, 1, session);
int offset = 2;
lockable.getIdentifierType().nullSafeSet(st, id, offset, session);
offset += lockable.getIdentifierType().getColumnSpan(factory);
if (lockable.isVersioned()) {
lockable.getVersionType().nullSafeSet(st, version, offset, session);
}
final int affected = session.getJdbcCoordinator().getResultSetReturn().executeUpdate(st);
// todo: should this instead check for exactly one row modified?
if (affected < 0) {
if (factory.getStatistics().isStatisticsEnabled()) {
factory.getStatistics().optimisticFailure(lockable.getEntityName());
}
throw new StaleObjectStateException(lockable.getEntityName(), id);
}
} finally {
session.getJdbcCoordinator().getLogicalConnection().getResourceRegistry().release(st);
session.getJdbcCoordinator().afterStatementExecution();
}
} catch (SQLException e) {
throw session.getJdbcServices().getSqlExceptionHelper().convert(e, "could not lock: " + MessageHelper.infoString(lockable, id, session.getFactory()), sql);
}
} catch (JDBCException e) {
throw new PessimisticEntityLockException(object, "could not obtain pessimistic lock", e);
}
}
Aggregations