List of usage examples for org.hibernate HibernateException HibernateException
public HibernateException(String message, Throwable cause)
From source file:org.apache.shindig.social.opensocial.hibernate.utils.HibernateUtils.java
License:Apache License
private static void init(String resource) throws HibernateException { try {//from w w w .j a v a2s .co m if (resource != null && !resource.equals("")) { sessionFactory = new AnnotationConfiguration().configure(resource).buildSessionFactory(); } else { sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory(); } } catch (Exception e) { throw new HibernateException("Can't build hibernate sessionactory.", e); } }
From source file:org.apache.shindig.social.opensocial.hibernate.utils.HibernateUtils.java
License:Apache License
private static void init(File configFile) throws HibernateException { try {//from ww w .j av a 2 s . c om if (configFile != null) { sessionFactory = new AnnotationConfiguration().configure(configFile).buildSessionFactory(); } else { sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory(); } } catch (Exception e) { throw new HibernateException("Can't build hibernate sessionactory.", e); } }
From source file:org.apache.usergrid.apm.service.ApplicationServiceImpl.java
License:Apache License
public Long saveApplication(App application) throws HibernateException { Session session = null;// w w w.java 2s.co m Transaction transaction = null; try { Date d = new Date(); application.setCreatedDate(d); application.setLastModifiedDate(d); session = ServiceFactory.getHibernateSession(); transaction = session.beginTransaction(); Long generatedId = (Long) session.save(application); transaction.commit(); log.info("Application " + generatedId + " saved"); return generatedId; } catch (HibernateException e) { log.error(e.getCause()); transaction.rollback(); throw new HibernateException("Cannot save application due to: " + e.getCause(), e); } }
From source file:org.apache.usergrid.apm.service.ApplicationServiceImpl.java
License:Apache License
public void updateApplicationInDB(App appModel) { Session session = null;// w w w. j av a2s . c o m Transaction transaction = null; try { appModel.setLastModifiedDate(new Date()); session = ServiceFactory.getHibernateSession(); transaction = session.beginTransaction(); session.saveOrUpdate(appModel); transaction.commit(); log.info("Application record " + appModel.getAppName() + " updated"); } catch (HibernateException e) { transaction.rollback(); log.error(e); throw new HibernateException("Cannot update Application call record.", e); } }
From source file:org.apache.usergrid.apm.service.ApplicationServiceImpl.java
License:Apache License
private void updateApplicationInDBSimple(App appModel) { Session session = null;//from w w w. j a v a 2 s .co m Transaction transaction = null; try { session = ServiceFactory.getHibernateSession(); transaction = session.beginTransaction(); session.saveOrUpdate(appModel); transaction.commit(); log.info("Application record " + appModel.getAppName() + " updated"); } catch (HibernateException e) { transaction.rollback(); log.error(e); throw new HibernateException("Cannot update Application call record.", e); } }
From source file:org.apache.usergrid.apm.service.ApplicationServiceImpl.java
License:Apache License
@Override /**/*w w w.ja va2 s . c o m*/ * Not really deleting it ..just marking it for deletion */ public void deleteApplication(Long applicationId) { log.info("Deleting Application with id: " + applicationId); Session session = null; Transaction transaction = null; try { session = ServiceFactory.getHibernateSession(); transaction = session.beginTransaction(); App result = (App) session.get(App.class, applicationId); result.setDeleted(true); session.update(result); transaction.commit(); } catch (Exception e) { e.printStackTrace(); transaction.rollback(); throw new HibernateException("Cannot delete Application record : ", e); } }
From source file:org.apache.usergrid.apm.service.ApplicationServiceImpl.java
License:Apache License
@Override public App getApplication(Long instaOpsApplicationId) { if (instaOpsApplicationId == null) { log.error("Can not get an applicaiton with null application Id"); return null; }//from w ww . j a v a 2 s .com log.info("Getting Application with id: " + instaOpsApplicationId); Session session = null; Transaction transaction = null; try { session = ServiceFactory.getHibernateSession(); transaction = session.beginTransaction(); App result = (App) session.get(App.class, instaOpsApplicationId); transaction.commit(); return result; } catch (Exception e) { e.printStackTrace(); transaction.rollback(); throw new HibernateException("Cannot get Application record : ", e); } }
From source file:org.apache.usergrid.apm.service.ApplicationServiceImpl.java
License:Apache License
@SuppressWarnings("unchecked") @Override//from w w w. jav a 2 s . c o m public List<App> getAllApps() { log.info("Getting all applications"); List<App> apps = null; Session session = null; Transaction transaction = null; try { session = ServiceFactory.getHibernateSession(); transaction = session.beginTransaction(); Query query = session.createQuery("from App as m where m.deleted = false order by m.appName asc"); apps = (List<App>) query.list(); transaction.commit(); } catch (HibernateException e) { throw new HibernateException("Cannot get all applications ", e); } return apps; }
From source file:org.apache.usergrid.apm.service.ApplicationServiceImpl.java
License:Apache License
@SuppressWarnings("unchecked") @Override// w w w . ja v a 2 s. c om public Long getTotalApplicationsCount() { log.info("Getting total applications count !!"); List<App> apps = null; Session session = null; Transaction transaction = null; Long count = null; try { session = ServiceFactory.getHibernateSession(); transaction = session.beginTransaction(); Query query = session.createQuery("Select max(instaOpsApplicationId) from App"); count = (Long) query.uniqueResult(); transaction.commit(); } catch (HibernateException e) { log.error("problem getting total applications count"); throw new HibernateException("Cannot get applications. ", e); } return count; }
From source file:org.apache.usergrid.apm.service.ApplicationServiceImpl.java
License:Apache License
public App getApp(String fullAppName) { App app = null;// w ww .j av a2 s . co m Session session = null; Transaction transaction = null; try { session = ServiceFactory.getHibernateSession(); transaction = session.beginTransaction(); Query query = session.createQuery("from App as m where m.fullAppName=:fullName and m.deleted = false"); query.setParameter("fullName", fullAppName); app = (App) query.uniqueResult(); transaction.commit(); } catch (HibernateException e) { throw new HibernateException("Cannot get all applications ", e); } return app; }