Example usage for org.springframework.dao DataAccessException getMessage

List of usage examples for org.springframework.dao DataAccessException getMessage

Introduction

In this page you can find the example usage for org.springframework.dao DataAccessException getMessage.

Prototype

@Override
@Nullable
public String getMessage() 

Source Link

Document

Return the detail message, including the message from the nested exception if there is one.

Usage

From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java

public boolean addNewsItem(NewsItem newsItem) {
    if (log.isDebugEnabled()) {
        log.debug("addNewsItem( " + newsItem.toString() + ")");
    }//from   ww w  .  j av a2s.  c  o  m

    // news_time, title , entity_url, entity_ref, source_type, context_id, realm_id
    String subtype = newsItem.getSubtype();
    // DASH-191
    if (subtype != null && subtype.length() > MAX_LENGTH_SUBTYPE_FIELD) {
        StringBuilder buf = new StringBuilder();
        buf.append("addNewsItem().  Truncating subtype ");
        buf.append(subtype);
        buf.append(" for entity ");
        buf.append(newsItem.getEntityReference());
        log.warn(buf);
        subtype = subtype.substring(0, MAX_LENGTH_SUBTYPE_FIELD - 1);
    }

    try {
        JdbcTemplate template = getJdbcTemplate();
        template.update(getStatement("insert.NewsItem"),
                new Object[] { newsItem.getNewsTime(), newsItem.getTitle(), newsItem.getNewsTimeLabelKey(),
                        newsItem.getEntityReference(), subtype, newsItem.getSourceType().getId(),
                        newsItem.getContext().getId(), newsItem.getGroupingIdentifier() });

        return true;
    } catch (DataIntegrityViolationException e) {
        // this means we're trying to insert a duplicate
        log.debug("addNewsItem() " + e);
    } catch (DataAccessException ex) {
        log.warn("addNewsItem: Error executing query: " + ex.getClass() + ":" + ex.getMessage());
    }
    return false;
}

From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java

public boolean addNewsLink(NewsLink newsLink) {
    if (log.isDebugEnabled()) {
        log.debug("addNewsLink( " + newsLink.toString() + ")");
    }//from  ww w .  j av a 2 s. c  o  m

    //  person_id, item_id, context_id, realm_id

    try {

        getJdbcTemplate().update(getStatement("insert.NewsLink"),
                new Object[] { newsLink.getPerson().getId(), newsLink.getNewsItem().getId(),
                        newsLink.getContext().getId(), newsLink.isHidden(), newsLink.isSticky() });
        return true;
    } catch (DataIntegrityViolationException e) {
        // this means we're trying to insert a duplicate
        log.debug("addNewsLink() " + e);
        return false;
    } catch (DataAccessException ex) {
        log.warn("addNewsLink: Error executing query: " + ex.getClass() + ":" + ex.getMessage());
        return false;
    }
}

From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java

public int addNewsLinks(final List<NewsLink> newsLinks) {
    if (log.isDebugEnabled()) {
        log.debug("addNewsLinks( " + newsLinks.size() + ")");
    }//from ww  w.ja  v a  2 s .  co  m

    //  person_id, item_id, context_id, realm_id
    int count = 0;
    try {
        String sql = getStatement("insert.NewsLink");
        int[] updates = getJdbcTemplate().batchUpdate(sql, new BatchPreparedStatementSetter() {

            @Override
            public void setValues(PreparedStatement ps, int i) throws SQLException {
                NewsLink newsLink = newsLinks.get(i);
                ps.setLong(1, newsLink.getPerson().getId());
                ps.setLong(2, newsLink.getNewsItem().getId());
                ps.setLong(3, newsLink.getContext().getId());
                ps.setBoolean(4, newsLink.isHidden());
                ps.setBoolean(5, newsLink.isSticky());
            }

            @Override
            public int getBatchSize() {
                return newsLinks.size();
            }

        });
        if (updates != null && updates.length > 0) {
            for (int u : updates) {
                count += u;
            }
        }
    } catch (DataIntegrityViolationException e) {
        // this means we're trying to insert a duplicate
        log.debug("addNewsLink() " + e);
    } catch (DataAccessException ex) {
        log.warn("addNewsLink: Error executing query: " + ex.getClass() + ":" + ex.getMessage());
    }
    return count;
}

From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java

public boolean addPerson(Person person) {
    if (log.isDebugEnabled()) {
        log.debug("addPerson( " + person.toString() + ")");
    }/*from   w  w w  .  ja va2 s .co  m*/

    //  user_id,sakai_id

    try {
        getJdbcTemplate().update(getStatement("insert.Person"),
                new Object[] { person.getUserId(), person.getSakaiId() });
        return true;
    } catch (DataIntegrityViolationException e) {
        // this means we're trying to insert a duplicate
        log.debug("addPerson() " + e);
        return false;
    } catch (DataAccessException ex) {
        log.warn("addPerson: Error executing query: " + ex.getClass() + ":" + ex.getMessage());
        return false;
    }
}

From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java

public boolean addRepeatingCalendarItem(RepeatingCalendarItem repeatingCalendarItem) {
    if (log.isDebugEnabled()) {
        log.debug("addRepeatingCalendarItem( " + repeatingCalendarItem.toString() + ")");
    }/*from w  w w  .  j a va2  s.co  m*/
    //System.out.println("addRepeatingCalendarItem( " + repeatingCalendarItem.toString() + ")");

    //  first_time, last_time, frequency, count, calendar_time_label_key, title, entity_ref, entity_type, context_id
    String sql = getStatement("insert.RepeatingEvent");
    //System.out.println("addRepeatingCalendarItem() sql == " + sql);
    long sourceTypeId = repeatingCalendarItem.getSourceType().getId();
    long contextId = repeatingCalendarItem.getContext().getId();
    String subtype = repeatingCalendarItem.getSubtype();
    // DASH-191
    if (subtype != null && subtype.length() > MAX_LENGTH_SUBTYPE_FIELD) {
        StringBuilder buf = new StringBuilder();
        buf.append("addRepeatingCalendarItem().  Truncating subtype ");
        buf.append(subtype);
        buf.append(" for entity ");
        buf.append(repeatingCalendarItem.getEntityReference());
        log.warn(buf);
        subtype = subtype.substring(0, MAX_LENGTH_SUBTYPE_FIELD - 1);
    }
    Object[] params = new Object[] { repeatingCalendarItem.getFirstTime(), repeatingCalendarItem.getLastTime(),
            repeatingCalendarItem.getFrequency(), repeatingCalendarItem.getMaxCount(),
            repeatingCalendarItem.getCalendarTimeLabelKey(), repeatingCalendarItem.getTitle(),
            repeatingCalendarItem.getEntityReference(), subtype, sourceTypeId, contextId };

    try {
        getJdbcTemplate().update(sql, params);
        return true;
    } catch (DataIntegrityViolationException e) {
        // this means we're trying to insert a duplicate
        log.debug("addRepeatingCalendarItem() " + e);
        return false;
    } catch (DataAccessException ex) {
        log.warn("addRepeatingCalendarItem: Error executing query: " + ex.getClass() + ":" + ex.getMessage());
        //System.out.println("addRepeatingCalendarItem: Error executing query: " + ex.getClass() + ":" + ex.getMessage());
        return false;
    }
}

From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java

public boolean addSourceType(SourceType sourceType) {
    if (log.isDebugEnabled()) {
        log.debug("addSourceType( " + sourceType.toString() + ")");
    }//w w w. j a va  2  s .c  o m

    // identifier

    try {
        getJdbcTemplate().update(getStatement("insert.SourceType"), new Object[] { sourceType.getIdentifier() }

        );
        return true;
    } catch (DataIntegrityViolationException e) {
        // this means we're trying to insert a duplicate
        log.debug("addSourceType() " + e);
        return false;
    } catch (DataAccessException ex) {
        log.warn("addSourceType: Error executing query: " + ex.getClass() + ":" + ex.getMessage());
        return false;
    }
}

From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java

public boolean addTaskLock(TaskLock taskLock) {
    if (log.isDebugEnabled()) {
        log.debug("addTaskLock( " + taskLock.toString() + ")");
    }/*from w  ww  .j  a  v a 2 s  .  co  m*/

    //  task, server_id, claim_time, last_update

    try {
        getJdbcTemplate().update(getStatement("insert.TaskLock"),
                new Object[] { taskLock.getTask(), taskLock.getServerId(), taskLock.getClaimTime(),
                        taskLock.getLastUpdate(), taskLock.isHasLock() });
        return true;
    } catch (DataIntegrityViolationException e) {
        // this means we're trying to insert a duplicate
        log.debug("addTaskLock() " + e);
        return false;
    } catch (DataAccessException ex) {
        log.warn("addTaskLock: Error executing query: " + ex.getClass() + ":" + ex.getMessage());
        return false;
    }
}

From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java

public boolean deleteAvailabilityChecks(String entityReference) {
    if (log.isDebugEnabled()) {
        log.debug("deleteAllAvailabilityChecks( " + entityReference + ")");
    }/*  www  .  ja  v  a  2 s .  c o  m*/

    try {
        getJdbcTemplate().update(getStatement("delete.AvailabilityChecks.by.entityReference"),
                new Object[] { entityReference });
        return true;
    } catch (DataAccessException ex) {
        log.warn(
                "deleteAllAvailabilityChecks: Error executing query: " + ex.getClass() + ":" + ex.getMessage());
        return false;
    }

}

From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java

public boolean deleteAvailabilityChecksBeforeTime(Date time) {
    if (log.isDebugEnabled()) {
        log.debug("deleteAvailabilityChecksBeforeTime(" + time + ")");
    }/*  www.j a  v a  2 s.c  o m*/
    String sql = getStatement("delete.AvailabilityChecks.before.date");
    Object[] params = new Object[] { time };
    try {
        getJdbcTemplate().update(sql, params);
        return true;

    } catch (DataAccessException ex) {
        log.warn("deleteAvailabilityChecksBeforeTime: Error executing query: " + ex.getClass() + ":"
                + ex.getMessage());
        return false;
    }
}

From source file:org.sakaiproject.dash.dao.impl.DashboardDaoImpl.java

public boolean deleteCalendarItem(Long id) {
    if (log.isDebugEnabled()) {
        log.debug("deleteCalendarItem( " + id + ")");
    }//www .  j a va  2 s .com

    try {
        getJdbcTemplate().update(getStatement("delete.CalendarItem.by.id"), new Object[] { id });
        return true;
    } catch (DataAccessException ex) {
        log.warn("deleteCalendarItem: Error executing query: " + ex.getClass() + ":" + ex.getMessage());
        return false;
    }
}