/** * Find all Users with custom skins. * * @return a list of all Users with custom skins */ protected static List findBySkinId() throws SystemException { List list = new ArrayList(); Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getConnection(Constants.DATA_SOURCE); StringBuffer query = new StringBuffer(); query.append("SELECT userId "); query.append("FROM User_ WHERE "); query.append("userId = skinId"); ps = con.prepareStatement(query.toString()); rs = ps.executeQuery(); while (rs.next()) { User user = UserUtil.findByPrimaryKey(rs.getString(1)); list.add((User) user.getProtected()); } } catch (Exception e) { throw new SystemException(e); } finally { DataAccess.cleanUp(con, ps, rs); } return list; }
public List<User> findByC_FN_MN_LN_SN_EA_S( long companyId, String[] firstNames, String[] middleNames, String[] lastNames, String[] screenNames, String[] emailAddresses, int status, LinkedHashMap<String, Object> params, boolean andOperator, int start, int end, OrderByComparator obc) throws SystemException { firstNames = CustomSQLUtil.keywords(firstNames); middleNames = CustomSQLUtil.keywords(middleNames); lastNames = CustomSQLUtil.keywords(lastNames); screenNames = CustomSQLUtil.keywords(screenNames); emailAddresses = CustomSQLUtil.keywords(emailAddresses); if (params == null) { params = _emptyLinkedHashMap; } Long[] groupIds = null; if (params.get("usersGroups") instanceof Long) { Long groupId = (Long) params.get("usersGroups"); if (groupId > 0) { groupIds = new Long[] {groupId}; } } else { groupIds = (Long[]) params.get("usersGroups"); } boolean inherit = GetterUtil.getBoolean(params.get("inherit")); boolean doUnion = Validator.isNotNull(groupIds) && inherit; LinkedHashMap<String, Object> params1 = params; LinkedHashMap<String, Object> params2 = null; LinkedHashMap<String, Object> params3 = null; if (doUnion) { params2 = new LinkedHashMap<String, Object>(params1); params2.remove("usersGroups"); params3 = new LinkedHashMap<String, Object>(params1); params3.remove("usersGroups"); List<Long> organizationIds = new ArrayList<Long>(); List<Long> userGroupIds = new ArrayList<Long>(); for (long groupId : groupIds) { Group group = GroupLocalServiceUtil.fetchGroup(groupId); if ((group != null) && group.isOrganization()) { organizationIds.add(group.getOrganizationId()); } List<Organization> organizations = GroupUtil.getOrganizations(groupId); for (Organization organization : organizations) { organizationIds.add(organization.getOrganizationId()); } List<UserGroup> userGroups = GroupUtil.getUserGroups(groupId); for (int i = 0; i < userGroups.size(); i++) { UserGroup userGroup = userGroups.get(i); userGroupIds.add(userGroup.getUserGroupId()); } } params2.put("usersOrgs", organizationIds.toArray(new Long[organizationIds.size()])); params3.put("usersUserGroups", userGroupIds.toArray(new Long[userGroupIds.size()])); } Session session = null; try { session = openSession(); String sql = CustomSQLUtil.get(FIND_BY_C_FN_MN_LN_SN_EA_S); sql = CustomSQLUtil.replaceKeywords( sql, "lower(User_.firstName)", StringPool.LIKE, false, firstNames); sql = CustomSQLUtil.replaceKeywords( sql, "lower(User_.middleName)", StringPool.LIKE, false, middleNames); sql = CustomSQLUtil.replaceKeywords( sql, "lower(User_.lastName)", StringPool.LIKE, false, lastNames); sql = CustomSQLUtil.replaceKeywords( sql, "lower(User_.screenName)", StringPool.LIKE, false, screenNames); sql = CustomSQLUtil.replaceKeywords( sql, "lower(User_.emailAddress)", StringPool.LIKE, true, emailAddresses); if (status == WorkflowConstants.STATUS_ANY) { sql = StringUtil.replace(sql, _STATUS_SQL, StringPool.BLANK); } StringBundler sb = new StringBundler(); sb.append(StringPool.OPEN_PARENTHESIS); sb.append(replaceJoinAndWhere(sql, params1)); sb.append(StringPool.CLOSE_PARENTHESIS); if (doUnion) { sb.append(" UNION ("); sb.append(replaceJoinAndWhere(sql, params2)); sb.append(") UNION ("); sb.append(replaceJoinAndWhere(sql, params3)); sb.append(StringPool.CLOSE_PARENTHESIS); } if (obc != null) { sb.append(" ORDER BY "); sb.append(obc.toString()); } sql = sb.toString(); sql = CustomSQLUtil.replaceAndOperator(sql, andOperator); SQLQuery q = session.createSQLQuery(sql); q.addScalar("userId", Type.LONG); QueryPos qPos = QueryPos.getInstance(q); setJoin(qPos, params1); qPos.add(companyId); qPos.add(false); qPos.add(firstNames, 2); qPos.add(middleNames, 2); qPos.add(lastNames, 2); qPos.add(screenNames, 2); qPos.add(emailAddresses, 2); if (status != WorkflowConstants.STATUS_ANY) { qPos.add(status); } if (doUnion) { setJoin(qPos, params2); qPos.add(companyId); qPos.add(false); qPos.add(firstNames, 2); qPos.add(middleNames, 2); qPos.add(lastNames, 2); qPos.add(screenNames, 2); qPos.add(emailAddresses, 2); if (status != WorkflowConstants.STATUS_ANY) { qPos.add(status); } setJoin(qPos, params3); qPos.add(companyId); qPos.add(false); qPos.add(firstNames, 2); qPos.add(middleNames, 2); qPos.add(lastNames, 2); qPos.add(screenNames, 2); qPos.add(emailAddresses, 2); if (status != WorkflowConstants.STATUS_ANY) { qPos.add(status); } } List<Long> userIds = (List<Long>) QueryUtil.list(q, getDialect(), start, end); List<User> users = new ArrayList<User>(userIds.size()); for (Long userId : userIds) { User user = UserUtil.findByPrimaryKey(userId); users.add(user); } return users; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
/** * Find all Users associated with the specified company id, first name, last name, email address, * sex, age, instant messenger handle, or address. * * @return a list of all Users associated with the specified company id, first name, middle name, * last name, email address, sex, age, instant messenger handle, and address */ protected static List findByOr_C_FN_MN_LN_EA_M_BD_IM_A( String companyId, String firstName, String middleName, String lastName, String emailAddress, Boolean male, Timestamp age1, Timestamp age2, String im, String street1, String street2, String city, String state, String zip, String phone, String fax, String cell) throws SystemException { List list = new ArrayList(); Connection con = null; PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getConnection(Constants.DATA_SOURCE); StringBuffer query = new StringBuffer(); query.append("SELECT DISTINCT User_.userId "); query.append("FROM User_ "); query.append("LEFT JOIN Address ON ("); query.append("(Address.companyId = User_.companyId) AND "); query.append("(Address.className = 'com.liferay.portal.model.User')"); query.append(") WHERE "); query.append("(User_.companyId = ?) AND ("); query.append("(lower(firstName) LIKE ? AND ? IS NOT NULL) OR "); query.append("(lower(middleName) LIKE ? AND ? IS NOT NULL) OR "); query.append("(lower(lastName) LIKE ? AND ? IS NOT NULL) OR "); query.append("(lower(emailAddress) LIKE ? AND ? IS NOT NULL) OR "); query.append("(male = ? AND ? IS NOT NULL) OR "); query.append("(birthday >= ? AND ? IS NOT NULL) OR "); query.append("(birthday <= ? AND ? IS NOT NULL) OR "); query.append( "(lower(aimId) LIKE ? OR lower(icqId) LIKE ? OR lower(msnId) LIKE ? OR lower(ymId) LIKE ? AND ? IS NOT NULL) OR "); query.append( "(lower(Address.street1) LIKE ? AND Address.classPK = User_.userId AND ? IS NOT NULL) OR "); query.append( "(lower(Address.street2) LIKE ? AND Address.classPK = User_.userId AND ? IS NOT NULL) OR "); query.append( "(lower(Address.city) LIKE ? AND Address.classPK = User_.userId AND ? IS NOT NULL) OR "); query.append( "(lower(Address.state) LIKE ? AND Address.classPK = User_.userId AND ? IS NOT NULL) OR "); query.append( "(lower(Address.zip) LIKE ? AND Address.classPK = User_.userId AND ? IS NOT NULL) OR "); query.append( "(lower(Address.phone) LIKE ? AND Address.classPK = User_.userId AND ? IS NOT NULL) OR "); query.append( "(lower(Address.fax) LIKE ? AND Address.classPK = User_.userId AND ? IS NOT NULL) OR "); query.append( "(lower(Address.cell) LIKE ? AND Address.classPK = User_.userId AND ? IS NOT NULL) "); query.append(")"); ps = con.prepareStatement(query.toString()); ps.setString(1, companyId); ps.setString(2, firstName); ps.setString(3, firstName); ps.setString(4, middleName); ps.setString(5, middleName); ps.setString(6, lastName); ps.setString(7, lastName); ps.setString(8, emailAddress); ps.setString(9, emailAddress); if (male != null) { ps.setBoolean(10, male.booleanValue()); ps.setBoolean(11, male.booleanValue()); } else { ps.setNull(10, Types.NUMERIC); ps.setNull(11, Types.NUMERIC); } ps.setTimestamp(12, age1); ps.setTimestamp(13, age1); ps.setTimestamp(14, age2); ps.setTimestamp(15, age2); ps.setString(16, im); ps.setString(17, im); ps.setString(18, im); ps.setString(19, im); ps.setString(20, im); ps.setString(21, street1); ps.setString(22, street1); ps.setString(23, street2); ps.setString(24, street2); ps.setString(25, city); ps.setString(26, city); ps.setString(27, state); ps.setString(28, state); ps.setString(29, zip); ps.setString(30, zip); ps.setString(31, phone); ps.setString(32, phone); ps.setString(33, fax); ps.setString(34, fax); ps.setString(35, cell); ps.setString(36, cell); rs = ps.executeQuery(); while (rs.next()) { User user = UserUtil.findByPrimaryKey(rs.getString(1)); list.add((User) user.getProtected()); } } catch (Exception e) { throw new SystemException(e); } finally { DataAccess.cleanUp(con, ps, rs); } return list; }