use of org.hibernate.LockMode in project hibernate-orm by hibernate.
the class EncapsulatedCompositeAttributeResultSetProcessorTest method doCompare.
private void doCompare(SessionFactoryImplementor sf, OuterJoinLoadable persister) {
final LoadQueryInfluencers influencers = LoadQueryInfluencers.NONE;
final LockMode lockMode = LockMode.NONE;
final int batchSize = 1;
final EntityJoinWalker walker = new EntityJoinWalker(persister, persister.getKeyColumnNames(), batchSize, lockMode, sf, influencers);
final LoadQueryDetails details = Helper.INSTANCE.buildLoadQueryDetails(persister, sf);
compare(walker, details);
}
use of org.hibernate.LockMode in project hibernate-orm by hibernate.
the class AbstractTransactSQLDialect method applyLocksToSql.
@Override
public String applyLocksToSql(String sql, LockOptions aliasedLockOptions, Map<String, String[]> keyColumnNames) {
// TODO: merge additional lockoptions support in Dialect.applyLocksToSql
final Iterator itr = aliasedLockOptions.getAliasLockIterator();
final StringBuilder buffer = new StringBuilder(sql);
while (itr.hasNext()) {
final Map.Entry entry = (Map.Entry) itr.next();
final LockMode lockMode = (LockMode) entry.getValue();
if (lockMode.greaterThan(LockMode.READ)) {
final String alias = (String) entry.getKey();
int start = -1;
int end = -1;
if (sql.endsWith(" " + alias)) {
start = (buffer.length() - alias.length());
end = start + alias.length();
} else {
int position = buffer.indexOf(" " + alias + " ");
if (position <= -1) {
position = buffer.indexOf(" " + alias + ",");
}
if (position > -1) {
start = position + 1;
end = start + alias.length();
}
}
if (start > -1) {
final String lockHint = appendLockHint(aliasedLockOptions, alias);
buffer.replace(start, end, lockHint);
}
}
}
return buffer.toString();
}
use of org.hibernate.LockMode in project hibernate-orm by hibernate.
the class Loader method shouldUseFollowOnLocking.
protected boolean shouldUseFollowOnLocking(QueryParameters parameters, Dialect dialect, List<AfterLoadAction> afterLoadActions) {
if ((parameters.getLockOptions().getFollowOnLocking() == null && dialect.useFollowOnLocking(parameters)) || (parameters.getLockOptions().getFollowOnLocking() != null && parameters.getLockOptions().getFollowOnLocking())) {
// currently only one lock mode is allowed in follow-on locking
final LockMode lockMode = determineFollowOnLockMode(parameters.getLockOptions());
final LockOptions lockOptions = new LockOptions(lockMode);
if (lockOptions.getLockMode() != LockMode.UPGRADE_SKIPLOCKED) {
if (lockOptions.getLockMode() != LockMode.NONE) {
LOG.usingFollowOnLocking();
}
lockOptions.setTimeOut(parameters.getLockOptions().getTimeOut());
lockOptions.setScope(parameters.getLockOptions().getScope());
afterLoadActions.add(new AfterLoadAction() {
@Override
public void afterLoad(SharedSessionContractImplementor session, Object entity, Loadable persister) {
((Session) session).buildLockRequest(lockOptions).lock(persister.getEntityName(), entity);
}
});
parameters.setLockOptions(new LockOptions());
return true;
}
}
return false;
}
use of org.hibernate.LockMode in project hibernate-orm by hibernate.
the class CriteriaLoader method getLockModes.
@Override
protected LockMode[] getLockModes(LockOptions lockOptions) {
final String[] entityAliases = getAliases();
if (entityAliases == null) {
return null;
}
final int size = entityAliases.length;
LockMode[] lockModesArray = new LockMode[size];
for (int i = 0; i < size; i++) {
LockMode lockMode = lockOptions.getAliasSpecificLockMode(entityAliases[i]);
lockModesArray[i] = lockMode == null ? lockOptions.getLockMode() : lockMode;
}
return lockModesArray;
}
use of org.hibernate.LockMode in project hibernate-orm by hibernate.
the class Loader method processResultSet.
protected List processResultSet(ResultSet rs, QueryParameters queryParameters, SharedSessionContractImplementor session, boolean returnProxies, ResultTransformer forcedResultTransformer, int maxRows, List<AfterLoadAction> afterLoadActions) throws SQLException {
final int entitySpan = getEntityPersisters().length;
final EntityKey optionalObjectKey = getOptionalObjectKey(queryParameters, session);
final LockMode[] lockModesArray = getLockModes(queryParameters.getLockOptions());
final boolean createSubselects = isSubselectLoadingEnabled();
final List subselectResultKeys = createSubselects ? new ArrayList() : null;
final ArrayList hydratedObjects = entitySpan == 0 ? null : new ArrayList(entitySpan * 10);
final List results = new ArrayList();
handleEmptyCollections(queryParameters.getCollectionKeys(), rs, session);
// we can reuse it for each row
EntityKey[] keys = new EntityKey[entitySpan];
LOG.trace("Processing result set");
int count;
for (count = 0; count < maxRows && rs.next(); count++) {
if (DEBUG_ENABLED) {
LOG.debugf("Result set row: %s", count);
}
Object result = getRowFromResultSet(rs, session, queryParameters, lockModesArray, optionalObjectKey, hydratedObjects, keys, returnProxies, forcedResultTransformer);
results.add(result);
if (createSubselects) {
subselectResultKeys.add(keys);
// can't reuse in this case
keys = new EntityKey[entitySpan];
}
}
LOG.tracev("Done processing result set ({0} rows)", count);
initializeEntitiesAndCollections(hydratedObjects, rs, session, queryParameters.isReadOnly(session), afterLoadActions);
if (createSubselects) {
createSubselects(subselectResultKeys, queryParameters, session);
}
return results;
}
Aggregations