Example usage for org.hibernate.proxy HibernateProxyHelper getClassWithoutInitializingProxy

List of usage examples for org.hibernate.proxy HibernateProxyHelper getClassWithoutInitializingProxy

Introduction

In this page you can find the example usage for org.hibernate.proxy HibernateProxyHelper getClassWithoutInitializingProxy.

Prototype

public static Class getClassWithoutInitializingProxy(Object object) 

Source Link

Document

Get the class of an instance or the underlying class of a proxy (without initializing the proxy!).

Usage

From source file:org.jboss.tools.hibernate3_5.console.ConsoleExtension3_5.java

License:Open Source License

private boolean hasMetaData(Object object, Session currentSession) {
    return currentSession.getSessionFactory()
            .getClassMetadata(HibernateProxyHelper.getClassWithoutInitializingProxy(object)) != null;
}

From source file:org.jboss.tools.hibernate3_5.console.EntityPropertySource.java

License:Open Source License

public EntityPropertySource(final Object object, final Session currentSession, HibernateExtension extension) {
    this.currentSession = currentSession;
    this.extension = extension;
    reflectedObject = object;/* w ww . j a  v a2 s .co  m*/
    if (currentSession.isOpen()) {
        classMetadata = currentSession.getSessionFactory()
                .getClassMetadata(currentSession.getEntityName(reflectedObject));
    } else {
        classMetadata = currentSession.getSessionFactory()
                .getClassMetadata(HibernateProxyHelper.getClassWithoutInitializingProxy(reflectedObject));
    }

}

From source file:org.mzd.shap.hibernate.search.view.ReportBuilder.java

License:Open Source License

protected static String getShortClassName(Object obj) {
    return HibernateProxyHelper.getClassWithoutInitializingProxy(obj).getSimpleName();
}

From source file:org.mzd.shap.hibernate.search.view.ReportBuilderFactory.java

License:Open Source License

/**
 * Build a report from a target object. 
 * <p>// w w w.ja  v  a  2  s  .  c o  m
 * The method looks up the associated builder from the registry and then invokes its build method on
 * the same target object to produce a report.
 * 
 * @param score
 * @param targetObject
 * 
 * @return report for targetObject
 * @throws InstantiationException
 * @throws IllegalAccessException
 */
public Report buildReport(Float score, Object targetObject) {
    String className = HibernateProxyHelper.getClassWithoutInitializingProxy(targetObject).getName();

    return getBuilder(className).build(score, targetObject);
}

From source file:org.projectforge.framework.persistence.xstream.HibernateXmlConverter.java

License:Open Source License

/**
 * @param writer/* w w  w  .  j av a 2  s.  co m*/
 * @param includeHistory
 * @param session
 * @throws DataAccessException
 * @throws HibernateException
 */
private void writeObjects(final Writer writer, final boolean includeHistory, final Session session,
        final boolean preserveIds) throws DataAccessException, HibernateException {
    // Container fr die Objekte
    final List<Object> all = new ArrayList<Object>();
    final XStream stream = initXStream(session, true);
    final XStream defaultXStream = initXStream(session, false);

    session.flush();
    // Alles laden
    //    final List<Class<?>> entities = new ArrayList<Class<?>>();
    final List<Class<?>> entities = PfEmgrFactory.get().getMetadataRepository().getTableEntities().stream()
            .map((e) -> e.getJavaType()).collect(Collectors.toList());
    //    entities.addAll(HibernateEntities.instance().getOrderedEntities());
    //    entities.addAll(HibernateEntities.instance().getOrderedHistoryEntities());
    for (final Class<?> entityClass : entities) {
        final String entitySimpleName = entityClass.getSimpleName();
        final String entityType = entityClass.getName();

        if (includeHistory == false
                && entityType.startsWith("org.projectforge.framework.persistence.history.entities.") == true) {
            // Skip history entries.
            continue;
        }
        List<?> list = session.createQuery("select o from " + entityType + " o").setReadOnly(true).list();
        list = (List<?>) CollectionUtils.select(list, PredicateUtils.uniquePredicate());
        final int size = list.size();
        log.info("Writing " + size + " objects");
        for (final Iterator<?> it = list.iterator(); it.hasNext();) {
            final Object obj = it.next();
            if (log.isDebugEnabled()) {
                log.debug("loaded object " + obj);
            }
            Hibernate.initialize(obj);
            final Class<?> targetClass = HibernateProxyHelper.getClassWithoutInitializingProxy(obj);
            final ClassMetadata classMetadata = session.getSessionFactory().getClassMetadata(targetClass);
            if (classMetadata == null) {
                log.fatal("Can't init " + obj + " of type " + targetClass);
                continue;
            }
            // initalisierung des Objekts...
            defaultXStream.marshal(obj, new CompactWriter(new NullWriter()));

            if (preserveIds == false) {
                // Nun kann die ID gelscht werden
                HibernateCompatUtils.setClassMetaDataSetIdentifier(classMetadata, obj, EntityMode.POJO);
            }
            if (log.isDebugEnabled()) {
                log.debug("loading evicted object " + obj);
            }
            if (this.ignoreFromTopLevelListing.contains(targetClass) == false) {
                all.add(obj);
            }
        }
    }
    // und schreiben
    try {
        writer.write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n");
    } catch (final IOException ex) {
        // ignore, will fail on stream.marshal()
    }
    log.info("Wrote " + all.size() + " objects");
    final MarshallingStrategy marshallingStrategy = new ProxyIdRefMarshallingStrategy();
    stream.setMarshallingStrategy(marshallingStrategy);
    stream.marshal(all, new PrettyPrintWriter(writer));
}

From source file:org.riotfamily.common.hibernate.AnyIdAnyType.java

License:Apache License

public String toLoggableString(Object value, SessionFactoryImplementor factory) throws HibernateException {
    //TODO: terrible implementation!
    return value == null ? "null"
            : Hibernate.entity(HibernateProxyHelper.getClassWithoutInitializingProxy(value))
                    .toLoggableString(value, factory);
}

From source file:org.wise.portal.service.acl.impl.AclServiceImpl.java

License:Open Source License

public List<Permission> getPermissions(T object, User user) {
    List<Permission> permissions = new ArrayList<Permission>();
    if (object != null) {
        MutableAcl acl = null;/*w  w  w .j a v a 2  s  .c  o m*/
        ObjectIdentity objectIdentity = new ObjectIdentityImpl(
                HibernateProxyHelper.getClassWithoutInitializingProxy(object), object.getId());
        List<Sid> sid = new ArrayList<Sid>();
        sid.add(new PrincipalSid(user.getUserDetails().getUsername()));

        try {
            acl = (MutableAcl) mutableAclService.readAclById(objectIdentity, sid);
        } catch (NotFoundException nfe) {
            return permissions;
        }
        List<AccessControlEntry> aces = acl.getEntries();
        for (AccessControlEntry ace : aces) {
            if (ace.getSid().equals(sid.get(0))) {
                permissions.add(ace.getPermission());
            }
        }
        return permissions;
    } else {
        throw new IllegalArgumentException("Cannot retrieve ACL. Object not set.");
    }
}

From source file:org.wise.portal.service.acl.impl.AclServiceImpl.java

License:Open Source License

public List<Permission> getPermissions(T object, UserDetails userDetails) {
    List<Permission> permissions = new ArrayList<Permission>();
    if (object != null) {
        MutableAcl acl = null;//from   ww w.  ja  v  a 2 s .c o  m

        ObjectIdentity objectIdentity = new ObjectIdentityImpl(
                HibernateProxyHelper.getClassWithoutInitializingProxy(object), object.getId());
        List<Sid> sid = new ArrayList<Sid>();
        sid.add(new PrincipalSid(userDetails.getUsername()));

        try {
            acl = (MutableAcl) mutableAclService.readAclById(objectIdentity, sid);
        } catch (NotFoundException nfe) {
            return permissions;
        }
        List<AccessControlEntry> aces = acl.getEntries();
        for (AccessControlEntry ace : aces) {
            if (ace.getSid().equals(sid.get(0))) {
                permissions.add(ace.getPermission());
            }
        }
        return permissions;
    } else {
        throw new IllegalArgumentException("Cannot retrieve ACL. Object not set.");
    }
}

From source file:storybook.model.entity.AbstractEntity.java

License:Open Source License

@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }//from   ww  w.  j a  va  2s  . c  o  m
    if (obj == null) {
        return false;
    }
    // hibernate object may have class names like Person_$$_javassist_11
    Class<?> cl1 = HibernateProxyHelper.getClassWithoutInitializingProxy(this);
    Class<?> cl2 = HibernateProxyHelper.getClassWithoutInitializingProxy(obj);
    if (cl1 != cl2) {
        return false;
    }
    AbstractEntity test = (AbstractEntity) obj;
    // for test use getter here since hibernate may need to load it first
    if (isTransient()) {
        return transientId.equals(test.getTransientId());
    }
    return id.equals(test.getId());
}

From source file:ubic.gemma.model.expression.experiment.ExpressionExperiment.java

License:Apache License

@SuppressWarnings("EqualsWhichDoesntCheckParameterClass") // It does check, just not the classic way.
@Override/*from   w ww. j av  a 2 s . co  m*/
public boolean equals(Object object) {
    if (object == null)
        return false;
    Class<?> thisClass = HibernateProxyHelper.getClassWithoutInitializingProxy(this);
    Class<?> thatClass = HibernateProxyHelper.getClassWithoutInitializingProxy(object);
    if (!thisClass.equals(thatClass))
        return false;

    ExpressionExperiment that = (ExpressionExperiment) object;
    if (this.getId() != null && that.getId() != null) {
        return this.getId().equals(that.getId());
    } else if (this.getShortName() != null && that.getShortName() != null) {
        return this.getShortName().equals(that.getShortName());
    }
    return false;
}