Skip to content

Commit

Permalink
ParentRef cycle prevention. Automatic startup-time creation of global…
Browse files Browse the repository at this point in the history
… temporary table in Oracle. Updated manual creation scripts.
  • Loading branch information
mederly committed Oct 8, 2014
1 parent 3066dd9 commit aacd8e7
Show file tree
Hide file tree
Showing 15 changed files with 302 additions and 343 deletions.
12 changes: 1 addition & 11 deletions config/sql/midpoint/3.0/h2/h2-3.0.sql
Expand Up @@ -345,15 +345,9 @@ CREATE TABLE m_org (
);

CREATE TABLE m_org_closure (
descendant_oid VARCHAR(36) NOT NULL,
depthValue INTEGER NOT NULL,
ancestor_oid VARCHAR(36) NOT NULL,
PRIMARY KEY (descendant_oid, depthValue, ancestor_oid)
);

CREATE TABLE m_org_incorrect (
descendant_oid VARCHAR(36) NOT NULL,
ancestor_oid VARCHAR(36) NOT NULL,
val INTEGER NOT NULL,
PRIMARY KEY (descendant_oid, ancestor_oid)
);

Expand Down Expand Up @@ -730,10 +724,6 @@ CREATE INDEX iDescendant ON m_org_closure (descendant_oid);

CREATE INDEX iAncestor ON m_org_closure (ancestor_oid);

CREATE INDEX iAncestorDepth ON m_org_closure (ancestor_oid, depthValue);

CREATE INDEX iAncDescDepth ON m_org_closure (ancestor_oid, descendant_oid, depthValue);

ALTER TABLE m_org_closure
ADD CONSTRAINT fk_ancestor
FOREIGN KEY (ancestor_oid)
Expand Down
19 changes: 2 additions & 17 deletions config/sql/midpoint/3.0/mysql/mysql-3.0.sql
Expand Up @@ -436,20 +436,9 @@ CREATE TABLE m_org (
ENGINE =InnoDB;

CREATE TABLE m_org_closure (
id BIGINT NOT NULL,
ancestor_oid VARCHAR(36),
depthValue INTEGER,
descendant_oid VARCHAR(36),
relation VARCHAR(157),
PRIMARY KEY (id)
)
DEFAULT CHARACTER SET utf8
COLLATE utf8_bin
ENGINE =InnoDB;

CREATE TABLE m_org_incorrect (
descendant_oid VARCHAR(36) NOT NULL,
ancestor_oid VARCHAR(36) NOT NULL,
ancestor_oid VARCHAR(36) NOT NULL ,
val INTEGER NOT NULL ,
PRIMARY KEY (descendant_oid, ancestor_oid)
)
DEFAULT CHARACTER SET utf8
Expand Down Expand Up @@ -902,10 +891,6 @@ ADD CONSTRAINT fk_org
FOREIGN KEY (oid)
REFERENCES m_abstract_role (oid);

CREATE INDEX iAncestorDepth ON m_org_closure (ancestor_oid, depthValue);

CREATE INDEX iAncDescDepth ON m_org_closure (ancestor_oid, descendant_oid, depthValue);

ALTER TABLE m_org_closure
ADD INDEX fk_ancestor (ancestor_oid),
ADD CONSTRAINT fk_ancestor
Expand Down
21 changes: 8 additions & 13 deletions config/sql/midpoint/3.0/oracle/oracle-3.0.sql
Expand Up @@ -348,20 +348,19 @@ CREATE TABLE m_org (
) INITRANS 30;

CREATE TABLE m_org_closure (
id NUMBER(19, 0) NOT NULL,
ancestor_oid VARCHAR2(36 CHAR),
depthValue NUMBER(10, 0),
descendant_oid VARCHAR2(36 CHAR),
relation VARCHAR2(157 CHAR),
PRIMARY KEY (id)
) INITRANS 30;

CREATE TABLE m_org_incorrect (
descendant_oid VARCHAR2(36 CHAR) NOT NULL,
ancestor_oid VARCHAR2(36 CHAR) NOT NULL,
val NUMBER(10, 0) NOT NULL,
PRIMARY KEY (descendant_oid, ancestor_oid)
) INITRANS 30;

CREATE GLOBAL TEMPORARY TABLE m_org_closure_temp_delta (
descendant_oid VARCHAR2(36 CHAR) NOT NULL,
ancestor_oid VARCHAR2(36 CHAR) NOT NULL,
val NUMBER (10, 0) NOT NULL,
PRIMARY KEY (descendant_oid, ancestor_oid)
) ON COMMIT DELETE ROWS;

CREATE TABLE m_org_org_type (
org_oid VARCHAR2(36 CHAR) NOT NULL,
orgType VARCHAR2(255 CHAR)
Expand Down Expand Up @@ -735,10 +734,6 @@ CREATE INDEX iAncestor ON m_org_closure (ancestor_oid) INITRANS 30;

CREATE INDEX iDescendant ON m_org_closure (descendant_oid) INITRANS 30;

CREATE INDEX iAncestorDepth ON m_org_closure (ancestor_oid, depthValue) INITRANS 30;

CREATE INDEX iAncDescDepth ON m_org_closure (ancestor_oid, descendant_oid, depthValue) INITRANS 30;

ALTER TABLE m_org_closure
ADD CONSTRAINT fk_ancestor
FOREIGN KEY (ancestor_oid)
Expand Down
14 changes: 1 addition & 13 deletions config/sql/midpoint/3.0/postgresql/postgresql-3.0.sql
Expand Up @@ -345,17 +345,9 @@ CREATE TABLE m_org (
);

CREATE TABLE m_org_closure (
id INT8 NOT NULL,
ancestor_oid VARCHAR(36),
depthValue INT4,
descendant_oid VARCHAR(36),
relation VARCHAR(157),
PRIMARY KEY (id)
);

CREATE TABLE m_org_incorrect (
descendant_oid VARCHAR(36) NOT NULL,
ancestor_oid VARCHAR(36) NOT NULL,
val INT4 NOT NULL,
PRIMARY KEY (descendant_oid, ancestor_oid)
);

Expand Down Expand Up @@ -732,10 +724,6 @@ CREATE INDEX iAncestor ON m_org_closure (ancestor_oid);

CREATE INDEX iDescendant ON m_org_closure (descendant_oid);

CREATE INDEX iAncestorDepth ON m_org_closure (ancestor_oid, depthValue);

CREATE INDEX iAncDescDepth ON m_org_closure (ancestor_oid, descendant_oid, depthValue);

ALTER TABLE m_org_closure
ADD CONSTRAINT fk_ancestor
FOREIGN KEY (ancestor_oid)
Expand Down
14 changes: 1 addition & 13 deletions config/sql/midpoint/3.0/sqlserver/sqlserver-3.0.sql
Expand Up @@ -345,17 +345,9 @@ CREATE TABLE m_org (
);

CREATE TABLE m_org_closure (
id BIGINT NOT NULL,
ancestor_oid NVARCHAR(36) COLLATE database_default,
depthValue INT,
descendant_oid NVARCHAR(36) COLLATE database_default,
relation NVARCHAR(157) COLLATE database_default,
PRIMARY KEY (id)
);

CREATE TABLE m_org_incorrect (
descendant_oid NVARCHAR(36) COLLATE database_default NOT NULL,
ancestor_oid NVARCHAR(36) COLLATE database_default NOT NULL,
val INT NOT NULL,
PRIMARY KEY (descendant_oid, ancestor_oid)
);

Expand Down Expand Up @@ -732,10 +724,6 @@ CREATE INDEX iAncestor ON m_org_closure (ancestor_oid);

CREATE INDEX iDescendant ON m_org_closure (descendant_oid);

CREATE INDEX iAncestorDepth ON m_org_closure (ancestor_oid, depthValue);

CREATE INDEX iAncDescDepth ON m_org_closure (ancestor_oid, descendant_oid, depthValue);

ALTER TABLE m_org_closure
ADD CONSTRAINT fk_ancestor
FOREIGN KEY (ancestor_oid)
Expand Down
2 changes: 0 additions & 2 deletions repo/repo-sql-impl-test/sql-procedures/mysql.sql
Expand Up @@ -50,8 +50,6 @@ DETERMINISTIC
DELETE FROM m_system_configuration;
DELETE FROM m_generic_object;
DELETE FROM m_trigger;
DELETE FROM m_org_incorrect;
DELETE FROM m_org_closure;
DELETE FROM m_focus;
DELETE FROM m_security_policy;
DELETE FROM m_object;
Expand Down
2 changes: 0 additions & 2 deletions repo/repo-sql-impl-test/sql-procedures/postgresql.sql
Expand Up @@ -43,8 +43,6 @@ BEGIN
TRUNCATE TABLE m_system_configuration RESTART IDENTITY CASCADE;
TRUNCATE TABLE m_generic_object RESTART IDENTITY CASCADE;
TRUNCATE TABLE m_trigger RESTART IDENTITY CASCADE;
TRUNCATE TABLE m_org_incorrect RESTART IDENTITY CASCADE;
TRUNCATE TABLE m_org_closure RESTART IDENTITY CASCADE;
TRUNCATE TABLE m_focus RESTART IDENTITY CASCADE;
TRUNCATE TABLE m_security_policy RESTART IDENTITY CASCADE;
TRUNCATE TABLE m_object RESTART IDENTITY CASCADE;
Expand Down
2 changes: 0 additions & 2 deletions repo/repo-sql-impl-test/sql-procedures/sqlserver.sql
Expand Up @@ -54,8 +54,6 @@ AS
DELETE FROM m_system_configuration;
DELETE FROM m_generic_object;
DELETE FROM m_trigger;
DELETE FROM m_org_incorrect;
DELETE FROM m_org_closure;
DELETE FROM m_focus;
DELETE FROM m_security_policy;
DELETE FROM m_object;
Expand Down
Expand Up @@ -24,8 +24,6 @@
import com.evolveum.midpoint.prism.query.*;
import com.evolveum.midpoint.prism.util.PrismTestUtil;
import com.evolveum.midpoint.repo.sql.data.common.ROrgClosure;
import com.evolveum.midpoint.repo.sql.data.common.ROrgIncorrect;
import com.evolveum.midpoint.repo.sql.util.RUtil;
import com.evolveum.midpoint.schema.DeltaConvertor;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
Expand Down Expand Up @@ -266,11 +264,6 @@ public void test001addOrgStructObjectsIncorrect() throws Exception {
orgClosure = criteria.list();
AssertJUnit.assertEquals(4, orgClosure.size());

LOGGER.info("==============ORG INCORRECT TABLE==========");
List<ROrgIncorrect> orgIncorrect = session.createQuery("from ROrgIncorrect").list();
AssertJUnit.assertEquals(1, orgIncorrect.size());
AssertJUnit.assertEquals(ORG_F012_OID, orgIncorrect.get(0).getAncestorOid());


ObjectQuery query = new ObjectQuery();
PrismObjectDefinition<UserType> userObjectDef = prismContext.getSchemaRegistry().findObjectDefinitionByCompileTimeClass(UserType.class);
Expand Down Expand Up @@ -397,13 +390,6 @@ public void test002modifyOrgStructAddRefIncorrect() throws Exception {
AssertJUnit.assertEquals(MODIFY_ORG_INCORRECT_ADD_REF_OID, orgClosure.get(0).getDescendant().getOid());
}

Criteria criteria = session.createCriteria(ROrgIncorrect.class)
.add(Restrictions.eq("descendantOid", MODIFY_ORG_INCORRECT_ADD_REF_OID));

List<ROrgIncorrect> orgIncorrect = criteria.list();

AssertJUnit.assertEquals(1, orgIncorrect.size());
AssertJUnit.assertEquals(ORG_F012_OID, orgIncorrect.get(0).getAncestorOid());
} finally {
close(session);
}
Expand Down
Expand Up @@ -968,6 +968,32 @@ public void _test310AddRemoveUsers() throws Exception {
}
}

protected void _test390CyclePrevention() throws Exception {
OperationResult opResult = new OperationResult("===[ test390CyclePrevention ]===");
String childOid = orgsByLevels.get(1).get(0); // we hope it exists

OrgType child = repositoryService.getObject(OrgType.class, childOid, null, opResult).asObjectable();
ObjectReferenceType parentOrgRef = child.getParentOrgRef().get(0); // we hope it exists too
String parentOid = parentOrgRef.getOid();

System.out.println("Adding cycle-introducing link from " + parentOid + " to " + childOid);
List<ItemDelta> modifications = new ArrayList<>();
ObjectReferenceType ort = new ObjectReferenceType();
ort.setOid(childOid);
ort.setType(OrgType.COMPLEX_TYPE);
ItemDelta addParent = ReferenceDelta.createModificationAdd(OrgType.class, OrgType.F_PARENT_ORG_REF, prismContext, ort.asReferenceValue());
modifications.add(addParent);
try {
repositoryService.modifyObject(OrgType.class, parentOid, modifications, opResult);
throw new AssertionError("Cycle-introducing link from " + parentOid + " to " + childOid + " was successfully added!");
} catch (Exception e) {
// ok, expected
System.out.println("Got exception (as expected): " + e); // would be fine to check the kind of exception...
}

checkClosure(getVertices());
}

protected void _test400UnloadOrgStructure() throws Exception {
OperationResult opResult = new OperationResult("===[ unloadOrgStruct ]===");
long start = System.currentTimeMillis();
Expand Down
Expand Up @@ -62,6 +62,7 @@ public OrgClosureCorrectnessTest() {
@Test(enabled = true) public void test200AddRemoveLinks() throws Exception { _test200AddRemoveLinks(); }
@Test(enabled = true) public void test300AddRemoveOrgs() throws Exception { _test300AddRemoveOrgs(); }
@Test(enabled = true) public void test310AddRemoveUsers() throws Exception { _test310AddRemoveUsers(); }
@Test(enabled = true) public void test390CyclePrevention() throws Exception { _test390CyclePrevention(); }
@Test(enabled = true) public void test410RandomUnloadOrgStructure() throws Exception { _test410RandomUnloadOrgStructure(); }

@Override
Expand Down

0 comments on commit aacd8e7

Please sign in to comment.