Skip to content

Commit

Permalink
repo-sqale: more mapped entities as needed for midPoint startup
Browse files Browse the repository at this point in the history
  • Loading branch information
virgo47 committed Jan 29, 2021
1 parent e50ea07 commit 6ef528f
Show file tree
Hide file tree
Showing 20 changed files with 653 additions and 171 deletions.
2 changes: 2 additions & 0 deletions repo/repo-sqale/sql/optional-codes.sql
@@ -1,4 +1,6 @@
-- @formatter:off
-- This is incorporated into new repo with m_* prefix, this c_* version is better for old repo.

-- Describes c_object.objectClassType
CREATE TABLE c_objtype (
id INT PRIMARY KEY,
Expand Down
358 changes: 223 additions & 135 deletions repo/repo-sqale/sql/pgnew-repo.sql

Large diffs are not rendered by default.

Expand Up @@ -21,13 +21,19 @@
import com.evolveum.midpoint.repo.api.SqlPerformanceMonitorsCollection;
import com.evolveum.midpoint.repo.api.SystemConfigurationChangeDispatcher;
import com.evolveum.midpoint.repo.sqale.qmapping.QNodeMapping;
import com.evolveum.midpoint.repo.sqale.qmapping.QSecurityPolicyMapping;
import com.evolveum.midpoint.repo.sqale.qmapping.QSystemConfigurationMapping;
import com.evolveum.midpoint.repo.sqale.qmapping.QTaskMapping;
import com.evolveum.midpoint.repo.sqlbase.DataSourceFactory;
import com.evolveum.midpoint.repo.sqlbase.SqlRepoContext;
import com.evolveum.midpoint.repo.sqlbase.SystemConfigurationChangeDispatcherImpl;
import com.evolveum.midpoint.repo.sqlbase.mapping.QueryModelMappingRegistry;
import com.evolveum.midpoint.repo.sqlbase.perfmon.SqlPerformanceMonitorsCollectionImpl;
import com.evolveum.midpoint.schema.SchemaHelper;
import com.evolveum.midpoint.xml.ns._public.common.common_3.NodeType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityPolicyType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;

/**
* New SQL repository related configuration.
Expand All @@ -53,6 +59,7 @@ public SqaleRepositoryConfiguration sqaleRepositoryConfiguration(
MidpointConfiguration midpointConfiguration) throws RepositoryServiceFactoryException {
// TODO remove logging change, when better way to do it for initial start is found
((ch.qos.logback.classic.Logger) LoggerFactory.getLogger("com.querydsl.sql")).setLevel(Level.DEBUG);
((ch.qos.logback.classic.Logger) LoggerFactory.getLogger("org.postgresql")).setLevel(Level.DEBUG);

return new SqaleRepositoryConfiguration(
midpointConfiguration.getConfiguration(
Expand All @@ -79,7 +86,11 @@ public SqlRepoContext sqlRepoContext(
SqaleRepositoryConfiguration repositoryConfiguration,
DataSource dataSource) {
QueryModelMappingRegistry mappingRegistry = new QueryModelMappingRegistry()
// ordered alphabetically here
.register(NodeType.COMPLEX_TYPE, QNodeMapping.INSTANCE)
.register(SecurityPolicyType.COMPLEX_TYPE, QSecurityPolicyMapping.INSTANCE)
.register(SystemConfigurationType.COMPLEX_TYPE, QSystemConfigurationMapping.INSTANCE)
.register(TaskType.COMPLEX_TYPE, QTaskMapping.INSTANCE)
.seal();

return new SqlRepoContext(repositoryConfiguration, dataSource, mappingRegistry);
Expand Down
Expand Up @@ -137,7 +137,7 @@ private <S extends ObjectType, Q extends QObject<R>, R extends MObject> S readBy
@NotNull Class<S> schemaType,
@NotNull UUID oid,
Collection<SelectorOptions<GetOperationOptions>> options)
throws SchemaException {
throws SchemaException, ObjectNotFoundException {

// context.processOptions(options); TODO how to process option, is setting of select expressions enough?

Expand All @@ -153,6 +153,12 @@ private <S extends ObjectType, Q extends QObject<R>, R extends MObject> S readBy
.where(root.oid.eq(oid))
.fetchOne();
}
if (result == null || result.get(root.fullObject) == null) {
// TODO is there a case when fullObject can be null?
String oidString = oid.toString();
throw new ObjectNotFoundException("Object of type '" + schemaType.getSimpleName()
+ "' with oid '" + oidString + "' was not found.", oidString);
}

return rootMapping.createTransformer(transformerContext, sqlRepoContext)
.toSchemaObject(result, root, options);
Expand Down
@@ -0,0 +1,15 @@
/*
* Copyright (C) 2010-2021 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.qbean;

import com.evolveum.midpoint.repo.sqale.qmodel.QSecurityPolicy;

/**
* Querydsl "row bean" type related to {@link QSecurityPolicy}.
*/
public class MSecurityPolicy extends MObject {
}
@@ -0,0 +1,15 @@
/*
* Copyright (C) 2010-2021 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.qbean;

import com.evolveum.midpoint.repo.sqale.qmodel.QSystemConfiguration;

/**
* Querydsl "row bean" type related to {@link QSystemConfiguration}.
*/
public class MSystemConfiguration extends MObject {
}
@@ -0,0 +1,19 @@
/*
* Copyright (C) 2010-2021 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.qbean;

import com.evolveum.midpoint.repo.sqale.qmodel.QTask;

/**
* Querydsl "row bean" type related to {@link QTask}.
*/
public class MTask extends MObject {

/* TODO
*/
}
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2010-2021 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.qmapping;

import com.evolveum.midpoint.repo.sqale.qbean.MSecurityPolicy;
import com.evolveum.midpoint.repo.sqale.qmodel.QSecurityPolicy;
import com.evolveum.midpoint.repo.sqlbase.SqlRepoContext;
import com.evolveum.midpoint.repo.sqlbase.SqlTransformerContext;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SecurityPolicyType;

/**
* Mapping between {@link QSecurityPolicy} and {@link SecurityPolicyType}.
*/
public class QSecurityPolicyMapping
extends QObjectMapping<SecurityPolicyType, QSecurityPolicy, MSecurityPolicy> {

public static final String DEFAULT_ALIAS_NAME = "sp";

public static final QSecurityPolicyMapping INSTANCE = new QSecurityPolicyMapping();

private QSecurityPolicyMapping() {
super(QSecurityPolicy.TABLE_NAME, DEFAULT_ALIAS_NAME,
SecurityPolicyType.class, QSecurityPolicy.class);
}

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

@Override
public ObjectSqlTransformer<SecurityPolicyType, QSecurityPolicy, MSecurityPolicy>
createTransformer(SqlTransformerContext transformerContext, SqlRepoContext sqlRepoContext) {
// no special class needed, no additional columns
return new ObjectSqlTransformer<>(transformerContext, this);
}

@Override
public MSecurityPolicy newRowObject() {
return new MSecurityPolicy();
}
}
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2010-2021 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.qmapping;

import com.evolveum.midpoint.repo.sqale.qbean.MSystemConfiguration;
import com.evolveum.midpoint.repo.sqale.qmodel.QSystemConfiguration;
import com.evolveum.midpoint.repo.sqlbase.SqlRepoContext;
import com.evolveum.midpoint.repo.sqlbase.SqlTransformerContext;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType;

/**
* Mapping between {@link QSystemConfiguration} and {@link SystemConfigurationType}.
*/
public class QSystemConfigurationMapping
extends QObjectMapping<SystemConfigurationType, QSystemConfiguration, MSystemConfiguration> {

public static final String DEFAULT_ALIAS_NAME = "sc";

public static final QSystemConfigurationMapping INSTANCE = new QSystemConfigurationMapping();

private QSystemConfigurationMapping() {
super(QSystemConfiguration.TABLE_NAME, DEFAULT_ALIAS_NAME,
SystemConfigurationType.class, QSystemConfiguration.class);
}

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

@Override
public ObjectSqlTransformer<SystemConfigurationType, QSystemConfiguration, MSystemConfiguration>
createTransformer(SqlTransformerContext transformerContext, SqlRepoContext sqlRepoContext) {
// no special class needed, no additional columns
return new ObjectSqlTransformer<>(transformerContext, this);
}

@Override
public MSystemConfiguration newRowObject() {
return new MSystemConfiguration();
}
}
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2010-2021 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.qmapping;

import com.evolveum.midpoint.repo.sqale.qbean.MTask;
import com.evolveum.midpoint.repo.sqale.qmodel.QTask;
import com.evolveum.midpoint.repo.sqlbase.SqlRepoContext;
import com.evolveum.midpoint.repo.sqlbase.SqlTransformerContext;
import com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType;

/**
* Mapping between {@link QTask} and {@link TaskType}.
*/
public class QTaskMapping
extends QObjectMapping<TaskType, QTask, MTask> {

public static final String DEFAULT_ALIAS_NAME = "t";

public static final QTaskMapping INSTANCE = new QTaskMapping();

private QTaskMapping() {
super(QTask.TABLE_NAME, DEFAULT_ALIAS_NAME,
TaskType.class, QTask.class);
}

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

@Override
public ObjectSqlTransformer<TaskType, QTask, MTask>
createTransformer(SqlTransformerContext transformerContext, SqlRepoContext sqlRepoContext) {
// no special class needed, no additional columns
return new ObjectSqlTransformer<>(transformerContext, this);
}

@Override
public MTask newRowObject() {
return new MTask();
}
}
Expand Up @@ -11,14 +11,15 @@
import com.evolveum.midpoint.repo.sqale.qbean.MObject;
import com.evolveum.midpoint.repo.sqale.qmodel.QObject;
import com.evolveum.midpoint.repo.sqlbase.mapping.QueryModelMapping;
import com.evolveum.midpoint.repo.sqlbase.querydsl.FlexibleRelationalPathBase;

/**
* Mapping superclass with common functions for {@link QObject} and non-objects (e.g. containers).
*
* @see QueryModelMapping
*/
// TODO change the type of QObject to something more abstract later (ScaleObject?)
public abstract class SqaleModelMapping<S, Q extends QObject<R>, R extends MObject>
public abstract class SqaleModelMapping<S, Q extends FlexibleRelationalPathBase<R>, R extends MObject>
extends QueryModelMapping<S, Q, R> {

protected SqaleModelMapping(
Expand Down
Expand Up @@ -16,7 +16,7 @@
import com.evolveum.midpoint.repo.sqale.qbean.MNode;

/**
* Querydsl query type for M_OBJECT table.
* Querydsl query type for {@value #TABLE_NAME} table.
*/
@SuppressWarnings("unused")
public class QNode extends QObject<MNode> {
Expand Down
Expand Up @@ -24,7 +24,7 @@
import com.evolveum.midpoint.repo.sqlbase.querydsl.UuidPath;

/**
* Querydsl query type for M_OBJECT table.
* Querydsl query type for {@value #TABLE_NAME} table.
*/
@SuppressWarnings("unused")
public abstract class QObject<T extends MObject> extends FlexibleRelationalPathBase<T> {
Expand All @@ -42,51 +42,51 @@ public abstract class QObject<T extends MObject> extends FlexibleRelationalPathB
public static final ColumnMetadata OID =
ColumnMetadata.named("oid").ofType(UUID_TYPE).notNull();
public static final ColumnMetadata EVENT_TYPE =
ColumnMetadata.named("objectTypeClass").ofType(Types.INTEGER).withSize(10).notNull();
ColumnMetadata.named("objectTypeClass").ofType(Types.INTEGER).notNull();
public static final ColumnMetadata NAME_NORM =
ColumnMetadata.named("name_norm").ofType(Types.VARCHAR).withSize(255).notNull();
public static final ColumnMetadata NAME_ORIG =
ColumnMetadata.named("name_orig").ofType(Types.VARCHAR).withSize(255).notNull();
public static final ColumnMetadata FULL_OBJECT =
ColumnMetadata.named("fullObject").ofType(Types.BINARY);
public static final ColumnMetadata CREATOR_REF_RELATION_ID =
ColumnMetadata.named("creatorRef_relation_id").ofType(Types.INTEGER).withSize(10);
ColumnMetadata.named("creatorRef_relation_id").ofType(Types.INTEGER);
public static final ColumnMetadata CREATOR_REF_TARGET_OID =
ColumnMetadata.named("creatorRef_targetOid").ofType(UUID_TYPE);
public static final ColumnMetadata CREATOR_REF_TARGET_TYPE =
ColumnMetadata.named("creatorRef_targetType").ofType(Types.INTEGER).withSize(10);
ColumnMetadata.named("creatorRef_targetType").ofType(Types.INTEGER);
public static final ColumnMetadata CREATE_CHANNEL_ID =
ColumnMetadata.named("createChannel_id").ofType(Types.INTEGER).withSize(10);
ColumnMetadata.named("createChannel_id").ofType(Types.INTEGER);
public static final ColumnMetadata CREATE_TIMESTAMP =
ColumnMetadata.named("createTimestamp").ofType(Types.TIMESTAMP_WITH_TIMEZONE).notNull();
public static final ColumnMetadata MODIFIER_REF_RELATION_ID =
ColumnMetadata.named("modifierRef_relation_id").ofType(Types.INTEGER).withSize(10);
ColumnMetadata.named("modifierRef_relation_id").ofType(Types.INTEGER);
public static final ColumnMetadata MODIFIER_REF_TARGET_OID =
ColumnMetadata.named("modifierRef_targetOid").ofType(UUID_TYPE);
public static final ColumnMetadata MODIFIER_REF_TARGET_TYPE =
ColumnMetadata.named("modifierRef_targetType").ofType(Types.INTEGER).withSize(10);
ColumnMetadata.named("modifierRef_targetType").ofType(Types.INTEGER);
public static final ColumnMetadata MODIFY_CHANNEL_ID =
ColumnMetadata.named("modifyChannel_id").ofType(Types.INTEGER).withSize(10);
ColumnMetadata.named("modifyChannel_id").ofType(Types.INTEGER);
public static final ColumnMetadata MODIFY_TIMESTAMP =
ColumnMetadata.named("modifyTimestamp").ofType(Types.TIMESTAMP_WITH_TIMEZONE).notNull();
public static final ColumnMetadata TENANT_REF_RELATION_ID =
ColumnMetadata.named("tenantRef_relation_id").ofType(Types.INTEGER).withSize(10);
ColumnMetadata.named("tenantRef_relation_id").ofType(Types.INTEGER);
public static final ColumnMetadata TENANT_REF_TARGET_OID =
ColumnMetadata.named("tenantRef_targetOid").ofType(UUID_TYPE);
public static final ColumnMetadata TENANT_REF_TARGET_TYPE =
ColumnMetadata.named("tenantRef_targetType").ofType(Types.INTEGER).withSize(10);
ColumnMetadata.named("tenantRef_targetType").ofType(Types.INTEGER);
public static final ColumnMetadata LIFECYCLE_STATE =
ColumnMetadata.named("lifecycleState").ofType(Types.VARCHAR).withSize(255);
public static final ColumnMetadata VERSION =
ColumnMetadata.named("version").ofType(Types.INTEGER).withSize(10).notNull();
ColumnMetadata.named("version").ofType(Types.INTEGER).notNull();
public static final ColumnMetadata EXT =
ColumnMetadata.named("ext").ofType(Types.BINARY);

// columns and relations
public final UuidPath oid = createUuid("oid", OID);
public final StringPath nameNorm = createString("nameNorm", NAME_NORM);
public final StringPath nameOrig = createString("nameOrig", NAME_ORIG);
public final ArrayPath<byte[], Byte> fullObject = createBlob("fullObject", FULL_OBJECT);
public final ArrayPath<byte[], Byte> fullObject = createByteArray("fullObject", FULL_OBJECT);
public final NumberPath<Integer> creatorRefRelationId =
createInteger("creatorRefRelationId", CREATOR_REF_RELATION_ID);
public final UuidPath creatorRefTargetOid =
Expand Down Expand Up @@ -115,7 +115,7 @@ public abstract class QObject<T extends MObject> extends FlexibleRelationalPathB
createInteger("tenantRefTargetType", TENANT_REF_TARGET_TYPE);
public final StringPath lifecycleState = createString("lifecycleState", LIFECYCLE_STATE);
public final NumberPath<Integer> version = createInteger("version", VERSION);
public final ArrayPath<byte[], Byte> ext = createBlob("ext", EXT); // TODO is byte[] the right type?
public final ArrayPath<byte[], Byte> ext = createByteArray("ext", EXT); // TODO is byte[] the right type?

public final PrimaryKey<T> pk = createPrimaryKey(oid);
public final ForeignKey<QQName> createChannelIdFk =
Expand Down
Expand Up @@ -19,7 +19,8 @@
import com.evolveum.midpoint.repo.sqlbase.querydsl.FlexibleRelationalPathBase;

/**
* Querydsl query type for M_QNAME table that contains repetitive URIs (e.g. channels).
* Querydsl query type for {@value #TABLE_NAME} table that contains repetitive URIs (e.g. channels).
* This entity is not registered to any schema type so it doesn't have related mapping class.
*/
public class QQName extends FlexibleRelationalPathBase<MQName> {

Expand All @@ -28,7 +29,7 @@ public class QQName extends FlexibleRelationalPathBase<MQName> {
public static final String TABLE_NAME = "m_qname";

public static final ColumnMetadata ID =
ColumnMetadata.named("id").ofType(Types.INTEGER).withSize(10).notNull();
ColumnMetadata.named("id").ofType(Types.INTEGER).notNull();
public static final ColumnMetadata URI =
ColumnMetadata.named("uri").ofType(Types.VARCHAR).withSize(255).notNull();

Expand Down

0 comments on commit 6ef528f

Please sign in to comment.