コード例 #1
0
 /**
  * Create ITidePersistenceManager for a PersistenceController
  *
  * @param component
  * @param controller
  * @return a ITidePersistenceManager.
  */
 public static TidePersistenceManager createTidePersistence(
     Component component, PersistenceController<?> controller) {
   TidePersistenceManager pm = TidePersistenceFactory.createTidePersistence(component, controller);
   if (pm != null) return pm;
   String controllerName = component.getName();
   if (controller.getPersistenceContext() instanceof Session)
     return new HibernatePersistenceControllerManager(controllerName);
   return null;
 }
コード例 #2
0
  /**
   * Attach the passed in entity with the EntityManager stored in the EntityHome object.
   *
   * @param entity
   * @return the attached hibernate object
   */
  @Override
  public Object fetchEntity(Object entity, String[] fetch) {
    PersistenceController<?> controller =
        (PersistenceController<?>) Component.getInstance(controllerName);
    EntityManager em = (EntityManager) controller.getPersistenceContext();
    Serializable id = (Serializable) Entity.forClass(entity.getClass()).getIdentifier(entity);
    if (id == null) return null;

    if (fetch == null || em.getDelegate().getClass().getName().indexOf(".hibernate.") < 0)
      return em.find(entity.getClass(), id);

    for (String f : fetch) {
      Query q =
          em.createQuery(
              "select e from "
                  + entity.getClass().getName()
                  + " e left join fetch e."
                  + f
                  + " where e = :entity");
      q.setParameter("entity", entity);
      entity = q.getSingleResult();
    }
    return entity;
  }