use of org.hibernate.engine.spi.SessionImplementor in project hibernate-orm by hibernate.
the class OnLockVisitor method processCollection.
@Override
public Object processCollection(Object collection, CollectionType type) throws HibernateException {
if (collection == null) {
return null;
}
final SessionImplementor session = getSession();
final CollectionPersister persister = session.getFactory().getCollectionPersister(type.getRole());
if (collection instanceof PersistentCollection) {
final PersistentCollection persistentCollection = (PersistentCollection) collection;
if (persistentCollection.setCurrentSession(session)) {
if (isOwnerUnchanged(persistentCollection, persister, extractCollectionKeyFromOwner(persister))) {
// a "detached" collection that originally belonged to the same entity
if (persistentCollection.isDirty()) {
throw new HibernateException("reassociated object has dirty collection");
}
reattachCollection(persistentCollection, type);
} else {
// a "detached" collection that belonged to a different entity
throw new HibernateException("reassociated object has dirty collection reference");
}
} else {
// to the entity passed to update()
throw new HibernateException("reassociated object has dirty collection reference");
}
} else {
//TODO: or an array!! we can't lock objects with arrays now??
throw new HibernateException("reassociated object has dirty collection reference (or an array)");
}
return null;
}
use of org.hibernate.engine.spi.SessionImplementor in project hibernate-orm by hibernate.
the class AbstractManipulationCriteriaQuery method interpret.
@Override
public CriteriaInterpretation interpret(RenderingContext renderingContext) {
final String jpaqlString = renderQuery(renderingContext);
return new CriteriaInterpretation() {
@Override
@SuppressWarnings("unchecked")
public QueryImplementor buildCompiledQuery(SessionImplementor entityManager, final InterpretedParameterMetadata interpretedParameterMetadata) {
final Map<String, Class> implicitParameterTypes = extractTypeMap(interpretedParameterMetadata.implicitParameterBindings());
QueryImplementor query = entityManager.createQuery(jpaqlString, null, null, new HibernateEntityManagerImplementor.QueryOptions() {
@Override
public List<ValueHandlerFactory.ValueHandler> getValueHandlers() {
return null;
}
@Override
public Map<String, Class> getNamedParameterExplicitTypes() {
return implicitParameterTypes;
}
@Override
public ResultMetadataValidator getResultMetadataValidator() {
return null;
}
});
for (ImplicitParameterBinding implicitParameterBinding : interpretedParameterMetadata.implicitParameterBindings()) {
implicitParameterBinding.bind(query);
}
return query;
}
private Map<String, Class> extractTypeMap(List<ImplicitParameterBinding> implicitParameterBindings) {
final HashMap<String, Class> map = new HashMap<>();
for (ImplicitParameterBinding implicitParameter : implicitParameterBindings) {
map.put(implicitParameter.getParameterName(), implicitParameter.getJavaType());
}
return map;
}
};
}
use of org.hibernate.engine.spi.SessionImplementor in project hibernate-orm by hibernate.
the class TransactionTimeoutTest method testTransactionTimeoutFailure.
@Test
public void testTransactionTimeoutFailure() throws InterruptedException {
Session session = openSession();
try {
Transaction transaction = session.getTransaction();
transaction.setTimeout(1);
assertEquals(-1, ((SessionImplementor) session).getJdbcCoordinator().determineRemainingTransactionTimeOutPeriod());
transaction.begin();
Thread.sleep(1000);
session.persist(new Person("Lukasz", "Antoniak"));
transaction.commit();
} catch (TransactionException e) {
// expected
} catch (PersistenceException e) {
assertTyping(TransactionException.class, e.getCause());
} finally {
session.close();
}
}
use of org.hibernate.engine.spi.SessionImplementor in project hibernate-orm by hibernate.
the class AuditProcessManager method get.
public AuditProcess get(EventSource session) {
final Transaction transaction = session.accessTransaction();
AuditProcess auditProcess = auditProcesses.get(transaction);
if (auditProcess == null) {
// No worries about registering a transaction twice - a transaction is single thread
auditProcess = new AuditProcess(revisionInfoGenerator, session);
auditProcesses.put(transaction, auditProcess);
session.getActionQueue().registerProcess(new BeforeTransactionCompletionProcess() {
public void doBeforeTransactionCompletion(SessionImplementor session) {
final AuditProcess process = auditProcesses.get(transaction);
if (process != null) {
process.doBeforeTransactionCompletion(session);
}
}
});
session.getActionQueue().registerProcess(new AfterTransactionCompletionProcess() {
public void doAfterTransactionCompletion(boolean success, SharedSessionContractImplementor session) {
auditProcesses.remove(transaction);
}
});
}
return auditProcess;
}
use of org.hibernate.engine.spi.SessionImplementor in project hibernate-orm by hibernate.
the class CrossTypeRevisionChangesReaderImpl method findEntityTypes.
@Override
@SuppressWarnings({ "unchecked" })
public Set<Pair<String, Class>> findEntityTypes(Number revision) throws IllegalStateException, IllegalArgumentException {
checkNotNull(revision, "Entity revision");
checkPositive(revision, "Entity revision");
checkSession();
final Session session = auditReaderImplementor.getSession();
final SessionImplementor sessionImplementor = auditReaderImplementor.getSessionImplementor();
final Set<Number> revisions = new HashSet<>(1);
revisions.add(revision);
final Query<?> query = enversService.getRevisionInfoQueryCreator().getRevisionsQuery(session, revisions);
final Object revisionInfo = query.uniqueResult();
if (revisionInfo != null) {
// If revision exists.
final Set<String> entityNames = enversService.getModifiedEntityNamesReader().getModifiedEntityNames(revisionInfo);
if (entityNames != null) {
// Generate result that contains entity names and corresponding Java classes.
final Set<Pair<String, Class>> result = new HashSet<>();
for (String entityName : entityNames) {
result.add(Pair.make(entityName, EntityTools.getEntityClass(sessionImplementor, entityName)));
}
return result;
}
}
return Collections.EMPTY_SET;
}
Aggregations