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.ItemDaoImpl.java

public void removeItem(Item item) {
    try {// ww w . j av a 2s.  co  m

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

        if (item instanceof HomeCollectionItem) {
            throw new IllegalArgumentException("cannot remove root item");
        }

        removeItemInternal(item);
        getSession().flush();

    } catch (ObjectNotFoundException onfe) {
        throw new ItemNotFoundException("item not found");
    } catch (ObjectDeletedException ode) {
        throw new ItemNotFoundException("item not found");
    } catch (UnresolvableObjectException uoe) {
        throw new ItemNotFoundException("item not found");
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}

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

public HomeCollectionItem getRootItem(User user) {
    try {//from   w  w  w.j a v a 2  s.  com
        return findRootItem(getBaseModelObject(user).getId());
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}

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

public HomeCollectionItem createRootItem(User user) {
    try {//from   w w  w. j a  v a 2s.co m

        if (user == null) {
            throw new IllegalArgumentException("invalid user");
        }

        if (findRootItem(getBaseModelObject(user).getId()) != null) {
            throw new CosmoException("user already has root item", new CosmoException());
        }

        HomeCollectionItem newItem = new HibHomeCollectionItem();

        newItem.setOwner(user);
        newItem.setName(user.getUsername());
        //do not set this, it might be sensitive or different than name
        //newItem.setDisplayName(newItem.getName()); 
        setBaseItemProps(newItem);
        getSession().save(newItem);
        getSession().flush();
        return newItem;
    } 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 addItemToCollection(Item item, CollectionItem collection) {
    try {//from w w  w  . j  av  a 2 s. co m
        addItemToCollectionInternal(item, collection);
        getSession().flush();
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}

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

public void removeItemFromCollection(Item item, CollectionItem collection) {
    try {/* w  ww  . j av a2  s.  c o m*/
        removeItemFromCollectionInternal(item, collection);
        getSession().flush();
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}

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

public Set<Ticket> getTickets(Item item) {
    if (item == null) {
        throw new IllegalArgumentException("item cannot be null");
    }/*from  www. ja v  a  2 s .  co  m*/

    try {
        getSession().refresh(item);
        return item.getTickets();
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}

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

public Ticket findTicket(String key) {
    if (key == null) {
        throw new IllegalArgumentException("key cannot be null");
    }// ww w .j a va  2s. c  o  m

    try {
        // prevent auto flushing when looking up ticket
        getSession().setFlushMode(FlushMode.MANUAL);
        Query hibQuery = getSession().getNamedQuery("ticket.by.key").setParameter("key", key);
        hibQuery.setCacheable(true);
        hibQuery.setFlushMode(FlushMode.MANUAL);
        return (Ticket) hibQuery.uniqueResult();
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}

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

public void createTicket(Item item, Ticket ticket) {
    try {/* w ww  . jav a  2s. c  om*/
        if (ticket == null) {
            throw new IllegalArgumentException("ticket cannot be null");
        }

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

        User owner = ticket.getOwner();
        if (owner == null) {
            throw new IllegalArgumentException("ticket must have owner");
        }

        if (ticket.getKey() == null) {
            ticket.setKey(ticketKeyGenerator.allocateToken("").getKey());
        }

        ticket.setCreated(new Date());
        getSession().update(item);
        item.addTicket(ticket);
        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 Ticket getTicket(Item item, String key) {
    try {/* w w w  .  j  av a 2  s.c  om*/
        getSession().refresh(item);
        return getTicketRecursive(item, key);
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }
}

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

public void removeTicket(Item item, Ticket ticket) {
    try {/*from www  .ja v  a 2  s. c  om*/
        getSession().update(item);
        item.removeTicket(ticket);
        getSession().flush();
    } catch (HibernateException e) {
        getSession().clear();
        throw SessionFactoryUtils.convertHibernateAccessException(e);
    }

}