Example usage for org.springframework.orm.hibernate5 SessionFactoryUtils convertHibernateAccessException

List of usage examples for org.springframework.orm.hibernate5 SessionFactoryUtils convertHibernateAccessException

Introduction

In this page you can find the example usage for org.springframework.orm.hibernate5 SessionFactoryUtils convertHibernateAccessException.

Prototype

public static DataAccessException convertHibernateAccessException(HibernateException ex) 

Source Link

Document

Convert the given HibernateException to an appropriate exception from the org.springframework.dao hierarchy.

Usage

From source file:org.unitedinternet.cosmo.dao.hibernate.ContentDaoImpl.java

public Set<ContentItem> loadChildren(CollectionItem collection, Date timestamp) {
    try {/* ww w  . j a v a  2s  . co m*/
        Set<ContentItem> children = new HashSet<ContentItem>();
        Query query = null;

        // use custom HQL query that will eager fetch all associations
        if (timestamp == null) {
            query = getSession().getNamedQuery("contentItem.by.parent").setParameter("parent", collection);
        } else {
            query = getSession().getNamedQuery("contentItem.by.parent.timestamp")
                    .setParameter("parent", collection).setParameter("timestamp", timestamp);
        }
        query.setFlushMode(FlushMode.MANUAL);
        List results = query.list();
        for (Iterator it = results.iterator(); it.hasNext();) {
            ContentItem content = (ContentItem) it.next();
            initializeItem(content);
            children.add(content);
        }

        return children;

    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}

From source file:org.unitedinternet.cosmo.dao.hibernate.ContentDaoImpl.java

@Override
public void initializeItem(Item item) {
    super.initializeItem(item);

    // Initialize master NoteItem if applicable
    try {//from ww w.jav  a2s  . co m
        if (item instanceof NoteItem) {
            NoteItem note = (NoteItem) item;
            if (note.getModifies() != null) {
                Hibernate.initialize(note.getModifies());
                initializeItem(note.getModifies());
            }
        }
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }

}

From source file:org.unitedinternet.cosmo.dao.hibernate.EventLogDaoImpl.java

public void addEventLogEntry(EventLogEntry entry) {
    try {/*from  w ww  .  j ava 2s. c  o  m*/
        addEventLogEntryInternal(entry);
        getSession().flush();
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}

From source file:org.unitedinternet.cosmo.dao.hibernate.EventLogDaoImpl.java

public void addEventLogEntries(List<EventLogEntry> entries) {

    try {//from   ww w . j  a  v a 2 s. c  o m
        for (EventLogEntry entry : entries) {
            addEventLogEntryInternal(entry);
        }

        getSession().flush();
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}

From source file:org.unitedinternet.cosmo.dao.hibernate.EventLogDaoImpl.java

/**
 * {@inheritDoc}/*from w ww.ja v a2s . c o  m*/
 */
public List<ItemChangeRecord> findChangesForCollection(CollectionItem collection, Date start, Date end) {
    try {
        Query hibQuery = getSession().getNamedQuery("logEntry.by.collection.date");
        hibQuery.setParameter("parentId", ((HibItem) collection).getId());
        hibQuery.setParameter("startDate", start);
        hibQuery.setParameter("endDate", end);
        List<HibEventLogEntry> results = hibQuery.list();

        ArrayList<ItemChangeRecord> changeRecords = new ArrayList<ItemChangeRecord>();

        for (HibEventLogEntry result : results) {
            changeRecords.add(convertToItemChangeRecord(result));
        }

        return changeRecords;

    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}

From source file:org.unitedinternet.cosmo.dao.hibernate.ItemDaoImpl.java

public Item findItemByPath(String path) {
    try {//from  w w  w . j  a  v  a  2 s .  c  om
        Item dbItem = itemPathTranslator.findItemByPath(path);
        return dbItem;
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}

From source file:org.unitedinternet.cosmo.dao.hibernate.ItemDaoImpl.java

public Item findItemByPath(String path, String parentUid) {
    try {/*from www. j  a v a2  s  . c om*/
        Item parent = findItemByUid(parentUid);
        if (parent == null) {
            return null;
        }
        Item item = itemPathTranslator.findItemByPath(path, (CollectionItem) parent);
        return item;
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}

From source file:org.unitedinternet.cosmo.dao.hibernate.ItemDaoImpl.java

public Item findItemParentByPath(String path) {
    try {/*from  w w w.jav  a2 s  . c  o m*/
        Item dbItem = itemPathTranslator.findItemParent(path);
        return dbItem;
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}

From source file:org.unitedinternet.cosmo.dao.hibernate.ItemDaoImpl.java

@SuppressWarnings("unchecked")
public <STAMP_TYPE extends Stamp> STAMP_TYPE findStampByInternalItemUid(String internalItemUid,
        Class<STAMP_TYPE> clazz) {
    try (StatelessSession session = this.openStatelessSession()) {

        List<Stamp> stamps = (List<Stamp>) session.createNamedQuery("item.stamps.by.uid")
                .setParameter("uid", internalItemUid)
                .setHint(AvailableSettings.JPA_SHARED_CACHE_STORE_MODE, null)
                .setHint(AvailableSettings.JPA_SHARED_CACHE_RETRIEVE_MODE, null).getResultList();
        for (Stamp stamp : stamps) {
            if (clazz.isInstance(stamp)) {
                return clazz.cast(stamp);
            }/* w w w.j av  a 2  s . co m*/
        }
    } catch (HibernateException e) {
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
    return null;
}

From source file:org.unitedinternet.cosmo.dao.hibernate.ItemDaoImpl.java

public Item findItemByUid(String uid) {
    try {// w  w  w.j ava 2 s .c o m
        // prevent auto flushing when looking up item by uid
        getSession().setFlushMode(FlushMode.MANUAL);
        return (Item) getSession().byNaturalId(HibItem.class).using("uid", uid).load();
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}