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;
}
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);
}
}
Aggregations