use of org.mycore.backend.jpa.links.MCRLINKHREF 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);
}
}
use of org.mycore.backend.jpa.links.MCRLINKHREF in project mycore by MyCoRe-Org.
the class MCRHIBLinkTableStore method delete.
/**
* The method removes a item for the from ID from 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
*/
@Override
public final void delete(String from, String to, String type) {
if (from == null || (from = from.trim()).length() == 0) {
throw new MCRPersistenceException("The from value is null or empty.");
}
StringBuilder sb = new StringBuilder();
sb.append("from ").append(classname).append(" where MCRFROM = '").append(from).append("'");
if (to != null && (to = to.trim()).length() > 0) {
sb.append(" and MCRTO = '").append(to).append("'");
}
if (type != null && (type = type.trim()).length() > 0) {
sb.append(" and MCRTYPE = '").append(type).append("'");
}
LOGGER.debug("Deleting {} from database MCRLINKHREF", from);
Session session = getSession();
for (MCRLINKHREF mcrlinkhref : session.createQuery(sb.toString(), MCRLINKHREF.class).getResultList()) {
session.delete(mcrlinkhref);
}
}
use of org.mycore.backend.jpa.links.MCRLINKHREF in project mycore by MyCoRe-Org.
the class MCRMigrationCommands method fixMissingChildren.
@MCRCommand(syntax = "add missing children", help = "Adds missing children to structure of parent objects using MCRLinkTableManager. (MCR-1480)", order = 20)
public static List<String> fixMissingChildren() throws IOException, JDOMException, SAXException {
EntityManager em = MCREntityManagerProvider.getCurrentEntityManager();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> query = cb.createQuery(String.class);
Root<MCRLINKHREF> ac = query.from(MCRLINKHREF.class);
return em.createQuery(query.select(cb.concat(cb.literal("add missing children to "), ac.get(MCRLINKHREF_.key).get(MCRLINKHREFPK_.mcrto))).where(cb.equal(ac.get(MCRLINKHREF_.key).get(MCRLINKHREFPK_.mcrtype), MCRLinkTableManager.ENTRY_TYPE_PARENT)).distinct(true).orderBy(cb.asc(cb.literal(1)))).getResultList();
}
Aggregations