Skip to content

Commit

Permalink
sqale: Use selectExpressions in prepareUpdateContext
Browse files Browse the repository at this point in the history
  • Loading branch information
tonydamage committed Aug 30, 2021
1 parent d0dae8e commit c4a47a6
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,26 @@ private void updateMaps(MExtItem row) {
}
return extItem;
}

public @Nullable MExtItem getExtensionItem(Integer id) {
if (jdbcSessionSupplier == null) {
throw new IllegalStateException("Ext item cache was not initialized yet!");
}
MExtItem extItem = idToExtItem.get(id);
if (extItem != null) {
return extItem;
}

extItem = jdbcSessionSupplier.get()
.newQuery()
.from(QExtItem.DEFAULT)
.select(QExtItem.DEFAULT)
.where(QExtItem.DEFAULT.id.eq(id))
.fetchOne();

if (extItem != null) {
updateMaps(extItem);
}
return extItem;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,8 @@ public QName resolveUriIdToQName(Integer uriId) {
public @Nullable MExtItem getExtensionItem(@NotNull MExtItem.ItemNameKey extItemKey) {
return extItemCache.getExtensionItem(extItemKey);
}

public @Nullable MExtItem getExtensionItem(Integer id) {
return extItemCache.getExtensionItem(id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import com.google.common.base.Strings;
import com.querydsl.core.Tuple;
import com.querydsl.core.types.Path;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.sql.SQLQuery;
import org.apache.commons.lang3.Validate;
Expand Down Expand Up @@ -103,6 +104,7 @@ public class SqaleRepositoryService implements RepositoryService {

private static final int MAX_CONFLICT_WATCHERS = 10;

private final Collection<SelectorOptions<GetOperationOptions>> getForUpdateOptions;
private final SqaleRepoContext repositoryContext;
private final SqlQueryExecutor sqlQueryExecutor;
private final SqlPerformanceMonitorsCollection sqlPerformanceMonitorsCollection;
Expand All @@ -128,6 +130,11 @@ public SqaleRepositoryService(
repositoryConfiguration().getPerformanceStatisticsLevel(),
repositoryConfiguration().getPerformanceStatisticsFile());
sqlPerformanceMonitorsCollection.register(performanceMonitor);

getForUpdateOptions = SchemaService.get()
.getOperationOptionsBuilder()
.retrieve()
.build();
}

@Override
Expand Down Expand Up @@ -541,7 +548,7 @@ private <T extends ObjectType> ModifyObjectResult<T> executeModifyObject(
long opHandle = registerOperationStart(OP_MODIFY_OBJECT, type);
try {
if (updateContext == null) {
updateContext = prepareUpdateContext(jdbcSession, type, oidUuid, Collections.emptyList());
updateContext = prepareUpdateContext(jdbcSession, type, oidUuid, getForUpdateOptions);
}

PrismObject<T> prismObject = updateContext.getPrismObject();
Expand Down Expand Up @@ -573,7 +580,7 @@ RootUpdateContext<S, Q, R> prepareUpdateContext(
@NotNull Class<S> schemaType,
@NotNull UUID oid)
throws SchemaException, ObjectNotFoundException {
return prepareUpdateContext(jdbcSession, schemaType, oid, Collections.emptyList());
return prepareUpdateContext(jdbcSession, schemaType, oid, getForUpdateOptions);
}

/** Read object for update and returns update context that contains it. */
Expand All @@ -589,8 +596,13 @@ RootUpdateContext<S, Q, R> prepareUpdateContext(
repositoryContext.getMappingBySchemaType(schemaType);
QObject<R> entityPath = rootMapping.defaultAlias();

@NotNull
Path<?>[] selectExpressions = rootMapping.selectExpressions(entityPath, getOptions);
selectExpressions = Arrays.copyOf(selectExpressions, selectExpressions.length + 1);
selectExpressions[selectExpressions.length -1 ] = entityPath.containerIdSeq;

Tuple result = jdbcSession.newQuery()
.select(entityPath.oid, entityPath.fullObject, entityPath.containerIdSeq)
.select(selectExpressions)
.from(entityPath)
.where(entityPath.oid.eq(oid))
.forUpdate()
Expand Down

0 comments on commit c4a47a6

Please sign in to comment.