本文整理汇总了Java中org.apache.shiro.util.JdbcUtils.closeResultSet方法的典型用法代码示例。如果您正苦于以下问题:Java JdbcUtils.closeResultSet方法的具体用法?Java JdbcUtils.closeResultSet怎么用?Java JdbcUtils.closeResultSet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.shiro.util.JdbcUtils
的用法示例。
在下文中一共展示了JdbcUtils.closeResultSet方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getObject
import org.apache.shiro.util.JdbcUtils; //导入方法依赖的package包/类
@Override
public Map<String, String> getObject() throws Exception {
Connection connection = dataSource.getConnection();
PreparedStatement ps = connection.prepareStatement(sql);
ResultSet rs = null;
Map<String, String> filters = new LinkedHashMap<>();
try {
rs = ps.executeQuery();
while (rs.next()) {
String url = rs.getString(1);
String permission = rs.getString(2);
filters.put(url, String.format(PERMISSION_STRING, permission));
LOGGER.debug("Load filter chain via JDBC: {} -> {}", url, permission);
}
} finally {
JdbcUtils.closeResultSet(rs);
}
return filters;
}
示例2: getObject
import org.apache.shiro.util.JdbcUtils; //导入方法依赖的package包/类
public Map<String, String> getObject() throws Exception {
Connection connection = dataSource.getConnection();
PreparedStatement ps = connection.prepareStatement(sql);
ResultSet rs = null;
Map<String, String> filters = new LinkedHashMap<String, String>();
try {
rs = ps.executeQuery();
while (rs.next()) {
String url = rs.getString(1);
String permission = rs.getString(2);
filters.put(url, String.format(PERMISSION_STRING, permission));
}
} finally {
JdbcUtils.closeResultSet(rs);
}
return filters;
}
示例3: getUserIdFromUserName
import org.apache.shiro.util.JdbcUtils; //导入方法依赖的package包/类
private int getUserIdFromUserName(Connection conn, String username)
throws SQLException {
PreparedStatement ps = null;
ResultSet rs = null;
int uid = -1;
try {
ps = conn.prepareStatement(USER_ID_QUERY);
ps.setString(1, username);
// Execute query
rs = ps.executeQuery();
rs.next();
uid = rs.getInt(1);
} finally {
JdbcUtils.closeResultSet(rs);
JdbcUtils.closeStatement(ps);
}
return uid;
}
示例4: getRoleNamesForUser
import org.apache.shiro.util.JdbcUtils; //导入方法依赖的package包/类
protected Set<String> getRoleNamesForUser(Connection conn, String username) throws SQLException {
PreparedStatement ps = null;
ResultSet rs = null;
Set<String> roleNames = new LinkedHashSet<String>();
try {
ps = conn.prepareStatement(userRolesQuery);
ps.setString(1, username);
// Execute query
rs = ps.executeQuery();
// Loop over results and add each returned role to a set
while (rs.next()) {
String roleName = rs.getString(1);
// Add the role to the list of names if it isn't null
if (roleName != null) {
roleNames.add(roleName);
} else {
if (log.isWarnEnabled()) {
log.warn("Null role name found while retrieving role names for user [" + username + "]");
}
}
}
} finally {
JdbcUtils.closeResultSet(rs);
JdbcUtils.closeStatement(ps);
}
return roleNames;
}
示例5: getPermissions
import org.apache.shiro.util.JdbcUtils; //导入方法依赖的package包/类
protected Set<String> getPermissions(Connection conn, String username, Collection<String> roleNames) throws SQLException {
PreparedStatement ps = null;
Set<String> permissions = new LinkedHashSet<String>();
try {
ps = conn.prepareStatement(permissionsQuery);
for (String roleName : roleNames) {
ps.setString(1, roleName);
ResultSet rs = null;
try {
// Execute query
rs = ps.executeQuery();
// Loop over results and add each returned role to a set
while (rs.next()) {
String permissionString = rs.getString(1);
// Add the permission to the set of permissions
permissions.add(permissionString);
}
} finally {
JdbcUtils.closeResultSet(rs);
}
}
} finally {
JdbcUtils.closeStatement(ps);
}
return permissions;
}
示例6: getRoleNamesForUser
import org.apache.shiro.util.JdbcUtils; //导入方法依赖的package包/类
protected Set<String> getRoleNamesForUser(Connection conn, String username)
throws SQLException {
PreparedStatement ps = null;
ResultSet rs = null;
Set<String> roleNames = new LinkedHashSet<String>();
try {
ps = conn.prepareStatement(userRolesQuery);
ps.setString(1, username);
// Execute query
rs = ps.executeQuery();
// Loop over results and add each returned role to a set
while (rs.next()) {
String roleName = rs.getString(1);
// Add the role to the list of names if it isn't null
if (roleName != null) {
roleNames.add(roleName);
} else {
if (log.isWarnEnabled()) {
log.warn("Null role name found while retrieving role names for user ["
+ username + "]");
}
}
}
} finally {
JdbcUtils.closeResultSet(rs);
JdbcUtils.closeStatement(ps);
}
return roleNames;
}
示例7: getPasswordForUser
import org.apache.shiro.util.JdbcUtils; //导入方法依赖的package包/类
private String[] getPasswordForUser(Connection conn, String username) throws SQLException {
String[] result;
boolean returningSeparatedSalt = false;
switch (saltStyle) {
case NO_SALT:
case CRYPT:
case EXTERNAL:
result = new String[1];
break;
default:
result = new String[2];
returningSeparatedSalt = true;
}
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = conn.prepareStatement(authenticationQuery);
ps.setString(1, username);
// Execute query
rs = ps.executeQuery();
// Loop over results - although we are only expecting one result, since usernames should be unique
boolean foundResult = false;
while (rs.next()) {
// Check to ensure only one row is processed
if (foundResult) {
throw new AuthenticationException("More than one user row found for user [" + username + "]. Usernames must be unique.");
}
result[0] = rs.getString(1);
if (returningSeparatedSalt) {
result[1] = rs.getString(2);
}
foundResult = true;
}
} finally {
JdbcUtils.closeResultSet(rs);
JdbcUtils.closeStatement(ps);
}
return result;
}
示例8: getPasswordForUser
import org.apache.shiro.util.JdbcUtils; //导入方法依赖的package包/类
private String[] getPasswordForUser(Connection conn, String username) throws SQLException {
String[] result;
boolean returningSeparatedSalt = false;
switch (saltStyle) {
case NO_SALT:
case CRYPT:
case EXTERNAL:
result = new String[1];
break;
default:
result = new String[2];
returningSeparatedSalt = true;
}
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = conn.prepareStatement(authenticationQuery);
ps.setString(1, username);
// Execute query
rs = ps.executeQuery();
// Loop over results - although we are only expecting one result, since usernames should be unique
boolean foundResult = false;
while (rs.next()) {
// Check to ensure only one row is processed
if (foundResult) {
throw new AuthenticationException("More than one user row found for user [" + username + "]. Usernames must be unique.");
}
result[0] = rs.getString(1);
if (returningSeparatedSalt) {
result[1] = rs.getString(2);
}
foundResult = true;
}
} finally {
JdbcUtils.closeResultSet(rs);
JdbcUtils.closeStatement(ps);
}
return result;
}
示例9: getPasswordForUser
import org.apache.shiro.util.JdbcUtils; //导入方法依赖的package包/类
private String[] getPasswordForUser(Connection conn, String email)
throws SQLException {
String[] result;
boolean returningSeparatedSalt = false;
switch (saltStyle) {
case NO_SALT:
case CRYPT:
case EXTERNAL:
result = new String[1];
break;
default:
result = new String[2];
returningSeparatedSalt = true;
}
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = conn.prepareStatement(authenticationQuery);
ps.setString(1, email); // set email address
// Loop over results - although we are only expecting one result,
// since usernames should be unique
rs = ps.executeQuery();
boolean foundResult = false;
while (rs.next()) {
// Check to ensure only one row is processed
if (foundResult) {
throw new AuthenticationException(
"More than one user row found for user [" + email
+ "]. Emails must be unique.");
}
result[0] = rs.getString(1);
if (returningSeparatedSalt) {
result[1] = rs.getString(2);
}
foundResult = true;
}
} finally {
JdbcUtils.closeResultSet(rs);
JdbcUtils.closeStatement(ps);
}
return result;
}
示例10: getPasswordForUser
import org.apache.shiro.util.JdbcUtils; //导入方法依赖的package包/类
private String[] getPasswordForUser(Connection conn, String username)
throws SQLException {
String[] result;
boolean returningSeparatedSalt = false;
switch (saltStyle) {
case NO_SALT:
case CRYPT:
case EXTERNAL:
result = new String[1];
break;
default:
result = new String[2];
returningSeparatedSalt = true;
}
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = conn.prepareStatement(authenticationQuery);
ps.setString(1, username);
// Execute query
rs = ps.executeQuery();
// Loop over results - although we are only expecting one result,
// since usernames should be unique
boolean foundResult = false;
while (rs.next()) {
// Check to ensure only one row is processed
if (foundResult) {
throw new AuthenticationException(
"More than one user row found for user ["
+ username + "]. Usernames must be unique.");
}
result[0] = rs.getString(1);
if (returningSeparatedSalt) {
result[1] = rs.getString(2);
}
foundResult = true;
}
} finally {
JdbcUtils.closeResultSet(rs);
JdbcUtils.closeStatement(ps);
}
return result;
}
示例11: getPermissions
import org.apache.shiro.util.JdbcUtils; //导入方法依赖的package包/类
/**
* refactored this to perform a single query -- much more performant
*
* @param conn
* @param username
* @param roleNames
* @return
* @throws SQLException
*/
protected Set<String> getPermissions(Connection conn, String username,
Collection<String> roleNames) throws SQLException {
if (cachedPermissions.get(username) != null) {
System.out.println("JdbcRealm permissions cache hit for: "
+ username);
return (Set) cachedPermissions.get(username);
}
PreparedStatement ps = null;
Set<String> permissions = new LinkedHashSet<String>();
try {
String roleNamex = "";
for (String roleName : roleNames) {
roleNamex += "'" + roleName + "',";
}
roleNamex = roleNamex.substring(0, roleNamex.length() - 1); // strip
// final
// comma
roleNamex += ")";
ps = conn.prepareStatement(permissionsQuery + roleNamex);
// ps.setString(1, roleNamex);
ResultSet rs = null;
try {
// Execute query
rs = ps.executeQuery();
// Loop over results and add each returned role to a set
while (rs.next()) {
String permissionString = rs.getString(1);
// Add the permission to the set of permissions
permissions.add(permissionString);
}
} finally {
JdbcUtils.closeResultSet(rs);
}
} finally {
JdbcUtils.closeStatement(ps);
}
cachedPermissions.put(username, permissions);
return permissions;
}