
com.liferay.commerce.discount.service.persistence.impl.CommerceDiscountAccountRelFinderImpl Maven / Gradle / Ivy
/**
* SPDX-FileCopyrightText: (c) 2000 Liferay, Inc. https://liferay.com
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06
*/
package com.liferay.commerce.discount.service.persistence.impl;
import com.liferay.commerce.discount.model.CommerceDiscount;
import com.liferay.commerce.discount.model.CommerceDiscountAccountRel;
import com.liferay.commerce.discount.model.impl.CommerceDiscountAccountRelImpl;
import com.liferay.commerce.discount.service.persistence.CommerceDiscountAccountRelFinder;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.dao.orm.custom.sql.CustomSQL;
import com.liferay.portal.kernel.dao.orm.QueryPos;
import com.liferay.portal.kernel.dao.orm.QueryUtil;
import com.liferay.portal.kernel.dao.orm.SQLQuery;
import com.liferay.portal.kernel.dao.orm.Session;
import com.liferay.portal.kernel.dao.orm.Type;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.security.permission.InlineSQLHelperUtil;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.Validator;
import java.util.Iterator;
import java.util.List;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
/**
* @author Riccardo Alberti
*/
@Component(service = CommerceDiscountAccountRelFinder.class)
public class CommerceDiscountAccountRelFinderImpl
extends CommerceDiscountAccountRelFinderBaseImpl
implements CommerceDiscountAccountRelFinder {
public static final String COUNT_BY_COMMERCE_DISCOUNT_ID =
CommerceDiscountAccountRelFinder.class.getName() +
".countByCommerceDiscountId";
public static final String FIND_BY_COMMERCE_DISCOUNT_ID =
CommerceDiscountAccountRelFinder.class.getName() +
".findByCommerceDiscountId";
@Override
public int countByCommerceDiscountId(long commerceDiscountId, String name) {
return countByCommerceDiscountId(commerceDiscountId, name, false);
}
@Override
public int countByCommerceDiscountId(
long commerceDiscountId, String name, boolean inlineSQLHelper) {
Session session = null;
try {
session = openSession();
String sql = _customSQL.get(
getClass(), COUNT_BY_COMMERCE_DISCOUNT_ID);
if (inlineSQLHelper) {
sql = InlineSQLHelperUtil.replacePermissionCheck(
sql, CommerceDiscount.class.getName(),
"CommerceDiscount.commerceDiscountId", null, null,
new long[] {0}, null);
}
String[] keywords = _customSQL.keywords(name, true);
if (Validator.isNotNull(name)) {
sql = _customSQL.replaceKeywords(
sql, "(LOWER(AccountEntry.name)", StringPool.LIKE, true,
keywords);
sql = _customSQL.replaceAndOperator(sql, false);
}
else {
sql = StringUtil.removeSubstring(
sql,
" AND (LOWER(AccountEntry.name) LIKE ? " +
"[$AND_OR_NULL_CHECK$])");
}
SQLQuery sqlQuery = session.createSynchronizedSQLQuery(sql);
sqlQuery.addScalar(COUNT_COLUMN_NAME, Type.LONG);
QueryPos queryPos = QueryPos.getInstance(sqlQuery);
queryPos.add(commerceDiscountId);
if (Validator.isNotNull(name)) {
queryPos.add(keywords, 2);
}
Iterator iterator = sqlQuery.iterate();
if (iterator.hasNext()) {
Long count = iterator.next();
if (count != null) {
return count.intValue();
}
}
return 0;
}
catch (Exception exception) {
throw new SystemException(exception);
}
finally {
closeSession(session);
}
}
@Override
public List findByCommerceDiscountId(
long commerceDiscountId, String name, int start, int end) {
return findByCommerceDiscountId(
commerceDiscountId, name, start, end, false);
}
@Override
public List findByCommerceDiscountId(
long commerceDiscountId, String name, int start, int end,
boolean inlineSQLHelper) {
Session session = null;
try {
session = openSession();
String[] keywords = _customSQL.keywords(name, true);
String sql = _customSQL.get(
getClass(), FIND_BY_COMMERCE_DISCOUNT_ID);
if (inlineSQLHelper) {
sql = InlineSQLHelperUtil.replacePermissionCheck(
sql, CommerceDiscount.class.getName(),
"CommerceDiscount.commerceDiscountId", null, null,
new long[] {0}, null);
}
if (Validator.isNotNull(name)) {
sql = _customSQL.replaceKeywords(
sql, "(LOWER(AccountEntry.name)", StringPool.LIKE, true,
keywords);
sql = _customSQL.replaceAndOperator(sql, false);
}
else {
sql = StringUtil.removeSubstring(
sql,
" AND (LOWER(AccountEntry.name) LIKE ? " +
"[$AND_OR_NULL_CHECK$])");
}
SQLQuery sqlQuery = session.createSynchronizedSQLQuery(sql);
sqlQuery.addEntity(
CommerceDiscountAccountRelImpl.TABLE_NAME,
CommerceDiscountAccountRelImpl.class);
QueryPos queryPos = QueryPos.getInstance(sqlQuery);
queryPos.add(commerceDiscountId);
if (Validator.isNotNull(name)) {
queryPos.add(keywords, 2);
}
return (List)QueryUtil.list(
sqlQuery, getDialect(), start, end);
}
catch (Exception exception) {
throw new SystemException(exception);
}
finally {
closeSession(session);
}
}
@Reference
private CustomSQL _customSQL;
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy