use of com.liferay.knowledgebase.model.KBFolder in project liferay-ide by liferay.
the class KBFolderPersistenceImpl method filterGetByG_P_PrevAndNext.
protected KBFolder filterGetByG_P_PrevAndNext(Session session, KBFolder kbFolder, long groupId, long parentKBFolderId, OrderByComparator orderByComparator, boolean previous) {
StringBundler query = null;
if (orderByComparator != null) {
query = new StringBundler(6 + (orderByComparator.getOrderByFields().length * 6));
} else {
query = new StringBundler(3);
}
if (getDB().isSupportsInlineDistinct()) {
query.append(_FILTER_SQL_SELECT_KBFOLDER_WHERE);
} else {
query.append(_FILTER_SQL_SELECT_KBFOLDER_NO_INLINE_DISTINCT_WHERE_1);
}
query.append(_FINDER_COLUMN_G_P_GROUPID_2);
query.append(_FINDER_COLUMN_G_P_PARENTKBFOLDERID_2);
if (!getDB().isSupportsInlineDistinct()) {
query.append(_FILTER_SQL_SELECT_KBFOLDER_NO_INLINE_DISTINCT_WHERE_2);
}
if (orderByComparator != null) {
String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
if (orderByConditionFields.length > 0) {
query.append(WHERE_AND);
}
for (int i = 0; i < orderByConditionFields.length; i++) {
if (getDB().isSupportsInlineDistinct()) {
query.append(_ORDER_BY_ENTITY_ALIAS);
} else {
query.append(_ORDER_BY_ENTITY_TABLE);
}
query.append(orderByConditionFields[i]);
if ((i + 1) < orderByConditionFields.length) {
if (orderByComparator.isAscending() ^ previous) {
query.append(WHERE_GREATER_THAN_HAS_NEXT);
} else {
query.append(WHERE_LESSER_THAN_HAS_NEXT);
}
} else {
if (orderByComparator.isAscending() ^ previous) {
query.append(WHERE_GREATER_THAN);
} else {
query.append(WHERE_LESSER_THAN);
}
}
}
query.append(ORDER_BY_CLAUSE);
String[] orderByFields = orderByComparator.getOrderByFields();
for (int i = 0; i < orderByFields.length; i++) {
if (getDB().isSupportsInlineDistinct()) {
query.append(_ORDER_BY_ENTITY_ALIAS);
} else {
query.append(_ORDER_BY_ENTITY_TABLE);
}
query.append(orderByFields[i]);
if ((i + 1) < orderByFields.length) {
if (orderByComparator.isAscending() ^ previous) {
query.append(ORDER_BY_ASC_HAS_NEXT);
} else {
query.append(ORDER_BY_DESC_HAS_NEXT);
}
} else {
if (orderByComparator.isAscending() ^ previous) {
query.append(ORDER_BY_ASC);
} else {
query.append(ORDER_BY_DESC);
}
}
}
} else {
if (getDB().isSupportsInlineDistinct()) {
query.append(KBFolderModelImpl.ORDER_BY_JPQL);
} else {
query.append(KBFolderModelImpl.ORDER_BY_SQL);
}
}
String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), KBFolder.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId);
SQLQuery q = session.createSQLQuery(sql);
q.setFirstResult(0);
q.setMaxResults(2);
if (getDB().isSupportsInlineDistinct()) {
q.addEntity(_FILTER_ENTITY_ALIAS, KBFolderImpl.class);
} else {
q.addEntity(_FILTER_ENTITY_TABLE, KBFolderImpl.class);
}
QueryPos qPos = QueryPos.getInstance(q);
qPos.add(groupId);
qPos.add(parentKBFolderId);
if (orderByComparator != null) {
Object[] values = orderByComparator.getOrderByConditionValues(kbFolder);
for (Object value : values) {
qPos.add(value);
}
}
List<KBFolder> list = q.list();
if (list.size() == 2) {
return list.get(1);
} else {
return null;
}
}
use of com.liferay.knowledgebase.model.KBFolder in project liferay-ide by liferay.
the class KBFolderPersistenceImpl method getByUuid_C_PrevAndNext.
protected KBFolder getByUuid_C_PrevAndNext(Session session, KBFolder kbFolder, String uuid, long companyId, OrderByComparator orderByComparator, boolean previous) {
StringBundler query = null;
if (orderByComparator != null) {
query = new StringBundler(6 + (orderByComparator.getOrderByFields().length * 6));
} else {
query = new StringBundler(3);
}
query.append(_SQL_SELECT_KBFOLDER_WHERE);
boolean bindUuid = false;
if (uuid == null) {
query.append(_FINDER_COLUMN_UUID_C_UUID_1);
} else if (uuid.equals(StringPool.BLANK)) {
query.append(_FINDER_COLUMN_UUID_C_UUID_3);
} else {
bindUuid = true;
query.append(_FINDER_COLUMN_UUID_C_UUID_2);
}
query.append(_FINDER_COLUMN_UUID_C_COMPANYID_2);
if (orderByComparator != null) {
String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
if (orderByConditionFields.length > 0) {
query.append(WHERE_AND);
}
for (int i = 0; i < orderByConditionFields.length; i++) {
query.append(_ORDER_BY_ENTITY_ALIAS);
query.append(orderByConditionFields[i]);
if ((i + 1) < orderByConditionFields.length) {
if (orderByComparator.isAscending() ^ previous) {
query.append(WHERE_GREATER_THAN_HAS_NEXT);
} else {
query.append(WHERE_LESSER_THAN_HAS_NEXT);
}
} else {
if (orderByComparator.isAscending() ^ previous) {
query.append(WHERE_GREATER_THAN);
} else {
query.append(WHERE_LESSER_THAN);
}
}
}
query.append(ORDER_BY_CLAUSE);
String[] orderByFields = orderByComparator.getOrderByFields();
for (int i = 0; i < orderByFields.length; i++) {
query.append(_ORDER_BY_ENTITY_ALIAS);
query.append(orderByFields[i]);
if ((i + 1) < orderByFields.length) {
if (orderByComparator.isAscending() ^ previous) {
query.append(ORDER_BY_ASC_HAS_NEXT);
} else {
query.append(ORDER_BY_DESC_HAS_NEXT);
}
} else {
if (orderByComparator.isAscending() ^ previous) {
query.append(ORDER_BY_ASC);
} else {
query.append(ORDER_BY_DESC);
}
}
}
} else {
query.append(KBFolderModelImpl.ORDER_BY_JPQL);
}
String sql = query.toString();
Query q = session.createQuery(sql);
q.setFirstResult(0);
q.setMaxResults(2);
QueryPos qPos = QueryPos.getInstance(q);
if (bindUuid) {
qPos.add(uuid);
}
qPos.add(companyId);
if (orderByComparator != null) {
Object[] values = orderByComparator.getOrderByConditionValues(kbFolder);
for (Object value : values) {
qPos.add(value);
}
}
List<KBFolder> list = q.list();
if (list.size() == 2) {
return list.get(1);
} else {
return null;
}
}
use of com.liferay.knowledgebase.model.KBFolder in project liferay-ide by liferay.
the class KBFolderPersistenceImpl method findByG_P_UT.
/**
* Returns the k b folder where groupId = ? and parentKBFolderId = ? and urlTitle = ? or throws a {@link com.liferay.knowledgebase.NoSuchFolderException} if it could not be found.
*
* @param groupId the group ID
* @param parentKBFolderId the parent k b folder ID
* @param urlTitle the url title
* @return the matching k b folder
* @throws com.liferay.knowledgebase.NoSuchFolderException if a matching k b folder could not be found
* @throws SystemException if a system exception occurred
*/
@Override
public KBFolder findByG_P_UT(long groupId, long parentKBFolderId, String urlTitle) throws NoSuchFolderException, SystemException {
KBFolder kbFolder = fetchByG_P_UT(groupId, parentKBFolderId, urlTitle);
if (kbFolder == null) {
StringBundler msg = new StringBundler(8);
msg.append(_NO_SUCH_ENTITY_WITH_KEY);
msg.append("groupId=");
msg.append(groupId);
msg.append(", parentKBFolderId=");
msg.append(parentKBFolderId);
msg.append(", urlTitle=");
msg.append(urlTitle);
msg.append(StringPool.CLOSE_CURLY_BRACE);
if (_log.isWarnEnabled()) {
_log.warn(msg.toString());
}
throw new NoSuchFolderException(msg.toString());
}
return kbFolder;
}
use of com.liferay.knowledgebase.model.KBFolder in project liferay-ide by liferay.
the class KBFolderPersistenceImpl method fetchByUUID_G.
/**
* Returns the k b folder where uuid = ? and groupId = ? or returns <code>null</code> if it could not be found, optionally using the finder cache.
*
* @param uuid the uuid
* @param groupId the group ID
* @param retrieveFromCache whether to use the finder cache
* @return the matching k b folder, or <code>null</code> if a matching k b folder could not be found
* @throws SystemException if a system exception occurred
*/
@Override
public KBFolder fetchByUUID_G(String uuid, long groupId, boolean retrieveFromCache) throws SystemException {
Object[] finderArgs = new Object[] { uuid, groupId };
Object result = null;
if (retrieveFromCache) {
result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs, this);
}
if (result instanceof KBFolder) {
KBFolder kbFolder = (KBFolder) result;
if (!Validator.equals(uuid, kbFolder.getUuid()) || (groupId != kbFolder.getGroupId())) {
result = null;
}
}
if (result == null) {
StringBundler query = new StringBundler(4);
query.append(_SQL_SELECT_KBFOLDER_WHERE);
boolean bindUuid = false;
if (uuid == null) {
query.append(_FINDER_COLUMN_UUID_G_UUID_1);
} else if (uuid.equals(StringPool.BLANK)) {
query.append(_FINDER_COLUMN_UUID_G_UUID_3);
} else {
bindUuid = true;
query.append(_FINDER_COLUMN_UUID_G_UUID_2);
}
query.append(_FINDER_COLUMN_UUID_G_GROUPID_2);
String sql = query.toString();
Session session = null;
try {
session = openSession();
Query q = session.createQuery(sql);
QueryPos qPos = QueryPos.getInstance(q);
if (bindUuid) {
qPos.add(uuid);
}
qPos.add(groupId);
List<KBFolder> list = q.list();
if (list.isEmpty()) {
FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs, list);
} else {
KBFolder kbFolder = list.get(0);
result = kbFolder;
cacheResult(kbFolder);
if ((kbFolder.getUuid() == null) || !kbFolder.getUuid().equals(uuid) || (kbFolder.getGroupId() != groupId)) {
FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs, kbFolder);
}
}
} catch (Exception e) {
FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_UUID_G, finderArgs);
throw processException(e);
} finally {
closeSession(session);
}
}
if (result instanceof List<?>) {
return null;
} else {
return (KBFolder) result;
}
}
use of com.liferay.knowledgebase.model.KBFolder in project liferay-ide by liferay.
the class KBFolderPersistenceImpl method remove.
/**
* Removes the k b folder with the primary key from the database. Also notifies the appropriate model listeners.
*
* @param primaryKey the primary key of the k b folder
* @return the k b folder that was removed
* @throws com.liferay.knowledgebase.NoSuchFolderException if a k b folder with the primary key could not be found
* @throws SystemException if a system exception occurred
*/
@Override
public KBFolder remove(Serializable primaryKey) throws NoSuchFolderException, SystemException {
Session session = null;
try {
session = openSession();
KBFolder kbFolder = (KBFolder) session.get(KBFolderImpl.class, primaryKey);
if (kbFolder == null) {
if (_log.isWarnEnabled()) {
_log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
}
throw new NoSuchFolderException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
}
return remove(kbFolder);
} catch (NoSuchFolderException nsee) {
throw nsee;
} catch (Exception e) {
throw processException(e);
} finally {
closeSession(session);
}
}
Aggregations