Search in sources :

Example 6 with MExtItem

use of com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem in project midpoint by Evolveum.

the class ExtItemCache method resolveExtensionItem.

@NotNull
public synchronized MExtItem resolveExtensionItem(@NotNull MExtItem.Key extItemKey) {
    if (jdbcSessionSupplier == null) {
        throw new IllegalStateException("Ext item cache was not initialized yet!");
    }
    MExtItem extItem = keyToExtItem.get(extItemKey);
    if (extItem != null) {
        return extItem;
    }
    QExtItem ei = QExtItem.DEFAULT;
    try (JdbcSession jdbcSession = jdbcSessionSupplier.get().startTransaction()) {
        Integer id = jdbcSession.newInsert(ei).set(ei.itemName, extItemKey.itemName).set(ei.valueType, extItemKey.valueType).set(ei.holderType, extItemKey.holderType).set(ei.cardinality, extItemKey.cardinality).executeWithKey(ei.id);
        jdbcSession.commit();
        extItem = MExtItem.of(id, extItemKey);
        updateMaps(extItem);
    } catch (RuntimeException e) {
        if (SqaleUtils.isUniqueConstraintViolation(e)) {
            extItem = retrieveFromDb(extItemKey);
        } else {
            throw e;
        }
    }
    LOGGER.debug("Ext item cache row inserted: {}", extItem);
    return extItem;
}
Also used : JdbcSession(com.evolveum.midpoint.repo.sqlbase.JdbcSession) MExtItem(com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem) QExtItem(com.evolveum.midpoint.repo.sqale.qmodel.ext.QExtItem) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with MExtItem

use of com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem in project midpoint by Evolveum.

the class ExtItemCache method retrieveFromDb.

private MExtItem retrieveFromDb(@NotNull MExtItem.Key key) {
    QExtItem ei = QExtItem.DEFAULT;
    MExtItem row;
    try (JdbcSession jdbcSession = jdbcSessionSupplier.get().startReadOnlyTransaction()) {
        row = jdbcSession.newQuery().select(ei).from(ei).where(ei.itemName.eq(key.itemName)).where(ei.valueType.eq(key.valueType)).where(ei.holderType.eq(key.holderType)).where(ei.cardinality.eq(key.cardinality)).fetchOne();
    }
    if (row != null) {
        updateMaps(row);
    }
    return row;
}
Also used : JdbcSession(com.evolveum.midpoint.repo.sqlbase.JdbcSession) MExtItem(com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem) QExtItem(com.evolveum.midpoint.repo.sqale.qmodel.ext.QExtItem)

Example 8 with MExtItem

use of com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem in project midpoint by Evolveum.

the class ExtItemCache method initialize.

/**
 * Initializes the ext-item cache.
 * Provided {@link JdbcSession} supplier will be used for later writes as well.
 */
public synchronized void initialize(Supplier<JdbcSession> jdbcSessionSupplier) {
    this.jdbcSessionSupplier = jdbcSessionSupplier;
    // this can be called repeatedly in tests, so the clear may be necessary
    idToExtItem.clear();
    keyToExtItem.clear();
    QExtItem uri = QExtItem.DEFAULT;
    List<MExtItem> result;
    try (JdbcSession jdbcSession = jdbcSessionSupplier.get().startReadOnlyTransaction()) {
        result = jdbcSession.newQuery().select(uri).from(uri).fetch();
        jdbcSession.commit();
    }
    for (MExtItem row : result) {
        updateMaps(row);
    }
    LOGGER.info("Ext item cache initialized with {} items.", result.size());
}
Also used : JdbcSession(com.evolveum.midpoint.repo.sqlbase.JdbcSession) MExtItem(com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem) QExtItem(com.evolveum.midpoint.repo.sqale.qmodel.ext.QExtItem)

Example 9 with MExtItem

use of com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem in project midpoint by Evolveum.

the class QShadowMapping method definitionsFrom.

private Map<QName, MExtItem> definitionsFrom(Jsonb rowAttributes) {
    Map<QName, MExtItem> definitions = new HashMap<>();
    if (rowAttributes == null) {
        return definitions;
    }
    Map<String, Object> attributes = Jsonb.toMap(rowAttributes);
    for (String id : attributes.keySet()) {
        var extItem = repositoryContext().getExtensionItem(Integer.valueOf(id));
        if (extItem != null) {
            QName key = QNameUtil.uriToQName(extItem.itemName);
            definitions.put(key, extItem);
        }
    }
    return definitions;
}
Also used : MExtItem(com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem) QName(javax.xml.namespace.QName)

Aggregations

MExtItem (com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem)9 QExtItem (com.evolveum.midpoint.repo.sqale.qmodel.ext.QExtItem)3 JdbcSession (com.evolveum.midpoint.repo.sqlbase.JdbcSession)3 QName (javax.xml.namespace.QName)3 ExtensionProcessor (com.evolveum.midpoint.repo.sqale.ExtensionProcessor)2 QueryException (com.evolveum.midpoint.repo.sqlbase.QueryException)2 Nullable (org.jetbrains.annotations.Nullable)2 ItemName (com.evolveum.midpoint.prism.path.ItemName)1 PropertyValueFilter (com.evolveum.midpoint.prism.query.PropertyValueFilter)1 ExtUtils (com.evolveum.midpoint.repo.sqale.ExtUtils)1 ExtItemInfo (com.evolveum.midpoint.repo.sqale.ExtensionProcessor.ExtItemInfo)1 SqaleRepoContext (com.evolveum.midpoint.repo.sqale.SqaleRepoContext)1 Jsonb (com.evolveum.midpoint.repo.sqale.jsonb.Jsonb)1 JsonbPath (com.evolveum.midpoint.repo.sqale.jsonb.JsonbPath)1 Key (com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem.Key)1 FilterOperation (com.evolveum.midpoint.repo.sqlbase.filtering.item.FilterOperation)1 ShadowAttributesType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAttributesType)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 NotNull (org.jetbrains.annotations.NotNull)1