Skip to content

Commit

Permalink
Remove R*Ext* -> RExtItem association
Browse files Browse the repository at this point in the history
Now we keep only the identifier in R*Ext* entities.

TODO: create foreign keys by annotations
  • Loading branch information
mederly committed May 16, 2018
1 parent 449e24d commit 8718a4e
Show file tree
Hide file tree
Showing 25 changed files with 99 additions and 183 deletions.
Expand Up @@ -863,7 +863,7 @@ public void test200ReplaceAttributes() throws Exception {
List shadows = session.createQuery("from RShadow").list();
LOGGER.info("shadows:\n{}", shadows);
//noinspection unchecked
List<Object[]> extStrings = session.createQuery("select e.owner.oid, e.item.id, e.value from ROExtString e").list();
List<Object[]> extStrings = session.createQuery("select e.owner.oid, e.itemId, e.value from ROExtString e").list();
for (Object[] extString : extStrings) {
LOGGER.info("-> {}", Arrays.asList(extString));
}
Expand Down
Expand Up @@ -35,12 +35,12 @@
import com.evolveum.midpoint.repo.sql.data.common.RUser;
import com.evolveum.midpoint.repo.sql.data.common.any.RAnyValue;
import com.evolveum.midpoint.repo.sql.data.common.any.RAssignmentExtension;
import com.evolveum.midpoint.repo.sql.data.common.any.RExtItem;
import com.evolveum.midpoint.repo.sql.data.common.container.RAssignment;
import com.evolveum.midpoint.repo.sql.data.common.embedded.RActivation;
import com.evolveum.midpoint.repo.sql.data.common.embedded.RPolyString;
import com.evolveum.midpoint.repo.sql.data.common.enums.RActivationStatus;
import com.evolveum.midpoint.repo.sql.testing.QueryCountInterceptor;
import com.evolveum.midpoint.repo.sql.util.RUtil;
import com.evolveum.midpoint.schema.constants.SchemaConstants;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.util.DOMUtil;
Expand All @@ -64,6 +64,7 @@
import java.util.Objects;

import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertNull;

/**
* Created by Viliam Repan (lazyman).
Expand Down Expand Up @@ -173,7 +174,7 @@ public void test115DeleteActivation() throws Exception {
public void test110ReplaceNonIndexedExtensionProperty() throws Exception {
OperationResult result = new OperationResult("test110ReplaceExtensionProperty");

ObjectDelta delta = ObjectDelta.createEmptyModifyDelta(UserType.class, userOid, prismContext);
ObjectDelta<?> delta = ObjectDelta.createEmptyModifyDelta(UserType.class, userOid, prismContext);
delta.addModificationReplaceProperty(new ItemPath(UserType.F_EXTENSION, LOOT), 34);

queryCountInterceptor.startCounter();
Expand All @@ -185,20 +186,21 @@ public void test110ReplaceNonIndexedExtensionProperty() throws Exception {

Session session = factory.openSession();
try {
RUser u = session.get(RUser.class, userOid);

assertAnyValues(u.getLongs(), LOOT);
//RUser u = session.get(RUser.class, userOid);
RExtItem extItemDef = extItemDictionary
.findItemByDefinition(delta.getModifications().iterator().next().getDefinition());
assertNull("ext item definition for loot exists", extItemDef);
} finally {
session.close();
}
}

private void assertAnyValues(Collection<? extends RAnyValue> collection, QName name, Object... values) {
Collection<RAnyValue> filtered = new ArrayList();
private void assertAnyValues(Collection<? extends RAnyValue> collection, Integer extItemId, Object... values) {
Collection<RAnyValue> filtered = new ArrayList<>();

if (collection != null) {
for (RAnyValue v : collection) {
if (RUtil.qnameToString(name).equals(v.getName())) {
if (extItemId.equals(v.getItemId())) {
filtered.add(v);
}
}
Expand All @@ -225,21 +227,22 @@ private void assertAnyValues(Collection<? extends RAnyValue> collection, QName n
public void test120AddExtensionProperty() throws Exception {
OperationResult result = new OperationResult("test120AddExtensionProperty");

ObjectDelta delta = ObjectDelta.createEmptyModifyDelta(UserType.class, userOid, prismContext);
ObjectDelta<?> delta = ObjectDelta.createEmptyModifyDelta(UserType.class, userOid, prismContext);
delta.addModificationReplaceProperty(new ItemPath(UserType.F_EXTENSION, WEAPON), "weapon1", "weapon2");

queryCountInterceptor.startCounter();
repositoryService.modifyObject(UserType.class, userOid, delta.getModifications(), result);

if (baseHelper.getConfiguration().isUsingH2()) {
AssertJUnit.assertEquals(6, queryCountInterceptor.getQueryCount());
AssertJUnit.assertEquals(5, queryCountInterceptor.getQueryCount());
}

Session session = factory.openSession();
try {
RUser u = session.get(RUser.class, userOid);

assertAnyValues(u.getStrings(), WEAPON, "weapon1", "weapon2");
RExtItem extItemDef = extItemDictionary.findItemByDefinition(delta.getModifications().iterator().next().getDefinition());
assertAnyValues(u.getStrings(), extItemDef.getId(), "weapon1", "weapon2");
} finally {
session.close();
}
Expand Down
Expand Up @@ -532,13 +532,13 @@ public void test0070QueryGenericLong() throws Exception {
" g.oid, g.fullObject, g.stringsCount, g.longsCount, g.datesCount, g.referencesCount, g.polysCount, g.booleansCount\n" +
"from\n" +
" RGenericObject g\n" +
" left join g.longs l with ( l.ownerType = :ownerType and l.item.id = :id )\n" +
" left join g.longs l with ( l.ownerType = :ownerType and l.itemId = :itemId )\n" +
"where\n" +
" ( g.nameCopy.norm = :norm and l.value = :value )\n";

assertEqualsIgnoreWhitespace(expected, real);

assertEquals("Wrong property ID for 'intType'", intTypeDefinition.getId(), realQuery.getQuerySource().getParameters().get("id").getValue());
assertEquals("Wrong property ID for 'intType'", intTypeDefinition.getId(), realQuery.getQuerySource().getParameters().get("itemId").getValue());
} finally {
close(session);
}
Expand All @@ -563,8 +563,8 @@ public void test0071QueryGenericLongTwice() throws Exception {
" g.oid, g.fullObject, g.stringsCount, g.longsCount, g.datesCount, g.referencesCount, g.polysCount, g.booleansCount\n" +
"from\n" +
" RGenericObject g\n" +
" left join g.longs l with ( l.ownerType = :ownerType and l.item.id = :id )\n" +
" left join g.longs l2 with ( l2.ownerType = :ownerType2 and l2.item.id = :id2 )\n" +
" left join g.longs l with ( l.ownerType = :ownerType and l.itemId = :itemId )\n" +
" left join g.longs l2 with ( l2.ownerType = :ownerType2 and l2.itemId = :itemId2 )\n" +
"where\n" +
" (\n" +
" g.nameCopy.norm = :norm and\n" +
Expand All @@ -576,8 +576,8 @@ public void test0071QueryGenericLongTwice() throws Exception {
// note l and l2 cannot be merged as they point to different extension properties (intType, longType)
assertEqualsIgnoreWhitespace(expected, real);

assertEquals("Wrong property ID for 'intType'", intTypeDefinition.getId(), source.getParameters().get("id").getValue());
assertEquals("Wrong property ID for 'longType'", longTypeDefinition.getId(), source.getParameters().get("id2").getValue());
assertEquals("Wrong property ID for 'intType'", intTypeDefinition.getId(), source.getParameters().get("itemId").getValue());
assertEquals("Wrong property ID for 'longType'", longTypeDefinition.getId(), source.getParameters().get("itemId2").getValue());
} finally {
close(session);
}
Expand Down Expand Up @@ -612,7 +612,7 @@ public void test0073QueryAccountByAttribute() throws Exception {
" s.oid, s.fullObject, s.stringsCount, s.longsCount, s.datesCount, s.referencesCount, s.polysCount, s.booleansCount\n" +
"from\n" +
" RShadow s\n" +
" left join s.strings s2 with ( s2.ownerType = :ownerType and s2.item.id = :id )\n" +
" left join s.strings s2 with ( s2.ownerType = :ownerType and s2.itemId = :itemId )\n" +
"where\n" +
" s2.value = :value\n";
assertEqualsIgnoreWhitespace(expected, real);
Expand All @@ -632,17 +632,17 @@ public void test0074QueryAccountByAttributeAndExtensionValue() throws Exception
" s.oid, s.fullObject, s.stringsCount, s.longsCount, s.datesCount, s.referencesCount, s.polysCount, s.booleansCount\n" +
"from\n" +
" RShadow s\n" +
" left join s.strings s2 with ( s2.ownerType = :ownerType and s2.item.id = :id )\n" +
" left join s.longs l with ( l.ownerType = :ownerType2 and l.item.id = :id2 )\n" +
" left join s.strings s2 with ( s2.ownerType = :ownerType and s2.itemId = :itemId )\n" +
" left join s.longs l with ( l.ownerType = :ownerType2 and l.itemId = :itemId2 )\n" +
"where\n" +
" (\n" +
" s2.value = :value and\n" +
" l.value = :value2\n" +
" )";
assertEqualsIgnoreWhitespace(expected, realQuery.getQuery().getQueryString());

assertEquals("Wrong property ID for 'a1'", a1Definition.getId(), realQuery.getQuerySource().getParameters().get("id").getValue());
assertEquals("Wrong property ID for 'shoeSize'", shoeSizeDefinition.getId(), realQuery.getQuerySource().getParameters().get("id2").getValue());
assertEquals("Wrong property ID for 'a1'", a1Definition.getId(), realQuery.getQuerySource().getParameters().get("itemId").getValue());
assertEquals("Wrong property ID for 'shoeSize'", shoeSizeDefinition.getId(), realQuery.getQuerySource().getParameters().get("itemId2").getValue());
} finally {
close(session);
}
Expand Down Expand Up @@ -675,8 +675,8 @@ public void test0076QueryOrComposite() throws Exception {
" s.oid, s.fullObject, s.stringsCount, s.longsCount, s.datesCount, s.referencesCount, s.polysCount, s.booleansCount\n" +
"from\n" +
" RShadow s\n" +
" left join s.strings s2 with ( s2.ownerType = :ownerType and s2.item.id = :id )\n" +
" left join s.strings s3 with ( s3.ownerType = :ownerType2 and s3.item.id = :id2 )\n" +
" left join s.strings s2 with ( s2.ownerType = :ownerType and s2.itemId = :itemId )\n" +
" left join s.strings s3 with ( s3.ownerType = :ownerType2 and s3.itemId = :itemId2 )\n" +
"where\n" +
" (\n" +
" s.intent = :intent or\n" +
Expand All @@ -701,8 +701,8 @@ public void test0076QueryOrComposite() throws Exception {
type = com.evolveum.midpoint.repo.sql.data.common.other.RObjectType.RESOURCE
*/
assertEqualsIgnoreWhitespace(expected, realQuery.getQuery().getQueryString());
assertEquals("Wrong property ID for 'foo'", fooDefinition.getId(), realQuery.getQuerySource().getParameters().get("id").getValue());
assertEquals("Wrong property ID for 'stringType'", stringTypeDefinition.getId(), realQuery.getQuerySource().getParameters().get("id2").getValue());
assertEquals("Wrong property ID for 'foo'", fooDefinition.getId(), realQuery.getQuerySource().getParameters().get("itemId").getValue());
assertEquals("Wrong property ID for 'stringType'", stringTypeDefinition.getId(), realQuery.getQuerySource().getParameters().get("itemId2").getValue());

System.out.println("Query parameters: " + realQuery.getQuerySource().getParameters());
} finally {
Expand Down Expand Up @@ -1152,7 +1152,7 @@ public void test0130QueryAccountByAttributesAndResourceRef() throws Exception {
" s.booleansCount\n" +
"from\n" +
" RShadow s\n" +
" left join s.strings s2 with ( s2.ownerType = :ownerType and s2.item.id = :id )\n" +
" left join s.strings s2 with ( s2.ownerType = :ownerType and s2.itemId = :itemId )\n" +
"where\n" +
" (\n" +
" (\n" +
Expand Down Expand Up @@ -2745,14 +2745,14 @@ public void test0580QueryObjectypeByTypeAndExtensionAttribute() throws Exception
" o.booleansCount\n" +
"from\n" +
" RObject o\n" +
" left join o.strings s with ( s.ownerType = :ownerType and s.item.id = :id )\n" +
" left join o.strings s with ( s.ownerType = :ownerType and s.itemId = :itemId )\n" +
"where\n" +
" (\n" +
" o.objectTypeClass = :objectTypeClass and\n" +
" s.value = :value\n" +
" )\n";
assertEqualsIgnoreWhitespace(expected, realQuery.getQuery().getQueryString());
assertEquals("Wrong property ID for 'weapon'", weaponDefinition.getId(), realQuery.getQuerySource().getParameters().get("id").getValue());
assertEquals("Wrong property ID for 'weapon'", weaponDefinition.getId(), realQuery.getQuerySource().getParameters().get("itemId").getValue());

} finally {
close(session);
Expand Down Expand Up @@ -3016,7 +3016,7 @@ public void test0620QueryGenericString() throws Exception {
" g.booleansCount\n" +
"from\n" +
" RGenericObject g\n" +
" left join g.strings s with ( s.ownerType = :ownerType and s.item.id = :id )\n" +
" left join g.strings s with ( s.ownerType = :ownerType and s.itemId = :itemId )\n" +
"where\n" +
" s.value = :value\n";
assertEqualsIgnoreWhitespace(expected, real);
Expand Down Expand Up @@ -3089,12 +3089,12 @@ public void test0630QueryGenericBoolean() throws Exception {
" g.booleansCount\n" +
"from\n" +
" RGenericObject g\n" +
" left join g.booleans b with ( b.ownerType = :ownerType and b.item.id = :id )\n" +
" left join g.booleans b with ( b.ownerType = :ownerType and b.itemId = :itemId )\n" +
"where\n" +
" b.value = :value\n";

assertEqualsIgnoreWhitespace(expected, realQuery.getQuery().getQueryString());
assertEquals("Wrong property ID for 'skipAutogeneration'", skipAutogenerationDefinition.getId(), realQuery.getQuerySource().getParameters().get("id").getValue());
assertEquals("Wrong property ID for 'skipAutogeneration'", skipAutogenerationDefinition.getId(), realQuery.getQuerySource().getParameters().get("itemId").getValue());

OperationResult result = new OperationResult("search");
List<PrismObject<GenericObjectType>> objects = repositoryService.searchObjects(GenericObjectType.class,
Expand Down Expand Up @@ -3146,7 +3146,7 @@ public void test0640queryAssignmentExtensionBoolean() throws Exception {
" RUser u\n" +
" left join u.assignments a with a.assignmentOwner = :assignmentOwner\n" +
" left join a.extension e\n" +
" left join e.booleans b with b.item.id = :id\n" +
" left join e.booleans b with b.itemId = :itemId\n" +
"where\n" +
" b.value = :value";
assertEqualsIgnoreWhitespace(expected, real);
Expand Down Expand Up @@ -3210,12 +3210,12 @@ public void test0650QueryExtensionEnum() throws Exception {
+ " RUser u\n"
+ " left join u.strings s with (\n"
+ " s.ownerType = :ownerType and\n"
+ " s.item.id = :id\n"
+ " s.itemId = :itemId\n"
+ ")\n"
+ "where\n"
+ " s.value = :value\n";
assertEqualsIgnoreWhitespace(expected, real);
assertEquals("Wrong property ID for 'overrideActivation'", overrideActivationDefinition.getId(), realQuery.getQuerySource().getParameters().get("id").getValue());
assertEquals("Wrong property ID for 'overrideActivation'", overrideActivationDefinition.getId(), realQuery.getQuerySource().getParameters().get("itemId").getValue());
} finally {
close(session);
}
Expand All @@ -3242,7 +3242,7 @@ public void test0660QueryExtensionRef() throws Exception {
+ " RGenericObject g\n"
+ " left join g.references r with (\n"
+ " r.ownerType = :ownerType and\n"
+ " r.item.id = :id\n"
+ " r.itemId = :itemId\n"
+ " )\n"
+ "where\n"
+ " (\n"
Expand Down
Expand Up @@ -90,12 +90,12 @@
@NamedQuery(name = "existOrgClosure", query = "select count(*) from ROrgClosure as o where o.ancestorOid = :ancestorOid and o.descendantOid = :descendantOid"),
@NamedQuery(name = "sqlDeleteOrgClosure", query = "delete from ROrgClosure as o where o.descendantOid = :oid or o.ancestorOid = :oid"),
@NamedQuery(name = "listResourceObjectShadows", query = "select s.oid, s.fullObject, s.stringsCount, s.longsCount, s.datesCount, s.referencesCount, s.polysCount, s.booleansCount from RShadow as s left join s.resourceRef as ref where ref.targetOid = :oid"),
@NamedQuery(name = "getDefinition.ROExtDate", query = "select c.item.name, c.item.type, c.item.kind from ROExtDate as c where c.owner.oid = :oid and c.ownerType = :ownerType"),
@NamedQuery(name = "getDefinition.ROExtString", query = "select c.item.name, c.item.type, c.item.kind from ROExtString as c where c.owner.oid = :oid and c.ownerType = :ownerType"),
@NamedQuery(name = "getDefinition.ROExtPolyString", query = "select c.item.name, c.item.type, c.item.kind from ROExtPolyString as c where c.owner.oid = :oid and c.ownerType = :ownerType"),
@NamedQuery(name = "getDefinition.ROExtLong", query = "select c.item.name, c.item.type, c.item.kind from ROExtLong as c where c.owner.oid = :oid and c.ownerType = :ownerType"),
@NamedQuery(name = "getDefinition.ROExtReference", query = "select c.item.name, c.item.type, c.item.kind from ROExtReference as c where c.owner.oid = :oid and c.ownerType = :ownerType"),
@NamedQuery(name = "getDefinition.ROExtBoolean", query = "select c.item.name, c.item.type, c.item.kind from ROExtBoolean as c where c.owner.oid = :oid and c.ownerType = :ownerType"),
@NamedQuery(name = "getDefinition.ROExtDate", query = "select c.itemId from ROExtDate as c where c.owner.oid = :oid and c.ownerType = :ownerType"),
@NamedQuery(name = "getDefinition.ROExtString", query = "select c.itemId from ROExtString as c where c.owner.oid = :oid and c.ownerType = :ownerType"),
@NamedQuery(name = "getDefinition.ROExtPolyString", query = "select c.itemId from ROExtPolyString as c where c.owner.oid = :oid and c.ownerType = :ownerType"),
@NamedQuery(name = "getDefinition.ROExtLong", query = "select c.itemId from ROExtLong as c where c.owner.oid = :oid and c.ownerType = :ownerType"),
@NamedQuery(name = "getDefinition.ROExtReference", query = "select c.itemId from ROExtReference as c where c.owner.oid = :oid and c.ownerType = :ownerType"),
@NamedQuery(name = "getDefinition.ROExtBoolean", query = "select c.itemId from ROExtBoolean as c where c.owner.oid = :oid and c.ownerType = :ownerType"),
@NamedQuery(name = "isAnySubordinateAttempt.oneLowerOid", query = "select count(*) from ROrgClosure o where o.ancestorOid=:aOid and o.descendantOid=:dOid"),
@NamedQuery(name = "isAnySubordinateAttempt.moreLowerOids", query = "select count(*) from ROrgClosure o where o.ancestorOid=:aOid and o.descendantOid in (:dOids)"),
@NamedQuery(name = "get.lookupTableLastId", query = "select max(r.id) from RLookupTableRow r where r.ownerOid = :oid"),
Expand Down
Expand Up @@ -115,7 +115,7 @@ public int hashCode() {
@Override
public String toString() {
return getClass().getSimpleName() + "{" +
"item=" + getItem() +
"item id=" + getItemId() +
", value=" + getValue() +
'}';
}
Expand Down

0 comments on commit 8718a4e

Please sign in to comment.