Example usage for org.springframework.dao DataAccessException printStackTrace

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

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:edu.harvard.i2b2.pm.dao.PMDbDao.java

public List<DBInfoType> getParam(Object utype, boolean showStatus) throws I2B2Exception, I2B2DAOException {
    //      log.info(sql + domainId + projectId + ownerId);
    List<DBInfoType> queryResult = null;
    try {// w ww  .j  a  v a  2s . com
        if (utype instanceof ProjectType) {
            if (((ProjectType) utype).getUserName() != null
                    && !((ProjectType) utype).getUserName().equals("")) {
                String sql = "select * from pm_project_user_params where id=?  "
                        + (showStatus == false ? "" : " and status_cd<>'D'");

                if (((ProjectType) utype).getParam().get(0).getId() != null)
                    queryResult = jt.query(sql, getParam(), ((ProjectType) utype).getParam().get(0).getId());

            } else {
                String sql = "select * from pm_project_params where id=?  "
                        + (showStatus == false ? "" : " and status_cd<>'D'");

                if (((ProjectType) utype).getParam().get(0).getId() != null)
                    queryResult = jt.query(sql, getParam(), ((ProjectType) utype).getParam().get(0).getId());
            }
        } else if (utype instanceof GlobalDataType) {
            String sql = "select * from pm_global_params where id=? "
                    + (showStatus == false ? "" : " and status_cd<>'D'");

            if (((GlobalDataType) utype).getParam().get(0).getId() != null)
                queryResult = jt.query(sql, getGlobal(), ((GlobalDataType) utype).getParam().get(0).getId());
        } else if (utype instanceof ApprovalType) {
            String sql = "select * from pm_approval_params where id=? "
                    + (showStatus == false ? "" : " and status_cd<>'D'");

            if (((ApprovalType) utype).getParam().get(0).getId() != null)
                queryResult = jt.query(sql, getParam(), ((UserType) utype).getParam().get(0).getId());
        } else if (utype instanceof UserType) {
            String sql = "select * from pm_user_params where id=? "
                    + (showStatus == false ? "" : " and status_cd<>'D'");

            if (((UserType) utype).getParam().get(0).getId() != null)
                queryResult = jt.query(sql, getParam(), ((UserType) utype).getParam().get(0).getId());
        } else if (utype instanceof CellDataType) {
            String sql = "select * from pm_cell_params where id=? "
                    + (showStatus == false ? "" : " and status_cd<>'D'");

            if (((CellDataType) utype).getParam().get(0).getId() != null)
                queryResult = jt.query(sql, getParam(), ((CellDataType) utype).getParam().get(0).getId());
        } else if (utype instanceof RoleType) {
            String sql = "select * from pm_project_user_roles where project_id=? and user_id=? "
                    + (showStatus == false ? "" : " and status_cd<>'D'");

            queryResult = jt.query(sql, getRole(), ((RoleType) utype).getProjectId(),
                    ((RoleType) utype).getUserName());

        } else if (utype instanceof ConfigureType) {
            if (((ConfigureType) utype).getParam().isEmpty() == false) // || (((ConfigureType) utype).getDomainId()).size() == 0))
            {
                String sql = "select * from pm_hive_params where id=? "
                        + (showStatus == false ? "" : " and status_cd<>'D'");

                if (((ConfigureType) utype).getParam().get(0).getId() != null)
                    queryResult = jt.query(sql, getParam(), ((ConfigureType) utype).getParam().get(0).getId());

            } else {
                String sql = "select * from pm_hive_data where active = '1' and domain_id=? "
                        + (showStatus == false ? "" : " and status_cd<>'D'");

                if (((ConfigureType) utype).getParam().get(0).getId() != null)
                    queryResult = jt.query(sql, getEnvironment(), ((ConfigureType) utype).getDomainId());
            }
        }
    } catch (DataAccessException e) {
        log.error(e.getMessage());
        e.printStackTrace();
        throw new I2B2DAOException("Database error");
    }
    return queryResult;
}

From source file:edu.mit.isda.permitservice.dataobjects.GeneralSelection.java

/**
 * retrieves a Criteria Set by selection ID and certificate username.
 *
 * @param   selectionID//from   w  ww .j a v a  2s  . com
 * @param   username
 * @return  {@link Category} matching the category code
 * @throws  InvalidInputException   If the category code is NULL or more than 4 characters long
 * @throws  ObjectNotFoundException If no category is found in the database matching the category code
 * @throws  AuthorizationException  in case of hibernate error   
 */
public Collection<Criteria> getCriteriaSet(String selectionID, String userName)
        throws InvalidInputException, ObjectNotFoundException, AuthorizationException {
    if (null == userName)
        throw new InvalidInputException();

    String name = userName.trim().toUpperCase();

    if (name.length() <= 0)
        throw new InvalidInputException();

    HibernateTemplate t = getHibernateTemplate();
    Collection crits = null;
    try {
        crits = t.findByNamedQuery("GET_CRITERIA", new String[] { name, selectionID });
        t.initialize(crits);
    } catch (DataAccessException e) {
        Exception re = (Exception) e.getCause();
        re.printStackTrace();
        SQLException se = null;
        if (re instanceof org.hibernate.exception.SQLGrammarException) {
            se = ((org.hibernate.exception.SQLGrammarException) re).getSQLException();
        } else if (e.getCause() instanceof SQLException) {
            se = (SQLException) e.getCause();
        }
        if (null != se) {
            int i = se.getErrorCode();
            String msg = se.getMessage();
            String errorMessage = se.getMessage() + " Error Code: " + se.getErrorCode();
            int index = msg.indexOf("\n");
            if (index > 0)
                msg = msg.substring(0, index);
            if (i == InvalidInputException.FunctionCategoryInvalidLength
                    || i == InvalidInputException.FunctionNameInvalidLength
                    || i == InvalidInputException.NeedKerberosName
                    || i == InvalidInputException.NeedFunctionCategory
                    || i == InvalidInputException.InvalidFunction
                    || i == InvalidInputException.QualifierTypeInvalidLength)
                throw new InvalidInputException(errorMessage, i);

            else
                throw new AuthorizationException(errorMessage);
        } else
            throw new AuthorizationException(e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (crits == null) {
        throw new AuthorizationException("error retrieving viewable categories");
    }

    return crits;
}

From source file:edu.mit.isda.permitservice.dataobjects.GeneralSelection.java

/**
 * retrieves a selection list by certificate username.
 *
 * @param   username//  w  w  w. j a  v  a2  s. com
 * @return  {@link Category} matching the category code
 * @throws  InvalidInputException   If the category code is NULL or more than 4 characters long
 * @throws  ObjectNotFoundException If no category is found in the database matching the category code
 * @throws  AuthorizationException  in case of hibernate error   
 */
public Collection<SelectionList> getSelectionList(String userName)
        throws InvalidInputException, ObjectNotFoundException, AuthorizationException {

    if (null == userName) {
        throw new InvalidInputException();
    }

    String name = userName.trim().toUpperCase();

    if (name.length() <= 0)
        throw new InvalidInputException();

    HibernateTemplate t = getHibernateTemplate();
    Collection crits = null;
    try {
        crits = t.findByNamedQuery("SELECTION_LIST", new String[] { name, name });
        t.initialize(crits);
    } catch (DataAccessException e) {
        Exception re = (Exception) e.getCause();
        re.printStackTrace();

        SQLException se = null;
        if (re instanceof org.hibernate.exception.SQLGrammarException) {
            se = ((org.hibernate.exception.SQLGrammarException) re).getSQLException();
        } else if (e.getCause() instanceof SQLException) {
            se = (SQLException) e.getCause();
        }
        if (null != se) {
            int i = se.getErrorCode();
            String msg = se.getMessage();
            String errorMessage = se.getMessage() + " Error Code: " + se.getErrorCode();
            int index = msg.indexOf("\n");
            if (index > 0)
                msg = msg.substring(0, index);
            if (i == InvalidInputException.FunctionCategoryInvalidLength
                    || i == InvalidInputException.FunctionNameInvalidLength
                    || i == InvalidInputException.NeedKerberosName
                    || i == InvalidInputException.NeedFunctionCategory
                    || i == InvalidInputException.InvalidFunction
                    || i == InvalidInputException.QualifierTypeInvalidLength)
                throw new InvalidInputException(errorMessage, i);

            else {
                throw new AuthorizationException(errorMessage);
            }
        } else {
            throw new AuthorizationException(e.getMessage());
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println(e.getMessage());

    }
    if (crits == null) {
        throw new AuthorizationException("error retrieving viewable categories");
    }

    return crits;
}

From source file:edu.mit.isda.permitservice.dataobjects.HibernateAuthorizationMgr.java

/**
* Select Criteria Qualifiers for which userName is authorized. 
*
* @param userName user's kerberos Id// ww w  . ja  va 2s.c om
* @param functionName funtion name
* @param qualifierType Qualifer Type
* @throws  InvalidInputException if qualifier type code is NULL or if the code is more than 4 characters long
* @throws  ObjectNotFoundException If no Qualifier is found 
* @throws  AuthorizationException  in case of hibernate error   
*/
public String getQualifierXMLForCriteriaQuery(String userName, String functionName, String qualifierType)
        throws InvalidInputException, PermissionException, AuthorizationException {
    if (null == userName || ((null == functionName) && (null == qualifierType)))
        throw new InvalidInputException();

    StringBuffer xmlBuff = new StringBuffer();
    Iterator qIt = null;
    Qualifier xmlqual = null;
    String pname = userName.trim().toUpperCase();
    String fname = "";
    String qtype = "";
    if (null != functionName) {
        fname = functionName.trim().toUpperCase();
    }
    if (null != qualifierType) {
        qtype = qualifierType.trim().toUpperCase();
    }
    // String qtype = "ZLEVELS_" + qualifier_type.trim().toUpperCase();

    total_qualifiers = 0;

    if (pname.length() <= 0 || (fname.length() <= 0 && qtype.length() <= 0))
        throw new InvalidInputException();

    HibernateTemplate t = getHibernateTemplate();
    Collection<Qualifier> quals = null;

    try {
        if (qtype.length() > 0) {
            quals = t.findByNamedQuery("QUALIFIER_ROOT_LIST", new String[] { qtype });

        } else {
            quals = t.findByNamedQuery("QUALIFIER_LIST_FOR_CRITERIA_LIST", new String[] { fname });
        }
        //System.out.println(t.toString());
        t.initialize(quals);
    }

    catch (DataAccessException e) {
        Exception re = (Exception) e.getCause();
        e.printStackTrace();

        SQLException se = null;
        if (re instanceof org.hibernate.exception.SQLGrammarException) {
            se = ((org.hibernate.exception.SQLGrammarException) re).getSQLException();
        } else if (e.getCause() instanceof SQLException) {
            se = (SQLException) e.getCause();
        }
        if (null != se) {
            int i = se.getErrorCode();
            String msg = se.getMessage();
            String errorMessage = se.getMessage() + " Error Code: " + se.getErrorCode();

            int index = msg.indexOf("\n");
            if (index > 0)
                msg = msg.substring(0, index);
            if (i == InvalidInputException.FunctionCategoryInvalidLength
                    || i == InvalidInputException.FunctionNameInvalidLength
                    || i == InvalidInputException.NeedKerberosName
                    || i == InvalidInputException.NeedFunctionCategory
                    || i == InvalidInputException.InvalidFunction
                    || i == InvalidInputException.QualifierTypeInvalidLength)
                throw new InvalidInputException(errorMessage, i);

            else if (i == PermissionException.ProxyNotAuthorized
                    || i == PermissionException.ServerNotAuthorized)
                throw new PermissionException(errorMessage, i);
            else
                throw new AuthorizationException(errorMessage);
        } else
            throw new AuthorizationException(e.getMessage());
    }

    xmlBuff.append("<qualifiers>");

    if (quals == null)
        throw new AuthorizationException("error retrieving qualifiers for user " + userName);

    //Set<PickableQualifier> qualSet = new HashSet<PickableQualifier>(quals);
    //System.out.println(quals.size());
    //System.out.println(qualSet.size());

    //qIt = qualSet.iterator();
    qIt = quals.iterator();

    while (qIt.hasNext()) {
        total_qualifiers++;
        //System.out.println("Total = " + total_qualifiers);
        xmlqual = (Qualifier) qIt.next();
        xmlBuff.append("<qualifier>");
        xmlBuff.append("<qid>");
        xmlBuff.append(xmlqual.getId());
        xmlBuff.append("</qid>");
        xmlBuff.append("<expanded>");
        xmlBuff.append("true");
        xmlBuff.append("</expanded>");
        xmlBuff.append("<qcode>");
        xmlBuff.append(cleanup(xmlqual.getCode(), false));
        xmlBuff.append("</qcode>");
        xmlBuff.append("<qname>");
        xmlBuff.append(cleanup(xmlqual.getName(), false));
        xmlBuff.append("</qname>");
        xmlBuff.append("<hasChild>");
        xmlBuff.append(cleanup(xmlqual.getHasChild().toString(), false));
        xmlBuff.append("</hasChild>");
        // Get children only for non DEPT qualifyers
        if (xmlqual.getHasChild()) {
            xmlBuff.append("<qchildren>");
            xmlBuff.append(getChildrenXML(xmlqual.getId().toString(), 1, 1));
            xmlBuff.append("</qchildren>");
        }
        xmlBuff.append("</qualifier>");
    }

    xmlBuff.append("</qualifiers>");
    //System.out.println("Final Buffer = " + xmlBuff.toString());
    return xmlBuff.toString();
}

From source file:edu.psu.citeseerx.myciteseer.web.groups.ViewGroupMembersController.java

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    String errMsg = null;/*  w w  w  .jav  a 2 s.c o m*/
    boolean error = false;

    try {
        String tab = ServletRequestUtils.getStringParameter(request, "tab", "Members");
        long groupID = ServletRequestUtils.getLongParameter(request, "gid", -1);

        // Do validations
        if (groupID == -1) {
            error = true;
            errMsg = "Bad group ID: \"" + groupID + "\"";
        }

        Group group = null;
        Account account = MCSUtils.getLoginAccount();
        if (!error) {
            group = myciteseer.getGroup(groupID);
            if (group == null) {
                error = true;
                errMsg = "Bad group ID: \"" + groupID + "\"";
            }
        }

        if (error) {
            // Something wrong happened send the error to the user 
            return MCSUtils.errorPage(errMsg);
        }

        List<GroupMember> members = new ArrayList<GroupMember>();
        List<GroupMember> validating = new ArrayList<GroupMember>();
        List<GroupMember> allMembers = myciteseer.getMembers(group);

        for (Iterator<GroupMember> it = allMembers.iterator(); it.hasNext();) {
            GroupMember member = (GroupMember) it.next();
            if (member.getValidating()) {
                validating.add(member);
            } else {
                members.add(member);
            }

        }

        // Obtain the members to be shown (because of pagination)
        int membersPageNumber = ServletRequestUtils.getIntParameter(request, "mpn", 1);
        String mSort = ServletRequestUtils.getStringParameter(request, "msort", SORT_NAME);
        String smType = ServletRequestUtils.getStringParameter(request, "smtype", "asc");
        Paginator membersPaginator = new Paginator();
        membersPaginator.setComparator(getUserGroupComparator(mSort, smType));
        membersPaginator.setPageSize(MCSConstants.MAX_RECORDS_PER_PAGE);
        Page membersPage = membersPaginator.fetchPage(membersPageNumber, members);

        // Obtain users to be validate as group members  to be shown 
        // (because of pagination)
        int validatingPageNumber = ServletRequestUtils.getIntParameter(request, "vpn", 1);
        String vSort = ServletRequestUtils.getStringParameter(request, "vsort", "name");
        String svType = ServletRequestUtils.getStringParameter(request, "svtype", "asc");
        Paginator validatingPaginator = new Paginator();
        validatingPaginator.setComparator(getUserGroupComparator(vSort, svType));
        validatingPaginator.setPageSize(MCSConstants.MAX_RECORDS_PER_PAGE);
        Page validatingPage = validatingPaginator.fetchPage(validatingPageNumber, validating);

        // Generate page parameters.
        // Generate parameters
        String pageParam = "?gid=" + group.getId();

        // Add page number and item used to sort for members
        String nameQueryMembers = pageParam + "&amp;mpn=" + membersPageNumber + "&amp;vpn="
                + validatingPageNumber;

        nameQueryMembers += "&amp;smtype=" + (smType.equalsIgnoreCase("asc") ? "desc" : "asc") + "&amp;msort="
                + mSort + "&amp;svtype=" + (svType.equalsIgnoreCase("asc") ? "desc" : "asc") + "&amp;vsort="
                + vSort;
        String nameQueryVal = nameQueryMembers;

        nameQueryMembers += "&amp;tab=Members";
        nameQueryVal += "&amp;tab=Validating";

        pageParam += "&amp;msort=" + mSort + "&amp;smtype=" + smType + "&amp;vsort=" + vSort + "&amp;svtype="
                + svType;

        // Next page parameters
        String nextPageParamsMembers = null;
        if (membersPage.getPageNumber() < membersPage.getTotalPages()) {
            nextPageParamsMembers = pageParam + "&amp;tab=Members&amp;mpn=" + (membersPage.getPageNumber() + 1)
                    + "&amp;vpn=" + validatingPageNumber;
        }
        String nextPageParamsValidating = null;
        if (validatingPage.getPageNumber() < validatingPage.getTotalPages()) {
            nextPageParamsValidating = pageParam + "&amp;tab=Validating&amp;vpn="
                    + (validatingPage.getPageNumber() + 1) + "&amp;mpn=" + membersPageNumber;
        }
        // Previous page parameters   
        String previousPageParamsMembers = null;
        if (membersPage.getPageNumber() > 1) {
            previousPageParamsMembers = pageParam + "&amp;tab=Members&amp;mpn="
                    + (membersPage.getPageNumber() - 1) + "&amp;vpn=" + validatingPageNumber;
        }
        String previousPageParamsValidating = null;
        if (validatingPage.getPageNumber() > 1) {
            previousPageParamsValidating = pageParam + "&amp;tab=Validating&amp;gmopn="
                    + (validatingPage.getPageNumber() - 1) + "&amp;mpn=" + membersPageNumber;
        }
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("members", membersPage.getPageContent());
        model.put("msize", members.size());
        model.put("tpm", membersPage.getTotalPages());
        model.put("mpn", membersPage.getPageNumber());
        model.put("validating", validatingPage.getPageContent());
        model.put("vsize", validating.size());
        model.put("tpv", validatingPage.getTotalPages());
        model.put("vpn", validatingPage.getPageNumber());
        model.put("nextpageparamsmem", nextPageParamsMembers);
        model.put("previouspageparamsmem", previousPageParamsMembers);
        model.put("nextpageparamsval", nextPageParamsValidating);
        model.put("previouspageparamsval", previousPageParamsValidating);
        model.put("nameqm", nameQueryMembers);
        model.put("nameqv", nameQueryVal);
        model.put("smtype", smType);
        model.put("msort", mSort);
        model.put("svtype", svType);
        model.put("vsort", vSort);
        model.put("group", group);
        model.put("tab", tab);
        boolean isOwner = group.getOwner().compareToIgnoreCase(account.getUsername()) == 0 ? true : false;
        model.put("isowner", isOwner);
        return new ModelAndView("viewGroupMembers", model);
    } catch (DataAccessException e) {
        e.printStackTrace();
        errMsg = "An error ocurred while trying to get the group users.";
        return MCSUtils.errorPage(errMsg);
    }
}

From source file:org.sakaiproject.sitemanage.impl.SiteSetupQuestionServiceImpl.java

/**
 * {@inheritDoc}//from   w ww  . jav a 2s .  c om
 */
public boolean saveSiteSetupQuestion(SiteSetupQuestion q) {
    try {
        getHibernateTemplate().saveOrUpdate(q);
        return true;
    } catch (DataAccessException e) {
        e.printStackTrace();
        Log.warn(this + ".saveSiteSetupQuestion() Hibernate could not save. question=" + q.getQuestion());
        return false;
    }
}

From source file:org.sakaiproject.sitemanage.impl.SiteSetupQuestionServiceImpl.java

/**
 * {@inheritDoc}//from  w w w. j  av  a 2s.  co m
 */
public boolean removeSiteSetupQuestion(SiteSetupQuestion question) {
    try {
        //org.hibernate.LockMode cannot be resolved. It is indirectly referenced from required .class files.
        getHibernateTemplate().delete(question);
        return true;
    } catch (DataAccessException e) {
        e.printStackTrace();
        if (Log.isErrorEnabled())
            Log.error(this + ".removeSiteSetupQuestion() Hibernate could not delete: question="
                    + question.getQuestion());
        return false;
    }
}

From source file:org.sakaiproject.sitemanage.impl.SiteSetupQuestionServiceImpl.java

/**
 * {@inheritDoc}/*from  w w w .jav  a  2  s. com*/
 */
public boolean saveSiteSetupQuestionAnswer(SiteSetupQuestionAnswer answer) {
    try {
        getHibernateTemplate().saveOrUpdate(answer);
        return true;
    } catch (DataAccessException e) {
        e.printStackTrace();
        Log.warn(
                this + ".saveSiteSetupQuestionAnswer() Hibernate could not save. answer=" + answer.getAnswer());
        return false;
    }
}

From source file:org.sakaiproject.sitemanage.impl.SiteSetupQuestionServiceImpl.java

/**
 * {@inheritDoc}/*from   w ww.  j  av a 2s.  c  om*/
 */
public boolean removeSiteSetupQuestionAnswer(SiteSetupQuestionAnswer answer) {
    try {
        //org.hibernate.LockMode cannot be resolved. It is indirectly referenced from required .class files.
        getHibernateTemplate().delete(answer);
        return true;
    } catch (DataAccessException e) {
        e.printStackTrace();
        if (Log.isErrorEnabled())
            Log.error(this + ".removeSiteSetupQuestionAnswer() Hibernate could not delete: answer="
                    + answer.getAnswer());
        return false;
    }
}

From source file:org.sakaiproject.sitemanage.impl.SiteSetupQuestionServiceImpl.java

/**
 * {@inheritDoc}/*from ww w  .  ja  v  a2s . c o  m*/
 */
public boolean saveSiteTypeQuestions(SiteTypeQuestions siteTypeQuestions) {
    try {
        getHibernateTemplate().saveOrUpdate(siteTypeQuestions);
        return true;
    } catch (DataAccessException e) {
        e.printStackTrace();
        Log.warn(this + ".saveSiteTypeQuestions() Hibernate could not save. siteType="
                + siteTypeQuestions.getSiteType());
        return false;
    }
}