Skip to content

Commit

Permalink
fix for reference storing, metadata with the same createApproverRef a…
Browse files Browse the repository at this point in the history
…nd modifyApproverRef couldn't be stored.
  • Loading branch information
1azyman committed Feb 17, 2015
1 parent fc57cf3 commit 97ad913
Show file tree
Hide file tree
Showing 32 changed files with 118 additions and 517 deletions.
4 changes: 0 additions & 4 deletions repo/repo-sql-impl-test/STATS

This file was deleted.

Expand Up @@ -129,7 +129,7 @@ public void test070ModifyBigUser() throws Exception {
repositoryService.modifyObject(UserType.class, userBigOid, delta.getModifications(), new OperationResult("asdf"));
}

@Test(enabled = false)
@Test
public void test100ModifyUserApproverMetadata() throws Exception {
PrismObjectDefinition userDefinition = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class);
ReferenceDelta delta1 = ReferenceDelta.createModificationAdd(
Expand Down
Expand Up @@ -19,7 +19,6 @@
import com.evolveum.midpoint.prism.Objectable;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismObjectDefinition;
import com.evolveum.midpoint.prism.PrismPropertyDefinition;
import com.evolveum.midpoint.prism.match.PolyStringNormMatchingRule;
import com.evolveum.midpoint.prism.match.PolyStringOrigMatchingRule;
import com.evolveum.midpoint.prism.path.ItemPath;
Expand All @@ -35,27 +34,19 @@
import com.evolveum.midpoint.repo.sql.data.common.other.RObjectType;
import com.evolveum.midpoint.repo.sql.data.common.type.RAssignmentExtensionType;
import com.evolveum.midpoint.repo.sql.data.common.type.RObjectExtensionType;
import com.evolveum.midpoint.repo.sql.data.common.type.RParentOrgRef;
import com.evolveum.midpoint.repo.sql.query.QueryEngine;
import com.evolveum.midpoint.repo.sql.query.QueryException;
import com.evolveum.midpoint.repo.sql.query.RQuery;
import com.evolveum.midpoint.repo.sql.query.RQueryCriteriaImpl;
import com.evolveum.midpoint.repo.sql.type.XMLGregorianCalendarType;
import com.evolveum.midpoint.repo.sql.util.HibernateToSqlTranslator;
import com.evolveum.midpoint.schema.MidPointPrismContextFactory;
import com.evolveum.midpoint.schema.SchemaConstantsGenerated;
import com.evolveum.midpoint.schema.constants.MidPointConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.PrettyPrinter;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.*;
import org.hibernate.sql.JoinType;
Expand Down Expand Up @@ -945,7 +936,8 @@ public void queryOrgTreeFindOrgs() throws Exception {
addFullObjectProjectionList("o", projections, false);
main.setProjection(projections);

DetachedCriteria detached = DetachedCriteria.forClass(RParentOrgRef.class, "p");
DetachedCriteria detached = DetachedCriteria.forClass(RObjectReference.class, "p");
detached.add(Restrictions.eq("referenceType", 0));
detached.setProjection(Projections.distinct(Projections.property("p.ownerOid")));
detached.add(Restrictions.eq("p.targetOid", "some oid"));

Expand Down Expand Up @@ -1140,7 +1132,8 @@ public void test310QueryNameAndOrg() throws Exception {
Session session = open();

try {
DetachedCriteria detached = DetachedCriteria.forClass(RParentOrgRef.class, "p");
DetachedCriteria detached = DetachedCriteria.forClass(RObjectReference.class, "p");
detached.add(Restrictions.eq("referenceType", 0));
detached.setProjection(Projections.distinct(Projections.property("p.ownerOid")));
detached.add(Property.forName("targetOid").in(
DetachedCriteria.forClass(ROrgClosure.class, "cl")
Expand Down
Expand Up @@ -619,14 +619,14 @@ private void registerVertexIfNeeded(String oid) {
}

protected List<String> getChildren(String oid) {
Query childrenQuery = getSession().createQuery("select distinct ownerOid from RParentOrgRef where targetOid=:oid");
Query childrenQuery = getSession().createQuery("select distinct ownerOid from RObjectReference where targetOid=:oid and referenceType=0");
childrenQuery.setString("oid", oid);
return childrenQuery.list();
}

private List<String> getOrgChildren(String oid) {
Query childrenQuery = getSession().createQuery("select distinct parentRef.ownerOid from RParentOrgRef as parentRef" +
" join parentRef.owner as owner where parentRef.targetOid=:oid" +
Query childrenQuery = getSession().createQuery("select distinct parentRef.ownerOid from RObjectReference as parentRef" +
" join parentRef.owner as owner where parentRef.targetOid=:oid and parentRef.referenceType=0" +
" and owner.objectTypeClass = :orgType");
childrenQuery.setParameter("orgType", RObjectType.ORG); // TODO eliminate use of parameter here
childrenQuery.setString("oid", oid);
Expand Down
Expand Up @@ -1275,14 +1275,14 @@ private <T extends ObjectType> boolean isTypeNonLeaf(Class<T> type) {
}

private List<String> getParents(String oid, Session session) {
Query parentsQuery = session.createQuery("select distinct targetOid from RParentOrgRef where ownerOid=:oid");
Query parentsQuery = session.createQuery("select distinct targetOid from RObjectReference where ownerOid=:oid and referenceType=0");
parentsQuery.setString("oid", oid);
return parentsQuery.list();
}

private List<String> getChildren(String oid, Session session) {
Query childrenQuery = session.createQuery("select distinct parentRef.ownerOid from RParentOrgRef as parentRef" +
" join parentRef.owner as owner where parentRef.targetOid=:oid" +
Query childrenQuery = session.createQuery("select distinct parentRef.ownerOid from RObjectReference as parentRef" +
" join parentRef.owner as owner where parentRef.targetOid=:oid and parentRef.referenceType=0" +
" and owner.objectTypeClass = :orgType");
childrenQuery.setParameter("orgType", RObjectType.ORG); // TODO eliminate use of parameter here
childrenQuery.setString("oid", oid);
Expand Down
Expand Up @@ -22,7 +22,6 @@
import com.evolveum.midpoint.repo.sql.data.common.container.RExclusion;
import com.evolveum.midpoint.repo.sql.data.common.other.RAssignmentOwner;
import com.evolveum.midpoint.repo.sql.data.common.other.RReferenceOwner;
import com.evolveum.midpoint.repo.sql.data.common.type.RRoleApproverRef;
import com.evolveum.midpoint.repo.sql.query.definition.JaxbName;
import com.evolveum.midpoint.repo.sql.query.definition.QueryEntity;
import com.evolveum.midpoint.repo.sql.query.definition.VirtualCollection;
Expand All @@ -34,7 +33,6 @@
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ExclusionType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.Index;
Expand All @@ -44,7 +42,6 @@
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

import java.util.HashSet;
import java.util.Set;

Expand Down Expand Up @@ -92,7 +89,7 @@ public Set<RExclusion> getExclusion() {
return exclusion;
}

@Where(clause = RObjectReference.REFERENCE_TYPE + "=" + RRoleApproverRef.DISCRIMINATOR)
@Where(clause = RObjectReference.REFERENCE_TYPE + "= 3")
@OneToMany(mappedBy = "owner", orphanRemoval = true)
@ForeignKey(name = "none")
@Cascade({org.hibernate.annotations.CascadeType.ALL})
Expand Down Expand Up @@ -177,7 +174,7 @@ public static <T extends AbstractRoleType> void copyFromJAXB(AbstractRoleType ja
repo.getApproverRef().add(ref);
}
}

PrismObjectDefinition<AbstractRoleType> roleDefinition = jaxb.asPrismObject().getDefinition();

repo.setApprovalProcess(jaxb.getApprovalProcess());
Expand Down
Expand Up @@ -21,7 +21,6 @@
import com.evolveum.midpoint.repo.sql.data.common.embedded.RActivation;
import com.evolveum.midpoint.repo.sql.data.common.other.RAssignmentOwner;
import com.evolveum.midpoint.repo.sql.data.common.other.RReferenceOwner;
import com.evolveum.midpoint.repo.sql.data.common.type.RLinkRef;
import com.evolveum.midpoint.repo.sql.query.definition.JaxbName;
import com.evolveum.midpoint.repo.sql.query.definition.QueryEntity;
import com.evolveum.midpoint.repo.sql.query.definition.VirtualCollection;
Expand All @@ -31,7 +30,6 @@
import com.evolveum.midpoint.repo.sql.util.RUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.Index;
Expand All @@ -41,7 +39,6 @@
import javax.persistence.Entity;
import javax.persistence.OneToMany;
import javax.persistence.Transient;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
Expand All @@ -65,7 +62,7 @@ public abstract class RFocus<T extends FocusType> extends RObject<T> {
private Set<RAssignment> assignments;
private RActivation activation;

@Where(clause = RObjectReference.REFERENCE_TYPE + "=" + RLinkRef.DISCRIMINATOR)
@Where(clause = RObjectReference.REFERENCE_TYPE + "= 1")
@OneToMany(mappedBy = "owner", orphanRemoval = true)
@ForeignKey(name = "none")
@Cascade({org.hibernate.annotations.CascadeType.ALL})
Expand Down
Expand Up @@ -23,9 +23,9 @@
/**
* @author Viliam Repan (lazyman)
*/
//@Entity
//@ForeignKey(name = "fk_lookup_table")
//@Table(uniqueConstraints = @UniqueConstraint(name = "uc_lookup_name", columnNames = {"name_norm"}))
@Entity
@ForeignKey(name = "fk_lookup_table")
@Table(uniqueConstraints = @UniqueConstraint(name = "uc_lookup_name", columnNames = {"name_norm"}))
public class RLookupTable extends RObject<LookupTableType> {

private RPolyString name;
Expand Down
Expand Up @@ -25,10 +25,7 @@
import com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString;
import com.evolveum.midpoint.repo.sql.data.common.other.RObjectType;
import com.evolveum.midpoint.repo.sql.data.common.other.RReferenceOwner;
import com.evolveum.midpoint.repo.sql.data.common.type.RCreateApproverRef;
import com.evolveum.midpoint.repo.sql.data.common.type.RModifyApproverRef;
import com.evolveum.midpoint.repo.sql.data.common.type.RObjectExtensionType;
import com.evolveum.midpoint.repo.sql.data.common.type.RParentOrgRef;
import com.evolveum.midpoint.repo.sql.data.factory.MetadataFactory;
import com.evolveum.midpoint.repo.sql.util.*;
import com.evolveum.midpoint.schema.GetOperationOptions;
Expand All @@ -43,7 +40,6 @@

import javax.persistence.*;
import javax.persistence.Entity;
import javax.persistence.ForeignKey;
import javax.persistence.Index;
import javax.persistence.Table;
import javax.xml.datatype.XMLGregorianCalendar;
Expand Down Expand Up @@ -146,7 +142,7 @@ public Set<RTrigger> getTrigger() {
return trigger;
}

@Where(clause = RObjectReference.REFERENCE_TYPE + "=" + RParentOrgRef.DISCRIMINATOR)
@Where(clause = RObjectReference.REFERENCE_TYPE + "= 0")
@OneToMany(mappedBy = RObjectReference.F_OWNER, orphanRemoval = true)
@Cascade({org.hibernate.annotations.CascadeType.ALL})
public Set<RObjectReference> getParentOrgRef() {
Expand Down Expand Up @@ -182,7 +178,7 @@ public byte[] getFullObject() {
return fullObject;
}

@Where(clause = RObjectReference.REFERENCE_TYPE + "=" + RCreateApproverRef.DISCRIMINATOR)
@Where(clause = RObjectReference.REFERENCE_TYPE + "= 5")
@OneToMany(mappedBy = RObjectReference.F_OWNER, orphanRemoval = true)
// @JoinTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@Cascade({org.hibernate.annotations.CascadeType.ALL})
Expand Down Expand Up @@ -211,7 +207,7 @@ public REmbeddedReference getModifierRef() {
return modifierRef;
}

@Where(clause = RObjectReference.REFERENCE_TYPE + "=" + RModifyApproverRef.DISCRIMINATOR)
@Where(clause = RObjectReference.REFERENCE_TYPE + "= 6")
@OneToMany(mappedBy = RObjectReference.F_OWNER, orphanRemoval = true)
// @JoinTable(foreignKey = @ForeignKey(name = "none"))
@Cascade({org.hibernate.annotations.CascadeType.ALL})
Expand Down
Expand Up @@ -19,6 +19,7 @@
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.repo.sql.data.common.id.RObjectReferenceId;
import com.evolveum.midpoint.repo.sql.data.common.other.RObjectType;
import com.evolveum.midpoint.repo.sql.data.common.other.RReferenceOwner;
import com.evolveum.midpoint.repo.sql.query.definition.JaxbType;
import com.evolveum.midpoint.repo.sql.util.ClassMapper;
import com.evolveum.midpoint.repo.sql.util.RUtil;
Expand All @@ -36,17 +37,17 @@
@JaxbType(type = ObjectReferenceType.class)
@Entity
@IdClass(RObjectReferenceId.class)
@Table(name = "m_reference")
@org.hibernate.annotations.Table(appliesTo = "m_reference",
indexes = {@Index(name = "iReferenceTargetOid", columnNames = "targetOid")})
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = RObjectReference.REFERENCE_TYPE, discriminatorType = DiscriminatorType.INTEGER)
@Table(name = "m_reference", indexes = {
@javax.persistence.Index(name = "iReferenceTargetOid", columnList = "targetOid")
})
public class RObjectReference implements ObjectReference {

public static final String REFERENCE_TYPE = "reference_type";

public static final String F_OWNER = "owner";

private RReferenceOwner referenceType;

//owner
private RObject owner;
private String ownerOid;
Expand Down Expand Up @@ -87,6 +88,16 @@ public String getRelation() {
return relation;
}

@Id
@Column(name = REFERENCE_TYPE, nullable = false)
public RReferenceOwner getReferenceType() {
return referenceType;
}

public void setReferenceType(RReferenceOwner referenceType) {
this.referenceType = referenceType;
}

/**
* Represents {@link javax.xml.namespace.QName} type attribute in reference e.g.
* {@link com.evolveum.midpoint.xml.ns._public.common.common_3.UserType} represented
Expand Down
Expand Up @@ -17,25 +17,20 @@
package com.evolveum.midpoint.repo.sql.data.common;

import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObjectDefinition;
import com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString;
import com.evolveum.midpoint.repo.sql.data.common.enums.RObjectTemplateType;
import com.evolveum.midpoint.repo.sql.data.common.other.RReferenceOwner;
import com.evolveum.midpoint.repo.sql.data.common.type.RIncludeRef;
import com.evolveum.midpoint.repo.sql.util.DtoTranslationException;
import com.evolveum.midpoint.repo.sql.util.IdGeneratorResult;
import com.evolveum.midpoint.repo.sql.util.RUtil;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.xml.ns._public.common.common_3.MappingType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectTemplateType;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.Where;

import javax.persistence.*;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
Expand All @@ -52,7 +47,7 @@ public class RObjectTemplate extends RObject<ObjectTemplateType> {
private RObjectTemplateType type;
private Set<RObjectReference> includeRef;

@Where(clause = RObjectReference.REFERENCE_TYPE + "=" + RIncludeRef.DISCRIMINATOR)
@Where(clause = RObjectReference.REFERENCE_TYPE + "= 7")
@OneToMany(mappedBy = RObjectReference.F_OWNER, orphanRemoval = true)
@ForeignKey(name = "none")
@Cascade({org.hibernate.annotations.CascadeType.ALL})
Expand Down
Expand Up @@ -16,17 +16,12 @@

package com.evolveum.midpoint.repo.sql.data.common;

import com.evolveum.midpoint.prism.ItemDefinition;
import com.evolveum.midpoint.prism.PrismContainerDefinition;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismObjectDefinition;
import com.evolveum.midpoint.repo.sql.data.common.embedded.REmbeddedReference;
import com.evolveum.midpoint.repo.sql.data.common.embedded.ROperationalState;
import com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString;
import com.evolveum.midpoint.repo.sql.data.common.enums.RResourceAdministrativeState;
import com.evolveum.midpoint.repo.sql.data.common.other.RReferenceOwner;
import com.evolveum.midpoint.repo.sql.data.common.type.RResourceApproverRef;
import com.evolveum.midpoint.repo.sql.util.DtoTranslationException;
import com.evolveum.midpoint.repo.sql.util.IdGeneratorResult;
import com.evolveum.midpoint.repo.sql.util.RUtil;
Expand All @@ -36,13 +31,11 @@
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceBusinessConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.Where;

import javax.persistence.*;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -71,7 +64,7 @@ public RResourceAdministrativeState getAdministrativeState() {
return administrativeState;
}

@Where(clause = RObjectReference.REFERENCE_TYPE + "=" + RResourceApproverRef.DISCRIMINATOR)
@Where(clause = RObjectReference.REFERENCE_TYPE + "= 2")
@OneToMany(mappedBy = "owner", orphanRemoval = true)
@ForeignKey(name = "none")
@Cascade({org.hibernate.annotations.CascadeType.ALL})
Expand Down

0 comments on commit 97ad913

Please sign in to comment.