Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix blocking repository update many query #897

Merged
merged 1 commit into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.opendatadiscovery.oddplatform.repository;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -42,6 +43,7 @@ public abstract class AbstractCRUDRepository<R extends UpdatableRecord<R>, P> im
protected final Table<R> recordTable;
protected final Field<Long> idField;
protected final Field<String> nameField;
protected final Field<LocalDateTime> createdAtField;
protected final Field<LocalDateTime> updatedAtField;
protected final Class<P> pojoClass;

Expand Down Expand Up @@ -154,8 +156,10 @@ protected <E> List<E> bulkUpdate(final Collection<E> entities, final Class<E> en

final Table<?> table = DSL.table(result);

final List<Field<?>> nonUpdatableFields = getNonUpdatableFields();
final Map<? extends Field<?>, Field<?>> fields = Arrays
.stream(recordTable.fields())
.filter(f -> !nonUpdatableFields.contains(f))
.map(r -> Pair.of(r, table.field(r.getName())))
.collect(Collectors.toMap(Pair::getLeft, Pair::getRight));

Expand Down Expand Up @@ -196,6 +200,17 @@ protected List<Condition> listCondition(final String nameQuery) {
return StringUtils.hasLength(nameQuery) ? List.of(nameField.containsIgnoreCase(nameQuery)) : emptyList();
}

protected List<Field<?>> getNonUpdatableFields() {
final List<Field<?>> fields = new ArrayList<>();
if (idField != null) {
fields.add(idField);
}
if (createdAtField != null) {
fields.add(createdAtField);
}
return fields;
}

protected <E> List<E> bulkInsert(final Collection<E> entities, final Class<E> entityClass) {
final List<R> records = entities.stream()
.map(e -> dslContext.newRecord(recordTable, e))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ public AbstractSoftDeleteCRUDRepository(final DSLContext dslContext,
final Field<Boolean> deletedField,
final Field<String> collisionIdentifier,
final Field<String> nameField,
final Field<LocalDateTime> createdAtField,
final Field<LocalDateTime> updatedAtField,
final Class<P> pojoClass) {
this(dslContext, jooqQueryHelper, recordTable, idField, deletedField, List.of(collisionIdentifier),
nameField, updatedAtField, pojoClass);
nameField, createdAtField, updatedAtField, pojoClass);
}

public AbstractSoftDeleteCRUDRepository(final DSLContext dslContext,
Expand All @@ -47,9 +48,10 @@ public AbstractSoftDeleteCRUDRepository(final DSLContext dslContext,
final Field<Boolean> deletedField,
final List<Field<String>> collisionIdentifiers,
final Field<String> nameField,
final Field<LocalDateTime> createdAtField,
final Field<LocalDateTime> updatedAtField,
final Class<P> pojoClass) {
super(dslContext, jooqQueryHelper, recordTable, idField, nameField, updatedAtField, pojoClass);
super(dslContext, jooqQueryHelper, recordTable, idField, nameField, createdAtField, updatedAtField, pojoClass);
this.deletedField = deletedField;
this.collisionIdentifiers = List.copyOf(collisionIdentifiers);
}
Expand Down Expand Up @@ -175,6 +177,15 @@ protected List<Condition> listCondition(final String nameQuery) {
return addSoftDeleteFilter(super.listCondition(nameQuery));
}

@Override
protected List<Field<?>> getNonUpdatableFields() {
final List<Field<?>> fields = new ArrayList<>(super.getNonUpdatableFields());
if (deletedField != null) {
fields.add(deletedField);
}
return fields;
}

protected List<Condition> addSoftDeleteFilter(final List<Condition> conditions) {
final ArrayList<Condition> conditionsList = new ArrayList<>(conditions);
conditionsList.add(deletedField.isFalse());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public DataEntityRepositoryImpl(final DSLContext dslContext,
final DatasetVersionRepository datasetVersionRepository,
final TermRepository termRepository,
final LineageRepository lineageRepository) {
super(dslContext, jooqQueryHelper, DATA_ENTITY, DATA_ENTITY.ID, null,
super(dslContext, jooqQueryHelper, DATA_ENTITY, DATA_ENTITY.ID, null, null,
DATA_ENTITY.UPDATED_AT, DataEntityDimensionsDto.class);

this.jooqFTSHelper = jooqFTSHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class DataEntityTaskRunRepositoryImpl

public DataEntityTaskRunRepositoryImpl(final DSLContext dslContext, final JooqQueryHelper jooqQueryHelper) {
super(dslContext, jooqQueryHelper, DATA_ENTITY_TASK_RUN, DATA_ENTITY_TASK_RUN.ID,
DATA_ENTITY_TASK_RUN.NAME, null, DataEntityTaskRunPojo.class);
DATA_ENTITY_TASK_RUN.NAME, null, null, DataEntityTaskRunPojo.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public DatasetVersionRepositoryImpl(final DSLContext dslContext,
final JooqRecordHelper jooqRecordHelper,
final JooqQueryHelper jooqQueryHelper) {
super(dslContext, jooqQueryHelper, DATASET_VERSION, DATASET_VERSION.ID, null,
null, DatasetVersionPojo.class);
DATASET_VERSION.CREATED_AT, null, DatasetVersionPojo.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class MetadataFieldRepositoryImpl
public MetadataFieldRepositoryImpl(final DSLContext dslContext, final JooqQueryHelper jooqQueryHelper) {
super(dslContext, jooqQueryHelper, METADATA_FIELD, METADATA_FIELD.ID, METADATA_FIELD.IS_DELETED,
List.of(METADATA_FIELD.NAME, METADATA_FIELD.TYPE),
METADATA_FIELD.NAME, null, MetadataFieldPojo.class);
METADATA_FIELD.NAME, null, null, MetadataFieldPojo.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class MetadataFieldValueRepositoryImpl

public MetadataFieldValueRepositoryImpl(final DSLContext dslContext, final JooqQueryHelper jooqQueryHelper) {
super(dslContext, jooqQueryHelper, METADATA_FIELD_VALUE, null, null,
null, MetadataFieldValuePojo.class);
null, null, MetadataFieldValuePojo.class);
}

@Override
Expand Down