Skip to content

Commit

Permalink
removed m_any from m_object
Browse files Browse the repository at this point in the history
  • Loading branch information
1azyman committed Mar 23, 2014
1 parent 4ee0872 commit 37849ff
Show file tree
Hide file tree
Showing 22 changed files with 426 additions and 662 deletions.
Expand Up @@ -25,7 +25,6 @@
import com.evolveum.midpoint.prism.query.LessFilter;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.xml.XmlTypeConverter;
import com.evolveum.midpoint.repo.sql.data.common.any.RAnyContainer;
import com.evolveum.midpoint.repo.sql.data.common.RShadow;
import com.evolveum.midpoint.repo.sql.data.common.RSynchronizationSituationDescription;
import com.evolveum.midpoint.repo.sql.data.common.RUser;
Expand Down Expand Up @@ -477,12 +476,11 @@ public void simpleModifyExtensionDateTest() throws Exception {
session.beginTransaction();
user = (RUser) session.createQuery("from RUser as u where u.oid = :oid").setParameter("oid", id).uniqueResult();

RAnyContainer extension = user.getExtension();
AssertJUnit.assertEquals(1, extension.getClobs().size());
AssertJUnit.assertEquals(1, extension.getDates().size());
AssertJUnit.assertEquals(2, extension.getStrings().size());
AssertJUnit.assertEquals(1, extension.getLongs().size());
hasLong(extension.getLongs(), 456L);
AssertJUnit.assertEquals(1, user.getClobs().size());
AssertJUnit.assertEquals(1, user.getDates().size());
AssertJUnit.assertEquals(2, user.getStrings().size());
AssertJUnit.assertEquals(1, user.getLongs().size());
hasLong(user.getLongs(), 456L);

session.getTransaction().commit();
session.close();
Expand Down Expand Up @@ -519,18 +517,14 @@ private RUser createUser(Long lootValue, Timestamp dateValue) {
user.setFamilyName(new RPolyString("fa1", "fa1"));
user.setGivenName(new RPolyString("gi1", "gi1"));

RAnyContainer any = new RAnyContainer();
any.setOwnerType(RObjectType.USER);
any.setOwner(user);
user.setExtension(any);

Set<RAnyDate> dates = new HashSet<RAnyDate>();
any.setDates(dates);
user.setDates(dates);

final String namespace = "http://example.com/p";

RAnyDate date = new RAnyDate();
date.setAnyContainer(any);
date.setOwner(user);
date.setOwnerType(RObjectType.OBJECT);
date.setDynamic(false);
date.setName(RUtil.qnameToString(new QName(namespace, "funeralDate")));
date.setType(RUtil.qnameToString(new QName("http://www.w3.org/2001/XMLSchema", "dateTime")));
Expand All @@ -539,10 +533,11 @@ private RUser createUser(Long lootValue, Timestamp dateValue) {
date.setValueType(RValueType.PROPERTY);

Set<RAnyLong> longs = new HashSet<RAnyLong>();
any.setLongs(longs);
user.setLongs(longs);

RAnyLong l = new RAnyLong();
l.setAnyContainer(any);
l.setOwner(user);
l.setOwnerType(RObjectType.OBJECT);
longs.add(l);
l.setDynamic(false);
l.setName(RUtil.qnameToString(new QName(namespace, "loot")));
Expand All @@ -551,10 +546,11 @@ private RUser createUser(Long lootValue, Timestamp dateValue) {
l.setValueType(RValueType.PROPERTY);

Set<RAnyString> strings = new HashSet<RAnyString>();
any.setStrings(strings);
user.setStrings(strings);

RAnyString s1 = new RAnyString();
s1.setAnyContainer(any);
s1.setOwner(user);
s1.setOwnerType(RObjectType.OBJECT);
strings.add(s1);
s1.setDynamic(false);
s1.setName(RUtil.qnameToString(new QName(namespace, "weapon")));
Expand All @@ -563,7 +559,8 @@ private RUser createUser(Long lootValue, Timestamp dateValue) {
s1.setValueType(RValueType.PROPERTY);

RAnyString s2 = new RAnyString();
s2.setAnyContainer(any);
s2.setOwner(user);
s2.setOwnerType(RObjectType.OBJECT);
strings.add(s2);
s2.setDynamic(false);
s2.setName(RUtil.qnameToString(new QName(namespace, "shipName")));
Expand All @@ -572,11 +569,12 @@ private RUser createUser(Long lootValue, Timestamp dateValue) {
s2.setValueType(RValueType.PROPERTY);

Set<RAnyClob> clobs = new HashSet<RAnyClob>();
any.setClobs(clobs);
user.setClobs(clobs);

RAnyClob c1 = new RAnyClob();
clobs.add(c1);
c1.setAnyContainer(any);
c1.setOwner(user);
c1.setOwnerType(RObjectType.OBJECT);
c1.setDynamic(false);
c1.setName(RUtil.qnameToString(new QName(namespace, "someContainer")));
c1.setType(RUtil.qnameToString(new QName("http://www.w3.org/2001/XMLSchema", "string")));
Expand Down
Expand Up @@ -27,6 +27,7 @@

import com.evolveum.midpoint.prism.query.*;
import com.evolveum.midpoint.repo.sql.data.common.*;
import com.evolveum.midpoint.repo.sql.data.common.other.RObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_2a.*;
import org.hibernate.Criteria;
import org.hibernate.FetchMode;
Expand Down Expand Up @@ -220,13 +221,13 @@ public void queryGenericLong() throws Exception {
Session session = open();
Criteria main = session.createCriteria(RGenericObject.class, "g");

Criteria extension = main.createCriteria("extension", "e");
Criteria stringExt = extension.createCriteria("longs", "l");
Criteria stringExt = main.createCriteria("longs", "l");

//and
Criterion c1 = Restrictions.eq("name.norm", "generic object");
//and
Conjunction c2 = Restrictions.conjunction();
c2.add(Restrictions.eq("l.ownerType", RObjectType.OBJECT));
c2.add(Restrictions.eq("l.value", 123L));
c2.add(Restrictions.eq("l.name", new QName("http://example.com/p", "intType")));
c2.add(Restrictions.eq("l.type", new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "integer")));
Expand All @@ -253,24 +254,22 @@ public void queryOrComposite() throws Exception {
Criteria main = session.createCriteria(RShadow.class, "r");
main.setProjection(Projections.property("r.fullObject"));

Criteria attributes = main.createCriteria("attributes", "a");
Criteria stringAttr = attributes.createCriteria("strings", "s1x");

Criteria extension = main.createCriteria("extension", "e");
Criteria stringExt = extension.createCriteria("strings", "s2x");
Criteria stringExt = main.createCriteria("strings", "s1");

//or
Criterion c1 = Restrictions.eq("intent", "some account type");
//or
Conjunction c2 = Restrictions.conjunction();
c2.add(Restrictions.eq("s1x.value", "foo value"));
c2.add(Restrictions.eq("s1x.name", new QName("http://midpoint.evolveum.com/blabla", "foo")));
c2.add(Restrictions.eq("s1x.type", new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "string")));
c2.add(Restrictions.eq("s1.ownerType", RObjectType.SHADOW));
c2.add(Restrictions.eq("s1.value", "foo value"));
c2.add(Restrictions.eq("s1.name", new QName("http://midpoint.evolveum.com/blabla", "foo")));
c2.add(Restrictions.eq("s1.type", new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "string")));
//or
Conjunction c3 = Restrictions.conjunction();
c3.add(Restrictions.eq("s2x.value", "uid=test,dc=example,dc=com"));
c3.add(Restrictions.eq("s2x.name", new QName("http://example.com/p", "stringType")));
c3.add(Restrictions.eq("s2x.type", new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "string")));
c3.add(Restrictions.eq("s1.ownerType", RObjectType.OBJECT));
c3.add(Restrictions.eq("s1.value", "uid=test,dc=example,dc=com"));
c3.add(Restrictions.eq("s1.name", new QName("http://example.com/p", "stringType")));
c3.add(Restrictions.eq("s1.type", new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "string")));
//or
Criterion c4 = Restrictions.conjunction().add(
Restrictions.eq("r.resourceRef.targetOid", "d0db5be9-cb93-401f-b6c1-86ffffe4cd5e"));
Expand Down Expand Up @@ -403,14 +402,14 @@ public void queryAccountByAttributesAndResourceRef() throws Exception {
Session session = open();
Criteria main = session.createCriteria(RShadow.class, "r");

Criteria attributes = main.createCriteria("attributes", "a");
Criteria stringAttr = attributes.createCriteria("strings", "s1x");
Criteria stringAttr = main.createCriteria("strings", "s1x");

//and
Criterion c1 = Restrictions.conjunction().add(
Restrictions.eq("r.resourceRef.targetOid", "aae7be60-df56-11df-8608-0002a5d5c51b"));
//and
Conjunction c2 = Restrictions.conjunction();
c2.add(Restrictions.eq("s1x.ownerType", RObjectType.SHADOW));
c2.add(Restrictions.eq("s1x.value", "uid=jbond,ou=People,dc=example,dc=com"));
c2.add(Restrictions.eq("s1x.name", new QName("http://midpoint.evolveum.com/blabla", "foo")));
c2.add(Restrictions.eq("s1x.type", new QName(XMLConstants.W3C_XML_SCHEMA_NS_URI, "string")));
Expand Down
Expand Up @@ -149,8 +149,8 @@ private static void validateObject(RObject rObject, PrismObject object) {
validateReferences(rObject.getParentOrgRef(), object.findReference(ObjectType.F_PARENT_ORG_REF));

//todo
rObject.getExtension();
rObject.getTrigger();
// rObject.getExtension();
// rObject.getTrigger();
}

private static void validateReferences(Set<ObjectReference> set, PrismReference reference) {
Expand Down
Expand Up @@ -982,10 +982,10 @@ private <T extends ObjectType> PrismObject<T> updateLoadedObject(Object object,

LOGGER.debug("Loading definitions for shadow attributes.");

//todo improve query -> can be already fetched during get/search through projection
Query query = session.createQuery("select stringsCount, longsCount, datesCount, referencesCount, clobsCount,"
+ " polysCount from RAnyContainer where ownerOid = :oid and ownerType = :ownerType");
+ " polysCount from RObject where oid = :oid");
query.setParameter("oid", prismObject.getOid());
query.setParameter("ownerType", RObjectType.SHADOW);

Object[] counts = (Object[]) query.uniqueResult();
Class[] classes = new Class[]{RAnyString.class, RAnyLong.class, RAnyDate.class, RAnyReference.class,
Expand All @@ -1000,6 +1000,8 @@ private <T extends ObjectType> PrismObject<T> updateLoadedObject(Object object,
applyShadowAttributeDefinitions(classes[i], prismObject, session);
}
}

LOGGER.debug("Definitions for attributes loaded. Counts: {}", Arrays.toString(counts));
}

validateObjectType(prismObject, type);
Expand Down

0 comments on commit 37849ff

Please sign in to comment.