Skip to content

Commit

Permalink
MID-8928: Updated repository schema for tasks / affects indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
tonydamage committed Aug 1, 2023
1 parent b92818a commit e086872
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 2 deletions.
35 changes: 35 additions & 0 deletions config/sql/native-new/postgres-new-upgrade.sql
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,41 @@ call apply_change(15, $aa$
ALTER TABLE m_resource ADD abstract BOOLEAN;
$aa$);

-- Task Affected Indexing (Changes to types)
call apply_change(16, $aa$
ALTER TYPE ContainerType ADD VALUE IF NOT EXISTS 'AFFECTED_RESOURCE_OBJECTS' AFTER 'ACCESS_CERTIFICATION_WORK_ITEM';
ALTER TYPE ContainerType ADD VALUE IF NOT EXISTS 'AFFECTED_OBJECTS' AFTER 'AFFECTED_RESOURCE_OBJECTS';
$aa)

-- Task Affected Indexing (tables)

call apply_change(17, $aa$
CREATE TABLE m_task_affects_resource_objects (
ownerOid UUID NOT NULL REFERENCES m_object_oid(oid) ON DELETE CASCADE,
containerType ContainerType GENERATED ALWAYS AS ('AFFECTED_RESOURCE_OBJECTS') STORED
CHECK (containerType = 'AFFECTED_RESOURCE_OBJECTS'),
objectClassId INTEGER REFERENCES m_uri(id),
resourceRefTargetOid UUID,
resourceRefTargetType ObjectType,
resourceRefRelationId INTEGER REFERENCES m_uri(id),
intent TEXT,
kind ShadowKindType,
PRIMARY KEY (ownerOid, cid)
) INHERITS(m_container);

CREATE TABLE m_task_affects_objects (
ownerOid UUID NOT NULL REFERENCES m_object_oid(oid) ON DELETE CASCADE,
containerType ContainerType GENERATED ALWAYS AS ('AFFECTED_OBJECTS') STORED
CHECK (containerType = 'AFFECTED_OBJECTS'),
type ObjectType,
archetypeRefTargetOid UUID,
archetypeRefTargetType ObjectType,
archetypeRefRelationId INTEGER REFERENCES m_uri(id),
PRIMARY KEY (ownerOid, cid)
) INHERITS(m_container);

$aa)
---
-- WRITE CHANGES ABOVE ^^
-- IMPORTANT: update apply_change number at the end of postgres-new.sql
-- to match the number used in the last change here!
Expand Down
27 changes: 26 additions & 1 deletion config/sql/native-new/postgres-new.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1308,6 +1308,31 @@ CREATE INDEX m_task_ext_idx ON m_task USING gin(ext);
CREATE INDEX m_task_fullTextInfo_idx ON m_task USING gin(fullTextInfo gin_trgm_ops);
CREATE INDEX m_task_createTimestamp_idx ON m_task (createTimestamp);
CREATE INDEX m_task_modifyTimestamp_idx ON m_task (modifyTimestamp);

CREATE TABLE m_task_affects_resource_objects (
ownerOid UUID NOT NULL REFERENCES m_object_oid(oid) ON DELETE CASCADE,
containerType ContainerType GENERATED ALWAYS AS ('AFFECTED_RESOURCE_OBJECTS') STORED
CHECK (containerType = 'AFFECTED_RESOURCE_OBJECTS'),
objectClassId INTEGER REFERENCES m_uri(id),
resourceRefTargetOid UUID,
resourceRefTargetType ObjectType,
resourceRefRelationId INTEGER REFERENCES m_uri(id),
intent TEXT,
kind ShadowKindType,
PRIMARY KEY (ownerOid, cid)
) INHERITS(m_container);

CREATE TABLE m_task_affects_objects (
ownerOid UUID NOT NULL REFERENCES m_object_oid(oid) ON DELETE CASCADE,
containerType ContainerType GENERATED ALWAYS AS ('AFFECTED_OBJECTS') STORED
CHECK (containerType = 'AFFECTED_OBJECTS'),
type ObjectType,
archetypeRefTargetOid UUID,
archetypeRefTargetType ObjectType,
archetypeRefRelationId INTEGER REFERENCES m_uri(id),
PRIMARY KEY (ownerOid, cid)
) INHERITS(m_container);

-- endregion

-- region cases
Expand Down Expand Up @@ -2087,4 +2112,4 @@ END $$;
-- This is important to avoid applying any change more than once.
-- Also update SqaleUtils.CURRENT_SCHEMA_CHANGE_NUMBER
-- repo/repo-sqale/src/main/java/com/evolveum/midpoint/repo/sqale/SqaleUtils.java
call apply_change(15, $$ SELECT 1 $$, true);
call apply_change(17, $$ SELECT 1 $$, true);
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class SqaleUtils {
*/
public static final String SCHEMA_AUDIT_CHANGE_NUMBER = "schemaAuditChangeNumber";

public static final int CURRENT_SCHEMA_CHANGE_NUMBER = 15;
public static final int CURRENT_SCHEMA_CHANGE_NUMBER = 17;

public static final int CURRENT_SCHEMA_AUDIT_CHANGE_NUMBER = 4;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (C) 2023 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.repo.sqale.qmodel.task;

import com.evolveum.midpoint.repo.sqale.qmodel.common.MContainer;
import com.evolveum.midpoint.repo.sqale.qmodel.object.MObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType;

import java.util.UUID;

public class MAffectedResourceObjects extends MContainer {

public Integer objectClassId;
public UUID resourceRefTargetOid;
public MObjectType resourceRefTargetType;
public Integer resourceRefRelationId;
public String intent;
public String tag;
public ShadowKindType kind;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2023 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.repo.sqale.qmodel.task;

import com.evolveum.midpoint.repo.sqale.qmodel.common.QContainer;
import com.evolveum.midpoint.repo.sqale.qmodel.object.MObjectType;
import com.evolveum.midpoint.repo.sqlbase.querydsl.UuidPath;

import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType;

import com.querydsl.core.types.dsl.EnumPath;
import com.querydsl.core.types.dsl.NumberPath;
import com.querydsl.core.types.dsl.StringPath;
import com.querydsl.sql.ColumnMetadata;

import java.sql.Types;

public class QAffectedResourceObjects extends QContainer<MAffectedResourceObjects, MTask> {

public static final String TABLE_NAME = " m_task_affects_resource_objects";

public static final ColumnMetadata OBJECT_CLASS_ID =
ColumnMetadata.named("objectClassId").ofType(Types.INTEGER);
public static final ColumnMetadata RESOURCE_REF_TARGET_OID =
ColumnMetadata.named("resourceRefTargetOid").ofType(UuidPath.UUID_TYPE);
public static final ColumnMetadata RESOURCE_REF_TARGET_TYPE =
ColumnMetadata.named("resourceRefTargetType").ofType(Types.OTHER);
public static final ColumnMetadata RESOURCE_REF_RELATION_ID =
ColumnMetadata.named("resourceRefRelationId").ofType(Types.INTEGER);
public static final ColumnMetadata INTENT =
ColumnMetadata.named("intent").ofType(Types.VARCHAR);
public static final ColumnMetadata KIND =
ColumnMetadata.named("kind").ofType(Types.OTHER);

public final NumberPath<Integer> objectClassId =
createInteger("objectClassId", OBJECT_CLASS_ID);
public final UuidPath resourceRefTargetOid =
createUuid("resourceRefTargetOid", RESOURCE_REF_TARGET_OID);
public final EnumPath<MObjectType> resourceRefTargetType =
createEnum("resourceRefTargetType", MObjectType.class, RESOURCE_REF_TARGET_TYPE);
public final NumberPath<Integer> resourceRefRelationId =
createInteger("resourceRefRelationId", RESOURCE_REF_RELATION_ID);
public final StringPath intent = createString("intent", INTENT);
public final EnumPath<ShadowKindType> kind = createEnum("kind", ShadowKindType.class, KIND);

public QAffectedResourceObjects(String variable) {
this(variable, DEFAULT_SCHEMA_NAME, TABLE_NAME);
}

public QAffectedResourceObjects(String variable, String schema, String table) {
super(MAffectedResourceObjects.class, variable, schema, table);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package com.evolveum.midpoint.repo.sqale.qmodel.task;

import com.evolveum.midpoint.repo.sqale.SqaleRepoContext;
import com.evolveum.midpoint.repo.sqale.qmodel.common.QContainerMapping;
import com.evolveum.midpoint.repo.sqale.qmodel.resource.QResourceMapping;
import com.evolveum.midpoint.repo.sqlbase.JdbcSession;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.BasicResourceObjectSetType;

import static com.evolveum.midpoint.xml.ns._public.common.common_3.BasicResourceObjectSetType.*;

import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;

import org.jetbrains.annotations.NotNull;

public class QAffectedResourceObjectsMapping extends QContainerMapping<BasicResourceObjectSetType,QAffectedResourceObjects,MAffectedResourceObjects,MTask> {

public static final String DEFAULT_ALIAS_NAME = "aro";

private static QAffectedResourceObjectsMapping instance;


// Explanation in class Javadoc for SqaleTableMapping
public static QAffectedResourceObjectsMapping init(@NotNull SqaleRepoContext repositoryContext) {
if (needsInitialization(instance, repositoryContext)) {
instance = new QAffectedResourceObjectsMapping(repositoryContext);
}
return instance;
}

protected QAffectedResourceObjectsMapping(@NotNull SqaleRepoContext repositoryContext) {
super(QAffectedResourceObjects.TABLE_NAME, DEFAULT_ALIAS_NAME, BasicResourceObjectSetType.class, QAffectedResourceObjects.class, repositoryContext);

addItemMapping(ShadowType.F_OBJECT_CLASS, uriMapper(q -> q.objectClassId));
addRefMapping(F_RESOURCE_REF,
q -> q.resourceRefTargetOid,
q -> q.resourceRefTargetType,
q -> q.resourceRefRelationId,
QResourceMapping::get);
addItemMapping(F_INTENT, stringMapper(q -> q.intent));
addItemMapping(F_KIND, enumMapper(q -> q.kind));
}

public static QAffectedResourceObjectsMapping get() {
return instance;
}

@Override
public MAffectedResourceObjects newRowObject() {
return new MAffectedResourceObjects();
}

@Override
public MAffectedResourceObjects newRowObject(MTask ownerRow) {
var row = super.newRowObject();
row.ownerOid = ownerRow.oid;
return row;
}

@Override
protected QAffectedResourceObjects newAliasInstance(String alias) {
return new QAffectedResourceObjects(alias);
}

@Override
public MAffectedResourceObjects insert(BasicResourceObjectSetType object, MTask ownerRow, JdbcSession jdbcSession) throws SchemaException {
MAffectedResourceObjects row = initRowObject(object, ownerRow);
setReference(object.getResourceRef(),
o -> row.resourceRefTargetOid = o ,
t -> row.resourceRefTargetType = t,
r -> row.resourceRefRelationId = r
);
row.kind = object.getKind();
row.intent = object.getIntent();
row.objectClassId = processCacheableUri(object.getObjectclass());
insert(row, jdbcSession);
return row;
}
}

0 comments on commit e086872

Please sign in to comment.