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 updateRepeatingCalendarItemTitle(String entityReference, String newTitle) {
    if (log.isDebugEnabled()) {
        log.debug("updateRepeatingCalendarItemTitle( " + entityReference + "," + newTitle + ")");
    }//from ww w  .  j a v a 2s. c  o  m

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

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

public boolean updateTaskLock(long id, boolean hasLock, Date lastUpdate) {
    if (log.isDebugEnabled()) {
        log.debug("updateTaskLock( " + id + "," + hasLock + "," + lastUpdate + ")");
    }//from   w ww  .  j  a v  a 2 s  .  co m

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

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

public boolean updateTaskLock(String task, String serverId, Date lastUpdate) {
    if (log.isDebugEnabled()) {
        log.debug("updateTaskLock( " + task + "," + serverId + "," + lastUpdate + ")");
    }//from   ww  w  .  j a  v a2  s .c  om

    try {
        getJdbcTemplate().update(getStatement("update.TaskLock.lastUpdate"),
                new Object[] { lastUpdate, task, serverId });
        return true;
    } catch (DataAccessException ex) {
        log.warn("updateTaskLock: Error executing query: " + ex.getClass() + ":" + ex.getMessage());
        return false;
    }
}

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

/**
 * @param sqlStatement/*from   ww w. ja va 2 s . co  m*/
 */
protected void executeSqlStatement(String key) {
    String sqlStatement = getStatement(key);
    if (sqlStatement == null || sqlStatement.trim().equals("")) {
        log.warn("Missing key in database properties file (" + statements.getFileName() + "): " + key);
    } else {
        String parts[] = sqlStatement.split(";");
        if (parts != null) {
            for (String sql : parts) {
                if (sql != null && !sql.trim().equals("")) {
                    try {
                        getJdbcTemplate().execute(sql.trim());

                    } catch (DataIntegrityViolationException e) {
                        // this means we're trying to insert a duplicate
                        log.debug("executeSqlStatement() " + e);
                    } catch (DataAccessException ex) {
                        log.warn("Error executing SQL statement with key: " + key + " -- " + ex.getClass()
                                + ": " + ex.getMessage());
                        //System.out.println("\nError executing SQL statement with key: " + key + " -- " + ex.getClass() + ": \n" + ex.getMessage() + "\n");
                    }
                }
            }
        }
    }
}

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

public void setConfigProperty(String propertyName, Integer propertyValue) {

    if (log.isDebugEnabled()) {
        log.debug("setConfigProperty( " + propertyName + "," + propertyValue + ")");
    }/*from  w  w w  . j  a  va2s .  co m*/

    // insert into dash_config (property_name, property_value) values (?, ?)
    String sql_insert = getStatement("insert.Config");
    Object[] params_insert = new Object[] { propertyName, propertyValue };

    // update dash_config set property_value=? where property_name=?
    String sql_update = getStatement("update.Config.propertyName");
    Object[] params_update = new Object[] { propertyValue, propertyName };

    JdbcTemplate jdbcTemplate = getJdbcTemplate();
    try {
        jdbcTemplate.update(sql_insert, params_insert);
    } catch (DataIntegrityViolationException e) {
        // this means we're trying to insert a duplicate
        log.debug("setConfigProperty() " + e);
    } catch (Exception e) {
        // insert failed -- try update instead of insert
        try {
            jdbcTemplate.update(sql_update, params_update);
        } catch (DataAccessException ex) {
            log.warn("setConfigProperty: Error executing query: " + ex.getClass() + ":" + ex.getMessage());
        } catch (Exception ex) {
            log.warn("setConfigProperty: Error executing query: " + ex.getClass() + ":" + ex.getMessage());
        }
    }

}

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

public boolean deleteRepeatingEvent(Long id) {
    if (log.isDebugEnabled()) {
        log.debug("deleteRepeatingEvent( " + id + ")");
    }/*w  w w .  j  ava  2 s .  c o  m*/

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

From source file:org.sakaiproject.tool.assessment.facade.AssessmentFacadeQueries.java

public AssessmentFacade getAssessment(Long assessmentId) {
    try {//  ww  w  .ja va 2s. c om
        AssessmentData assessment = (AssessmentData) getHibernateTemplate().load(AssessmentData.class,
                assessmentId);
        assessment.setSectionSet(getSectionSetForAssessment(assessment));
        return new AssessmentFacade(assessment);
    } catch (DataAccessException e) {
        log.warn("error retieving assemement: " + assessmentId.toString() + " " + e.getMessage());
    }
    return null;
}

From source file:org.sakaiproject.tool.assessment.facade.ItemFacadeQueries.java

public void deleteItem(Long itemId, String agent) {
    ItemData item = null;/*from   w w w. j  a  v a 2  s  . c o  m*/
    try {
        item = (ItemData) getHibernateTemplate().load(ItemData.class, itemId);
    } catch (DataAccessException e) {
        log.warn("unable to retrieve item " + itemId + " due to:" + e);
        return;
    }
    // get list of attachment in item
    AssessmentService service = new AssessmentService();
    List itemAttachmentList = service.getItemResourceIdList(item);
    service.deleteResources(itemAttachmentList);

    int retryCount = PersistenceService.getInstance().getPersistenceHelper().getRetryCount().intValue();
    while (retryCount > 0) {
        try {
            SectionDataIfc section = item.getSection();
            // section might be null if you are deleting an item created inside a pool, that's not linked to any assessment. 
            if (section != null) {
                Set set = section.getItemSet();
                set.remove(item);
            }
            getHibernateTemplate().delete(item);
            retryCount = 0;
        } catch (Exception e) {
            log.warn("problem deleting item: " + e.getMessage());
            retryCount = PersistenceService.getInstance().getPersistenceHelper().retryDeadlock(e, retryCount);
        }
    }
}

From source file:org.sakaiproject.tool.assessment.facade.QuestionPoolFacadeQueries.java

/**
 * Delete pool and questions attached to it plus any subpool under it
 *
 * @param itemId DOCUMENTATION PENDING//from  w  ww.  jav  a 2s  .c  o  m
 * @param poolId DOCUMENTATION PENDING
 */
public void deletePool(final Long poolId, final String agent, Tree tree) {
    try {
        QuestionPoolData questionPool = (QuestionPoolData) getHibernateTemplate().load(QuestionPoolData.class,
                poolId);

        // #1. delete all questions which mean AssetBeanie (not ItemImpl) 'cos AssetBeanie
        // is the one that is associated with the DB
        // lydial:  getting list of items that only belong to this pool and not linked to any assessments. 
        List itemList = getAllItemsInThisPoolOnlyAndDetachFromAssessment(poolId);

        int retryCount = PersistenceService.getInstance().getPersistenceHelper().getRetryCount().intValue();
        while (retryCount > 0) {
            try {
                getHibernateTemplate().deleteAll(itemList); // delete all AssetBeanie
                retryCount = 0;
            } catch (DataAccessException e) {
                log.warn("problem delete all items in pool: " + e.getMessage());
                retryCount = PersistenceService.getInstance().getPersistenceHelper().retryDeadlock(e,
                        retryCount);
            }
        }

        // #2. delete question and questionpool map.
        retryCount = PersistenceService.getInstance().getPersistenceHelper().getRetryCount().intValue();
        while (retryCount > 0) {
            try {
                final HibernateCallback hcb = new HibernateCallback() {
                    public Object doInHibernate(Session session) throws HibernateException, SQLException {
                        Query q = session.createQuery(
                                "select qpi from QuestionPoolItemData as qpi where qpi.questionPoolId= ?");
                        q.setLong(0, poolId.longValue());
                        return q.list();
                    };
                };
                List list = getHibernateTemplate().executeFind(hcb);

                // a. delete item and pool association in SAM_ITEMMETADATA_T - this is the primary
                // pool that item is attached to
                ArrayList<ItemMetaDataIfc> metaList = new ArrayList<>();
                for (int j = 0; j < list.size(); j++) {
                    Long itemId = ((QuestionPoolItemData) list.get(j)).getItemId();
                    String query = "from ItemMetaData as meta where meta.item.itemId=? and meta.label=?";
                    Object[] values = { Long.valueOf(itemId), ItemMetaDataIfc.POOLID };
                    List m = getHibernateTemplate().find(query, values);
                    if (m.size() > 0) {
                        ItemMetaDataIfc meta = (ItemMetaDataIfc) m.get(0);
                        meta.setEntry(null);
                        metaList.add(meta);
                    }
                }
                try {
                    for (ItemMetaDataIfc meta : metaList) {
                        getHibernateTemplate().saveOrUpdate(meta);
                    }
                    retryCount = 0;
                } catch (DataAccessException e) {
                    log.warn("problem delete question and questionpool map inside itemMetaData: "
                            + e.getMessage());
                    retryCount = PersistenceService.getInstance().getPersistenceHelper().retryDeadlock(e,
                            retryCount);
                }

                // b. delete item and pool association in SAM_QUESTIONPOOLITEM_T
                if (list.size() > 0) {
                    questionPool.setQuestionPoolItems(new HashSet());
                    getHibernateTemplate().deleteAll(list);
                    retryCount = 0;
                } else
                    retryCount = 0;
            } catch (DataAccessException e) {
                log.warn("problem delete question and questionpool map: " + e.getMessage());
                retryCount = PersistenceService.getInstance().getPersistenceHelper().retryDeadlock(e,
                        retryCount);
            }
        }

        // #3. Pool is owned by one but can be shared by multiple agents. So need to
        // delete all QuestionPoolAccessData record first. This seems to be missing in Navigo, nope? - daisyf
        // Actually, I don't think we have ever implemented sharing between agents. So we may wnat to
        // clean up this bit of code - daisyf 07/07/06
        // #3a. Delete all shared pool by him sons
        final HibernateCallback hcb = new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException, SQLException {
                Query q = session
                        .createQuery("select qpa from QuestionPoolAccessData as qpa, QuestionPoolData as qpp "
                                + "where qpa.questionPoolId = qpp.questionPoolId and (qpp.questionPoolId=? or qpp.parentPoolId=?) ");
                q.setLong(0, poolId.longValue());
                q.setLong(1, poolId.longValue());
                return q.list();
            };
        };
        List qpaList = getHibernateTemplate().executeFind(hcb);
        retryCount = PersistenceService.getInstance().getPersistenceHelper().getRetryCount().intValue();
        while (retryCount > 0) {
            try {
                getHibernateTemplate().deleteAll(qpaList);
                retryCount = 0;
            } catch (DataAccessException e) {
                log.warn("problem delete question pool access data: " + e.getMessage());
                retryCount = PersistenceService.getInstance().getPersistenceHelper().retryDeadlock(e,
                        retryCount);
            }
        }

        // #4. Ready! delete pool now
        final HibernateCallback hcb2 = new HibernateCallback() {
            public Object doInHibernate(Session session) throws HibernateException, SQLException {
                Query q = session.createQuery("select qp from QuestionPoolData as qp where qp.id= ?");
                q.setLong(0, poolId.longValue());
                return q.list();
            };
        };
        List qppList = getHibernateTemplate().executeFind(hcb2);
        retryCount = PersistenceService.getInstance().getPersistenceHelper().getRetryCount().intValue();
        while (retryCount > 0) {
            try {
                getHibernateTemplate().deleteAll(qppList);
                retryCount = 0;
            } catch (DataAccessException e) {
                log.warn("problem delete all pools: " + e.getMessage());
                retryCount = PersistenceService.getInstance().getPersistenceHelper().retryDeadlock(e,
                        retryCount);
            }
        }

        // #5. delete all subpools if any, this is recursive
        Iterator citer = (tree.getChildList(poolId)).iterator();
        while (citer.hasNext()) {
            deletePool((Long) citer.next(), agent, tree);
        }
    } catch (DataAccessException e) {
        log.warn("error deleting pool. " + e.getMessage());
    }
}

From source file:org.sakaiproject.tool.assessment.facade.QuestionPoolFacadeQueries.java

/**
 * Move pool under another pool. The dest pool must not be the
 * descendant of the source nor can they be the same pool .
 *///from  www.  j  a v a 2s . com
public void movePool(String agentId, Long sourcePoolId, Long destPoolId) {
    try {
        QuestionPoolFacade sourcePool = getPool(sourcePoolId, agentId);
        if (destPoolId.equals(QuestionPoolFacade.ROOT_POOL)
                && !sourcePoolId.equals(QuestionPoolFacade.ROOT_POOL)) {
            sourcePool.setParentPoolId(QuestionPoolFacade.ROOT_POOL);
            int retryCount = PersistenceService.getInstance().getPersistenceHelper().getRetryCount().intValue();
            while (retryCount > 0) {
                try {
                    getHibernateTemplate().update((QuestionPoolData) sourcePool.getData());
                    retryCount = 0;
                } catch (DataAccessException e) {
                    log.warn("problem moving pool: " + e.getMessage());
                    retryCount = PersistenceService.getInstance().getPersistenceHelper().retryDeadlock(e,
                            retryCount);
                }
            }
        } else {
            QuestionPoolFacade destPool = getPool(destPoolId, agentId);
            sourcePool.setParentPoolId(destPool.getQuestionPoolId());
            int retryCount = PersistenceService.getInstance().getPersistenceHelper().getRetryCount().intValue();
            while (retryCount > 0) {
                try {
                    getHibernateTemplate().update((QuestionPoolData) sourcePool.getData());
                    retryCount = 0;
                } catch (DataAccessException e) {
                    log.warn("problem update source pool: " + e.getMessage());
                    retryCount = PersistenceService.getInstance().getPersistenceHelper().retryDeadlock(e,
                            retryCount);
                }
            }
        }
    } catch (RuntimeException e) {
        log.warn(e.getMessage());
    }
}