use of org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException in project Openfire by igniterealtime.
the class PropertyDAO method getUsernameByProperty.
/**
* Gets the username by property key and or value.
*
* @param propertyName
* the property name
* @param propertyValue
* the property value (can be null)
* @return the username by property
* @throws ServiceException
* the service exception
*/
public static List<String> getUsernameByProperty(String propertyName, String propertyValue) throws ServiceException {
List<String> usernames = new ArrayList<String>();
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
con = DbConnectionManager.getConnection();
// Load property by key and value
if (propertyValue != null) {
pstmt = con.prepareStatement(LOAD_PROPERTY);
pstmt.setString(1, propertyName);
pstmt.setString(2, propertyValue);
} else {
// Load property by key
pstmt = con.prepareStatement(LOAD_PROPERTY_BY_KEY);
pstmt.setString(1, propertyName);
}
rs = pstmt.executeQuery();
while (rs.next()) {
usernames.add(rs.getString(1));
}
} catch (SQLException sqle) {
throw new ServiceException("Could not get username by property", propertyName, ExceptionType.PROPERTY_NOT_FOUND, Response.Status.NOT_FOUND, sqle);
} finally {
DbConnectionManager.closeConnection(rs, pstmt, con);
}
return usernames;
}
Aggregations