public static Details getDetails(Object[] state, String[] names) { return (Details) state[detailsIndex(names)]; }
@Override protected void copyValues(EntityPersister persister, Object entity, Object target, SessionImplementor source, Map copyCache) { if (entity instanceof IObject) { HibernateUtils.fixNulledOrFilteredCollections((IObject) entity, (IObject) target, persister, source); propagateHiddenValues((IObject) entity, (IObject) target); } super.copyValues(persister, entity, target, source, copyCache); }
void throwIfGroupsDontMatch( ExperimenterGroup changedObjectGroup, IObject changedObject, ExperimenterGroup linkedGroup, IObject linkedObject) { if (linkedGroup != null && !HibernateUtils.idEqual(linkedGroup, changedObjectGroup)) { throw new GroupSecurityViolation(String.format( "MIXED GROUP: " + "%s(group=%s) and %s(group=%s) cannot be linked.", changedObject, changedObjectGroup, linkedObject, linkedGroup)); } }
int detailsIndex = detailsIndex(propertyNames); Details d = (Details) currentState[detailsIndex]; if (d != null) { for (String string : s) { string = LsidUtils.parseField(string); int idx = index(string, propertyNames); Object previous = previousState[idx]; if (!(previous instanceof Collection)) // implies log("Copying filtered collection ", string); Collection copy = copy(((Collection) previous)); persister.setPropertyValue(entity, idx, copy, source .getEntityMode()); log("Skipping uninitialized collection: ", propertyNames[i]); persister.setPropertyValue(entity, i, previous, source .getEntityMode()); } else { log("Copying nulled collection: ", propertyNames[i]); Collection copy = copy(((Collection) previous)); persister.setPropertyValue(entity, i, copy, source .getEntityMode()); log("Skipping uninitialized map: ", propertyNames[i]); persister.setPropertyValue(entity, i, previous, source .getEntityMode()); } else { Map copy = copy((Map) previous);
return false; final Long ownerId = HibernateUtils.nullSafeOwnerId(iObject); final Long groupId; // see 2874 and chmod if (iObject instanceof ExperimenterGroup) { groupId = iObject.getId(); } else { groupId = HibernateUtils.nullSafeGroupId(iObject);
if (entity instanceof IObject) { IObject iobj = (IObject) entity; int idx = HibernateUtils.detailsIndex(propertyNames); final int pathIndex = HibernateUtils.index(IDX_FILE_PATH, propertyNames); final int nameIndex = HibernateUtils.index(IDX_FILE_NAME, propertyNames); final String currentPath = (String) currentState[pathIndex]; final String currentName = (String) currentState[nameIndex]; final int repoIndex = HibernateUtils.index(IDX_FILE_REPO, propertyNames); if (previousState != null && !ObjectUtils.equals(previousState[repoIndex], currentState[repoIndex])) { log.warn("reverting change to OriginalFile.repo");
public boolean onPreUpdate(PreUpdateEvent event) { Object entity = event.getEntity(); Object[] state = event.getOldState(); String[] names = event.getPersister().getPropertyNames(); if (entity instanceof IObject) { IObject obj = (IObject) entity; if (!aclVoter.allowUpdate(obj, HibernateUtils.getDetails(state, names))) { aclVoter.throwUpdateViolation(obj); } } return false; }
/** * @see RefreshEventListener#onRefresh(RefreshEvent, Map) */ @SuppressWarnings("unchecked") public void onRefresh(RefreshEvent event, Map refreshedAlready) throws HibernateException { IObject orig = (IObject) event.getObject(); if (orig.getId() == null) { throw new ApiUsageException( "Transient entities cannot be refreshed."); } if (HibernateUtils.isUnloaded(orig)) { final EventSource source = event.getSession(); log("Reloading unloaded entity:", orig.getClass(), ":", orig .getId()); Object obj = source.load(orig.getClass(), orig.getId()); refreshedAlready.put(orig, obj); return; // EARLY EXIT! } }
public static int detailsIndex(String[] propertyNames) { return index(DETAILS, propertyNames); }
throw new ApiUsageException("Object can't be null"); final Long o = HibernateUtils.nullSafeOwnerId(object); final Long g; // see 2874 and chmod if (object instanceof ExperimenterGroup) { g = object.getId(); } else { g = HibernateUtils.nullSafeGroupId(object);
public boolean onPreDelete(PreDeleteEvent event) { Object entity = event.getEntity(); Object[] state = event.getDeletedState(); String[] names = event.getPersister().getPropertyNames(); if (entity instanceof IObject) { IObject obj = (IObject) entity; if (!aclVoter.allowDelete(obj, HibernateUtils.getDetails(state, names))) { aclVoter.throwDeleteViolation(obj); } } return false; }
@Override @SuppressWarnings("unchecked") protected void entityIsDetached(MergeEvent event, Map copyCache) { final IObject orig = (IObject) event.getOriginal(); final EventSource source = event.getSession(); if (HibernateUtils.isUnloaded(orig)) { log("Reloading unloaded entity:", event.getEntityName(), ":", orig .getId()); Class<?> k = Utils.trueClass(orig.getClass()); Object obj = source.load(k, orig.getId()); event.setResult(obj); copyCache.put(event.getEntity(), obj); // TODO this was maybe a bug. check if findDirty is superfluous. } else if (orig instanceof Event) { final Object obj = source.load(Event.class, orig.getId()); event.setResult(obj); copyCache.put(event.getEntity(), obj); } else { super.entityIsDetached(event, copyCache); } fillReplacement(event); }
/** * @param new_d the new details * @param old_d the old details * @return if the non-permissions fields are the same */ public static boolean onlyPermissionsChanged(Details new_d, Details old_d) { if (idEqual(new_d.getOwner(), old_d.getOwner()) && idEqual(new_d.getGroup(), old_d.getGroup()) && idEqual(new_d.getCreationEvent(), old_d.getCreationEvent()) && idEqual(new_d.getUpdateEvent(), old_d.getUpdateEvent()) && idEqual(new_d.getExternalInfo(), old_d.getExternalInfo())) { return true; } return false; }
@Override protected void copyValues(EntityPersister persister, Object entity, Object target, SessionImplementor source, Map copyCache, ForeignKeyDirection foreignKeyDirection) { if (entity instanceof IObject) { HibernateUtils.fixNulledOrFilteredCollections((IObject) entity, (IObject) target, persister, source); propagateHiddenValues((IObject) entity, (IObject) target); } super.copyValues(persister, entity, target, source, copyCache, foreignKeyDirection); }
/** * calls back to {@link BasicSecuritySystem#newTransientDetails(IObject)} for * properly setting {@link IObject#getDetails() Details} */ public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) { debug("Intercepted save."); this.stats.updatedObjects(1); if (entity instanceof IObject) { IObject iobj = (IObject) entity; int idx = HibernateUtils.detailsIndex(propertyNames); Details d = evaluateLinkages(iobj); // Get a new details based on the current context d = newTransientDetails(iobj, d); state[idx] = d; } return true; // transferDetails ALWAYS edits the new entity. }
if (!HibernateUtils.idEqual(previous, current)) { throw new SecurityViolation(String.format( "Cannot update ExternalInfo for %s from %s to %s", obj,
public void addGroups(final Experimenter user, final ExperimenterGroup... groups) { final Session session = sf.getSession(); final List<String> added = new ArrayList<String>(); Experimenter foundUser = userById(user.getId(), session); for (ExperimenterGroup group : groups) { ExperimenterGroup foundGroup = groupById(group.getId(), session); boolean found = false; for (ExperimenterGroup currentGroup : foundUser .linkedExperimenterGroupList()) { found |= HibernateUtils.idEqual(foundGroup, currentGroup); } if (!found) { linkGroupAndUser(foundGroup, foundUser, false); added.add(foundGroup.getName()); } } fixDefaultGroup(foundUser, session); }
if (!HibernateUtils.idEqual(previousDetails.getOwner(), currentDetails .getOwner())) {
if (!HibernateUtils.idEqual(previousDetails.getGroup(), currentDetails .getGroup())) {