Ejemplo n.º 1
0
 public String toLoggableString(Object value, SessionFactoryImplementor factory)
     throws HibernateException {
   // TODO: terrible implementation!
   return value == null
       ? "null"
       : Hibernate.entity(HibernateProxyHelper.getClassWithoutInitializingProxy(value))
           .toLoggableString(value, factory);
 }
  /**
   * @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
    List<?> list = session.createQuery("select o from java.lang.Object 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);
      }
      if ((obj instanceof HistoryEntry || obj instanceof PropertyDelta)
          && includeHistory == false) {
        continue;
      }
      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));
  }
Ejemplo n.º 3
0
 /**
  * Return <code>true</code> if <code>other</code> is the same Group as this object, <code>false
  * </code> otherwise
  *
  * @param obj object to compare to
  * @return <code>true</code> if object passed in represents the same group as this object
  */
 @Override
 public boolean equals(Object obj) {
   if (obj == null) {
     return false;
   }
   Class<?> objClass = HibernateProxyHelper.getClassWithoutInitializingProxy(obj);
   if (getClass() != objClass) {
     return false;
   }
   final Group other = (Group) obj;
   return this.getID().equals(other.getID());
 }
Ejemplo n.º 4
0
  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    Class<?> objClass = HibernateProxyHelper.getClassWithoutInitializingProxy(o);
    if (getClass() != objClass) {
      return false;
    }

    final Version that = (Version) o;
    if (this.getID() != that.getID()) {
      return false;
    }

    return true;
  }