use of org.mycore.common.MCRPersistenceException 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.common.MCRPersistenceException 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.common.MCRPersistenceException in project mycore by MyCoRe-Org.
the class MCRCStoreIFS2 method exists.
@Override
protected boolean exists(org.mycore.datamodel.ifs.MCRFile fr) {
int slotID = getSlotID(fr.getOwnerID());
String base = getBase(fr.getOwnerID());
MCRFileStore store = getStore(base);
try {
MCRFileCollection slot = store.retrieve(slotID);
if (slot == null)
return false;
String path = fr.getAbsolutePath();
MCRNode node = slot.getNodeByPath(path);
return (node != null);
} catch (IOException ex) {
String msg = "Exception checking existence of file " + fr.getAbsolutePath();
throw new MCRPersistenceException(msg, ex);
}
}
use of org.mycore.common.MCRPersistenceException in project mycore by MyCoRe-Org.
the class MCRDirectoryStream method deleteFileSystemNode.
/**
* Deletes {@link MCRFilesystemNode} if it exists.
*
* @param path
* relative or absolute
* @throws IOException
*/
private void deleteFileSystemNode(MCRPath path) throws IOException {
checkClosed();
if (path.isAbsolute()) {
Files.delete(path);
}
MCRFilesystemNode childByPath = dir.getChildByPath(path.toString());
if (childByPath == null) {
throw new NoSuchFileException(dir.toPath().toString(), path.toString(), null);
}
try {
childByPath.delete();
} catch (MCRPersistenceException e) {
throw new IOException("Error whil deleting file system node.", e);
}
}
use of org.mycore.common.MCRPersistenceException in project mycore by MyCoRe-Org.
the class MCRHIBFileMetadataStore method storeNode.
@Override
public void storeNode(MCRFilesystemNode node) throws MCRPersistenceException {
String ID = node.getID();
String PID = node.getParentID();
String OWNER = node.getOwnerID();
String NAME = node.getName();
String LABEL = node.getLabel();
long SIZE = node.getSize();
GregorianCalendar DATE = node.getLastModified();
String TYPE = null;
String STOREID = null;
String STORAGEID = null;
String FCTID = null;
String MD5 = null;
int NUMCHDD = 0;
int NUMCHDF = 0;
int NUMCHTD = 0;
int NUMCHTF = 0;
if (node instanceof MCRFile) {
MCRFile file = (MCRFile) node;
TYPE = "F";
STOREID = file.getStoreID();
STORAGEID = file.getStorageID();
FCTID = file.getContentTypeID();
MD5 = file.getMD5();
} else if (node instanceof MCRDirectory) {
MCRDirectory dir = (MCRDirectory) node;
TYPE = "D";
NUMCHDD = dir.getNumChildren(MCRDirectory.DIRECTORIES, MCRDirectory.HERE);
NUMCHDF = dir.getNumChildren(MCRDirectory.FILES, MCRDirectory.HERE);
NUMCHTD = dir.getNumChildren(MCRDirectory.DIRECTORIES, MCRDirectory.TOTAL);
NUMCHTF = dir.getNumChildren(MCRDirectory.FILES, MCRDirectory.TOTAL);
} else {
throw new MCRPersistenceException("MCRFilesystemNode must be either MCRFile or MCRDirectory");
}
Session session = getSession();
MCRFSNODES fs = session.get(MCRFSNODES.class, ID);
if (fs == null) {
fs = new MCRFSNODES();
fs.setId(ID);
}
fs.setPid(PID);
fs.setType(TYPE);
fs.setOwner(OWNER);
fs.setName(NAME);
fs.setLabel(LABEL);
fs.setSize(SIZE);
fs.setDate(new Timestamp(DATE.getTime().getTime()));
fs.setStoreid(STOREID);
fs.setStorageid(STORAGEID);
fs.setFctid(FCTID);
fs.setMd5(MD5);
fs.setNumchdd(NUMCHDD);
fs.setNumchdf(NUMCHDF);
fs.setNumchtd(NUMCHTD);
fs.setNumchtf(NUMCHTF);
if (!session.contains(fs)) {
session.saveOrUpdate(fs);
}
}
Aggregations