Skip to content

Commit

Permalink
sqale: Created common superclass for containers with full objects
Browse files Browse the repository at this point in the history
  • Loading branch information
tonydamage committed Nov 22, 2023
1 parent 94e5649 commit 2e5e147
Show file tree
Hide file tree
Showing 18 changed files with 164 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@

import com.evolveum.midpoint.repo.sqale.jsonb.Jsonb;
import com.evolveum.midpoint.repo.sqale.qmodel.common.MContainer;
import com.evolveum.midpoint.repo.sqale.qmodel.common.MContainerWithFullObject;
import com.evolveum.midpoint.repo.sqale.qmodel.object.MObjectType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TimeIntervalStatusType;

/**
* Querydsl "row bean" type related to {@link QAssignment}.
*/
public class MAssignment extends MContainer {
public class MAssignment extends MContainerWithFullObject {

public MObjectType ownerType;
public String lifecycleState;
Expand Down Expand Up @@ -62,5 +63,4 @@ public class MAssignment extends MContainer {
public Integer modifyChannelId;
public Instant modifyTimestamp;

public byte[] fullObject;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.sql.Types;
import java.time.Instant;

import com.evolveum.midpoint.repo.sqale.qmodel.common.QContainerWithFullObject;

import com.querydsl.core.types.dsl.*;
import com.querydsl.sql.ColumnMetadata;

Expand All @@ -26,7 +28,7 @@
* Querydsl query type for {@value #TABLE_NAME} table.
*/
@SuppressWarnings("unused")
public class QAssignment<OR extends MObject> extends QContainer<MAssignment, OR> {
public class QAssignment<OR extends MObject> extends QContainerWithFullObject<MAssignment, OR> {

private static final long serialVersionUID = 7068031681581618788L;

Expand Down Expand Up @@ -117,8 +119,6 @@ public class QAssignment<OR extends MObject> extends QContainer<MAssignment, OR>
public static final ColumnMetadata MODIFY_TIMESTAMP =
ColumnMetadata.named("modifyTimestamp").ofType(Types.TIMESTAMP_WITH_TIMEZONE);

public static final ColumnMetadata FULL_OBJECT =
ColumnMetadata.named("fullObject").ofType(Types.BINARY);

// attributes

Expand Down Expand Up @@ -196,7 +196,6 @@ public class QAssignment<OR extends MObject> extends QContainer<MAssignment, OR>
public final DateTimePath<Instant> modifyTimestamp =
createInstant("modifyTimestamp", MODIFY_TIMESTAMP);

public final ArrayPath<byte[], Byte> fullObject = createByteArray("fullObject", FULL_OBJECT);

public QAssignment(String variable) {
this(variable, DEFAULT_SCHEMA_NAME, TABLE_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import com.evolveum.midpoint.prism.PrismContainer;
import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.repo.sqale.qmodel.common.QContainerWithFullObjectMapping;
import com.evolveum.midpoint.repo.sqale.update.SqaleUpdateContext;
import com.evolveum.midpoint.util.exception.SchemaException;

Expand Down Expand Up @@ -44,7 +46,7 @@
* @param <OR> type of the owner row
*/
public class QAssignmentMapping<OR extends MObject>
extends QContainerMapping<AssignmentType, QAssignment<OR>, MAssignment, OR> {
extends QContainerWithFullObjectMapping<AssignmentType, QAssignment<OR>, MAssignment, OR> {

public static final String DEFAULT_ALIAS_NAME = "a";

Expand Down Expand Up @@ -87,6 +89,7 @@ public static <OR extends MObject> QAssignmentMapping<OR> getInducementMapping()
}

private final MContainerType containerType;
private final ItemPath path;

// We can't declare Class<QAssignment<OR>>.class, so we cheat a bit.
@SuppressWarnings({ "unchecked", "rawtypes" })
Expand All @@ -96,6 +99,7 @@ private QAssignmentMapping(
super(QAssignment.TABLE_NAME, DEFAULT_ALIAS_NAME,
AssignmentType.class, (Class) QAssignment.class, repositoryContext);
this.containerType = containerType;
this.path = MContainerType.INDUCEMENT == containerType ? AbstractRoleType.F_INDUCEMENT : AbstractRoleType.F_ASSIGNMENT;

addRelationResolver(PrismConstants.T_PARENT,
// mapping supplier is used to avoid cycles in the initialization code
Expand Down Expand Up @@ -212,11 +216,7 @@ public MAssignment newRowObject(OR ownerRow) {
@SuppressWarnings("DuplicatedCode")
@Override
public MAssignment insert(AssignmentType assignment, OR ownerRow, JdbcSession jdbcSession) throws SchemaException {
MAssignment row = initRowObject(assignment, ownerRow);

// Insert full Object here
row.fullObject = createFullObject(assignment);

MAssignment row = initRowObjectWithFullObject(assignment, ownerRow);

row.lifecycleState = assignment.getLifecycleState();
row.orderValue = assignment.getOrder();
Expand Down Expand Up @@ -290,15 +290,7 @@ public MAssignment insert(AssignmentType assignment, OR ownerRow, JdbcSession jd
}

@Override
public void afterModify(SqaleUpdateContext<AssignmentType, QAssignment<OR>, MAssignment> updateContext) throws SchemaException {
// insert fullObject here
PrismContainer<AssignmentType> identityContainer =
updateContext.findValueOrItem(FocusType.F_ASSIGNMENT);
// row in context already knows its CID
PrismContainerValue<AssignmentType> pcv = identityContainer.findValue(updateContext.row().cid);
byte[] fullObject = createFullObject(pcv.asContainerable());
updateContext.set(updateContext.entityPath().fullObject, fullObject);


protected ItemPath getContainerPath() {
return path;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.evolveum.midpoint.repo.sqale.qmodel.common;

public class MContainerWithFullObject extends MContainer {

public byte[] fullObject;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.evolveum.midpoint.repo.sqale.qmodel.common;

import com.querydsl.core.types.dsl.ArrayPath;
import com.querydsl.sql.ColumnMetadata;

import java.sql.Types;

public class QContainerWithFullObject<R extends MContainerWithFullObject, OR> extends QContainer<R, OR> {


public static final ColumnMetadata FULL_OBJECT =
ColumnMetadata.named("fullObject").ofType(Types.BINARY);

public final ArrayPath<byte[], Byte> fullObject = createByteArray("fullObject", FULL_OBJECT);

public QContainerWithFullObject(Class<? extends R> type, String variable, String schema, String table) {
super(type, variable, schema, table);
}

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

import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.PrismContainer;
import com.evolveum.midpoint.prism.PrismContainerValue;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.repo.sqale.SqaleRepoContext;

import com.evolveum.midpoint.repo.sqale.qmodel.assignment.MAssignment;
import com.evolveum.midpoint.repo.sqale.update.SqaleUpdateContext;
import com.evolveum.midpoint.util.exception.SchemaException;

import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;

import org.jetbrains.annotations.NotNull;

public abstract class QContainerWithFullObjectMapping<S extends Containerable, Q extends QContainerWithFullObject<R, OR>, R extends MContainerWithFullObject, OR> extends QContainerMapping<S,Q,R,OR> {

protected QContainerWithFullObjectMapping(@NotNull String tableName, @NotNull String defaultAliasName, @NotNull Class<S> schemaType, @NotNull Class<Q> queryType, @NotNull SqaleRepoContext repositoryContext) {
super(tableName, defaultAliasName, schemaType, queryType, repositoryContext);
}

abstract protected ItemPath getContainerPath();

public R initRowObjectWithFullObject(S schemaObject, OR ownerRow) throws SchemaException {
R row = super.initRowObject(schemaObject, ownerRow);
row.fullObject = createFullObject(schemaObject);
return row;
}

@Override
public void afterModify(SqaleUpdateContext<S, Q, R> updateContext) throws SchemaException {
super.afterModify(updateContext);
// insert fullObject here
PrismContainer<AssignmentType> identityContainer =
updateContext.findValueOrItem(getContainerPath());
// row in context already knows its CID
PrismContainerValue<AssignmentType> pcv = identityContainer.findValue(updateContext.row().cid);
byte[] fullObject = createFullObject(pcv.asContainerable());
updateContext.set(updateContext.entityPath().fullObject, fullObject);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
import java.util.UUID;

import com.evolveum.midpoint.repo.sqale.qmodel.common.MContainer;
import com.evolveum.midpoint.repo.sqale.qmodel.common.MContainerWithFullObject;
import com.evolveum.midpoint.repo.sqale.qmodel.object.QOperationExecution;

/**
* Querydsl "row bean" type related to {@link QOperationExecution}.
*/
public class MFocusIdentity extends MContainer {
public class MFocusIdentity extends MContainerWithFullObject {

public byte[] fullObject; // serialized container value, without items
public UUID sourceResourceRefTargetOid; // target type and relation is implied/fixed
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import java.sql.Types;

import com.evolveum.midpoint.repo.sqale.qmodel.common.QContainerWithFullObject;

import com.querydsl.core.types.dsl.ArrayPath;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.sql.ColumnMetadata;
Expand All @@ -19,7 +21,7 @@
* Querydsl query type for {@value #TABLE_NAME} table.
*/
@SuppressWarnings("unused")
public class QFocusIdentity<OR extends MFocus> extends QContainer<MFocusIdentity, OR> {
public class QFocusIdentity<OR extends MFocus> extends QContainerWithFullObject<MFocusIdentity, OR> {

private static final long serialVersionUID = -6856661540710930040L;

Expand All @@ -32,14 +34,11 @@ public class QFocusIdentity<OR extends MFocus> extends QContainer<MFocusIdentity

public static final String TABLE_NAME = "m_focus_identity";

public static final ColumnMetadata FULL_OBJECT =
ColumnMetadata.named("fullObject").ofType(Types.BINARY);
public static final ColumnMetadata SOURCE_RESOURCE_REF_TARGET_OID =
ColumnMetadata.named("sourceResourceRefTargetOid").ofType(UuidPath.UUID_TYPE);

// attributes

public final ArrayPath<byte[], Byte> fullObject = createByteArray("fullObject", FULL_OBJECT);
public final UuidPath sourceResourceRefTargetOid =
createUuid("sourceResourceRefTargetOid", SOURCE_RESOURCE_REF_TARGET_OID);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.util.Objects;
import java.util.UUID;

import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.repo.sqale.qmodel.common.QContainerWithFullObjectMapping;
import com.evolveum.midpoint.repo.sqale.qmodel.resource.QResourceMapping;

import org.jetbrains.annotations.NotNull;
Expand All @@ -32,10 +34,11 @@
* @param <OR> type of the owner row
*/
public class QFocusIdentityMapping<OR extends MFocus>
extends QContainerMapping<FocusIdentityType, QFocusIdentity<OR>, MFocusIdentity, OR> {
extends QContainerWithFullObjectMapping<FocusIdentityType, QFocusIdentity<OR>, MFocusIdentity, OR> {

public static final String DEFAULT_ALIAS_NAME = "fi";

public static final ItemPath PATH = ItemPath.create(FocusType.F_IDENTITIES, FocusIdentitiesType.F_IDENTITY);
private static QFocusIdentityMapping<?> instance;

public static <OR extends MFocus> QFocusIdentityMapping<OR> init(
Expand Down Expand Up @@ -90,8 +93,7 @@ public MFocusIdentity newRowObject(OR ownerRow) {
@Override
public MFocusIdentity insert(
FocusIdentityType schemaObject, OR ownerRow, JdbcSession jdbcSession) throws SchemaException {
MFocusIdentity row = initRowObject(schemaObject, ownerRow);
row.fullObject = createFullObject(schemaObject);
MFocusIdentity row = initRowObjectWithFullObject(schemaObject, ownerRow);

FocusIdentitySourceType source = schemaObject.getSource();
if (source != null) {
Expand All @@ -105,6 +107,11 @@ public MFocusIdentity insert(
return row;
}

@Override
protected ItemPath getContainerPath() {
return PATH;
}

@Override
public FocusIdentityType toSchemaObject(MFocusIdentity row) throws SchemaException {
return parseSchemaObject(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
import java.util.UUID;

import com.evolveum.midpoint.repo.sqale.qmodel.common.MContainer;
import com.evolveum.midpoint.repo.sqale.qmodel.common.MContainerWithFullObject;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationExecutionRecordTypeType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultStatusType;

/**
* Querydsl "row bean" type related to {@link QOperationExecution}.
*/
public class MOperationExecution extends MContainer {
public class MOperationExecution extends MContainerWithFullObject {

public OperationResultStatusType status;
public OperationExecutionRecordTypeType recordType;
Expand All @@ -28,5 +29,4 @@ public class MOperationExecution extends MContainer {
public Integer taskRefRelationId;
public Instant timestamp;

public byte[] fullObject;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.sql.Types;
import java.time.Instant;

import com.evolveum.midpoint.repo.sqale.qmodel.common.QContainerWithFullObject;

import com.querydsl.core.types.dsl.*;
import com.querydsl.sql.ColumnMetadata;

Expand All @@ -21,7 +23,7 @@
* Querydsl query type for {@value #TABLE_NAME} table.
*/
@SuppressWarnings("unused")
public class QOperationExecution<OR extends MObject> extends QContainer<MOperationExecution, OR> {
public class QOperationExecution<OR extends MObject> extends QContainerWithFullObject<MOperationExecution, OR> {

private static final long serialVersionUID = -6856661540710930040L;

Expand Down Expand Up @@ -53,9 +55,6 @@ public class QOperationExecution<OR extends MObject> extends QContainer<MOperati
ColumnMetadata.named("taskRefRelationId").ofType(Types.INTEGER);
public static final ColumnMetadata TIMESTAMP =
ColumnMetadata.named("timestamp").ofType(Types.TIMESTAMP_WITH_TIMEZONE);
public static final ColumnMetadata FULL_OBJECT =
ColumnMetadata.named("fullObject").ofType(Types.BINARY);


// attributes

Expand All @@ -78,8 +77,6 @@ public class QOperationExecution<OR extends MObject> extends QContainer<MOperati
public final DateTimePath<Instant> timestamp =
createInstant("timestamp", TIMESTAMP);

public final ArrayPath<byte[], Byte> fullObject = createByteArray("fullObject", FULL_OBJECT);

public QOperationExecution(String variable) {
this(variable, DEFAULT_SCHEMA_NAME, TABLE_NAME);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
import java.util.*;
import java.util.stream.Collectors;

import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.repo.sqale.qmodel.assignment.MAssignment;
import com.evolveum.midpoint.repo.sqale.qmodel.assignment.QAssignment;
import com.evolveum.midpoint.repo.sqale.qmodel.common.QContainerWithFullObjectMapping;
import com.evolveum.midpoint.repo.sqale.update.SqaleUpdateContext;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType;

import com.querydsl.core.Tuple;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -39,7 +47,7 @@
* @param <OR> type of the owner row
*/
public class QOperationExecutionMapping<OR extends MObject>
extends QContainerMapping<OperationExecutionType, QOperationExecution<OR>, MOperationExecution, OR> {
extends QContainerWithFullObjectMapping<OperationExecutionType, QOperationExecution<OR>, MOperationExecution, OR> {

public static final String DEFAULT_ALIAS_NAME = "opex";

Expand Down Expand Up @@ -105,8 +113,8 @@ public MOperationExecution newRowObject(OR ownerRow) {

@Override
public MOperationExecution insert(
OperationExecutionType schemaObject, OR ownerRow, JdbcSession jdbcSession) {
MOperationExecution row = initRowObject(schemaObject, ownerRow);
OperationExecutionType schemaObject, OR ownerRow, JdbcSession jdbcSession) throws SchemaException {
MOperationExecution row = initRowObjectWithFullObject(schemaObject, ownerRow);

row.status = schemaObject.getStatus();
row.recordType = schemaObject.getRecordType();
Expand Down Expand Up @@ -186,4 +194,9 @@ public OperationExecutionType transform(Tuple rowTuple,
}
};
}

@Override
protected ItemPath getContainerPath() {
return ObjectType.F_OPERATION_EXECUTION;
}
}

0 comments on commit 2e5e147

Please sign in to comment.