Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
19 changed files
with
280 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...o-sqale/src/main/java/com/evolveum/midpoint/repo/sqale/delta/ItemDeltaValueProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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.delta; | ||
|
||
import java.util.Collection; | ||
|
||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Applies item delta values to an item and arranges necessary SQL changes using update context. | ||
* This typically means adding set clauses to the update but can also mean adding rows | ||
* for containers, etc. | ||
* This kind of item delta processor does not resolve multi-part item paths, see other | ||
* subclasses of {@link ItemDeltaProcessor} for that. | ||
* | ||
* @param <T> expected type of the real value for the modification (after optional conversion) | ||
*/ | ||
public interface ItemDeltaValueProcessor<T> extends ItemDeltaProcessor { | ||
|
||
/** Default conversion for one value is a mere type cast, override as necessary. */ | ||
@Nullable | ||
default T convertRealValue(Object realValue) { | ||
//noinspection unchecked | ||
return (T) realValue; | ||
} | ||
|
||
/** | ||
* Sets the database columns to reflect the provided real values (may be conversion). | ||
* This is a general case covering both multi-value and single-value items. | ||
*/ | ||
void setRealValues(Collection<?> value); | ||
|
||
/** Resets the database columns, exposed for the needs of container processing. */ | ||
void delete(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
.../main/java/com/evolveum/midpoint/repo/sqale/delta/item/ItemDeltaSingleValueProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* 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.delta.item; | ||
|
||
import java.util.Collection; | ||
|
||
import com.evolveum.midpoint.prism.PrismValue; | ||
import com.evolveum.midpoint.prism.delta.ItemDelta; | ||
import com.evolveum.midpoint.repo.sqale.SqaleUpdateContext; | ||
import com.evolveum.midpoint.repo.sqale.delta.ItemDeltaValueProcessor; | ||
import com.evolveum.midpoint.repo.sqlbase.RepositoryException; | ||
|
||
/** | ||
* Applies single item delta value to an item. | ||
* This class implements {@link #setRealValues} (for multiple values) and requires | ||
* {@link #setValue} (for a single value) to be implemented by the subclasses. | ||
*/ | ||
public abstract class ItemDeltaSingleValueProcessor<T> implements ItemDeltaValueProcessor<T> { | ||
|
||
protected final SqaleUpdateContext<?, ?, ?> context; | ||
|
||
protected ItemDeltaSingleValueProcessor(SqaleUpdateContext<?, ?, ?> context) { | ||
this.context = context; | ||
} | ||
|
||
@Override | ||
public void process(ItemDelta<?, ?> modification) throws RepositoryException { | ||
T value = getAnyValue(modification); | ||
|
||
if (modification.isDelete() || value == null) { | ||
// Repo does not check deleted value for single-value properties. | ||
// This should be handled already by narrowing the modifications. | ||
delete(); | ||
} else { | ||
// We treat add and replace the same way for single-value properties. | ||
setValue(value); | ||
} | ||
} | ||
|
||
/** | ||
* Often the single real value is necessary, optionally converted using | ||
* {@link #convertRealValue(Object)} to get expected type. | ||
* Either method can be overridden or not used at all depending on the complexity | ||
* of the concrete delta processor. | ||
*/ | ||
protected T getAnyValue(ItemDelta<?, ?> modification) { | ||
PrismValue anyValue = modification.getAnyValue(); | ||
return anyValue != null ? convertRealValue(anyValue.getRealValue()) : null; | ||
} | ||
|
||
/** Sets the database columns to reflect the provided value (converted if necessary). */ | ||
public abstract void setValue(T value); | ||
|
||
@Override | ||
public void setRealValues(Collection<?> values) { | ||
if (values.size() > 1) { | ||
throw new IllegalArgumentException( | ||
"Multiple values when single value is expected: " + values); | ||
} | ||
|
||
setValue(values.isEmpty() ? null : convertRealValue(values.iterator().next())); | ||
} | ||
} |
57 changes: 0 additions & 57 deletions
57
...le/src/main/java/com/evolveum/midpoint/repo/sqale/delta/item/ItemDeltaValueProcessor.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.