List of usage examples for org.springframework.orm.hibernate5 SessionFactoryUtils convertHibernateAccessException
public static DataAccessException convertHibernateAccessException(HibernateException ex)
From source file:org.unitedinternet.cosmo.dao.hibernate.ItemDaoImpl.java
public void removeItemByPath(String path) { try {//from w ww . j a va 2s .com Item item = itemPathTranslator.findItemByPath(path); if (item == null) { throw new ItemNotFoundException("item at " + path + " not found"); } removeItem(item); } catch (HibernateException e) { getSession().clear(); throw SessionFactoryUtils.convertHibernateAccessException(e); } }
From source file:org.unitedinternet.cosmo.dao.hibernate.ItemDaoImpl.java
public void removeItemByUid(String uid) { try {//w w w . java 2s . c om Item item = findItemByUid(uid); if (item == null) { throw new ItemNotFoundException("item with uid " + uid + " not found"); } removeItem(item); } catch (HibernateException e) { getSession().clear(); throw SessionFactoryUtils.convertHibernateAccessException(e); } }
From source file:org.unitedinternet.cosmo.dao.hibernate.ItemDaoImpl.java
public void copyItem(Item item, String destPath, boolean deepCopy) { try {/*w ww . ja v a 2 s. co m*/ String copyName = itemPathTranslator.getItemName(destPath); if (copyName == null || "".equals(copyName)) { throw new IllegalArgumentException("path must include name"); } if (item instanceof HomeCollectionItem) { throw new IllegalArgumentException("cannot copy root collection"); } CollectionItem newParent = (CollectionItem) itemPathTranslator.findItemParent(destPath); if (newParent == null) { throw new ItemNotFoundException("parent collection not found"); } verifyNotInLoop(item, newParent); Item newItem = copyItemInternal(item, newParent, deepCopy); newItem.setName(copyName); getSession().flush(); } catch (HibernateException e) { getSession().clear(); throw SessionFactoryUtils.convertHibernateAccessException(e); } catch (ConstraintViolationException cve) { logConstraintViolationException(cve); throw cve; } }
From source file:org.unitedinternet.cosmo.dao.hibernate.ItemDaoImpl.java
public void moveItem(String fromPath, String toPath) { try {//from ww w.j a v a 2 s. com // Get current item Item item = itemPathTranslator.findItemByPath(fromPath); if (item == null) { throw new ItemNotFoundException("item " + fromPath + " not found"); } if (item instanceof HomeCollectionItem) { throw new IllegalArgumentException("cannot move root collection"); } // Name of moved item String moveName = itemPathTranslator.getItemName(toPath); if (moveName == null || "".equals(moveName)) { throw new IllegalArgumentException("path must include name"); } // Parent of moved item CollectionItem parent = (CollectionItem) itemPathTranslator.findItemParent(toPath); if (parent == null) { throw new ItemNotFoundException("parent collecion not found"); } // Current parent CollectionItem oldParent = (CollectionItem) itemPathTranslator.findItemParent(fromPath); verifyNotInLoop(item, parent); item.setName(moveName); if (!parent.getUid().equals(oldParent.getUid())) { ((HibCollectionItem) parent).removeTombstone(item); // Copy over existing CollectionItemDetails ((HibItem) item).addParent(parent); // Remove item from old parent collection getHibItem(oldParent).addTombstone(new HibItemTombstone(oldParent, item)); ((HibItem) item).removeParent(oldParent); } getSession().flush(); } catch (HibernateException e) { getSession().clear(); throw SessionFactoryUtils.convertHibernateAccessException(e); } catch (ConstraintViolationException cve) { logConstraintViolationException(cve); throw cve; } }
From source file:org.unitedinternet.cosmo.dao.hibernate.ItemDaoImpl.java
public void refreshItem(Item item) { try {// ww w. j a v a 2s . c om getSession().refresh(item); } catch (HibernateException e) { getSession().clear(); throw SessionFactoryUtils.convertHibernateAccessException(e); } }
From source file:org.unitedinternet.cosmo.dao.hibernate.ItemDaoImpl.java
public void initializeItem(Item item) { try {/*from www. ja v a 2 s .c om*/ LOG.info("initialize Item : " + item.getUid()); // initialize all the proxied-associations, to prevent // lazy-loading of this data Hibernate.initialize(item.getAttributes()); Hibernate.initialize(item.getStamps()); Hibernate.initialize(item.getTombstones()); } catch (HibernateException e) { getSession().clear(); throw SessionFactoryUtils.convertHibernateAccessException(e); } }
From source file:org.unitedinternet.cosmo.dao.hibernate.ItemDaoImpl.java
/** * find the set of collection items as children of the given collection item. * /*from w w w .j a v a2s . c o m*/ * @param collectionItem parent collection item * @return set of children collection items or empty list of parent collection has no children */ public Set<CollectionItem> findCollectionItems(CollectionItem collectionItem) { try { HashSet<CollectionItem> children = new HashSet<CollectionItem>(); Query hibQuery = getSession().getNamedQuery("collections.children.by.parent").setParameter("parent", collectionItem); List<?> results = hibQuery.list(); for (Iterator<?> it = results.iterator(); it.hasNext();) { CollectionItem content = (CollectionItem) it.next(); children.add(content); } return children; } catch (HibernateException e) { getSession().clear(); throw SessionFactoryUtils.convertHibernateAccessException(e); } }
From source file:org.unitedinternet.cosmo.dao.hibernate.ItemDaoImpl.java
/** * Find a set of items using an ItemFilter. * * @param filter criteria to filter items by * @return set of items matching ItemFilter *///from w w w . j ava2s.c o m public Set<Item> findItems(ItemFilter filter) { try { return itemFilterProcessor.processFilter(filter); } catch (HibernateException e) { getSession().clear(); throw SessionFactoryUtils.convertHibernateAccessException(e); } }
From source file:org.unitedinternet.cosmo.dao.hibernate.ItemDaoImpl.java
/** * Find a set of items using a set of ItemFilters. The set of items * returned includes all items that match any of the filters. * * @param filters criteria to filter items by * @return set of items matching any of the filters *//* ww w . j av a2 s .c o m*/ public Set<Item> findItems(ItemFilter[] filters) { try { HashSet<Item> returnSet = new HashSet<Item>(); for (ItemFilter filter : filters) { returnSet.addAll(itemFilterProcessor.processFilter(filter)); } return returnSet; } catch (HibernateException e) { getSession().clear(); throw SessionFactoryUtils.convertHibernateAccessException(e); } }
From source file:org.unitedinternet.cosmo.dao.hibernate.ServerPropertyDaoImpl.java
public String getServerProperty(String property) { try {//from w w w . j a va2 s. c om ServerProperty prop = (ServerProperty) getSession() .createQuery("from HibServerProperty where name=:name").setParameter("name", property) .uniqueResult(); if (prop != null) { return prop.getValue(); } else { return null; } } catch (HibernateException e) { throw SessionFactoryUtils.convertHibernateAccessException(e); } }