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 void createBatchContent(CollectionItem parent, Set<ContentItem> contents) {

    try {//from   w  w w.j  a  v  a 2s  .  c  om
        for (ContentItem content : contents) {
            createContentInternal(parent, content);
        }
        getSession().flush();
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    } catch (ConstraintViolationException cve) {
        getSession().clear();
        logConstraintViolationException(cve);
        throw cve;
    }
}

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

public void updateBatchContent(Set<ContentItem> contents) {
    try {//from w w w . ja va2 s . c  o m
        for (ContentItem content : contents) {
            updateContentInternal(content);
        }
        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.ContentDaoImpl.java

public void removeBatchContent(CollectionItem parent, Set<ContentItem> contents) {
    try {//  ww w .  java2s  . c om
        for (ContentItem content : contents) {
            removeItemFromCollectionInternal(content, parent);
        }
        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.ContentDaoImpl.java

public ContentItem createContent(Set<CollectionItem> parents, ContentItem content) {

    try {//from  ww w  .j a v  a2s .  com
        createContentInternal(parents, content);
        getSession().flush();
        return content;
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    } catch (ConstraintViolationException cve) {
        logConstraintViolationException(cve);
        throw cve;
    }
}

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

/**
 * Updates collection timestamp.//from ww w.j a v  a2  s .  co m
 *
 * @param collection The timestamp of this collection needs to be updated.
 * @return The new collection item updated.
 */
public CollectionItem updateCollectionTimestamp(CollectionItem collection) {
    try {
        if (!getSession().contains(collection)) {
            collection = (CollectionItem) getSession().merge(collection);
        }
        collection.updateTimestamp();
        getSession().flush();
        return collection;
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}

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

/**
 * Updates collection.// w  w w .j  av  a 2s  .c o m
 *
 * @param collection The updated collection.
 */
public CollectionItem updateCollection(CollectionItem collection) {
    try {

        updateCollectionInternal(collection);
        getSession().flush();

        return collection;
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    } catch (ConstraintViolationException cve) {
        logConstraintViolationException(cve);
        throw cve;
    }
}

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

/**
 * Updates content item./*from  w  w  w .  j  a  va  2s  .c o  m*/
 *
 * @param content The content that needs to be updated.
 * @return The updated content.
 */
public ContentItem updateContent(ContentItem content) {
    try {
        updateContentInternal(content);
        getSession().flush();
        return content;
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    } catch (ConstraintViolationException cve) {
        logConstraintViolationException(cve);
        throw cve;
    }
}

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

/**
 * Removes the collection given.//from  ww  w  .  java  2s. c  o  m
 *
 * @param collection The collection that needs to be removed.
 */
public void removeCollection(CollectionItem collection) {

    if (collection == null) {
        throw new IllegalArgumentException("collection cannot be null");
    }

    try {
        getSession().refresh(collection);
        removeCollectionRecursive(collection);
        getSession().flush();
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}

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

/**
 * Removes the content given.//  ww w. ja  va  2 s . c  om
 *
 * @param content The content item that need to be removed.
 */
public void removeContent(ContentItem content) {

    if (content == null) {
        throw new IllegalArgumentException("content cannot be null");
    }

    try {
        getSession().refresh(content);
        removeContentRecursive(content);
        getSession().flush();
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}

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

/**
 * Removes user content.//from  w w  w . j  ava  2 s .  c  om
 *
 * @param user The content of the user needs to be removed.
 */
public void removeUserContent(User user) {
    try {
        Query query = getSession().getNamedQuery("contentItem.by.owner").setParameter("owner", user);

        List<ContentItem> results = query.list();
        for (ContentItem content : results) {
            removeContentRecursive(content);
        }
        getSession().flush();
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}