<?xml version="1.0"?>

<custom-sql>
	<sql id="com.liferay.portal.service.persistence.PermissionUserFinder.countByAdminRole">
		<![CDATA[
			SELECT
				COUNT(DISTINCT Users_Roles.userId) AS COUNT_VALUE
			FROM
				Users_Roles
			INNER JOIN
				User_ ON
					User_.userId = Users_Roles.userId
			INNER JOIN
				Contact_ ON
					Contact_.contactId = Users_Roles.userId
			INNER JOIN
				Role_ ON
					Role_.roleId = Users_Roles.roleId
			WHERE
				(User_.companyId = ?) AND
				(Role_.name = 'Administrator') AND
				(
					(lower(Contact_.firstName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.middleName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.lastName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(User_.emailAddress) LIKE ? [$AND_OR_NULL_CHECK$])
				)
		]]>
	</sql>
	<sql id="com.liferay.portal.service.persistence.PermissionUserFinder.countByGroupPermission">
		<![CDATA[
			SELECT
				COUNT(DISTINCT Users_Groups.userId) AS COUNT_VALUE
			FROM
				Users_Groups
			INNER JOIN
				User_ ON
					User_.userId = Users_Groups.userId
			INNER JOIN
				Contact_ ON
					Contact_.contactId = Users_Groups.userId
			INNER JOIN
				Group_ ON
					Group_.groupId = Users_Groups.groupId
			INNER JOIN
				Groups_Permissions ON
					Groups_Permissions.groupId = Group_.groupId
			INNER JOIN
				Permission_ ON
					Permission_.permissionId = Groups_Permissions.permissionId
			INNER JOIN
				Resource_ ON
					Resource_.resourceId = Permission_.resourceId
			WHERE
				(Resource_.companyId = ?) AND
				(Resource_.name = ?) AND
				(Resource_.primKey = ?) AND
				(Resource_.scope = 'individual') AND
				(Permission_.actionId = ?) AND
				(
					(lower(Contact_.firstName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.middleName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.lastName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(User_.emailAddress) LIKE ? [$AND_OR_NULL_CHECK$])
				)
		]]>
	</sql>
	<sql id="com.liferay.portal.service.persistence.PermissionUserFinder.countByGroupRole">
		<![CDATA[
			SELECT
				COUNT(DISTINCT Users_Groups.userId) AS COUNT_VALUE
			FROM
				Users_Groups
			INNER JOIN
				User_ ON
					User_.userId = Users_Groups.userId
			INNER JOIN
				Contact_ ON
					Contact_.contactId = Users_Groups.userId
			INNER JOIN
				Group_ ON
					Group_.groupId = Users_Groups.groupId
			INNER JOIN
				Groups_Roles ON
					Groups_Roles.groupId = Group_.groupId
			INNER JOIN
				Role_ ON
					Role_.roleId = Groups_Roles.roleId
			INNER JOIN
				Roles_Permissions ON
					Roles_Permissions.roleId = Role_.roleId
			INNER JOIN
				Permission_ ON
					Permission_.permissionId = Roles_Permissions.permissionId
			INNER JOIN
				Resource_ ON
					Resource_.resourceId = Permission_.resourceId
			WHERE
				(Resource_.companyId = ?) AND
				(Resource_.name = ?) AND
				(
					(
						(Resource_.primKey = ?) AND
						(Resource_.scope = 'company')
					)
					OR
					(
						(Resource_.primKey = ?) AND
						(Resource_.scope = 'group')
					)
				) AND
				(Permission_.actionId = ?) AND
				(
					(lower(Contact_.firstName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.middleName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.lastName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(User_.emailAddress) LIKE ? [$AND_OR_NULL_CHECK$])
				)
		]]>
	</sql>
	<sql id="com.liferay.portal.service.persistence.PermissionUserFinder.countByOrgGroupPermission">
		<![CDATA[
			SELECT
				COUNT(DISTINCT Users_Orgs.userId) AS COUNT_VALUE
			FROM
				Users_Orgs
			INNER JOIN
				User_ ON
					User_.userId = Users_Orgs.userId
			INNER JOIN
				Contact_ ON
					Contact_.contactId = Users_Orgs.userId
			INNER JOIN
				Organization_ ON
					Organization_.organizationId = Users_Orgs.organizationId
			INNER JOIN
				Users_Groups ON
					Users_Groups.userId = Users_Orgs.userId
			INNER JOIN
				Group_ ON
					Group_.groupId = Users_Groups.groupId
			INNER JOIN
				OrgGroupPermission ON
					(OrgGroupPermission.organizationId = Organization_.organizationId) AND
					(OrgGroupPermission.groupId = Group_.groupId)
			INNER JOIN
				Permission_ ON
					Permission_.permissionId = OrgGroupPermission.permissionId
			INNER JOIN
				Resource_ ON
					Resource_.resourceId = Permission_.resourceId
			WHERE
				(Resource_.companyId = ?) AND
				(Resource_.name = ?) AND
				(Resource_.primKey = ?) AND
				(Resource_.scope = 'individual') AND
				(Permission_.actionId = ?) AND
				(
					(lower(Contact_.firstName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.middleName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.lastName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(User_.emailAddress) LIKE ? [$AND_OR_NULL_CHECK$])
				)
		]]>
	</sql>
	<sql id="com.liferay.portal.service.persistence.PermissionUserFinder.countByOrgGroupPermissions">
		<![CDATA[
			SELECT
				COUNT(OrgGroupPermission.permissionId) AS COUNT_VALUE
			FROM
				OrgGroupPermission
			INNER JOIN
				Permission_	ON
					Permission_.permissionId = OrgGroupPermission.permissionId
			INNER JOIN
				Resource_ ON
					Resource_.resourceId = Permission_.resourceId
			WHERE
				(Resource_.companyId = ?) AND
				(Resource_.name = ?) AND
				(Resource_.primKey = ?) AND
				(Resource_.scope = 'individual') AND
				(Permission_.actionId = ?)
		]]>
	</sql>
	<sql id="com.liferay.portal.service.persistence.PermissionUserFinder.countByOrgPermission">
		<![CDATA[
			SELECT
				COUNT(DISTINCT Users_Orgs.userId) AS COUNT_VALUE
			FROM
				Users_Orgs
			INNER JOIN
				User_ ON
					User_.userId = Users_Orgs.userId
			INNER JOIN
				Contact_ ON
					Contact_.contactId = Users_Orgs.userId
			INNER JOIN
				Group_ ON
					Group_.classPK = Users_Orgs.organizationId
			INNER JOIN
				Groups_Permissions ON
					Groups_Permissions.groupId = Group_.groupId
			INNER JOIN
				Permission_ ON
					Permission_.permissionId = Groups_Permissions.permissionId
			INNER JOIN
				Resource_ ON
					Resource_.resourceId = Permission_.resourceId
			WHERE
				(Resource_.companyId = ?) AND
				(Resource_.name = ?) AND
				(Resource_.primKey = ?) AND
				(Resource_.scope = 'individual') AND
				(Permission_.actionId = ?) AND
				(Group_.className = 'com.liferay.portal.model.Organization') AND
				(
					(lower(Contact_.firstName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.middleName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.lastName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(User_.emailAddress) LIKE ? [$AND_OR_NULL_CHECK$])
				)
		]]>
	</sql>
	<sql id="com.liferay.portal.service.persistence.PermissionUserFinder.countByOrgRole">
		<![CDATA[
			SELECT
				COUNT(DISTINCT Users_Orgs.userId) AS COUNT_VALUE
			FROM
				Users_Orgs
			INNER JOIN
				User_ ON
					User_.userId = Users_Orgs.userId
			INNER JOIN
				Contact_ ON
					Contact_.contactId = Users_Orgs.userId
			INNER JOIN
				Group_ ON
					Group_.classPK = Users_Orgs.organizationId
			INNER JOIN
				Groups_Roles ON
					Groups_Roles.groupId = Group_.groupId
			INNER JOIN
				Role_ ON
					Role_.roleId = Groups_Roles.roleId
			INNER JOIN
				Roles_Permissions ON
					Roles_Permissions.roleId = Role_.roleId
			INNER JOIN
				Permission_ ON
					Permission_.permissionId = Roles_Permissions.permissionId
			INNER JOIN
				Resource_ ON
					Resource_.resourceId = Permission_.resourceId
			WHERE
				(Resource_.companyId = ?) AND
				(Resource_.name = ?) AND
				(
					(
						(Resource_.primKey = ?) AND
						(Resource_.scope = 'company')
					)
					OR
					(
						(Resource_.primKey = ?) AND
						(Resource_.scope = 'group')
					)
				) AND
				(Permission_.actionId = ?) AND
				(Group_.className = 'com.liferay.portal.model.Organization') AND
				(
					(lower(Contact_.firstName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.middleName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.lastName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(User_.emailAddress) LIKE ? [$AND_OR_NULL_CHECK$])
				)
		]]>
	</sql>
	<sql id="com.liferay.portal.service.persistence.PermissionUserFinder.countByUserPermission">
		<![CDATA[
			SELECT
				COUNT(DISTINCT Users_Permissions.userId) AS COUNT_VALUE
			FROM
				Users_Permissions
			INNER JOIN
				User_ ON
					User_.userId = Users_Permissions.userId
			INNER JOIN
				Contact_ ON
					Contact_.contactId = Users_Permissions.userId
			INNER JOIN
				Permission_ ON
					Permission_.permissionId = Users_Permissions.permissionId
			INNER JOIN
				Resource_ ON
					Resource_.resourceId = Permission_.resourceId
			WHERE
				(Resource_.companyId = ?) AND
				(Resource_.name = ?) AND
				(Resource_.primKey = ?) AND
				(Resource_.scope = 'individual') AND
				(Permission_.actionId = ?) AND
				(
					(lower(Contact_.firstName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.middleName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.lastName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(User_.emailAddress) LIKE ? [$AND_OR_NULL_CHECK$])
				)
		]]>
	</sql>
	<sql id="com.liferay.portal.service.persistence.PermissionUserFinder.countByUserRole">
		<![CDATA[
			SELECT
				COUNT(DISTINCT Users_Roles.userId) AS COUNT_VALUE
			FROM
				Users_Roles
			INNER JOIN
				User_ ON
					User_.userId = Users_Roles.userId
			INNER JOIN
				Contact_ ON
					Contact_.contactId = Users_Roles.userId
			INNER JOIN
				Role_ ON
					Role_.roleId = Users_Roles.roleId
			INNER JOIN
				Roles_Permissions ON
					Roles_Permissions.roleId = Role_.roleId
			INNER JOIN
				Permission_ ON
					Permission_.permissionId = Roles_Permissions.permissionId
			INNER JOIN
				Resource_ ON
					Resource_.resourceId = Permission_.resourceId
			WHERE
				(Resource_.companyId = ?) AND
				(Resource_.name = ?) AND
				(
					(
						(Resource_.primKey = ?) AND
						(Resource_.scope = 'company')
					)
					OR
					(
						(Resource_.primKey = ?) AND
						(Resource_.scope = 'group')
					)
				) AND
				(Permission_.actionId = ?) AND
				(
					(lower(Contact_.firstName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.middleName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.lastName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(User_.emailAddress) LIKE ? [$AND_OR_NULL_CHECK$])
				)
		]]>
	</sql>
	<sql id="com.liferay.portal.service.persistence.PermissionUserFinder.findByAdminRole">
		<![CDATA[
			SELECT
				DISTINCT(Users_Roles.userId) AS userId, (Contact_.firstName) AS firstName, (Contact_.middleName) AS middleName, (Contact_.lastName) AS lastName
			FROM
				Users_Roles
			INNER JOIN
				User_ ON
					User_.userId = Users_Roles.userId
			INNER JOIN
				Contact_ ON
					Contact_.contactId = Users_Roles.userId
			INNER JOIN
				Role_ ON
					Role_.roleId = Users_Roles.roleId
			WHERE
				(User_.companyId = ?) AND
				(Role_.name = 'Administrator') AND
				(
					(lower(Contact_.firstName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.middleName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.lastName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(User_.emailAddress) LIKE ? [$AND_OR_NULL_CHECK$])
				)
		]]>
	</sql>
	<sql id="com.liferay.portal.service.persistence.PermissionUserFinder.findByGroupPermission">
		<![CDATA[
			SELECT
				DISTINCT(Users_Groups.userId) AS userId, (Contact_.firstName) AS firstName, (Contact_.middleName) AS middleName, (Contact_.lastName) AS lastName
			FROM
				Users_Groups
			INNER JOIN
				User_ ON
					User_.userId = Users_Groups.userId
			INNER JOIN
				Contact_ ON
					Contact_.contactId = Users_Groups.userId
			INNER JOIN
				Group_ ON
					Group_.groupId = Users_Groups.groupId
			INNER JOIN
				Groups_Permissions ON
					Groups_Permissions.groupId = Group_.groupId
			INNER JOIN
				Permission_ ON
					Permission_.permissionId = Groups_Permissions.permissionId
			INNER JOIN
				Resource_ ON
					Resource_.resourceId = Permission_.resourceId
			WHERE
				(Resource_.companyId = ?) AND
				(Resource_.name = ?) AND
				(Resource_.primKey = ?) AND
				(Resource_.scope = 'individual') AND
				(Permission_.actionId = ?) AND
				(
					(lower(Contact_.firstName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.middleName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.lastName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(User_.emailAddress) LIKE ? [$AND_OR_NULL_CHECK$])
				)
		]]>
	</sql>
	<sql id="com.liferay.portal.service.persistence.PermissionUserFinder.findByGroupRole">
		<![CDATA[
			SELECT
				DISTINCT(Users_Groups.userId) AS userId, (Contact_.firstName) AS firstName, (Contact_.middleName) AS middleName, (Contact_.lastName) AS lastName
			FROM
				Users_Groups
			INNER JOIN
				User_ ON
					User_.userId = Users_Groups.userId
			INNER JOIN
				Contact_ ON
					Contact_.contactId = Users_Groups.userId
			INNER JOIN
				Group_ ON
					Group_.groupId = Users_Groups.groupId
			INNER JOIN
				Groups_Roles ON
					Groups_Roles.groupId = Group_.groupId
			INNER JOIN
				Role_ ON
					Role_.roleId = Groups_Roles.roleId
			INNER JOIN
				Roles_Permissions ON
					Roles_Permissions.roleId = Role_.roleId
			INNER JOIN
				Permission_ ON
					Permission_.permissionId = Roles_Permissions.permissionId
			INNER JOIN
				Resource_ ON
					Resource_.resourceId = Permission_.resourceId
			WHERE
				(Resource_.companyId = ?) AND
				(Resource_.name = ?) AND
				(
					(
						(Resource_.primKey = ?) AND
						(Resource_.scope = 'company')
					)
					OR
					(
						(Resource_.primKey = ?) AND
						(Resource_.scope = 'group')
					)
				) AND
				(Permission_.actionId = ?) AND
				(
					(lower(Contact_.firstName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.middleName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.lastName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(User_.emailAddress) LIKE ? [$AND_OR_NULL_CHECK$])
				)
		]]>
	</sql>
	<sql id="com.liferay.portal.service.persistence.PermissionUserFinder.findByOrgGroupPermission">
		<![CDATA[
			SELECT
				DISTINCT(Users_Orgs.userId) AS userId, (Contact_.firstName) AS firstName, (Contact_.middleName) AS middleName, (Contact_.lastName) AS lastName
			FROM
				Users_Orgs
			INNER JOIN
				User_ ON
					User_.userId = Users_Orgs.userId
			INNER JOIN
				Contact_ ON
					Contact_.contactId = Users_Orgs.userId
			INNER JOIN
				Organization_ ON
					Organization_.organizationId = Users_Orgs.organizationId
			INNER JOIN
				Users_Groups ON
					Users_Groups.userId = Users_Orgs.userId
			INNER JOIN
				Group_ ON
					Group_.groupId = Users_Groups.groupId
			INNER JOIN
				OrgGroupPermission ON
					(OrgGroupPermission.organizationId = Organization_.organizationId) AND
					(OrgGroupPermission.groupId = Group_.groupId)
			INNER JOIN
				Permission_ ON
					Permission_.permissionId = OrgGroupPermission.permissionId
			INNER JOIN
				Resource_ ON
					Resource_.resourceId = Permission_.resourceId
			WHERE
				(Resource_.companyId = ?) AND
				(Resource_.name = ?) AND
				(Resource_.primKey = ?) AND
				(Resource_.scope = 'individual') AND
				(Permission_.actionId = ?) AND
				(
					(lower(Contact_.firstName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.middleName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.lastName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(User_.emailAddress) LIKE ? [$AND_OR_NULL_CHECK$])
				)
		]]>
	</sql>
	<sql id="com.liferay.portal.service.persistence.PermissionUserFinder.findByOrgPermission">
		<![CDATA[
			SELECT
				DISTINCT(Users_Orgs.userId) AS userId, (Contact_.firstName) AS firstName, (Contact_.middleName) AS middleName, (Contact_.lastName) AS lastName
			FROM
				Users_Orgs
			INNER JOIN
				User_ ON
					User_.userId = Users_Orgs.userId
			INNER JOIN
				Contact_ ON
					Contact_.contactId = Users_Orgs.userId
			INNER JOIN
				Group_ ON
					Group_.classPK = Users_Orgs.organizationId
			INNER JOIN
				Groups_Permissions ON
					Groups_Permissions.groupId = Group_.groupId
			INNER JOIN
				Permission_ ON
					Permission_.permissionId = Groups_Permissions.permissionId
			INNER JOIN
				Resource_ ON
					Resource_.resourceId = Permission_.resourceId
			WHERE
				(Resource_.companyId = ?) AND
				(Resource_.name = ?) AND
				(Resource_.primKey = ?) AND
				(Resource_.scope = 'individual') AND
				(Permission_.actionId = ?) AND
				(Group_.className = 'com.liferay.portal.model.Organization') AND
				(
					(lower(Contact_.firstName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.middleName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.lastName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(User_.emailAddress) LIKE ? [$AND_OR_NULL_CHECK$])
				)
		]]>
	</sql>
	<sql id="com.liferay.portal.service.persistence.PermissionUserFinder.findByOrgRole">
		<![CDATA[
			SELECT
				DISTINCT(Users_Orgs.userId) AS userId, (Contact_.firstName) AS firstName, (Contact_.middleName) AS middleName, (Contact_.lastName) AS lastName
			FROM
				Users_Orgs
			INNER JOIN
				User_ ON
					User_.userId = Users_Orgs.userId
			INNER JOIN
				Contact_ ON
					Contact_.contactId = Users_Orgs.userId
			INNER JOIN
				Group_ ON
					Group_.classPK = Users_Orgs.organizationId
			INNER JOIN
				Groups_Roles ON
					Groups_Roles.groupId = Group_.groupId
			INNER JOIN
				Role_ ON
					Role_.roleId = Groups_Roles.roleId
			INNER JOIN
				Roles_Permissions ON
					Roles_Permissions.roleId = Role_.roleId
			INNER JOIN
				Permission_ ON
					Permission_.permissionId = Roles_Permissions.permissionId
			INNER JOIN
				Resource_ ON
					Resource_.resourceId = Permission_.resourceId
			WHERE
				(Resource_.companyId = ?) AND
				(Resource_.name = ?) AND
				(
					(
						(Resource_.primKey = ?) AND
						(Resource_.scope = 'company')
					)
					OR
					(
						(Resource_.primKey = ?) AND
						(Resource_.scope = 'group')
					)
				) AND
				(Permission_.actionId = ?) AND
				(Group_.className = 'com.liferay.portal.model.Organization') AND
				(
					(lower(Contact_.firstName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.middleName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.lastName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(User_.emailAddress) LIKE ? [$AND_OR_NULL_CHECK$])
				)
		]]>
	</sql>
	<sql id="com.liferay.portal.service.persistence.PermissionUserFinder.findByUserPermission">
		<![CDATA[
			SELECT
				DISTINCT(Users_Permissions.userId) AS userId, (Contact_.firstName) AS firstName, (Contact_.middleName) AS middleName, (Contact_.lastName) AS lastName
			FROM
				Users_Permissions
			INNER JOIN
				User_ ON
					User_.userId = Users_Permissions.userId
			INNER JOIN
				Contact_ ON
					Contact_.contactId = Users_Permissions.userId
			INNER JOIN
				Permission_ ON
					Permission_.permissionId = Users_Permissions.permissionId
			INNER JOIN
				Resource_ ON
					Resource_.resourceId = Permission_.resourceId
			WHERE
				(Resource_.companyId = ?) AND
				(Resource_.name = ?) AND
				(Resource_.primKey = ?) AND
				(Resource_.scope = 'individual') AND
				(Permission_.actionId = ?) AND
				(
					(lower(Contact_.firstName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.middleName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.lastName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(User_.emailAddress) LIKE ? [$AND_OR_NULL_CHECK$])
				)
		]]>
	</sql>
	<sql id="com.liferay.portal.service.persistence.PermissionUserFinder.findByUserRole">
		<![CDATA[
			SELECT
				DISTINCT(Users_Roles.userId) AS userId, (Contact_.firstName) AS firstName, (Contact_.middleName) AS middleName, (Contact_.lastName) AS lastName
			FROM
				Users_Roles
			INNER JOIN
				User_ ON
					User_.userId = Users_Roles.userId
			INNER JOIN
				Contact_ ON
					Contact_.contactId = Users_Roles.userId
			INNER JOIN
				Role_ ON
					Role_.roleId = Users_Roles.roleId
			INNER JOIN
				Roles_Permissions ON
					Roles_Permissions.roleId = Role_.roleId
			INNER JOIN
				Permission_ ON
					Permission_.permissionId = Roles_Permissions.permissionId
			INNER JOIN
				Resource_ ON
					Resource_.resourceId = Permission_.resourceId
			WHERE
				(Resource_.companyId = ?) AND
				(Resource_.name = ?) AND
				(
					(
						(Resource_.primKey = ?) AND
						(Resource_.scope = 'company')
					)
					OR
					(
						(Resource_.primKey = ?) AND
						(Resource_.scope = 'group')
					)
				) AND
				(Permission_.actionId = ?) AND
				(
					(lower(Contact_.firstName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.middleName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(Contact_.lastName) LIKE ? [$AND_OR_NULL_CHECK$]) [$AND_OR_CONNECTOR$]
					(lower(User_.emailAddress) LIKE ? [$AND_OR_NULL_CHECK$])
				)
		]]>
	</sql>
</custom-sql>