Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
repo-sqale: first success in applying deltas to nested mappings
- Loading branch information
Showing
26 changed files
with
242 additions
and
92 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
91 changes: 91 additions & 0 deletions
91
...le/src/main/java/com/evolveum/midpoint/repo/sqale/delta/DelegatingItemDeltaProcessor.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,91 @@ | ||
/* | ||
* 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 javax.xml.namespace.QName; | ||
|
||
import com.evolveum.midpoint.prism.delta.ItemDelta; | ||
import com.evolveum.midpoint.prism.path.ItemName; | ||
import com.evolveum.midpoint.prism.path.ItemPath; | ||
import com.evolveum.midpoint.repo.sqale.SqaleUpdateContext; | ||
import com.evolveum.midpoint.repo.sqale.mapping.SqaleItemRelationResolver; | ||
import com.evolveum.midpoint.repo.sqale.mapping.SqaleItemSqlMapper; | ||
import com.evolveum.midpoint.repo.sqlbase.QueryException; | ||
import com.evolveum.midpoint.repo.sqlbase.RepositoryException; | ||
import com.evolveum.midpoint.repo.sqlbase.mapping.ItemRelationResolver; | ||
import com.evolveum.midpoint.repo.sqlbase.mapping.ItemSqlMapper; | ||
import com.evolveum.midpoint.repo.sqlbase.mapping.QueryModelMapping; | ||
|
||
/** | ||
* This is default item delta processor that decides what to do with the modification. | ||
* If the modification has multi-part name then it resolves it to the last component first. | ||
* | ||
* *Implementation note:* | ||
* This is a separate component used by {@link SqaleUpdateContext} but while the context is | ||
* one for all modifications this is instantiated for each modification (or even path resolution | ||
* step) which allows for state changes that don't affect processing of another modification. | ||
*/ | ||
public class DelegatingItemDeltaProcessor implements ItemDeltaProcessor { | ||
|
||
/** Query context and mapping is not final as it can change during complex path resolution. */ | ||
private SqaleUpdateContext<?, ?, ?> context; | ||
private QueryModelMapping<?, ?, ?> mapping; | ||
|
||
public DelegatingItemDeltaProcessor( | ||
SqaleUpdateContext<?, ?, ?> context, QueryModelMapping<?, ?, ?> mapping) { | ||
this.context = context; | ||
this.mapping = mapping; | ||
} | ||
|
||
@Override | ||
public void process(ItemDelta<?, ?> modification) throws RepositoryException { | ||
// TODO will we need various types of SqaleUpdateContext too? | ||
// E.g. AccessCertificationWorkItemType is container inside container and to add/delete | ||
// it we need to anchor the context in its parent, not in absolute root of update context. | ||
// Similar situation is adding multi-value references to containers like assignments. | ||
|
||
QName itemName = resolvePath(modification.getPath()); | ||
if (itemName == null) { | ||
// This may indicate forgotten mapping, but normally it means that the item is simply | ||
// not externalized and there is nothing to, update is only in fullObject. | ||
return; | ||
} | ||
|
||
ItemSqlMapper itemSqlMapper = mapping.getItemMapper(itemName); | ||
if (itemSqlMapper instanceof SqaleItemSqlMapper) { | ||
((SqaleItemSqlMapper) itemSqlMapper) | ||
.createItemDeltaProcessor(context) | ||
.process(modification); | ||
} else if (itemSqlMapper != null) { | ||
// This should not happen, all the Sqale mappings should use SqaleItemSqlMapper. | ||
throw new IllegalArgumentException("No delta processor available for " + itemName | ||
+ " in mapping " + mapping + "! (Only query mapping is available.)"); | ||
} | ||
|
||
// If the mapper is null, the item is not indexed ("externalized") attribute, no action. | ||
// It's a similar case like the fast return after resolving the path. | ||
} | ||
|
||
private QName resolvePath(ItemPath path) throws QueryException { | ||
while (!path.isSingleName()) { | ||
ItemName firstName = path.firstName(); | ||
path = path.rest(); | ||
|
||
ItemRelationResolver relationResolver = mapping.relationResolver(firstName); | ||
if (!(relationResolver instanceof SqaleItemRelationResolver)) { | ||
// Again, programmers fault. | ||
throw new IllegalArgumentException("Relation resolver for " + firstName | ||
+ " in mapping " + mapping + " does not support delta modifications!"); | ||
} | ||
SqaleItemRelationResolver resolver = (SqaleItemRelationResolver) relationResolver; | ||
SqaleItemRelationResolver.UpdateResolutionResult resolution = resolver.resolve(context); | ||
context = resolution.context; | ||
mapping = resolution.mapping; | ||
} | ||
return path.asSingleName(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
repo/repo-sqale/src/main/java/com/evolveum/midpoint/repo/sqale/delta/ItemDeltaProcessor.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,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.delta; | ||
|
||
import com.evolveum.midpoint.prism.delta.ItemDelta; | ||
import com.evolveum.midpoint.repo.sqlbase.RepositoryException; | ||
|
||
public interface ItemDeltaProcessor { | ||
|
||
void process(ItemDelta<?, ?> modification) throws RepositoryException; | ||
} |
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
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
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
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
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
37 changes: 37 additions & 0 deletions
37
...ale/src/main/java/com/evolveum/midpoint/repo/sqale/mapping/SqaleItemRelationResolver.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,37 @@ | ||
/* | ||
* 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.mapping; | ||
|
||
import com.evolveum.midpoint.repo.sqale.SqaleUpdateContext; | ||
import com.evolveum.midpoint.repo.sqlbase.mapping.ItemRelationResolver; | ||
import com.evolveum.midpoint.repo.sqlbase.mapping.QueryModelMapping; | ||
|
||
/** | ||
* Extension of {@link ItemRelationResolver}, this is a common contract for resolver | ||
* that helps with navigating over complex (non-single) item paths for both query | ||
* and application of delta modification. | ||
*/ | ||
public interface SqaleItemRelationResolver extends ItemRelationResolver { | ||
|
||
/** | ||
* Resolves current query context to {@link ResolutionResult} with new context and mapping. | ||
* The information about the resolved item is captured in the instance resolver already | ||
* in a manner that is specific for various types of resolution (JOIN or nested mapping). | ||
*/ | ||
UpdateResolutionResult resolve(SqaleUpdateContext<?, ?, ?> context); | ||
|
||
class UpdateResolutionResult { | ||
public final SqaleUpdateContext<?, ?, ?> context; // something update related | ||
public final QueryModelMapping<?, ?, ?> mapping; | ||
|
||
public UpdateResolutionResult( | ||
SqaleUpdateContext<?, ?, ?> context, QueryModelMapping<?, ?, ?> mapping) { | ||
this.context = context; | ||
this.mapping = mapping; | ||
} | ||
} | ||
} |
Oops, something went wrong.