当前位置: 首页>>代码示例>>Java>>正文


Java JdbcUtils.closeResultSet方法代码示例

本文整理汇总了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;
}
 
开发者ID:johntostring,项目名称:spring-boot-shiro,代码行数:24,代码来源:JdbcPermissionDefinitionsLoader.java

示例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;
}
 
开发者ID:storezhang,项目名称:utils,代码行数:20,代码来源:JdbcPermissionDefinitionsLoader.java

示例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;
}
 
开发者ID:StarterInc,项目名称:Ignite,代码行数:21,代码来源:RoleSecurityJdbcRealm.java

示例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;
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:32,代码来源:JdbcRealm.java

示例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;
}
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:35,代码来源:JdbcRealm.java

示例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;
}
 
开发者ID:StarterInc,项目名称:Ignite,代码行数:34,代码来源:JdbcRealm.java

示例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;
    }
 
开发者ID:xuegongzi,项目名称:rabbitframework,代码行数:48,代码来源:JdbcRealm.java

示例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;
}
 
开发者ID:nano-projects,项目名称:nano-framework,代码行数:47,代码来源:MyBatisRealm.java

示例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;
}
 
开发者ID:pires,项目名称:fabric8-cxf-shiro,代码行数:47,代码来源:SMRealm.java

示例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;
}
 
开发者ID:StarterInc,项目名称:Ignite,代码行数:52,代码来源:JdbcRealm.java

示例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;
}
 
开发者ID:StarterInc,项目名称:Ignite,代码行数:58,代码来源:JdbcRealm.java


注:本文中的org.apache.shiro.util.JdbcUtils.closeResultSet方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。