Java 类org.hibernate.proxy.HibernateProxyHelper 实例源码

项目:oStorybook    文件:AbstractEntity.java   
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    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());
}
项目:SE-410-Project    文件:AbstractEntity.java   
@Override
public boolean equals(Object obj) {
    if (this == obj) {
        return true;
    }
    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());
}
项目:lams    文件:AnyType.java   
@Override
public String toLoggableString(Object value, SessionFactoryImplementor factory) throws HibernateException {
    //TODO: terrible implementation!
    return value == null
            ? "null"
            : factory.getTypeHelper()
            .entity( HibernateProxyHelper.getClassWithoutInitializingProxy( value ) )
            .toLoggableString( value, factory );
}
项目:cacheonix-core    文件:AnyType.java   
public String toLoggableString(Object value, SessionFactoryImplementor factory) 
throws HibernateException {
    //TODO: terrible implementation!
    return value==null ?
            "null" :
            Hibernate.entity( HibernateProxyHelper.getClassWithoutInitializingProxy(value) )
                    .toLoggableString(value, factory);
}
项目:webanno    文件:EntityModel.java   
private void analyze(T aObject)
{
    if (aObject != null) {
        entityClass = HibernateProxyHelper.getClassWithoutInitializingProxy(aObject);

        String idProperty = null;
        Metamodel metamodel = getEntityManager().getMetamodel();
        EntityType entity = metamodel.entity(entityClass);
        Set<SingularAttribute> singularAttributes = entity.getSingularAttributes();
        for (SingularAttribute singularAttribute : singularAttributes) {
            if (singularAttribute.isId()) {
                idProperty = singularAttribute.getName();
                break;
            }
        }
        if (idProperty == null) {
            throw new RuntimeException("id field not found");
        }

        DirectFieldAccessor accessor = new DirectFieldAccessor(aObject);
        id = (Number) accessor.getPropertyValue(idProperty);
    }
    else {
        entityClass = null;
        id = null;
    }
}
项目:lams    文件:AbstractQueryImpl.java   
private Type guessType(Object param) throws HibernateException {
    Class clazz = HibernateProxyHelper.getClassWithoutInitializingProxy( param );
    return guessType( clazz );
}
项目:cacheonix-core    文件:AbstractQueryImpl.java   
private Type guessType(Object param) throws HibernateException {
    Class clazz = HibernateProxyHelper.getClassWithoutInitializingProxy( param );
    return guessType( clazz );
}
项目:screensaver    文件:AbstractEntity.java   
@SuppressWarnings("unchecked")
@Transient
final public Class<Entity<K>> getEntityClass()
{
  return HibernateProxyHelper.getClassWithoutInitializingProxy(this);
}
项目:projectforge-webapp    文件:HibernateXmlConverter.java   
/**
 * @param writer
 * @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 für 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< ? >>();
  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("de.micromata.hibernate.history.") == 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 gelöscht werden
        classMetadata.setIdentifier(obj, null, 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));
    }
项目:query-utils    文件:HibernateTypeProvider.java   
@Override
public Class<?> getEntityClass(IEntity<?> entity) {
    return HibernateProxyHelper.getClassWithoutInitializingProxy(entity);
}
项目:oscm    文件:DomainObject.java   
/**
 * Returns the domain class of this entity (e.g. Subscription.class).
 * WARNING: Never use the method entity.getClass(), because JPA might create
 * dynamic proxy classes during runtime (byte code injection). Always, use
 * this method instead.
 */
public static Class<?> getDomainClass(Object entityOrProxy) {
    return HibernateProxyHelper
            .getClassWithoutInitializingProxy(entityOrProxy);
}
项目:development    文件:DomainObject.java   
/**
 * Returns the domain class of this entity (e.g. Subscription.class).
 * WARNING: Never use the method entity.getClass(), because JPA might create
 * dynamic proxy classes during runtime (byte code injection). Always, use
 * this method instead.
 */
public static Class<?> getDomainClass(Object entityOrProxy) {
    return HibernateProxyHelper
            .getClassWithoutInitializingProxy(entityOrProxy);
}