Search in sources :

Example 1 with MCRLINKHREFPK

use of org.mycore.backend.jpa.links.MCRLINKHREFPK in project mycore by MyCoRe-Org.

the class MCRHIBLinkTableStore method getKey.

private static MCRLINKHREFPK getKey(String from, String to, String type) {
    MCRLINKHREFPK pk = new MCRLINKHREFPK();
    pk.setMcrfrom(from);
    pk.setMcrto(to);
    pk.setMcrtype(type);
    return pk;
}
Also used : MCRLINKHREFPK(org.mycore.backend.jpa.links.MCRLINKHREFPK)

Example 2 with MCRLINKHREFPK

use of org.mycore.backend.jpa.links.MCRLINKHREFPK in project mycore by MyCoRe-Org.

the class MCRHIBLinkTableStore method create.

/**
 * The method create a new item in the datastore.
 *
 * @param from
 *            a string with the link ID MCRFROM
 * @param to
 *            a string with the link ID MCRTO
 * @param type
 *            a string with the link ID MCRTYPE
 * @param attr
 *            a string with the link ID MCRATTR
 */
@Override
public final void create(String from, String to, String type, String attr) {
    if (from == null || (from = from.trim()).length() == 0) {
        throw new MCRPersistenceException("The from value is null or empty.");
    }
    if (to == null || (to = to.trim()).length() == 0) {
        throw new MCRPersistenceException("The to value is null or empty.");
    }
    if (type == null || (type = type.trim()).length() == 0) {
        throw new MCRPersistenceException("The type value is null or empty.");
    }
    if (attr == null || (attr = attr.trim()).length() == 0) {
        attr = "";
    }
    EntityManager entityMananger = MCREntityManagerProvider.getCurrentEntityManager();
    LOGGER.debug("Inserting {}/{}/{} into database MCRLINKHREF", from, to, type);
    MCRLINKHREFPK key = getKey(from, to, type);
    MCRLINKHREF linkHref = entityMananger.find(MCRLINKHREF.class, key);
    if (linkHref != null) {
        linkHref.setMcrattr(attr);
    } else {
        linkHref = new MCRLINKHREF();
        linkHref.setKey(key);
        linkHref.setMcrattr(attr);
        entityMananger.persist(linkHref);
    }
}
Also used : EntityManager(javax.persistence.EntityManager) MCRLINKHREFPK(org.mycore.backend.jpa.links.MCRLINKHREFPK) MCRLINKHREF(org.mycore.backend.jpa.links.MCRLINKHREF) MCRPersistenceException(org.mycore.common.MCRPersistenceException)

Aggregations

MCRLINKHREFPK (org.mycore.backend.jpa.links.MCRLINKHREFPK)2 EntityManager (javax.persistence.EntityManager)1 MCRLINKHREF (org.mycore.backend.jpa.links.MCRLINKHREF)1 MCRPersistenceException (org.mycore.common.MCRPersistenceException)1