org.eclipse.emf.teneo.hibernate.HbSessionWrapper Maven / Gradle / Ivy
/**
*
*
* Copyright (c) 2005, 2006, 2007, 2008 Springsite BV (The Netherlands) and others
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Martin Taal
* Benjamin Cabe
*
*
* $Id: HbSessionWrapper.java,v 1.12 2010/11/12 09:33:33 mtaal Exp $
*/
package org.eclipse.emf.teneo.hibernate;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import org.eclipse.emf.teneo.annotations.pannotation.InheritanceType;
import org.hibernate.FlushMode;
import org.hibernate.LockOptions;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.internal.SessionImpl;
import org.hibernate.metadata.ClassMetadata;
import org.hibernate.persister.entity.JoinedSubclassEntityPersister;
import org.hibernate.persister.entity.SingleTableEntityPersister;
import org.hibernate.persister.entity.UnionSubclassEntityPersister;
/**
* Wraps a standard hibernate session.
*
* @author Martin Taal
* @version $Revision: 1.12 $
*/
public class HbSessionWrapper implements SessionWrapper {
/** The hibernate session */
private Session session = null;
/** The datastore which created me */
private final HbDataStore hbDataStore;
private FlushMode flushMode;
/** Constructor */
public HbSessionWrapper(HbDataStore hbDataStore) {
this.hbDataStore = hbDataStore;
}
/** Set the session in the constructor */
public HbSessionWrapper(HbDataStore hbDataStore, Session session) {
this.hbDataStore = hbDataStore;
this.session = session;
}
/**
* Return the session, return is an object to support both session as well as entitymanager.
*/
public Object getSession() {
if (session == null) {
session = hbDataStore.getSessionFactory().openSession();
}
return session;
}
/** Convenience which casts */
private Session getSessionInternal() {
return (Session) getSession();
}
/** Begin a transaction */
public void beginTransaction() {
getSessionInternal().beginTransaction();
}
/** Commit a transaction */
public void commitTransaction() {
getSessionInternal().getTransaction().commit();
}
/** Rollback transaction */
public void rollbackTransaction() {
getSessionInternal().getTransaction().rollback();
}
/** Return an object using the entityname and a serializable id */
public Object get(String entityName, Serializable id) {
return getSessionInternal().get(entityName, id);
}
/** Query */
public List> executeQuery(String qry) {
final Query query = getSessionInternal().createQuery(qry);
return query.list();
}
/** Query */
public List> executeQuery(String qry, String entityParameter, Object entity) {
final Query query = getSessionInternal().createQuery(qry);
query.setEntity(entityParameter, entity);
return query.list();
}
/** Query */
public List> executeQuery(String qry, List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy