本文整理汇总了Java中net.sf.hibernate.Session类的典型用法代码示例。如果您正苦于以下问题:Java Session类的具体用法?Java Session怎么用?Java Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Session类属于net.sf.hibernate包,在下文中一共展示了Session类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSession
import net.sf.hibernate.Session; //导入依赖的package包/类
Session getSession(JCASessionImpl handle) {
// JCA 1.0, 5.5.4
// Ensure that there is at most one connection handle associated
// actively with a ManagedConnection instance. [skiped] Any operations
// on the ManagedConnection from any previously created connection
// handles should result in an application level exception.
// this might be pretty bad for performance, profile and find a
// better way if it is really bad
synchronized (handles) {
if ( handles.size() > 0 && handles.get(0) == handle) {
return session;
}
else {
final String message = "Inactive logical session handle called";
// cannot throw HibernateException because not all Session
// methods throws it. This is incompatible with the spec!
throw new IllegalStateException(message);
}
}
}
示例2: lookup
import net.sf.hibernate.Session; //导入依赖的package包/类
/**
* Retrieve the persistent object bound to the given name.
* @see org.odmg.Database#lookup(String)
*/
public Object lookup(String name) throws ObjectNameNotFoundException {
try {
Session s = getSession();
Name nameObj;
try {
nameObj = (Name) s.load(Name.class, name);
}
catch (ObjectNotFoundException onfe) {
throw new ObjectNameNotFoundException();
}
return s.load( nameObj.getPersistentClass(), nameObj.getId() );
}
catch (HibernateException he) {
throw new ODMGRuntimeException( he.getMessage() );
}
}
示例3: unbind
import net.sf.hibernate.Session; //导入依赖的package包/类
/**
* Unbind the given name.
* @see org.odmg.Database#unbind(String)
*/
public void unbind(String name) throws ObjectNameNotFoundException {
try {
Session s = getSession();
Name nameObj;
try {
nameObj = (Name) s.load(Name.class, name);
}
catch (ObjectNotFoundException onfe) {
throw new ObjectNameNotFoundException();
}
s.delete(nameObj);
}
catch (HibernateException he) {
throw new ODMGRuntimeException( he.getMessage() );
}
}
示例4: changeUserDetails
import net.sf.hibernate.Session; //导入依赖的package包/类
/**
* Demonstrates detached object support
*/
public void changeUserDetails(User user) throws Exception {
System.out.println("Changing user details for: " + user.getId() );
Session s = factory.openSession();
Transaction tx=null;
try {
tx = s.beginTransaction();
s.saveOrUpdate(user);
tx.commit();
}
catch (Exception e) {
if (tx!=null) tx.rollback();
throw e;
}
finally {
s.close();
}
}
示例5: changeItemDescription
import net.sf.hibernate.Session; //导入依赖的package包/类
/**
* Demonstrates automatic dirty checking
*/
public void changeItemDescription(Long itemId, String description) throws Exception {
System.out.println("Changing auction item description for: " + itemId );
Session s = factory.openSession();
Transaction tx=null;
try {
tx = s.beginTransaction();
AuctionItem item = (AuctionItem) s.get(AuctionItem.class, itemId);
if (item==null) throw new IllegalArgumentException("No item for the given id: " + itemId);
item.setDescription(description);
tx.commit();
}
catch (Exception e) {
if (tx!=null) tx.rollback();
throw e;
}
finally {
s.close();
}
}
示例6: saveChangeList
import net.sf.hibernate.Session; //导入依赖的package包/类
private int saveChangeList(final ChangeList chl, final Session session) throws HibernateException {
session.saveOrUpdate(chl);
// set synthetic change list number if necessary
final int changeListID = chl.getChangeListID();
if (StringUtils.isBlank(chl.getNumber())) {
chl.setNumber(Integer.toString(changeListID));
session.saveOrUpdate(chl);
}
for (final Iterator iter = chl.getChanges().iterator(); iter.hasNext(); ) {
final Change ch = (Change) iter.next();
if (ch.getChangeListID() == ChangeList.UNSAVED_ID) {
ch.setChangeListID(changeListID);
}
session.saveOrUpdate(ch);
}
return changeListID;
}
示例7: getStatsFromDB
import net.sf.hibernate.Session; //导入依赖的package包/类
/**
* Returns list of PersistentObject corresponding the type of
* the statistics.
*
* @param session
* @param buildID
* @param fromDate
* @return
* @throws HibernateException
*/
protected List getStatsFromDB(final Session session, final int buildID, final Date fromDate,
final Date toDate) throws HibernateException {
final Query q = session.createQuery("select ms from MonthlyTestStats ms " +
" where ms.activeBuildID = ? " +
" and ms.testCode = ? " +
" and ms.sampleTime >= ? " +
" and ms.sampleTime <= ?");
q.setCacheable(true);
q.setInteger(0, buildID);
q.setByte(1, getTestCode());
q.setDate(2, fromDate);
q.setDate(3, toDate);
return q.list();
}
示例8: getStatsFromDB
import net.sf.hibernate.Session; //导入依赖的package包/类
/**
* Returns list of PersistentObject corresponding the type of
* the statistics.
*
* @param session
* @param buildID
* @param fromDate
* @return
* @throws HibernateException
*/
protected List getStatsFromDB(final Session session, final int buildID, final Date fromDate,
final Date toDate) throws HibernateException {
final Query q = session.createQuery("select hts from HourlyTestStats hts " +
" where hts.activeBuildID = ? " +
" and hts.testCode = ? " +
" and hts.sampleTime >= ? " +
" and hts.sampleTime <= ?");
q.setCacheable(true);
q.setInteger(0, buildID);
q.setByte(1, getTestCode());
q.setDate(2, fromDate);
q.setDate(3, toDate);
return q.list();
}
示例9: getStatsFromDB
import net.sf.hibernate.Session; //导入依赖的package包/类
/**
* Returns list of PersistentObject corresponding the type of
* the statistics.
*
* @param session
* @param buildID
* @param fromDate
* @return
* @throws HibernateException
*/
protected List getStatsFromDB(final Session session, final int buildID, final Date fromDate,
final Date toDate) throws HibernateException {
final Query q = session.createQuery("select mts from MonthlyTestStats mts " +
" where mts.activeBuildID = ? " +
" and mts.testCode = ? " +
" and mts.sampleTime >= ? " +
" and mts.sampleTime <= ?");
q.setCacheable(true);
q.setInteger(0, buildID);
q.setByte(1, getTestCode());
q.setDate(2, fromDate);
q.setDate(3, toDate);
return q.list();
}
示例10: getStatsFromDB
import net.sf.hibernate.Session; //导入依赖的package包/类
/**
* Returns list of PersistentObject corresponding the type of
* the statistics.
*
* @param session
* @param buildID
* @param fromDate
* @return
* @throws HibernateException
*/
protected List getStatsFromDB(final Session session, final int buildID, final Date fromDate,
final Date toDate) throws HibernateException {
final Query q = session.createQuery("select dts from DailyTestStats dts " +
" where dts.activeBuildID = ? " +
" and dts.testCode = ? " +
" and dts.sampleTime >= ? " +
" and dts.sampleTime <= ?");
q.setCacheable(true);
q.setInteger(0, buildID);
q.setByte(1, getTestCode());
q.setDate(2, fromDate);
q.setDate(3, toDate);
return q.list();
}
示例11: obtenerPermiso
import net.sf.hibernate.Session; //导入依赖的package包/类
/**
* @ejb.interface-method
* @ejb.permission role-name="${role.gestor},${role.admin},${role.auto}"
*/
public Permiso obtenerPermiso(Long codigo) {
Session session = getSession();
try {
// Cargamos permiso
Permiso permiso = (Permiso) session.load(Permiso.class, codigo);
return permiso;
} catch (ObjectNotFoundException onfe) {
return null;
} catch (HibernateException he) {
throw new EJBException(he);
} finally {
close(session);
}
}
示例12: grabarPermiso
import net.sf.hibernate.Session; //导入依赖的package包/类
/**
* @ejb.interface-method
* @ejb.permission role-name="${role.admin}"
*/
public Long grabarPermiso(Permiso obj) {
Session session = getSession();
try {
if(obj.getCodigo()!=null)
session.update(obj);
else
session.save(obj);
return obj.getCodigo();
} catch (HibernateException he) {
throw new EJBException(he);
} finally {
close(session);
}
}
示例13: listarPuntosSalidaFormulario
import net.sf.hibernate.Session; //导入依赖的package包/类
/**
* Lista todos los puntos salida de un formulario
* @ejb.interface-method
* @ejb.permission unchecked="true"
*/
public List listarPuntosSalidaFormulario(Long idFormulario) {
Session session = getSession();
try {
List puntosSalida = new ArrayList();
Formulario formulario = (Formulario)session.load(Formulario.class, idFormulario);
List salidas = formulario.getSalidas();
for (int i = 0; i < salidas.size(); i++) {
Salida salida = (Salida) salidas.get(i);
puntosSalida.add(salida.getPunto());
}
return puntosSalida;
} catch (HibernateException he) {
throw new EJBException(he);
} finally {
close(session);
}
}
示例14: grabarNuevaNotificacionTelematica
import net.sf.hibernate.Session; //导入依赖的package包/类
/**
* @ejb.interface-method
* @ejb.permission role-name="${role.gestor}"
* @ejb.permission role-name="${role.auto}"
*/
public Long grabarNuevaNotificacionTelematica(NotificacionTelematica obj) {
Session session = getSession();
try {
if (obj.getCodigo() == null){
session.save(obj);
}else{
throw new Exception("No se permite actualizar notificacion telematica");
}
return obj.getCodigo();
} catch (Exception he) {
throw new EJBException(he);
} finally {
close(session);
}
}
示例15: gravarComponentePaleta
import net.sf.hibernate.Session; //导入依赖的package包/类
/**
* Crea o actualiza un componente de una paleta.
* @ejb.interface-method
* @ejb.permission role-name="${role.admin}"
*/
public void gravarComponentePaleta(Componente componente, Long paleta_id) {
Session session = getSession();
try {
if (componente.getId() == null) {
Paleta paleta = (Paleta) session.load(Paleta.class, paleta_id);
paleta.addComponente(componente);
session.flush();
} else {
session.update(componente);
}
} catch (HibernateException he) {
throw new EJBException(he);
} finally {
close(session);
}
}