Example usage for org.hibernate.proxy HibernateProxy getHibernateLazyInitializer

List of usage examples for org.hibernate.proxy HibernateProxy getHibernateLazyInitializer

Introduction

In this page you can find the example usage for org.hibernate.proxy HibernateProxy getHibernateLazyInitializer.

Prototype

public LazyInitializer getHibernateLazyInitializer();

Source Link

Document

Get the underlying lazy initialization handler.

Usage

From source file:com.viettel.vsaadmin.database.DAOHibernate.UsersDAOHE.java

License:Open Source License

/**
 * tim kiem danh sach chuyen vien cua don vi
 *
 * @param deptId/*from  w  ww  .ja v  a2s  .  com*/
 * @param userId
 * @param pos
 * @param objectId
 * @param objectType
 * @return
 */
public List<Users> getStaffOfDept(Long userId, Long deptId, String pos, Long objectId, Long objectType) {
    List lstResult = new ArrayList<Users>();
    List listParam = new ArrayList();
    String sql = "";
    try {
        sql = "SELECT u FROM Users u WHERE u.status = ? and (u.deptId = ? or u.deptRepresentId = ?)";
        listParam.add(Constants.Status.ACTIVE);
        listParam.add(deptId);
        listParam.add(deptId);
        if (pos != null && "LEADER".equals(pos)) {
            sql += " and u.posId in (SELECT p.posId FROM Position p WHERE p.status = 1 and p.posType = 1 and p.posCode like ? )";
            listParam.add("%" + Constants.POSITION.LEADER_CODE + "%");

            //get user by role
            sql += " OR (u.userId in (" + " SELECT ru.userId FROM RoleUserDept ru WHERE ru.deptId = ?"
                    + " AND ru.roleId in (SELECT r.roleId FROM Roles r WHERE r.roleCode like ? escape '!' or r.roleCode like ? escape '!' )))";
            listParam.add(deptId);
            listParam.add("%" + Constants.ROLES.LEAD_ROLE + "%");
            listParam.add("%" + Constants.ROLES.LEAD_OFFICE_ROLE + "%");
        } else if (pos != null && "STAFF".equals(pos)) {
            sql += " and u.posId not in (SELECT p.posId FROM Position p WHERE p.status = 1 and p.posType = 1 and (p.posCode like ? or p.posCode like ?) )";
            listParam.add("%" + Constants.POSITION.LEAD_CODE + "%");
            listParam.add("%" + Constants.POSITION.LEAD_OFFICE_CODE + "%");

            //get user by role
            sql += " OR (u.userId in (" + " SELECT ru.userId FROM RoleUserDept ru WHERE ru.deptId = ?"
                    + " AND ru.roleId not in (SELECT r.roleId FROM Roles r WHERE r.roleCode like ? escape '!' or r.roleCode like ? escape '!' )))";
            listParam.add(deptId);
            listParam.add("%" + Constants.ROLES.LEAD_ROLE + "%");
            listParam.add("%" + Constants.ROLES.LEAD_OFFICE_ROLE + "%");
        } else {
            sql += "OR u.userId in (" + " SELECT ru.userId FROM RoleUserDept ru WHERE ru.deptId = ?)";
            listParam.add(deptId);
        }
        //            sql += " and u.userId <> ?";
        //            listParam.add(userId);
        //            sql += " and u.userId not in (SELECT pr.sendUserId FROM Process pr WHERE pr.isActive = 1 and pr.sendUserId is not null "
        //                    + " and pr.objectId = ? and pr.objectType = ? and pr.status <> 5)";
        //            listParam.add(objectId);
        //            listParam.add(objectType);
        //            sql += " and u.userId not in (SELECT pr.receiveUserId FROM Process pr WHERE pr.isActive = 1 and pr.receiveUserId is not null "
        //                    + " and pr.objectId = ? and pr.objectType = ? and pr.status <> 5)";
        //            listParam.add(objectId);
        //            listParam.add(objectType);
        Query query = getSession().createQuery(sql);
        for (int i = 0; i < listParam.size(); i++) {
            query.setParameter(i, listParam.get(i));
        }
        lstResult = query.list();
        if (lstResult != null && !lstResult.isEmpty()) {
            for (int i = 0; i < lstResult.size(); i++) {
                Users user = (Users) lstResult.get(i);
                if (user instanceof HibernateProxy) {
                    HibernateProxy proxy = (HibernateProxy) user;
                    Users newUser = (Users) proxy.getHibernateLazyInitializer().getImplementation();
                    lstResult.set(i, newUser);
                }
            }
        }
    } catch (Exception ex) {
        LogUtil.addLog(ex);//binhnt sonar a160901
        //            e.getMessage();
        return new ArrayList<Users>();
    }
    return lstResult;
}

From source file:cz.datalite.dao.support.JpaMetamodelEntityInformation.java

License:Apache License

/**
 * Befor reflection access we need to get originl object (not the proxy).
 * @param obj object or a proxy//from w  w w.ja  v  a 2  s  . c  om
 * @param <T> object type
 * @return the object
 */
public static <T> T deproxy(T obj) {
    if (obj == null)
        return obj;
    if (obj instanceof HibernateProxy) {
        // Unwrap Proxy;
        //      -- loading, if necessary.
        HibernateProxy proxy = (HibernateProxy) obj;
        LazyInitializer li = proxy.getHibernateLazyInitializer();
        return (T) li.getImplementation();
    }
    return obj;
}

From source file:cz.jirutka.commons.hibernate.HibernateUtils.java

License:Open Source License

/**
 * If the given object is a {@linkplain HibernateProxy proxy}, then return
 * the underlying persistent object (initializing if necessary). Otherwise
 * just return the given object.//w  w w.j av a2  s .c  o m
 *
 * @param entity persistent instance or its proxy object
 * @return persistent instance
 */
public static <E> E deproxy(E entity) {
    if (entity instanceof HibernateProxy) {
        HibernateProxy proxy = (HibernateProxy) entity;
        return (E) proxy.getHibernateLazyInitializer().getImplementation();
    } else {
        return entity;
    }
}

From source file:de.iew.framework.persistence.hibernate.HbmUtils.java

License:Apache License

/**
 * Prft fr das angegebene Modell ob es ein {@link HibernateProxy}
 * ist und liefert gegebenenfalls das reale Modell Objekt zurck.
 * <p>/*  w  w  w. j av a 2s.c  o m*/
 * Wenn das angegebene Modell kein {@link HibernateProxy} ist
 * dann wird das Objekt unverndert zurckgegeben.
 * </p>
 * <pre>
 * DataSource simpleTextDataProxy = someNode.getDataSource();
 * DataSource realSimpleTextData = HbmUtils.fromProxy(simpleTextDataProxy);
 * assertTrue(realSimpleTextData instanceof SimpleTextData);
 * </pre>
 *
 * @param model Das umzuwandelnde Modell.
 * @return Das umgewandelte Modell.
 */
public static AbstractModel fromProxy(AbstractModel model) {
    if (model instanceof HibernateProxy) {
        HibernateProxy hibernateProxy = (HibernateProxy) model;
        model = (AbstractModel) hibernateProxy.getHibernateLazyInitializer().getImplementation();
    }

    return model;
}

From source file:de.innovationgate.webgate.api.jdbc.WGDocumentImpl.java

License:Open Source License

public void makeEditable() throws WGAPIException {

    if (_editable == false) {
        if (_parent.getSessionStatus().isInSaveOperation()) { // Do not make editable if already in save operation
            return;
        }//from   w w  w. ja  v  a  2 s .  co m

        if (_parent._saveIsolationActive) {
            _entity.loadFully();
            if (_entity instanceof HibernateProxy) { // Unproxying because of #00002040
                HibernateProxy proxy = (HibernateProxy) _entity;
                LazyInitializer lazyInitializer = proxy.getHibernateLazyInitializer();
                if (lazyInitializer.isUninitialized()) {
                    lazyInitializer.initialize();
                }
                _entity = (MainEntity) lazyInitializer.getImplementation();
                _parent.getSession().evict(proxy);
            } else {

                _parent.getSession().evict(_entity);
            }

        }
        _editable = true;
    }

}

From source file:de.micromata.genome.db.jpa.history.impl.DbRecordPropertyConverter.java

License:Apache License

@Override
public List<HistProp> convert(IEmgr<?> emgr, HistoryMetaInfo historyMetaInfo, Object entity,
        ColumnMetadata pd) {//from w w w  .  j ava  2  s . c o  m
    Object val = pd.getGetter().get(entity);
    DbRecord<?> dbrec = (DbRecord<?>) val;
    Serializable pk = null;
    HistProp hp = new HistProp();
    hp.setName("");
    if (dbrec != null) {
        // to avoid lazy initialization problems, only evaluate the proxy.
        if (dbrec instanceof HibernateProxy) {
            HibernateProxy hibernateProxy = (HibernateProxy) dbrec;
            pk = hibernateProxy.getHibernateLazyInitializer().getIdentifier();
        } else {
            pk = dbrec.getPk();
        }
    }
    if (pk != null) {
        hp.setValue(pk.toString());
    }
    Class<?> clazz = pd.getJavaType();
    if (val != null) {
        clazz = val.getClass();
    }
    hp.setType(clazz.getName());
    return Collections.singletonList(hp);
}

From source file:de.micromata.genome.db.jpa.xmldump.impl.ProxyIdRefMarshaller.java

License:Apache License

/**
 * get the implementation behind object if it proxied, otherwise the object itself
 * // w  w w .j ava  2  s.  com
 * @param <T> the type of the Object
 * @param object an object, might facaded by HibernateProxy
 * @return the initialized object behind the proxy
 */
@SuppressWarnings("unchecked")
public static <T> T unbox(T object) {
    if (object instanceof HibernateProxy) {
        HibernateProxy proxy = (HibernateProxy) object;
        return (T) proxy.getHibernateLazyInitializer().getImplementation();
    }
    return object;
}

From source file:edu.wustl.common.util.dbManager.HibernateMetaData.java

License:BSD License

/**
 * This method will return domain object from proxy Object
 * @param domainObject//  w  ww.  jav a2s  .  c  om
 * @return domain Object
 */
public static Object getProxyObjectImpl(Object domainObject) {
    if (domainObject instanceof HibernateProxy) {
        HibernateProxy hp = (HibernateProxy) domainObject;
        Object obj = hp.getHibernateLazyInitializer().getImplementation();
        //Logger.out.debug(obj+" : obj");
        return (AbstractDomainObject) obj;
    }
    return domainObject;
}

From source file:edu.wustl.dao.util.HibernateMetaData.java

License:BSD License

/**
 * This method will return domain object from proxy Object.
 * @param domainObject :/*w  ww. j  a v  a  2  s.  c  o m*/
 * @return domain Object :
 */
public static Object getProxyObjectImpl(Object domainObject) {
    Object object = domainObject;
    if (domainObject instanceof HibernateProxy) {
        HibernateProxy hiberProxy = (HibernateProxy) domainObject;
        object = hiberProxy.getHibernateLazyInitializer().getImplementation();
    }
    return object;
}

From source file:gr.interamerican.bo2.impl.open.hibernate.adapters.DoUnproxy.java

License:Open Source License

public PersistentObject<?> execute(PersistentObject<?> a) {
    HibernateProxy proxy = (HibernateProxy) a;
    Object unproxied = proxy.getHibernateLazyInitializer().getImplementation();
    PoUtils.setDetachStrategy(unproxied, new HibernateDetachStrategy());
    return (PersistentObject<?>) unproxied;
}