コード例 #1
0
 private void registerObject(final Object obj) {
   if (obj == null) {
     return;
   }
   if (HibernateUtils.isEntity(obj.getClass()) == false) {
     return;
   }
   if (this.ignoreFromSaving.contains(obj.getClass()) == true) {
     // Don't need this objects as "top level" objects in list. They're usually encapsulated.
     return;
   }
   List<Object> list = this.allObjects.get(obj.getClass());
   if (list == null) {
     list = new ArrayList<Object>();
     this.allObjects.put(obj.getClass(), list);
   }
   list.add(obj);
 }
コード例 #2
0
 private void save(final Class<?> type) {
   if (ignoreFromSaving.contains(type) == true || writtenObjectTypes.contains(type) == true) {
     // Already written.
     return;
   }
   writtenObjectTypes.add(type);
   // Persistente Klasse?
   if (HibernateUtils.isEntity(type) == false) {
     return;
   }
   if (log.isDebugEnabled() == true) {
     log.debug("Writing objects from type: " + type);
   }
   final List<Object> list = allObjects.get(type);
   if (list == null) {
     return;
   }
   for (final Object obj : list) {
     if (obj == null || writtenObjects.contains(obj) == true) {
       // Object null or already written. Skip this item.
       continue;
     }
     if (session.contains(obj) == true) {
       continue;
     }
     try {
       if (log.isDebugEnabled()) {
         log.debug("Try to write object " + obj);
       }
       Serializable id = onBeforeSave(session, obj);
       if (id == null) {
         id = save(obj);
       }
       onAfterSave(obj, id);
       if (log.isDebugEnabled() == true) {
         log.debug("wrote object " + obj + " under id " + id);
       }
     } catch (final HibernateException ex) {
       log.fatal("Failed to write " + obj + " ex=" + ex, ex);
     } catch (final NullPointerException ex) {
       log.fatal("Failed to write " + obj + " ex=" + ex, ex);
     }
   }
 }