Example #1
0
 public static int insertMedia(MediaTable item) {
   Session session = HibernateLoader.getSessionFactory().openSession();
   Transaction tx = null;
   int itemId = -1;
   try {
     tx = session.beginTransaction();
     if (!checkIfEntityExists(session, MediaTable.class, "filePath", item.getFilePath())) {
       session.save(item);
       itemId = 1;
     }
     tx.commit();
   } catch (HibernateException he) {
     he.printStackTrace();
     log.error("Unable to insert media");
   }
   session.close();
   return itemId;
 }
Example #2
0
 /**
  * Gets all the listings
  *
  * @return
  */
 public static List<MediaTable> queryAllMedia() {
   List<MediaTable> mediaTables = new ArrayList<MediaTable>();
   Session session = HibernateLoader.getSessionFactory().openSession();
   Transaction tx = null;
   try {
     tx = session.beginTransaction();
     List allMedia = session.createQuery("FROM MediaTable").list();
     for (Iterator iter = allMedia.listIterator(); iter.hasNext(); ) {
       MediaTable item = (MediaTable) iter.next();
       mediaTables.add(item);
     }
     tx.commit();
   } catch (HibernateException he) {
     he.printStackTrace();
     log.error("Unable to query all the mediaTables");
   } finally {
     session.close();
   }
   return mediaTables;
 }
Example #3
0
 public static List<MediaTable> queryMedia(int numInPage, int start) {
   List<MediaTable> items = new ArrayList<MediaTable>();
   Session session = HibernateLoader.getSessionFactory().openSession();
   Transaction tx = null;
   try {
     tx = session.beginTransaction();
     List allListings =
         session.createQuery("FROM MediaTable").list().subList(start, start + numInPage);
     for (Iterator iter = allListings.listIterator(); iter.hasNext(); ) {
       MediaTable item = (MediaTable) iter.next();
       items.add(item);
     }
     tx.commit();
   } catch (HibernateException he) {
     he.printStackTrace();
     log.error("Unable to query all the listings");
   } finally {
     session.close();
   }
   return items;
 }