/** Update */ public static void update(MimeType mt) throws DatabaseException { log.debug("update({})", mt); String qs = "select mt.imageContent, mt.imageMime from MimeType mt where mt.id=:id"; Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); if (mt.getImageContent() == null || mt.getImageContent().length() == 0) { Query q = session.createQuery(qs); q.setParameter("id", mt.getId()); Object[] data = (Object[]) q.setMaxResults(1).uniqueResult(); mt.setImageContent((String) data[0]); mt.setImageMime((String) data[1]); } session.update(mt); HibernateUtil.commit(tx); } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } log.debug("update: void"); }
/** Create */ public static long create(MimeType mt) throws DatabaseException { log.debug("create({})", mt); Session session = null; Transaction tx = null; try { session = HibernateUtil.getSessionFactory().openSession(); tx = session.beginTransaction(); Long id = (Long) session.save(mt); MimeType mtTmp = (MimeType) session.load(MimeType.class, id); for (String extensions : mt.getExtensions()) { mtTmp.getExtensions().add(extensions); } HibernateUtil.commit(tx); log.debug("create: {}", id); return id; } catch (HibernateException e) { HibernateUtil.rollback(tx); throw new DatabaseException(e.getMessage(), e); } finally { HibernateUtil.close(session); } }