Example usage for org.hibernate Hibernate isInitialized

List of usage examples for org.hibernate Hibernate isInitialized

Introduction

In this page you can find the example usage for org.hibernate Hibernate isInitialized.

Prototype

@SuppressWarnings("SimplifiableIfStatement")
public static boolean isInitialized(Object proxy) 

Source Link

Document

Check if the proxy or persistent collection is initialized.

Usage

From source file:com.yunguchang.model.EntityConvert.java

public static User fromEntityWithRoles(TRsDriverinfoEntity driverEntity) {
    if (driverEntity == null) {
        return null;
    }/*  ww w  . j  ava2  s.c om*/
    if (!Hibernate.isInitialized(driverEntity)) {
        Hibernate.initialize(driverEntity);
    }

    User user = new User(User.UserType.DRIVER);
    user.setUserId(driverEntity.getUuid());
    String name = driverEntity.getDrivername().trim();
    user.setUserName(name);
    user.setMobile(driverEntity.getMobile());
    user.setEid(driverEntity.getUuid());
    List<String> roles = new ArrayList<>();
    roles.add(Roles.DRIVER);
    user.setRoles(roles.toArray(new String[] {}));
    return user;
}

From source file:com.yunguchang.model.EntityConvert.java

public static SyncResult fromEntity(TSyncDataStatusEntity entity) {
    if (entity == null) {
        return null;
    }/*from   www. j  a v a  2s . com*/
    if (!Hibernate.isInitialized(entity)) {
        Hibernate.initialize(entity);
    }
    SyncResult result = new SyncResult();
    result.setResult("!!!" + entity.getUuid() + "#@" + (entity.getState().equals("1") ? true : false));
    return result;
}

From source file:cz.zcu.kiv.eegdatabase.data.dao.SimpleGenericDao.java

License:Apache License

protected void initializeProperty(Object property) {
    if (!Hibernate.isInitialized(property)) {
        getHibernateTemplate().initialize(property);
    }
}

From source file:edu.harvard.med.screensaver.db.ProxyInitializationTest.java

License:Open Source License

public void testInitializeExtantProxy() {
    TestTxn txn = new TestTxn();

    txn._cpr = genericEntityDao/*from w  w w  .j av  a  2s  .c  o  m*/
            .findAllEntitiesOfType(CherryPickRequest.class, true, CherryPickRequest.requestedBy).get(0);
    log.info("pre-txn cpr requestedBy initialized: " + Hibernate.isInitialized(txn._cpr.getRequestedBy()));
    log.info("pre-txn cpr requestedBy: " + txn._cpr.getRequestedBy().getClass() + " "
            + txn._cpr.getRequestedBy().getEntityId());
    genericEntityDao.doInTransaction(txn);

    //    log.info("post txn screening.screen.leadScreener=" + txn._screening.getScreen().getLeadScreener().getClass() + " " +
    //      txn._screening.getScreen().getLeadScreener());

    //txn._cpr.getRequestedBy().getLastName();
    //    txn._screen.getLeadScreener().getScreensaverUserId();
    //txn._screen.getLeadScreener().getEntityId();
}

From source file:edu.ku.brc.specify.treeutils.HibernateTreeDataServiceImpl.java

License:Open Source License

public synchronized Set<T> getChildNodes(final T parent) {
    if (Hibernate.isInitialized(parent.getChildren())) {
        return parent.getChildren();
    }// w  w  w.ja va  2  s  .  co  m

    Set<T> children = null;
    Session session = getNewSession(parent);
    try {
        children = parent.getChildren();
        // to force Set loading
        //int childCount = children.size();
        //log.debug("getChildNodes( " + parent + " ): " + childCount + " child(ren) of " + parent.getName() + " loaded");
        for (@SuppressWarnings("unused")
        T child : children) {
            //log.debug("\t" + nodeDebugInfo(child));
        }
    } catch (Exception ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(HibernateTreeDataServiceImpl.class, ex);
        log.error(ex);

    } finally {
        session.close();
    }
    return children;
}

From source file:es.caib.seycon.ng.model.RolAccountEntityDaoImpl.java

public void remove(es.caib.seycon.ng.model.RolAccountEntity rolsUsuaris) throws RuntimeException {
    try {/* w  w w . j a v  a 2 s .c  o  m*/
        RolAccount rolsUsuarisVO = toRolAccount(rolsUsuaris);
        ValorDomini valorDomini = rolsUsuarisVO.getValorDomini();

        String codiAplicacio = null;
        codiAplicacio = rolsUsuarisVO.getCodiAplicacio();

        String nomDomini = null;
        String valorDominiString = null;
        if (valorDomini != null) {
            nomDomini = valorDomini.getNomDomini();
            if (valorDomini.getValor() != null) {
                valorDominiString = valorDomini.getValor();
            }
        }

        // HERNCIA DE ROLS
        // Cerquem els rols que contenen (tenen atorgat) aquest rol per
        // propagar-los
        Collection rolsPropagar = getRolsContingutsPerPropagar(rolsUsuaris.getRol());
        // I si tenim cap... els propaguem
        if (rolsPropagar != null)
            propagarRols(rolsPropagar);

        // Enviem les notificacions de l'aplicaci (si estan activades)
        if (rolsUsuaris.getRol().getAplicacio() != null) {
            AplicacioEntity aplic = rolsUsuaris.getRol().getAplicacio();
            String correusNotificacio = aplic.getCorreusNotificacions();
            if (correusNotificacio != null) {
                String correus[] = correusNotificacio.split(","); //$NON-NLS-1$
                if (correus.length > 0) {
                    for (UserAccountEntity usu : rolsUsuaris.getAccount().getUsers()) {
                        // Hay que notificar: Creamos la notificacin
                        String informacio = Messages.getString("RolsUsuarisEntityDaoImpl.5"); //$NON-NLS-1$
                        // Creem l'instncia de la notificaci
                        NotificacioEntity notif = getNotificacioEntityDao().newNotificacioEntity();
                        notif.setAplicacio(aplic);
                        notif.setDataModificacio(new Date());
                        notif.setInformacio(informacio);
                        notif.setRol(rolsUsuaris.getRol());
                        notif.setUsuari(usu.getUser());
                        getNotificacioEntityDao().create(notif);
                    }
                }
            }
        }

        if (Hibernate.isInitialized(rolsUsuaris.getAccount())
                && Hibernate.isInitialized(rolsUsuaris.getAccount().getRoles())) {
            rolsUsuaris.getAccount().getRoles().remove(rolsUsuaris);
        }

        generateTasks(rolsUsuaris);

        super.remove(rolsUsuaris);

        auditarRolAccount("D", rolsUsuaris); //$NON-NLS-1$
    } catch (Throwable e) {
        String message = ExceptionTranslator.translate(e);
        throw new SeyconException(
                String.format(Messages.getString("RolsUsuarisEntityDaoImpl.6"), rolsUsuaris.getRol().getNom(), //$NON-NLS-1$
                        rolsUsuaris.getAccount().getName(), message));
    }
}

From source file:es.caib.seycon.ng.model.UsuariGrupEntityDaoImpl.java

public void remove(es.caib.seycon.ng.model.UsuariGrupEntity usuariGrup) throws RuntimeException {
    try {/*  ww  w  . java2  s .c  o  m*/
        if (usuariGrup.getUsuari().getCodi().equals(Security.getCurrentUser())) {
            throw new SeyconException(Messages.getString("UsuariGrupEntityDaoImpl.6")); //$NON-NLS-1$
        }

        super.remove(usuariGrup);
        getSession(false).flush();

        if (Hibernate.isInitialized(usuariGrup.getUsuari())
                && Hibernate.isInitialized(usuariGrup.getUsuari().getGrupsSecundaris())) {
            usuariGrup.getUsuari().getGrupsSecundaris().remove(usuariGrup);
        }

        if (Hibernate.isInitialized(usuariGrup.getGrup())
                && Hibernate.isInitialized(usuariGrup.getGrup().getUsuarisGrupSecundari())) {
            usuariGrup.getGrup().getUsuarisGrupSecundari().remove(usuariGrup);
        }

        String codiUsuari = usuariGrup.getUsuari().getCodi();
        String codiGrup = usuariGrup.getGrup().getCodi();
        TasqueEntity tasque = getTasqueEntityDao().newTasqueEntity();
        tasque.setData(new Timestamp(System.currentTimeMillis()));
        tasque.setTransa(TaskHandler.UPDATE_USER);
        tasque.setUsuari(usuariGrup.getUsuari().getCodi());
        getTasqueEntityDao().create(tasque);
        tasque = getTasqueEntityDao().newTasqueEntity();
        tasque.setData(new Timestamp(System.currentTimeMillis()));
        tasque.setTransa(TaskHandler.UPDATE_GROUP);
        tasque.setGrup(usuariGrup.getGrup().getCodi());
        getTasqueEntityDao().create(tasque);

        // Herencia de Roles: propagamos los roles heredados por el grupo (y
        // sus subgrupos)
        HashSet rolsAPropagar = new HashSet();
        Collection rolsAtorgatsGrupISubgrups = getRolsAtorgatsGrupIParesGrup(usuariGrup.getGrup());
        if (rolsAtorgatsGrupISubgrups != null)
            rolsAPropagar.addAll(rolsAtorgatsGrupISubgrups);
        // Propagamos los roles: (creamos las tareas)
        propagarRolsAtorgatsGrups(rolsAPropagar);

        getSession(false).flush();
        auditarUsuariGrup("D", codiUsuari, codiGrup); //$NON-NLS-1$
    } catch (Throwable e) {
        String message = ExceptionTranslator.translate(e);
        throw new SeyconException(String.format(Messages.getString("UsuariGrupEntityDaoImpl.7"), //$NON-NLS-1$
                usuariGrup.getUsuari().getCodi(), usuariGrup.getGrup().getCodi(), message));
    }
}

From source file:gov.nih.nci.system.client.proxy.ProxyHelperImpl.java

License:BSD License

public boolean isInitialized(MethodInvocation invocation) throws Throwable {
    Object retVal = invocation.proceed();
    return Hibernate.isInitialized(retVal);
}

From source file:gov.nih.nci.system.client.util.xml.BaseCastorFieldHandler.java

License:BSD License

private static Object convertObject(Object obj, Class klass, boolean getAssociations) throws Exception {

    Object convertedObject = klass.newInstance();

    Method[] methods = klass.getMethods();
    for (Method method : methods) {
        if (method.getName().startsWith("get") && !method.getName().equals("getClass")) {
            try {
                Method setterMethod = convertedObject.getClass()
                        .getMethod("set" + method.getName().substring(3), method.getReturnType());
                Object value = null;
                Class type = setterMethod.getParameterTypes()[0];
                if (getAssociations
                        || ((!type.getName().equals("java.util.Collection"))
                                && (type.getName().startsWith("java")))
                        || type.isPrimitive() || type.getName().startsWith("gov.nih.nci.iso21090."))
                    value = method.invoke(obj, (Object[]) null);

                if (!Hibernate.isInitialized(value)) {
                    value = null;//w  w  w .j a  va2s  .com
                } else {
                    if (value != null) {

                        if (value instanceof ListProxy) {
                            value = convertListProxy(value);
                        } else {
                            String className = value.getClass().getName();
                            if (className.indexOf('$') > 0) {
                                boolean includeAssociations = false;
                                value = convertObject(value, includeAssociations);
                            }
                        }
                    }
                }

                Object[] parameters = new Object[1];
                parameters[0] = value;

                setterMethod.invoke(convertedObject, (Object[]) parameters);
            } catch (NoSuchMethodException e) {
                //ignore - E.g., Strings have getChars(), getBytes() methods with no corresponding Setters
            } catch (Exception e) {
                log.error("Exception caught trying to convert proxy object to domain object for method "
                        + method.getName(), e);
            }
        }
    }

    return convertedObject;
}

From source file:gr.abiss.calipso.wicket.UserViewPanel.java

License:Open Source License

private void init(IBreadCrumbModel breadCrumbModel, final User user) {
    if (user == null) {
        logger.error("No user was provided");
    }//from  www .j a  v  a  2 s  .  c  o m
    final List<Space> userSpaces;
    if (Hibernate.isInitialized(user.getSpaces())) {
        userSpaces = new ArrayList<Space>(user.getSpaces());
    } else {// TODO: hql query
        userSpaces = new ArrayList<Space>(user.getSpaces());
    }
    final User currentUser = getPrincipal();

    WebMarkupContainer editContainer = new WebMarkupContainer("editContainer");
    editContainer.add(new BreadCrumbLink("edit", breadCrumbModel) {
        @Override
        protected IBreadCrumbParticipant getParticipant(String componentId) {
            return new UserFormPanel(componentId, getBreadCrumbModel(), user);
        }
    });
    add(editContainer.setVisible(false));

    if (currentUser.isGlobalAdmin()) {//if isAdmin
        editContainer.setVisible(true);
    } else if (currentUser.isSpaceAdmin()) {//if isSpaceAdmin
        //check if current user can edit this user
        //code from UserListPanel
        if (!user.isGlobalAdmin()) {
            for (Space us : userSpaces) {
                if (currentUser.getSpacesWhereUserIsAdmin().contains(us)) {
                    editContainer.setVisible(true);
                    break;
                }
            }
        }
    }

    add(new UserIconPanel("userIcon", user));
    add(new Label("loginName", user.getLoginName()));
    add(new Label("name", user.getName()));
    add(new Label("lastname", user.getLastname()));
    add(new Label("email", user.getEmail()));
    Country c = user.getCountry();
    add(new Label("country", c != null ? localize(c) : ""));
    add(new OrganizationViewLink("organization", breadCrumbModel, user.getOrganization()));
    add(new Label("address", user.getAddress()));
    add(new Label("phone", user.getPhone()));

    LoadableDetachableModel sharedSpacesListModel = new LoadableDetachableModel() {
        protected Object load() {
            List<Space> sharedSpacesList = new ArrayList<Space>();

            //get spaces for current user
            Set<Space> currentUserSpaces = currentUser.getSpaces();

            //find shared spaces
            for (Space currentUserSpace : currentUserSpaces) {
                if (userSpaces.contains(currentUserSpace)) {//if this space is shared for the 2 users
                    sharedSpacesList.add(currentUserSpace);
                }
            }
            return sharedSpacesList;
        }
    };

    if (CollectionUtils.isNotEmpty((List) sharedSpacesListModel.getObject())) {

        logger.debug("user has spaces");
        if (user.getLoginName().equals(getPrincipal().getLoginName())) {
            add(new Label("sharedSpaces", localize("UserViewPanel.yourSpaces")));
        } else {
            add(new Label("sharedSpaces", localize("UserViewPanel.yourSpaces", user.getName())));
        }
    } else {
        logger.debug("user has no spaces");
        add(new Label("sharedSpaces", ""));
    }
    final SimpleAttributeModifier sam = new SimpleAttributeModifier("class", "alt");

    ListView listView = new ListView("spaces", sharedSpacesListModel) {
        protected void populateItem(ListItem listItem) {
            final Space spaceItem = (Space) listItem.getModelObject();

            if (listItem.getIndex() % 2 == 1) {
                listItem.add(sam);
            }

            listItem.add(new Link("space") {
                @Override
                public void onClick() {
                    setCurrentSpace(spaceItem);
                    setResponsePage(SpacePage.class);
                }
            }.add(new Label("space", localize(spaceItem.getNameTranslationResourceKey()))));

        }
    };

    add(listView);

}