Exemplo n.º 1
0
 public static List<Trade> getOldVersionList(Trade trade) {
   Session session = HibernateUtil.getSession();
   List<Trade> result = new ArrayList<>();
   try {
     if (trade != null) {
       result.add(trade);
       AuditReader reader = AuditReaderFactory.get(session);
       List<Object[]> prior_revision =
           (List<Object[]>)
               reader
                   .createQuery()
                   .forRevisionsOfEntity(trade.getClass(), false, true)
                   .add(AuditEntity.property("tradeVersion").lt(trade.getTradeVersion()))
                   .add(AuditEntity.id().eq(trade.getId()))
                   .addOrder(AuditEntity.revisionNumber().desc())
                   .getResultList();
       for (Object[] objects : prior_revision) {
         Trade version = (Trade) objects[0];
         unProxyObject(version);
         result.add(version);
       }
     }
   } catch (ClassNotFoundException
       | IllegalAccessException
       | HibernateException
       | IllegalArgumentException
       | InvocationTargetException e) {
     logger.error(StringUtils.formatErrorMessage(e));
   } finally {
     session.close();
   }
   return result;
 }
Exemplo n.º 2
0
 /** Test of unLazyObjectRecursively method, of class AuditAccessor. */
 @Test
 public void testUnLazyObjectRecursively_Object_int() throws Exception {
   System.out.println("unLazyObjectRecursively");
   Trade trade =
       (Trade)
           HibernateUtil.getObjectWithQuery(
               "from Trade t where t.tradeId in (select min(tradeId) from Trade)");
   AuditAccessor.unLazyObjectRecursively(trade, 5);
   assertNotNull("failed lazy loading trade", trade);
 }
Exemplo n.º 3
0
 /** Test of unProxyObject method, of class AuditAccessor. */
 @Test
 public void testUnProxyObject() throws Exception {
   System.out.println("unProxyObject");
   Trade trade =
       (Trade)
           HibernateUtil.getObjectWithQuery(
               "from Trade t where t.tradeId in (select min(tradeId) from Trade)");
   AuditAccessor.unProxyObject(trade);
   assertNotNull(" failed unproxying trade", trade);
 }
Exemplo n.º 4
0
 /** Test of getPreviousVersion method, of class AuditAccessor. */
 @Test
 public void testGetPreviousVersion() {
   System.out.println("getPreviousVersion");
   Trade entity =
       (Trade)
           HibernateUtil.getObjectWithQuery(
               "from Trade t where t.tradeId in (select min(tradeId) from Trade)");
   Trade result = AuditAccessor.getPreviousVersion(entity);
   assertNotNull(" trade version not found", result);
 }
Exemplo n.º 5
0
 /** Test of getOldVersionList method, of class AuditAccessor. */
 @Test
 public void testGetOldVersionList() {
   System.out.println("getOldVersionList");
   Trade trade =
       (Trade)
           HibernateUtil.getObjectWithQuery(
               "from Trade t where t.tradeId in (select min(tradeId) from Trade)");
   List<Trade> result = AuditAccessor.getOldVersionList(trade);
   assertNotNull(" trade versions not found", result);
   assertFalse(" trade versions not found", result.isEmpty());
 }
Exemplo n.º 6
0
  public static Trade getPreviousVersion(Trade entity) {
    Session session = HibernateUtil.getSession();
    Trade trade = null;
    try {
      List<Trade> oldVersionList = getOldVersionList(entity);
      if (!oldVersionList.isEmpty()) {
        trade = oldVersionList.get(0);
      }
      if (trade != null) {
        unProxyObject(trade);
      }

    } catch (IllegalAccessException
        | IllegalArgumentException
        | InvocationTargetException
        | HibernateException
        | ClassNotFoundException e) {
      logger.error(StringUtils.formatErrorMessage(e));
    } finally {
      session.close();
    }
    return trade;
  }
Exemplo n.º 7
0
 /**
  * @param proxy
  * @return
  * @throws ClassNotFoundException
  */
 public static Object loadLazyObject(HibernateProxy proxy) throws ClassNotFoundException {
   LazyInitializer init = proxy.getHibernateLazyInitializer();
   logger.debug(init.getEntityName() + StringUtils.SPACE + init.getIdentifier());
   return HibernateUtil.getObject(Class.forName(init.getEntityName()), init.getIdentifier());
 }