Skip to content

Commit

Permalink
SqaleTransformerBase: mapper fields pushed one level lower
Browse files Browse the repository at this point in the history
This provides more specific type information where needed.
  • Loading branch information
virgo47 committed Apr 20, 2021
1 parent 322048f commit 702ecdb
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 13 deletions.
Expand Up @@ -44,7 +44,6 @@ public abstract class SqaleTransformerBase<S, Q extends FlexibleRelationalPathBa
protected final Logger logger = LoggerFactory.getLogger(getClass());

protected final SqaleTransformerSupport transformerSupport;
protected final QueryTableMapping<S, Q, R> mapping;

/**
* Constructor uses {@link SqlTransformerSupport} type even when it really is
Expand All @@ -53,16 +52,11 @@ public abstract class SqaleTransformerBase<S, Q extends FlexibleRelationalPathBa
* (Alternative is to parametrize {@link QueryTableMapping} with various {@link SqlTransformer}
* types which is not convenient at all. This little downcast is low price to pay.)
*/
protected SqaleTransformerBase(
SqlTransformerSupport transformerSupport,
QueryTableMapping<S, Q, R> mapping) {
protected SqaleTransformerBase(SqlTransformerSupport transformerSupport) {
this.transformerSupport = (SqaleTransformerSupport) transformerSupport;
this.mapping = mapping;
}

public QueryTableMapping<S, Q, R> mapping() {
return mapping;
}
protected abstract QueryTableMapping<S, Q, R> mapping();

@Override
public S toSchemaObject(R row) {
Expand Down
Expand Up @@ -23,10 +23,15 @@ public class ContainerSqlTransformer

public ContainerSqlTransformer(
SqlTransformerSupport transformerSupport, QContainerMapping<S, Q, R> mapping) {
super(transformerSupport, mapping);
super(transformerSupport);
this.mapping = mapping;
}

@Override
protected QContainerMapping<S, Q, R> mapping() {
return mapping;
}

/**
* This creates the right type of object and fills in the base {@link MContainer} attributes.
*/
Expand Down
Expand Up @@ -40,10 +40,15 @@ public class ObjectSqlTransformer<S extends ObjectType, Q extends QObject<R>, R
public ObjectSqlTransformer(
SqlTransformerSupport transformerSupport,
QObjectMapping<S, Q, R> mapping) {
super(transformerSupport, mapping);
super(transformerSupport);
this.mapping = mapping;
}

@Override
protected QObjectMapping<S, Q, R> mapping() {
return mapping;
}

@Override
public S toSchemaObject(Tuple row, Q entityPath,
Collection<SelectorOptions<GetOperationOptions>> options)
Expand All @@ -66,7 +71,7 @@ public S toSchemaObject(Tuple row, Q entityPath,
// This is a serious thing. We have corrupted XML in the repo. This may happen even
// during system init. We want really loud and detailed error here.
logger.error("Couldn't parse object {} {}: {}: {}\n{}",
mapping().schemaType().getSimpleName(), row.get(entityPath.oid),
mapping.schemaType().getSimpleName(), row.get(entityPath.oid),
e.getClass().getName(), e.getMessage(), serializedForm, e);
throw e;
}
Expand All @@ -88,7 +93,7 @@ public S toSchemaObject(Tuple row, Q entityPath,
@SuppressWarnings("DuplicatedCode") // see comment for metadata lower
@NotNull
public R toRowObjectWithoutFullObject(S schemaObject, JdbcSession jdbcSession) {
R row = mapping().newRowObject();
R row = mapping.newRowObject();

row.oid = oidToUUid(schemaObject.getOid());
// objectType MUST be left NULL, it's determined by PG
Expand Down
Expand Up @@ -20,10 +20,15 @@ public class ReferenceSqlTransformer<Q extends QReference<R>, R extends MReferen

public ReferenceSqlTransformer(
SqlTransformerSupport transformerSupport, QReferenceMapping<Q, R, ?, OR> mapping) {
super(transformerSupport, mapping);
super(transformerSupport);
this.mapping = mapping;
}

@Override
protected QReferenceMapping<Q, R, ?, OR> mapping() {
return mapping;
}

/**
* There is no need to override this, only reference creation is different and that is covered
* by {@link QReferenceMapping#newRowObject(Object)} including setting FK columns.
Expand Down

0 comments on commit 702ecdb

Please sign in to comment.