Java Code Examples for org.hibernate.Hibernate#isInitialized()

The following examples show how to use org.hibernate.Hibernate#isInitialized() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StatefulPersistenceContext.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
private boolean isFoundInParent(
		String property, 
		Object childEntity, 
		EntityPersister persister, 
		CollectionPersister collectionPersister,
		Object potentialParent
) {
	Object collection = persister.getPropertyValue( 
			potentialParent, 
			property, 
			session.getEntityMode() 
		);
	return collection!=null && Hibernate.isInitialized(collection) &&
			collectionPersister.getCollectionType()
					.contains(collection, childEntity, session);
}
 
Example 2
Source File: TaskDOConverter.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
public static TaskObject getTaskObject(TaskDO taskDO)
{
  if (taskDO == null) {
    return null;
  }
  if (Hibernate.isInitialized(taskDO) == false) {
    final Integer taskId = taskDO.getId();
    taskDO = Registry.instance().getTaskTree().getTaskById(taskId);
    if (taskDO == null) {
      log.error("Oups, task with id '" + taskId + "' not found.");
      return null;
    }
  }
  final TaskObject task = new TaskObject();
  DOConverter.copyFields(task, taskDO);
  task.setParentTaskId(taskDO.getParentTaskId());
  task.setDescription(taskDO.getDescription());
  task.setReference(taskDO.getReference());
  task.setTitle(taskDO.getTitle());
  task.setShortDescription(taskDO.getShortDescription());
  task.setMaxHours(taskDO.getMaxHours());
  task.setPriority(taskDO.getPriority());
  task.setStatus(taskDO.getStatus());
  return task;
}
 
Example 3
Source File: HibernateUtils.java    From projectforge-webapp with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Workaround for: http://opensource.atlassian.com/projects/hibernate/browse/HHH-3502:
 * @param obj
 * @return
 */
public static Serializable getIdentifier(final BaseDO< ? > obj)
{
  if (Hibernate.isInitialized(obj) == true) {
    return ((BaseDO< ? >) obj).getId();
  } else if (obj instanceof DefaultBaseDO) {
    return ((DefaultBaseDO) obj).getId();
  } else if (obj instanceof AccessEntryDO) {
    return ((AccessEntryDO) obj).getId();
  } else if (obj instanceof Kost2ArtDO) {
    return ((Kost2ArtDO) obj).getId();
  } else if (obj instanceof KundeDO) {
    return ((KundeDO) obj).getId();
  } else if (obj instanceof UserPrefEntryDO) {
    return ((UserPrefEntryDO) obj).getId();
  }
  log.error("Couldn't get the identifier of the given object (Jassist/Hibernate-Bug: HHH-3502) for class: " + obj.getClass().getName());
  return null;
}
 
Example 4
Source File: Location.java    From unitime with Apache License 2.0 5 votes vote down vote up
@Deprecated
  public String getHtmlHint(String preference) {
try {
	if (!Hibernate.isPropertyInitialized(this, "roomType") || !Hibernate.isInitialized(getRoomType())) {
		return LocationDAO.getInstance().get(getUniqueId()).getHtmlHintImpl(preference);
	} else {
		return getHtmlHintImpl(preference);
	}
} catch (LazyInitializationException e) {
	return LocationDAO.getInstance().get(getUniqueId()).getHtmlHintImpl(preference);
}
  }
 
Example 5
Source File: PFUserDOConverter.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
public static UserObject getUserObject(PFUserDO userDO)
{
  if (userDO == null) {
    return null;
  }
  if (Hibernate.isInitialized(userDO) == false) {
    final Integer userId = userDO.getId();
    userDO = Registry.instance().getUserGroupCache().getUser(userDO.getId());
    if (userDO == null) {
      log.error("Oups, user with id '" + userId + "' not found.");
      return null;
    }
  }
  final UserObject user = new UserObject();
  DOConverter.copyFields(user, userDO);
  user.setUsername(userDO.getUsername());
  user.setFirstName(userDO.getFirstname());
  user.setLastName(userDO.getLastname());
  user.setEmail(userDO.getEmail());
  TimeZone timeZone = userDO.getTimeZoneObject();
  if (timeZone == null) {
    timeZone = Configuration.getInstance().getDefaultTimeZone();
  }
  if (timeZone != null) {
    user.setTimeZone(timeZone.getID());
  }
  Locale locale = userDO.getLocale();
  if (locale == null) {
    locale = ConfigXml.getInstance().getDefaultLocale();
  }
  if (locale == null) {
    locale = Locale.getDefault();
  }
  if (locale != null) {
    user.setLocale(locale.toString());
  }
  return user;
}
 
Example 6
Source File: LayerDetailsDAOImpl.java    From geofence with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Set<String> getAllowedStyles(Long id) {
    LayerDetails found = find(id);
    if ( found != null ) {
        Set<String> styles = found.getAllowedStyles();

        if ( (styles != null) && !Hibernate.isInitialized(styles) ) {
            Hibernate.initialize(styles); // fetch the props
        }

        return styles;
    } else {
        throw new IllegalArgumentException("LayerDetails not found");
    }
}
 
Example 7
Source File: DistributionPref.java    From unitime with Apache License 2.0 5 votes vote down vote up
/**
 * @param aClass
 * @return
 */
public boolean appliesTo(Class_ aClass) {
	if (this.getDistributionObjects()==null) return false;
	Iterator it = null;
	try {
		it = getDistributionObjects().iterator();
	} catch (ObjectNotFoundException e) {
		Debug.error("Exception "+e.getMessage()+" seen for "+this);
   		new _RootDAO().getSession().refresh(this);
  			it = getDistributionObjects().iterator();
	}
	while (it.hasNext()) {
		DistributionObject dObj = (DistributionObject) it.next();
		
		//Class_ check
		//no checking whether dObj.getPrefGroup() is Class_ not needed since all PreferenceGroups have unique ids
		if (dObj.getPrefGroup().getUniqueId().equals(aClass.getUniqueId())) return true;
		
		//SchedulingSubpart check
		SchedulingSubpart ss = null;
		if (Hibernate.isInitialized(dObj.getPrefGroup())) {
			if (dObj.getPrefGroup() instanceof SchedulingSubpart) {
				ss = (SchedulingSubpart) dObj.getPrefGroup();
			}
		} else {
			//dObj.getPrefGroup() is a proxy -> try to load it
			PreferenceGroup pg = (new PreferenceGroupDAO()).get(dObj.getPrefGroup().getUniqueId());
			if (pg!=null && pg instanceof SchedulingSubpart)
				ss = (SchedulingSubpart)pg;
		}
		if (ss!=null && ss.getClasses()!=null && ss.getClasses().size()>0) {
			for (Iterator it2 = ss.getClasses().iterator();it2.hasNext();)
				if (((Class_)it2.next()).getUniqueId().equals(aClass.getUniqueId())) return true;
		}
	}
	return false;
}
 
Example 8
Source File: CollectionType.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public String toLoggableString(Object value, SessionFactoryImplementor factory)
		throws HibernateException {
	if ( value == null ) {
		return "null";
	}
	else if ( !Hibernate.isInitialized( value ) ) {
		return "<uninitialized>";
	}
	else {
		return renderLoggableString( value, factory );
	}
}
 
Example 9
Source File: TaskFormatter.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Writes the html formatted task to the given StringBuffer.
 * @param buf
 * @param task
 * @param enableLink If true, the task has a link to the EditTask.action.
 * @param showPathAsTooltip If true, an info icon with the whole task path as tooltip will be added.
 */
public void appendFormattedTask(final RequestCycle requestCycle, final StringBuffer buf, TaskDO task, final boolean showPathAsTooltip,
    final boolean lineThroughDeletedTask)
{
  Validate.notNull(buf);
  Validate.notNull(task);
  if (showPathAsTooltip == true) {
    final String taskPath = getTaskPath(requestCycle, task.getId(), null, false);
    if (taskPath != null) {
      htmlHelper.appendImageTag(requestCycle, buf, htmlHelper.getInfoImage(), taskPath);
    }
  }
  // if (enableLink == true) {
  // htmlHelper.appendAncorStartTag(locUrlBuilder, buf,
  // WicketUtils.getBookmarkablePageUrl(TaskEditPage.class, "id", String.valueOf(task.getId())));
  // }
  if (Hibernate.isInitialized(task) == false) {
    task = taskTree.getTaskById(task.getId());
  }
  if (task.isDeleted() == true) {
    if (lineThroughDeletedTask == true) {
      buf.append("<span");
      htmlHelper.attribute(buf, "style", "text-decoration: line-through;");
      buf.append(">");
      buf.append(HtmlHelper.escapeXml(task.getTitle()));
      buf.append("</span>");
    } else {
      buf.append(HtmlHelper.escapeXml(task.getTitle())).append(" (");
      buf.append(getI18nMessage("task.deleted"));
      buf.append(")");
    }
  } else {
    buf.append(HtmlHelper.escapeXml(task.getTitle()));
  }
  // if (enableLink == true) {
  // htmlHelper.appendAncorEndTag(buf);
  // }
}
 
Example 10
Source File: Kost2DOConverter.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
public static Cost2Object getCost2Object(Kost2DO kost2DO)
{
  if (kost2DO == null) {
    return null;
  }
  if (Hibernate.isInitialized(kost2DO) == false) {
    final Integer kost2Id = kost2DO.getId();
    kost2DO = Registry.instance().getDao(Kost2Dao.class).internalGetById(kost2Id);
    if (kost2DO == null) {
      log.error("Oups, kost2 with id '" + kost2Id + "' not found.");
      return null;
    }
  }
  final Cost2Object cost2 = new Cost2Object();
  DOConverter.copyFields(cost2, kost2DO);
  cost2.setNumber(kost2DO.getFormattedNumber());
  if (kost2DO.getKost2Art() != null) {
    cost2.setType(kost2DO.getKost2Art().getName());
  }
  final ProjektDO projektDO = kost2DO.getProjekt();
  KundeDO kundeDO = null;
  if (projektDO != null) {
    cost2.setProject(projektDO.getName());
    kundeDO = projektDO.getKunde();
    if (kundeDO != null) {
      cost2.setCustomer(kundeDO.getName());
    }
  }
  return cost2;
}
 
Example 11
Source File: GroupDO.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the collection of assigned users only if initialized. Avoids a LazyInitializationException.
 * @return
 */
@Transient
public Set<PFUserDO> getSafeAssignedUsers()
{
  if (this.assignedUsers == null || Hibernate.isInitialized(this.assignedUsers) == false) {
    return null;
  }
  return this.assignedUsers;
}
 
Example 12
Source File: StatefulPersistenceContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean reassociateIfUninitializedProxy(Object value) throws MappingException {
	if ( !Hibernate.isInitialized( value ) ) {
		final HibernateProxy proxy = (HibernateProxy) value;
		final LazyInitializer li = proxy.getHibernateLazyInitializer();
		reassociateProxy( li, proxy );
		return true;
	}
	else {
		return false;
	}
}
 
Example 13
Source File: TimesheetDao.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @see org.projectforge.core.BaseDao#prepareHibernateSearch(org.projectforge.core.ExtendedBaseDO, org.projectforge.access.OperationType)
 */
@Override
protected void prepareHibernateSearch(final TimesheetDO obj, final OperationType operationType)
{
  final PFUserDO user = obj.getUser();
  if (user != null && Hibernate.isInitialized(user) == false) {
    obj.setUser(userDao.getUserGroupCache().getUser(user.getId()));
  }
  final TaskDO task = obj.getTask();
  if (task != null && Hibernate.isInitialized(task) == false) {
    obj.setTask(taskTree.getTaskById(task.getId()));
  }
}
 
Example 14
Source File: ValidationUtil.java    From mPass with Apache License 2.0 5 votes vote down vote up
/**
 * 执行校验
 * 
 * @param dto
 */
public static <T> void validate(T dto, Class<?>... groups)
		throws ParamsNotValidException {
	//处理hibernate延迟及代理对象
	if (!Hibernate.isInitialized(dto)) {
		return;
	}
	Set<ConstraintViolation<T>> result = validator
			.validate((T) Hibernate.unproxy(dto), groups);
	handleConstraintViolation(result);
	if (dto instanceof Validatable) {
		((Validatable) dto).validate(groups);
	}
}
 
Example 15
Source File: DocumentNominalLabel.java    From AIDR with GNU Affero General Public License v3.0 4 votes vote down vote up
public boolean hasDocument() {
	return Hibernate.isInitialized(this.document);
}
 
Example 16
Source File: NominalLabel.java    From AIDR with GNU Affero General Public License v3.0 4 votes vote down vote up
public boolean hasNominalAttribute() {
	return Hibernate.isInitialized(this.nominalAttribute);
}
 
Example 17
Source File: NominalAttribute.java    From AIDR with GNU Affero General Public License v3.0 4 votes vote down vote up
public boolean hasUsers() {
	return Hibernate.isInitialized(this.users);
}
 
Example 18
Source File: Document.java    From AIDR with GNU Affero General Public License v3.0 4 votes vote down vote up
public boolean hasTaskAssignments() {
	return Hibernate.isInitialized(this.taskAssignments);
}
 
Example 19
Source File: NominalAttribute.java    From AIDR with GNU Affero General Public License v3.0 4 votes vote down vote up
public boolean hasNominalLabels() {
	return Hibernate.isInitialized(this.nominalLabels);
}
 
Example 20
Source File: CommonDAOSpringImpl.java    From EasyEE with MIT License 4 votes vote down vote up
@Override
public void initialize(Object proxy) {
	if (!Hibernate.isInitialized(proxy)) {
		Hibernate.initialize(proxy);
	}
}