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:com.sfs.whichdoctor.dao.OnlineApplicationDAOImpl.java

/**
 * Create or update the OnlineApplicationBean.
 * If an application exists with the same key or id value then update the existing.
 *
 * @param onlineApplication the online application
 *
 * @return the Id of the created OnlineApplication if successful
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 *//*  www .j av a 2  s .  c  o m*/
public final int createOrUpdate(final OnlineApplicationBean onlineApplication) throws WhichDoctorDaoException {

    if (StringUtils.isBlank(onlineApplication.getKey())) {
        throw new WhichDoctorDaoException("The online application requires a " + "valid key");
    }

    if (StringUtils.isBlank(onlineApplication.getFirstName())) {
        throw new WhichDoctorDaoException("The online application requires a " + "valid first name");
    }

    if (StringUtils.isBlank(onlineApplication.getLastName())) {
        throw new WhichDoctorDaoException("The online application requires a " + "valid last name");
    }

    int onlineApplicationId = 0;
    boolean updateOperation = false;

    if (StringUtils.isNotBlank(onlineApplication.getKey())) {
        // Check to see if an unprocessed online application with this key exists
        try {
            final OnlineApplicationBean existingApplication = this.load(onlineApplication.getKey(),
                    onlineApplication.getType());

            if (existingApplication != null) {
                // An online application exists with this key and type, check the id
                updateOperation = true;

                if (onlineApplication.getId() == 0) {
                    onlineApplication.setId(existingApplication.getId());
                }

                if (existingApplication.getId() != onlineApplication.getId()
                        && existingApplication.getProcessed()) {
                    // The two applications have different internal identifiers and
                    // the existing application is unprocessed - throw exception.
                    throw new WhichDoctorDaoException("A different online application"
                            + " with the same key already exists - potential conflict"
                            + ", so change not recorded");
                }
            }
        } catch (WhichDoctorDaoException wde) {
            dataLogger.error("Error loading online application: " + wde.getMessage());
        }
    }

    // Load the status and type ids (can throw an exception)
    Integer[] statusIdDetails = getStatusIdDetails(onlineApplication.getType(), onlineApplication.getStatus(),
            onlineApplication.getRecordNumber());

    // If the order Id = PROCESSED_ORDER_ID then the application is processed
    int statusId = statusIdDetails[0];
    int orderId = statusIdDetails[1];

    onlineApplication.setProcessed(false);
    if (orderId == PROCESSED_ORDER_ID) {
        onlineApplication.setProcessed(true);
    }

    if (updateOperation) {
        // Update the existing online application entry
        // Set the timestamp value
        Timestamp updateTimeStamp = new Timestamp(Calendar.getInstance().getTimeInMillis());

        try {
            final int updateCount = this.getJdbcTemplateWriter().update(
                    this.getSQL().getValue("onlineapplication/modify"),
                    new Object[] { onlineApplication.getKey(), onlineApplication.getFirstName(),
                            onlineApplication.getLastName(), onlineApplication.getPersonGUID(),
                            onlineApplication.getApplicationXml(), statusId, onlineApplication.getProcessed(),
                            updateTimeStamp, onlineApplication.getId() });

            if (updateCount > 0) {
                onlineApplicationId = onlineApplication.getId();
            }

        } catch (DataAccessException de) {
            dataLogger.error("Error updating the online application: " + de.getMessage());
        }

    } else {
        // Create a new online application entry
        // Set the timestamp value
        Timestamp creationTimeStamp = new Timestamp(Calendar.getInstance().getTimeInMillis());

        try {
            final int createCount = this.getJdbcTemplateWriter().update(
                    this.getSQL().getValue("onlineapplication/create"),
                    new Object[] { onlineApplication.getKey(), onlineApplication.getFirstName(),
                            onlineApplication.getLastName(), onlineApplication.getPersonGUID(),
                            onlineApplication.getApplicationXml(), statusId, onlineApplication.getProcessed(),
                            creationTimeStamp, creationTimeStamp });

            if (createCount > 0) {
                // Get the maximum id
                onlineApplicationId = this.getJdbcTemplateReader()
                        .queryForInt(this.getSQL().getValue("onlineapplication/findMax"));
            }

        } catch (DataAccessException de) {
            dataLogger.error("Error creating the online application: " + de.getMessage());
        }
    }

    return onlineApplicationId;
}

From source file:org.sakaiproject.delegatedaccess.dao.impl.DelegatedAccessDaoImpl.java

public List<String> getDelegatedAccessUsers() {
    try {/*from   w ww .j av a  2  s.  c  om*/
        return getJdbcTemplate().query(getStatement("select.delegatedaccess.user"), new RowMapper() {
            public Object mapRow(ResultSet resultSet, int i) throws SQLException {
                return resultSet.getString("userId");
            }
        });
    } catch (DataAccessException ex) {
        log.error("Error executing query: " + ex.getClass() + ":" + ex.getMessage(), ex);
        return null;
    }
}

From source file:com.webapp.security.SecurityDataContext.java

/**
* @param login//from  ww  w .  ja v  a 2  s  .c o  m
* 
* @return
*/
private String createLogin(final Login login) {

    final String insertSql = "insert into SECURITY_LOGIN (CONTEXT,NAME,PASSWORD,PARTY) values (?,?,?,?)";

    LOG.info("Inserting new login (" + login.getPrincipal().getName() + ") into " + getName());

    if (login.getCredentials() != null && login.getCredentials().contains(CredentialSet.PASSWORD)) {

        // Get the credentials
        byte[] value = login.getCredentials().getValue(CredentialSet.PASSWORD);

        // If there is a value for the password...
        if (value != null && value.length > 0) {

            // turn it into a hex string
            final String dbValue = ByteUtil.bytesToHex(value, null);

            KeyHolder keyHolder = new GeneratedKeyHolder();

            try {
                jdbcTemplate.update(new PreparedStatementCreator() {
                    public PreparedStatement createPreparedStatement(Connection connection)
                            throws SQLException {

                        PreparedStatement ps = connection.prepareStatement(insertSql.toString(),
                                Statement.RETURN_GENERATED_KEYS);
                        ps.setString(1, getName().toLowerCase()); //context
                        ps.setString(2, login.getPrincipal().getName().toLowerCase()); // name
                        ps.setString(3, dbValue); // password
                        ps.setLong(4, 0);// No party ID for now
                        return ps;
                    }
                }, keyHolder);
            } catch (DataAccessException e) {
                LOG.error("Could not create login: " + e.getMessage());
                return null;
            }

            // Return the ID of the login
            return keyHolder.getKey().toString();

        } else {
            LOG.error("Empty password - login not added");
        }
    } else {
        LOG.error("No login credentials - login not added");
    }

    return null;
}

From source file:org.sakaiproject.delegatedaccess.dao.impl.DelegatedAccessDaoImpl.java

@SuppressWarnings("unchecked")
public List<String> getDistinctSiteTerms(String termField) {
    try {/*from   w w w .  j a v a 2  s.  c om*/
        return getJdbcTemplate().query(getStatement("select.distinctTerms"), new String[] { termField },
                new RowMapper() {
                    public Object mapRow(ResultSet resultSet, int i) throws SQLException {
                        return resultSet.getString(1);
                    }
                });
    } catch (DataAccessException ex) {
        log.error("Error executing query: " + ex.getClass() + ":" + ex.getMessage(), ex);
        return null;
    }
}

From source file:org.sakaiproject.delegatedaccess.dao.impl.DelegatedAccessDaoImpl.java

public String getSiteProperty(String propertyName, String siteId) {
    try {//  w  w w. ja v a2 s.  c o m
        return (String) getJdbcTemplate().queryForObject(getStatement("select.siteProperty"),
                new Object[] { propertyName, siteId }, new RowMapper() {

                    public Object mapRow(ResultSet resultSet, int i) throws SQLException {
                        return resultSet.getString("VALUE");
                    }
                });
    } catch (DataAccessException ex) {
        log.error("Error executing query: " + ex.getClass() + ":" + ex.getMessage(), ex);
        return null;
    }
}

From source file:org.sakaiproject.delegatedaccess.dao.impl.DelegatedAccessDaoImpl.java

public List<String> getEmptyNonSiteNodes(String hierarchyId) {
    try {// w w  w  .j a  v  a2s  .  com
        return (List<String>) getJdbcTemplate().query(getStatement("select.emptyNodes"),
                new Object[] { hierarchyId }, new RowMapper() {

                    public Object mapRow(ResultSet resultSet, int i) throws SQLException {
                        return resultSet.getString("ID");
                    }
                });
    } catch (DataAccessException ex) {
        log.error("Error executing query: " + ex.getClass() + ":" + ex.getMessage(), ex);
        return null;
    }
}

From source file:com.sfs.whichdoctor.dao.IsbEntityDAOImpl.java

/**
 * Updates the Internal Update timestamp for all active ISB entities with
 * the specified GUID./*  www  . j  a  v a2 s  . com*/
 *
 * @param guid the guid
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final void update(final int guid) throws WhichDoctorDaoException {

    final Timestamp sqlTimeStamp = new Timestamp(Calendar.getInstance().getTimeInMillis());

    try {
        this.getJdbcTemplateWriter().update(this.getSQL().getValue("isbentity/updateId"),
                new Object[] { sqlTimeStamp, guid, true });

    } catch (DataAccessException de) {
        dataLogger.error("Error updating ISB entity update time: " + de.getMessage());
    }
}

From source file:com.sfs.whichdoctor.dao.IsbEntityDAOImpl.java

/**
 * Updates the Internal Update timestamp for all active ISB entities with
 * the specified identifier string.//from  w  w  w . ja v  a 2  s  .  co  m
 *
 * @param identifier the identifier
 *
 * @throws WhichDoctorDaoException the which doctor dao exception
 */
public final void update(final String identifier) throws WhichDoctorDaoException {

    final Timestamp sqlTimeStamp = new Timestamp(Calendar.getInstance().getTimeInMillis());

    try {

        this.getJdbcTemplateWriter().update(this.getSQL().getValue("isbentity/updateIdentifier"),
                new Object[] { sqlTimeStamp, identifier, true });

    } catch (DataAccessException de) {
        dataLogger.error("Error updating ISB entity update time: " + de.getMessage());
    }
}

From source file:com.webapp.security.SecurityDataContext.java

/**
 * @param role//  w ww .  j  a v a 2 s. com
 */
private boolean createRole(final Role role) {
    if (role != null) {
        final String insertRoleSql = "insert into SECURITY_ROLE (CONTEXT, ROLE, DESCRIPTION) values (?,?,?)";
        final String insertRolePermSql = "insert into SECURITY_ROLE_PERMISSION (CONTEXT, ROLE, TARGET, PERMISSION) values (?,?,?,?)";

        LOG.info("Inserting new role (" + role.getName() + "-" + role.getDescription() + ") into " + getName()
                + " context");

        // If there is a value for the password...
        if (role.getName() != null && role.getName().trim().length() > 0) {

            try {
                jdbcTemplate.update(new PreparedStatementCreator() {
                    public PreparedStatement createPreparedStatement(Connection connection)
                            throws SQLException {

                        PreparedStatement ps = connection.prepareStatement(insertRoleSql.toString(),
                                Statement.RETURN_GENERATED_KEYS);
                        ps.setString(1, getName().toLowerCase()); //context
                        ps.setString(2, role.getName().toLowerCase()); // name
                        ps.setString(3, role.getDescription()); // description
                        return ps;
                    }
                });
            } catch (DataAccessException e) {
                LOG.error("Could not create role: " + e.getMessage());
                return false;
            }

            // now we have to insert any permissions in the role

            List<Permission> perms = role.getPermissions();
            for (final Permission perm : perms) {

                try {
                    jdbcTemplate.update(new PreparedStatementCreator() {
                        public PreparedStatement createPreparedStatement(Connection connection)
                                throws SQLException {

                            PreparedStatement ps = connection.prepareStatement(insertRolePermSql.toString(),
                                    Statement.RETURN_GENERATED_KEYS);
                            ps.setString(1, getName().toLowerCase()); //context
                            ps.setString(2, role.getName().toLowerCase()); // name
                            ps.setString(3, perm.getTarget()); // target of the permission
                            ps.setLong(4, perm.getAction());
                            return ps;
                        }
                    });
                } catch (DataAccessException e) {
                    LOG.error("Could not record permission target '" + perm.getTarget() + "' for role '"
                            + role.getName() + "' : " + e.getMessage());
                    return false;
                }

            }

            return true;
        } else {
            LOG.error("Empty role name - role not added");
        }
    } else {
        LOG.error("Null role cannot be added to context");
    }
    return false;
}

From source file:org.sakaiproject.delegatedaccess.dao.impl.DelegatedAccessDaoImpl.java

public void removeSiteProperty(String[] siteIds, String propertyName) {
    try {//from w w  w. j av a  2  s  . c  om
        if (siteIds == null || siteIds.length == 0) {
            return;
        }
        int subArrayIndex = 0;
        do {
            int subArraySize = ORACLE_IN_CLAUSE_SIZE_LIMIT;
            if (subArrayIndex + subArraySize > siteIds.length) {
                subArraySize = (siteIds.length - subArrayIndex);
            }
            String[] subSiteRefs = Arrays.copyOfRange(siteIds, subArrayIndex, subArrayIndex + subArraySize);

            String query1 = getStatement("delete.siteProperty");

            String inParams = "(";
            for (int i = 0; i < subSiteRefs.length; i++) {
                inParams += "?";
                if (i < subSiteRefs.length - 1) {
                    inParams += ",";
                }
            }
            inParams += ")";
            query1 = query1.replace("(?)", inParams);
            List<String> parameters = new ArrayList<String>();
            parameters.add(propertyName);
            parameters.addAll(Arrays.asList(subSiteRefs));
            getJdbcTemplate().update(query1, parameters.toArray());
            subArrayIndex = subArrayIndex + subArraySize;
        } while (subArrayIndex < siteIds.length);
    } catch (DataAccessException ex) {
        log.error("Error executing query: " + ex.getClass() + ":" + ex.getMessage(), ex);
    }
}