List of usage examples for com.liferay.portal.kernel.util StringPool CLOSE_PARENTHESIS
String CLOSE_PARENTHESIS
To view the source code for com.liferay.portal.kernel.util StringPool CLOSE_PARENTHESIS.
Click Source Link
From source file:com.liferay.tasks.service.persistence.impl.TasksEntryPersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the tasks entries that the user has permission to view where groupId = ? and assigneeUserId = ? and status = any ?. * * <p>/*from w ww. j a va2 s. c om*/ * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.tasks.model.impl.TasksEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param groupId the group ID * @param assigneeUserId the assignee user ID * @param statuses the statuses * @param start the lower bound of the range of tasks entries * @param end the upper bound of the range of tasks entries (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching tasks entries that the user has permission to view */ @Override public List<TasksEntry> filterFindByG_A_S(long groupId, long assigneeUserId, int[] statuses, int start, int end, OrderByComparator<TasksEntry> orderByComparator) { if (!InlineSQLHelperUtil.isEnabled(groupId)) { return findByG_A_S(groupId, assigneeUserId, statuses, start, end, orderByComparator); } if (statuses == null) { statuses = new int[0]; } else { statuses = ArrayUtil.unique(statuses); } StringBundler query = new StringBundler(); if (getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_TASKSENTRY_WHERE); } else { query.append(_FILTER_SQL_SELECT_TASKSENTRY_NO_INLINE_DISTINCT_WHERE_1); } query.append(_FINDER_COLUMN_G_A_S_GROUPID_2); query.append(_FINDER_COLUMN_G_A_S_ASSIGNEEUSERID_2); if (statuses.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_G_A_S_STATUS_7); query.append(StringUtil.merge(statuses)); query.append(StringPool.CLOSE_PARENTHESIS); query.append(StringPool.CLOSE_PARENTHESIS); } query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)), query.index() - 1); if (!getDB().isSupportsInlineDistinct()) { query.append(_FILTER_SQL_SELECT_TASKSENTRY_NO_INLINE_DISTINCT_WHERE_2); } if (orderByComparator != null) { if (getDB().isSupportsInlineDistinct()) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator, true); } else { appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE, orderByComparator, true); } } else { if (getDB().isSupportsInlineDistinct()) { query.append(TasksEntryModelImpl.ORDER_BY_JPQL); } else { query.append(TasksEntryModelImpl.ORDER_BY_SQL); } } String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), TasksEntry.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId); Session session = null; try { session = openSession(); SQLQuery q = session.createSynchronizedSQLQuery(sql); if (getDB().isSupportsInlineDistinct()) { q.addEntity(_FILTER_ENTITY_ALIAS, TasksEntryImpl.class); } else { q.addEntity(_FILTER_ENTITY_TABLE, TasksEntryImpl.class); } QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(assigneeUserId); return (List<TasksEntry>) QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } }
From source file:com.liferay.tasks.service.persistence.impl.TasksEntryPersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the tasks entries where groupId = ? and assigneeUserId = ? and status = any ?. * * <p>/*w w w.java2 s . c o m*/ * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.tasks.model.impl.TasksEntryModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order. * </p> * * @param groupId the group ID * @param assigneeUserId the assignee user ID * @param statuses the statuses * @param start the lower bound of the range of tasks entries * @param end the upper bound of the range of tasks entries (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching tasks entries */ @Override public List<TasksEntry> findByG_A_S(long groupId, long assigneeUserId, int[] statuses, int start, int end, OrderByComparator<TasksEntry> orderByComparator) { if (statuses == null) { statuses = new int[0]; } else { statuses = ArrayUtil.unique(statuses); } if (statuses.length == 1) { return findByG_A_S(groupId, assigneeUserId, statuses[0], start, end, orderByComparator); } boolean pagination = true; Object[] finderArgs = null; if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) && (orderByComparator == null)) { pagination = false; finderArgs = new Object[] { groupId, assigneeUserId, StringUtil.merge(statuses) }; } else { finderArgs = new Object[] { groupId, assigneeUserId, StringUtil.merge(statuses), start, end, orderByComparator }; } List<TasksEntry> list = (List<TasksEntry>) FinderCacheUtil .getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_A_S, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (TasksEntry tasksEntry : list) { if ((groupId != tasksEntry.getGroupId()) || (assigneeUserId != tasksEntry.getAssigneeUserId()) || !ArrayUtil.contains(statuses, tasksEntry.getStatus())) { list = null; break; } } } if (list == null) { StringBundler query = new StringBundler(); query.append(_SQL_SELECT_TASKSENTRY_WHERE); query.append(_FINDER_COLUMN_G_A_S_GROUPID_2); query.append(_FINDER_COLUMN_G_A_S_ASSIGNEEUSERID_2); if (statuses.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_G_A_S_STATUS_7); query.append(StringUtil.merge(statuses)); query.append(StringPool.CLOSE_PARENTHESIS); query.append(StringPool.CLOSE_PARENTHESIS); } query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)), query.index() - 1); if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(TasksEntryModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(assigneeUserId); if (!pagination) { list = (List<TasksEntry>) QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = Collections.unmodifiableList(list); } else { list = (List<TasksEntry>) QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_A_S, finderArgs, list); } catch (Exception e) { FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_G_A_S, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; }
From source file:com.liferay.tasks.service.persistence.impl.TasksEntryPersistenceImpl.java
License:Open Source License
/** * Returns the number of tasks entries where groupId = ? and assigneeUserId = ? and status = any ?. * * @param groupId the group ID/*from w w w . jav a2 s. c o m*/ * @param assigneeUserId the assignee user ID * @param statuses the statuses * @return the number of matching tasks entries */ @Override public int countByG_A_S(long groupId, long assigneeUserId, int[] statuses) { if (statuses == null) { statuses = new int[0]; } else { statuses = ArrayUtil.unique(statuses); } Object[] finderArgs = new Object[] { groupId, assigneeUserId, StringUtil.merge(statuses) }; Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_A_S, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(); query.append(_SQL_COUNT_TASKSENTRY_WHERE); query.append(_FINDER_COLUMN_G_A_S_GROUPID_2); query.append(_FINDER_COLUMN_G_A_S_ASSIGNEEUSERID_2); if (statuses.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_G_A_S_STATUS_7); query.append(StringUtil.merge(statuses)); query.append(StringPool.CLOSE_PARENTHESIS); query.append(StringPool.CLOSE_PARENTHESIS); } query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)), query.index() - 1); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(assigneeUserId); count = (Long) q.uniqueResult(); FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_A_S, finderArgs, count); } catch (Exception e) { FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_G_A_S, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); }
From source file:com.liferay.tasks.service.persistence.impl.TasksEntryPersistenceImpl.java
License:Open Source License
/** * Returns the number of tasks entries that the user has permission to view where groupId = ? and assigneeUserId = ? and status = any ?. * * @param groupId the group ID/* w ww .j a v a 2 s. c om*/ * @param assigneeUserId the assignee user ID * @param statuses the statuses * @return the number of matching tasks entries that the user has permission to view */ @Override public int filterCountByG_A_S(long groupId, long assigneeUserId, int[] statuses) { if (!InlineSQLHelperUtil.isEnabled(groupId)) { return countByG_A_S(groupId, assigneeUserId, statuses); } if (statuses == null) { statuses = new int[0]; } else { statuses = ArrayUtil.unique(statuses); } StringBundler query = new StringBundler(); query.append(_FILTER_SQL_COUNT_TASKSENTRY_WHERE); query.append(_FINDER_COLUMN_G_A_S_GROUPID_2); query.append(_FINDER_COLUMN_G_A_S_ASSIGNEEUSERID_2); if (statuses.length > 0) { query.append(StringPool.OPEN_PARENTHESIS); query.append(_FINDER_COLUMN_G_A_S_STATUS_7); query.append(StringUtil.merge(statuses)); query.append(StringPool.CLOSE_PARENTHESIS); query.append(StringPool.CLOSE_PARENTHESIS); } query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)), query.index() - 1); String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(), TasksEntry.class.getName(), _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN, groupId); Session session = null; try { session = openSession(); SQLQuery q = session.createSynchronizedSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, com.liferay.portal.kernel.dao.orm.Type.LONG); QueryPos qPos = QueryPos.getInstance(q); qPos.add(groupId); qPos.add(assigneeUserId); Long count = (Long) q.uniqueResult(); return count.intValue(); } catch (Exception e) { throw processException(e); } finally { closeSession(session); } }
From source file:com.liferay.tasks.service.persistence.impl.TasksEntryPersistenceImpl.java
License:Open Source License
@Override public Map<Serializable, TasksEntry> fetchByPrimaryKeys(Set<Serializable> primaryKeys) { if (primaryKeys.isEmpty()) { return Collections.emptyMap(); }/*from w w w . j a va 2 s .co m*/ Map<Serializable, TasksEntry> map = new HashMap<Serializable, TasksEntry>(); if (primaryKeys.size() == 1) { Iterator<Serializable> iterator = primaryKeys.iterator(); Serializable primaryKey = iterator.next(); TasksEntry tasksEntry = fetchByPrimaryKey(primaryKey); if (tasksEntry != null) { map.put(primaryKey, tasksEntry); } return map; } Set<Serializable> uncachedPrimaryKeys = null; for (Serializable primaryKey : primaryKeys) { TasksEntry tasksEntry = (TasksEntry) EntityCacheUtil.getResult(TasksEntryModelImpl.ENTITY_CACHE_ENABLED, TasksEntryImpl.class, primaryKey); if (tasksEntry == null) { if (uncachedPrimaryKeys == null) { uncachedPrimaryKeys = new HashSet<Serializable>(); } uncachedPrimaryKeys.add(primaryKey); } else { map.put(primaryKey, tasksEntry); } } if (uncachedPrimaryKeys == null) { return map; } StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1); query.append(_SQL_SELECT_TASKSENTRY_WHERE_PKS_IN); for (Serializable primaryKey : uncachedPrimaryKeys) { query.append(String.valueOf(primaryKey)); query.append(StringPool.COMMA); } query.setIndex(query.index() - 1); query.append(StringPool.CLOSE_PARENTHESIS); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); for (TasksEntry tasksEntry : (List<TasksEntry>) q.list()) { map.put(tasksEntry.getPrimaryKeyObj(), tasksEntry); cacheResult(tasksEntry); uncachedPrimaryKeys.remove(tasksEntry.getPrimaryKeyObj()); } for (Serializable primaryKey : uncachedPrimaryKeys) { EntityCacheUtil.putResult(TasksEntryModelImpl.ENTITY_CACHE_ENABLED, TasksEntryImpl.class, primaryKey, _nullTasksEntry); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } return map; }
From source file:com.liferay.tasks.service.persistence.TasksEntryFinderImpl.java
License:Open Source License
public int countByG_P_A_R_S_T_N(long groupId, int priority, long assigneeUserId, long reporterUserId, int status, long[] assetTagIds, long[] notAssetTagIds) throws SystemException { Session session = null;/*from ww w . jav a 2s . c o m*/ try { session = openSession(); StringBuilder sb = new StringBuilder(); sb.append("SELECT COUNT(DISTINCT tasksEntryId) AS COUNT_VALUE "); sb.append("FROM TMS_TasksEntry WHERE"); if (groupId > 0) { sb.append(" AND TMS_TasksEntry.groupId = ?"); } if (priority > 0) { sb.append(" AND TMS_TasksEntry.priority = ?"); } if (assigneeUserId > 0) { sb.append(" AND TMS_TasksEntry.assigneeUserId = ?"); } if (reporterUserId > 0) { sb.append(" AND TMS_TasksEntry.userId = ?"); } if (status == TasksEntryConstants.STATUS_ALL) { } else if (status == TasksEntryConstants.STATUS_RESOLVED) { sb.append(" AND TMS_TasksEntry.finishDate IS NOT NULL"); } else { sb.append(" AND TMS_TasksEntry.finishDate IS NULL"); } if (assetTagIds.length > 0) { sb.append(" AND TMS_TasksEntry.tasksEntryId IN ("); for (int i = 0; i < assetTagIds.length; i++) { sb.append(CustomSQLUtil.get(FIND_BY_C_T)); if ((i + 1) < assetTagIds.length) { sb.append(" OR AssetEntry.classPK IN ("); } } for (int i = 0; i < assetTagIds.length; i++) { sb.append(StringPool.CLOSE_PARENTHESIS); } } if (notAssetTagIds.length > 0) { sb.append(" AND ("); for (int i = 0; i < notAssetTagIds.length; i++) { sb.append("TMS_TasksEntry.tasksEntryId NOT IN ("); sb.append(CustomSQLUtil.get(FIND_BY_C_T)); sb.append(StringPool.CLOSE_PARENTHESIS); if ((i + 1) < notAssetTagIds.length) { sb.append(" OR "); } } sb.append(StringPool.CLOSE_PARENTHESIS); } String sql = sb.toString(); sql = StringUtil.replaceFirst(sql, " WHERE AND ", " WHERE "); SQLQuery q = session.createSQLQuery(sql); q.addScalar(COUNT_COLUMN_NAME, Type.LONG); QueryPos qPos = QueryPos.getInstance(q); if (groupId > 0) { qPos.add(groupId); } if (priority > 0) { qPos.add(priority); } if (assigneeUserId > 0) { qPos.add(assigneeUserId); } if (reporterUserId > 0) { qPos.add(reporterUserId); } setTagsEntryIds(qPos, assetTagIds); setTagsEntryIds(qPos, notAssetTagIds); Iterator<Long> itr = q.iterate(); if (itr.hasNext()) { Long count = itr.next(); if (count != null) { return count.intValue(); } } return 0; } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
From source file:com.liferay.tasks.service.persistence.TasksEntryFinderImpl.java
License:Open Source License
public List<TasksEntry> findByG_P_A_R_S_T_N(long groupId, int priority, long assigneeUserId, long reporterUserId, int status, long[] assetTagIds, long[] notAssetTagIds, int start, int end) throws SystemException { Session session = null;//from w w w .jav a 2 s.co m try { session = openSession(); StringBuilder sb = new StringBuilder(); sb.append("SELECT DISTINCT {TMS_TasksEntry.*} "); sb.append("FROM TMS_TasksEntry WHERE"); if (groupId > 0) { sb.append(" AND TMS_TasksEntry.groupId = ?"); } if (priority > 0) { sb.append(" AND TMS_TasksEntry.priority = ?"); } if (assigneeUserId > 0) { sb.append(" AND TMS_TasksEntry.assigneeUserId = ?"); } if (reporterUserId > 0) { sb.append(" AND TMS_TasksEntry.userId = ?"); } if (status == TasksEntryConstants.STATUS_ALL) { } else if (status == TasksEntryConstants.STATUS_RESOLVED) { sb.append(" AND TMS_TasksEntry.finishDate IS NOT NULL"); } else { sb.append(" AND TMS_TasksEntry.finishDate IS NULL"); } if (assetTagIds.length > 0) { sb.append(" AND TMS_TasksEntry.tasksEntryId IN ("); for (int i = 0; i < assetTagIds.length; i++) { sb.append(CustomSQLUtil.get(FIND_BY_C_T)); if ((i + 1) < assetTagIds.length) { sb.append(" OR AssetEntry.classPK IN ("); } } for (int i = 0; i < assetTagIds.length; i++) { sb.append(StringPool.CLOSE_PARENTHESIS); } } if (notAssetTagIds.length > 0) { sb.append(" AND ("); for (int i = 0; i < notAssetTagIds.length; i++) { sb.append("TMS_TasksEntry.tasksEntryId NOT IN ("); sb.append(CustomSQLUtil.get(FIND_BY_C_T)); sb.append(StringPool.CLOSE_PARENTHESIS); if ((i + 1) < notAssetTagIds.length) { sb.append(" OR "); } } sb.append(StringPool.CLOSE_PARENTHESIS); } sb.append(" ORDER BY "); sb.append("priority ASC, "); sb.append("dueDate ASC, "); sb.append("createDate ASC"); String sql = sb.toString(); sql = StringUtil.replaceFirst(sql, " WHERE AND ", " WHERE "); SQLQuery q = session.createSQLQuery(sql); q.addEntity("TMS_TasksEntry", TasksEntryImpl.class); QueryPos qPos = QueryPos.getInstance(q); if (groupId > 0) { qPos.add(groupId); } if (priority > 0) { qPos.add(priority); } if (assigneeUserId > 0) { qPos.add(assigneeUserId); } if (reporterUserId > 0) { qPos.add(reporterUserId); } setTagsEntryIds(qPos, assetTagIds); setTagsEntryIds(qPos, notAssetTagIds); return (List<TasksEntry>) QueryUtil.list(q, getDialect(), start, end); } catch (Exception e) { throw new SystemException(e); } finally { closeSession(session); } }
From source file:com.liferay.testblob.service.persistence.impl.TestBlobEntryPersistenceImpl.java
License:Open Source License
@Override public Map<Serializable, TestBlobEntry> fetchByPrimaryKeys(Set<Serializable> primaryKeys) { if (primaryKeys.isEmpty()) { return Collections.emptyMap(); }// w w w . ja va 2 s .co m Map<Serializable, TestBlobEntry> map = new HashMap<Serializable, TestBlobEntry>(); if (primaryKeys.size() == 1) { Iterator<Serializable> iterator = primaryKeys.iterator(); Serializable primaryKey = iterator.next(); TestBlobEntry testBlobEntry = fetchByPrimaryKey(primaryKey); if (testBlobEntry != null) { map.put(primaryKey, testBlobEntry); } return map; } Set<Serializable> uncachedPrimaryKeys = null; for (Serializable primaryKey : primaryKeys) { TestBlobEntry testBlobEntry = (TestBlobEntry) EntityCacheUtil .getResult(TestBlobEntryModelImpl.ENTITY_CACHE_ENABLED, TestBlobEntryImpl.class, primaryKey); if (testBlobEntry == null) { if (uncachedPrimaryKeys == null) { uncachedPrimaryKeys = new HashSet<Serializable>(); } uncachedPrimaryKeys.add(primaryKey); } else { map.put(primaryKey, testBlobEntry); } } if (uncachedPrimaryKeys == null) { return map; } StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1); query.append(_SQL_SELECT_TESTBLOBENTRY_WHERE_PKS_IN); for (Serializable primaryKey : uncachedPrimaryKeys) { query.append(String.valueOf(primaryKey)); query.append(StringPool.COMMA); } query.setIndex(query.index() - 1); query.append(StringPool.CLOSE_PARENTHESIS); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); for (TestBlobEntry testBlobEntry : (List<TestBlobEntry>) q.list()) { map.put(testBlobEntry.getPrimaryKeyObj(), testBlobEntry); cacheResult(testBlobEntry); uncachedPrimaryKeys.remove(testBlobEntry.getPrimaryKeyObj()); } for (Serializable primaryKey : uncachedPrimaryKeys) { EntityCacheUtil.putResult(TestBlobEntryModelImpl.ENTITY_CACHE_ENABLED, TestBlobEntryImpl.class, primaryKey, _nullTestBlobEntry); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } return map; }
From source file:com.liferay.testtransaction.service.persistence.impl.BarPersistenceImpl.java
License:Open Source License
@Override public Map<Serializable, Bar> fetchByPrimaryKeys(Set<Serializable> primaryKeys) { if (primaryKeys.isEmpty()) { return Collections.emptyMap(); }//from w w w. j a v a2 s. c o m Map<Serializable, Bar> map = new HashMap<Serializable, Bar>(); if (primaryKeys.size() == 1) { Iterator<Serializable> iterator = primaryKeys.iterator(); Serializable primaryKey = iterator.next(); Bar bar = fetchByPrimaryKey(primaryKey); if (bar != null) { map.put(primaryKey, bar); } return map; } Set<Serializable> uncachedPrimaryKeys = null; for (Serializable primaryKey : primaryKeys) { Bar bar = (Bar) EntityCacheUtil.getResult(BarModelImpl.ENTITY_CACHE_ENABLED, BarImpl.class, primaryKey); if (bar == null) { if (uncachedPrimaryKeys == null) { uncachedPrimaryKeys = new HashSet<Serializable>(); } uncachedPrimaryKeys.add(primaryKey); } else { map.put(primaryKey, bar); } } if (uncachedPrimaryKeys == null) { return map; } StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1); query.append(_SQL_SELECT_BAR_WHERE_PKS_IN); for (Serializable primaryKey : uncachedPrimaryKeys) { query.append(String.valueOf(primaryKey)); query.append(StringPool.COMMA); } query.setIndex(query.index() - 1); query.append(StringPool.CLOSE_PARENTHESIS); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); for (Bar bar : (List<Bar>) q.list()) { map.put(bar.getPrimaryKeyObj(), bar); cacheResult(bar); uncachedPrimaryKeys.remove(bar.getPrimaryKeyObj()); } for (Serializable primaryKey : uncachedPrimaryKeys) { EntityCacheUtil.putResult(BarModelImpl.ENTITY_CACHE_ENABLED, BarImpl.class, primaryKey, _nullBar); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } return map; }
From source file:com.liferay.todo.service.persistence.impl.TodoPersistenceImpl.java
License:Open Source License
@Override public Map<Serializable, Todo> fetchByPrimaryKeys(Set<Serializable> primaryKeys) { if (primaryKeys.isEmpty()) { return Collections.emptyMap(); }//from w w w.j ava 2s. com Map<Serializable, Todo> map = new HashMap<Serializable, Todo>(); if (primaryKeys.size() == 1) { Iterator<Serializable> iterator = primaryKeys.iterator(); Serializable primaryKey = iterator.next(); Todo todo = fetchByPrimaryKey(primaryKey); if (todo != null) { map.put(primaryKey, todo); } return map; } Set<Serializable> uncachedPrimaryKeys = null; for (Serializable primaryKey : primaryKeys) { Serializable serializable = entityCache.getResult(TodoModelImpl.ENTITY_CACHE_ENABLED, TodoImpl.class, primaryKey); if (serializable != nullModel) { if (serializable == null) { if (uncachedPrimaryKeys == null) { uncachedPrimaryKeys = new HashSet<Serializable>(); } uncachedPrimaryKeys.add(primaryKey); } else { map.put(primaryKey, (Todo) serializable); } } } if (uncachedPrimaryKeys == null) { return map; } StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1); query.append(_SQL_SELECT_TODO_WHERE_PKS_IN); for (Serializable primaryKey : uncachedPrimaryKeys) { query.append((long) primaryKey); query.append(StringPool.COMMA); } query.setIndex(query.index() - 1); query.append(StringPool.CLOSE_PARENTHESIS); String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); for (Todo todo : (List<Todo>) q.list()) { map.put(todo.getPrimaryKeyObj(), todo); cacheResult(todo); uncachedPrimaryKeys.remove(todo.getPrimaryKeyObj()); } for (Serializable primaryKey : uncachedPrimaryKeys) { entityCache.putResult(TodoModelImpl.ENTITY_CACHE_ENABLED, TodoImpl.class, primaryKey, nullModel); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } return map; }