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.inikah.slayer.service.impl.MyKeyValueLocalServiceImpl.java
License:Open Source License
public List<KeyValuePair> getItemsForFilter(boolean bride, String column, long parentId, String parentColumn) { List<MyKeyValue> items = myKeyValueFinder.findResults(bride, column, parentId, parentColumn); List<KeyValuePair> kvPairs = new ArrayList<KeyValuePair>(); for (MyKeyValue myKeyValue : items) { long key = myKeyValue.getMyKey(); String name = LanguageUtil.get(Locale.ENGLISH, myKeyValue.getMyName()); if (column.contains("ountry")) { name = TextFormatter.formatName(name); }//from ww w .j a v a 2 s.c o m StringBuilder sb = new StringBuilder(name); sb.append(StringPool.SPACE); sb.append(StringPool.OPEN_PARENTHESIS); sb.append(myKeyValue.getMyValue()); sb.append(StringPool.CLOSE_PARENTHESIS); kvPairs.add(new KeyValuePair(String.valueOf(key), sb.toString())); } return ListUtil.sort(kvPairs, new KeyValuePairComparator(false, true)); }
From source file:com.kisti.science.platform.app.service.persistence.ScienceAppPersistenceImpl.java
License:Open Source License
/** * Returns an ordered range of all the science apps where name LIKE any ? and title LIKE any ? and targetLanguage = all ?. * * <p>/*from w w w .j av a 2 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.kisti.science.platform.app.model.impl.ScienceAppModelImpl}. 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 names the names * @param titles the titles * @param targetLanguages the target languages * @param start the lower bound of the range of science apps * @param end the upper bound of the range of science apps (not inclusive) * @param orderByComparator the comparator to order the results by (optionally <code>null</code>) * @return the ordered range of matching science apps * @throws SystemException if a system exception occurred */ @Override public List<ScienceApp> findByNameTitleWithTarget(String[] names, String[] titles, String[] targetLanguages, int start, int end, OrderByComparator orderByComparator) throws SystemException { if ((names != null) && (names.length == 1) && (titles != null) && (titles.length == 1) && (targetLanguages != null) && (targetLanguages.length == 1)) { return findByNameTitleWithTarget(names[0], titles[0], targetLanguages[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[] { StringUtil.merge(names), StringUtil.merge(titles), StringUtil.merge(targetLanguages) }; } else { finderArgs = new Object[] { StringUtil.merge(names), StringUtil.merge(titles), StringUtil.merge(targetLanguages), start, end, orderByComparator }; } List<ScienceApp> list = (List<ScienceApp>) FinderCacheUtil .getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_NAMETITLEWITHTARGET, finderArgs, this); if ((list != null) && !list.isEmpty()) { for (ScienceApp scienceApp : list) { if (!ArrayUtil.contains(names, scienceApp.getName()) || !ArrayUtil.contains(titles, scienceApp.getTitle()) || !ArrayUtil.contains(targetLanguages, scienceApp.getTargetLanguage())) { list = null; break; } } } if (list == null) { StringBundler query = new StringBundler(); query.append(_SQL_SELECT_SCIENCEAPP_WHERE); boolean conjunctionable = false; if ((names == null) || (names.length > 0)) { if (conjunctionable) { query.append(WHERE_AND); } query.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < names.length; i++) { String name = names[i]; if (name == null) { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_NAME_4); } else if (name.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_NAME_6); } else { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_NAME_5); } if ((i + 1) < names.length) { query.append(WHERE_OR); } } query.append(StringPool.CLOSE_PARENTHESIS); conjunctionable = true; } if ((titles == null) || (titles.length > 0)) { if (conjunctionable) { query.append(WHERE_AND); } query.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < titles.length; i++) { String title = titles[i]; if (title == null) { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_TITLE_4); } else if (title.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_TITLE_6); } else { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_TITLE_5); } if ((i + 1) < titles.length) { query.append(WHERE_OR); } } query.append(StringPool.CLOSE_PARENTHESIS); conjunctionable = true; } if ((targetLanguages == null) || (targetLanguages.length > 0)) { if (conjunctionable) { query.append(WHERE_AND); } query.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < targetLanguages.length; i++) { String targetLanguage = targetLanguages[i]; if (targetLanguage == null) { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_TARGETLANGUAGE_4); } else if (targetLanguage.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_TARGETLANGUAGE_6); } else { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_TARGETLANGUAGE_5); } if ((i + 1) < targetLanguages.length) { query.append(WHERE_AND); } } query.append(StringPool.CLOSE_PARENTHESIS); conjunctionable = true; } if (orderByComparator != null) { appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS, orderByComparator); } else if (pagination) { query.append(ScienceAppModelImpl.ORDER_BY_JPQL); } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (names != null) { qPos.add(names); } if (titles != null) { qPos.add(titles); } if (targetLanguages != null) { qPos.add(targetLanguages); } if (!pagination) { list = (List<ScienceApp>) QueryUtil.list(q, getDialect(), start, end, false); Collections.sort(list); list = new UnmodifiableList<ScienceApp>(list); } else { list = (List<ScienceApp>) QueryUtil.list(q, getDialect(), start, end); } cacheResult(list); FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_NAMETITLEWITHTARGET, finderArgs, list); } catch (Exception e) { FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_NAMETITLEWITHTARGET, finderArgs); throw processException(e); } finally { closeSession(session); } } return list; }
From source file:com.kisti.science.platform.app.service.persistence.ScienceAppPersistenceImpl.java
License:Open Source License
/** * Returns the number of science apps where name LIKE any ? and title LIKE any ? and targetLanguage = all ?. * * @param names the names/*from www. j ava 2s . co m*/ * @param titles the titles * @param targetLanguages the target languages * @return the number of matching science apps * @throws SystemException if a system exception occurred */ @Override public int countByNameTitleWithTarget(String[] names, String[] titles, String[] targetLanguages) throws SystemException { Object[] finderArgs = new Object[] { StringUtil.merge(names), StringUtil.merge(titles), StringUtil.merge(targetLanguages) }; Long count = (Long) FinderCacheUtil.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_NAMETITLEWITHTARGET, finderArgs, this); if (count == null) { StringBundler query = new StringBundler(); query.append(_SQL_COUNT_SCIENCEAPP_WHERE); boolean conjunctionable = false; if ((names == null) || (names.length > 0)) { if (conjunctionable) { query.append(WHERE_AND); } query.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < names.length; i++) { String name = names[i]; if (name == null) { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_NAME_4); } else if (name.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_NAME_6); } else { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_NAME_5); } if ((i + 1) < names.length) { query.append(WHERE_OR); } } query.append(StringPool.CLOSE_PARENTHESIS); conjunctionable = true; } if ((titles == null) || (titles.length > 0)) { if (conjunctionable) { query.append(WHERE_AND); } query.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < titles.length; i++) { String title = titles[i]; if (title == null) { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_TITLE_4); } else if (title.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_TITLE_6); } else { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_TITLE_5); } if ((i + 1) < titles.length) { query.append(WHERE_OR); } } query.append(StringPool.CLOSE_PARENTHESIS); conjunctionable = true; } if ((targetLanguages == null) || (targetLanguages.length > 0)) { if (conjunctionable) { query.append(WHERE_AND); } query.append(StringPool.OPEN_PARENTHESIS); for (int i = 0; i < targetLanguages.length; i++) { String targetLanguage = targetLanguages[i]; if (targetLanguage == null) { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_TARGETLANGUAGE_4); } else if (targetLanguage.equals(StringPool.BLANK)) { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_TARGETLANGUAGE_6); } else { query.append(_FINDER_COLUMN_NAMETITLEWITHTARGET_TARGETLANGUAGE_5); } if ((i + 1) < targetLanguages.length) { query.append(WHERE_AND); } } query.append(StringPool.CLOSE_PARENTHESIS); conjunctionable = true; } String sql = query.toString(); Session session = null; try { session = openSession(); Query q = session.createQuery(sql); QueryPos qPos = QueryPos.getInstance(q); if (names != null) { qPos.add(names); } if (titles != null) { qPos.add(titles); } if (targetLanguages != null) { qPos.add(targetLanguages); } count = (Long) q.uniqueResult(); FinderCacheUtil.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_NAMETITLEWITHTARGET, finderArgs, count); } catch (Exception e) { FinderCacheUtil.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_NAMETITLEWITHTARGET, finderArgs); throw processException(e); } finally { closeSession(session); } } return count.intValue(); }
From source file:com.liferay.adaptive.media.image.service.persistence.impl.AdaptiveMediaImageEntryPersistenceImpl.java
License:Open Source License
@Override public Map<Serializable, AdaptiveMediaImageEntry> fetchByPrimaryKeys(Set<Serializable> primaryKeys) { if (primaryKeys.isEmpty()) { return Collections.emptyMap(); }/*from ww w . j ava2 s . c om*/ Map<Serializable, AdaptiveMediaImageEntry> map = new HashMap<Serializable, AdaptiveMediaImageEntry>(); if (primaryKeys.size() == 1) { Iterator<Serializable> iterator = primaryKeys.iterator(); Serializable primaryKey = iterator.next(); AdaptiveMediaImageEntry adaptiveMediaImageEntry = fetchByPrimaryKey(primaryKey); if (adaptiveMediaImageEntry != null) { map.put(primaryKey, adaptiveMediaImageEntry); } return map; } Set<Serializable> uncachedPrimaryKeys = null; for (Serializable primaryKey : primaryKeys) { Serializable serializable = entityCache.getResult(AdaptiveMediaImageEntryModelImpl.ENTITY_CACHE_ENABLED, AdaptiveMediaImageEntryImpl.class, primaryKey); if (serializable != nullModel) { if (serializable == null) { if (uncachedPrimaryKeys == null) { uncachedPrimaryKeys = new HashSet<Serializable>(); } uncachedPrimaryKeys.add(primaryKey); } else { map.put(primaryKey, (AdaptiveMediaImageEntry) serializable); } } } if (uncachedPrimaryKeys == null) { return map; } StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1); query.append(_SQL_SELECT_ADAPTIVEMEDIAIMAGEENTRY_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 (AdaptiveMediaImageEntry adaptiveMediaImageEntry : (List<AdaptiveMediaImageEntry>) q.list()) { map.put(adaptiveMediaImageEntry.getPrimaryKeyObj(), adaptiveMediaImageEntry); cacheResult(adaptiveMediaImageEntry); uncachedPrimaryKeys.remove(adaptiveMediaImageEntry.getPrimaryKeyObj()); } for (Serializable primaryKey : uncachedPrimaryKeys) { entityCache.putResult(AdaptiveMediaImageEntryModelImpl.ENTITY_CACHE_ENABLED, AdaptiveMediaImageEntryImpl.class, primaryKey, nullModel); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } return map; }
From source file:com.liferay.adaptive.media.image.web.html.AdaptiveMediaImageHTMLTagFactoryImpl.java
License:Open Source License
private Optional<String> _getMediaQueryString(MediaQuery mediaQuery) { List<Condition> conditions = mediaQuery.getConditions(); if (conditions.isEmpty()) { return Optional.empty(); }/* ww w . jav a2 s .co m*/ String[] conditionStrings = new String[conditions.size()]; for (int i = 0; i < conditionStrings.length; i++) { Condition condition = conditions.get(i); StringBundler sb = new StringBundler(5); sb.append(StringPool.OPEN_PARENTHESIS); sb.append(condition.getAttribute()); sb.append(StringPool.COLON); sb.append(condition.getValue()); sb.append(StringPool.CLOSE_PARENTHESIS); conditionStrings[i] = sb.toString(); } return Optional.of(String.join(" and ", conditionStrings)); }
From source file:com.liferay.akismet.service.persistence.impl.AkismetDataPersistenceImpl.java
License:Open Source License
@Override public Map<Serializable, AkismetData> fetchByPrimaryKeys(Set<Serializable> primaryKeys) { if (primaryKeys.isEmpty()) { return Collections.emptyMap(); }/*from w w w .j a v a 2s . c om*/ Map<Serializable, AkismetData> map = new HashMap<Serializable, AkismetData>(); if (primaryKeys.size() == 1) { Iterator<Serializable> iterator = primaryKeys.iterator(); Serializable primaryKey = iterator.next(); AkismetData akismetData = fetchByPrimaryKey(primaryKey); if (akismetData != null) { map.put(primaryKey, akismetData); } return map; } Set<Serializable> uncachedPrimaryKeys = null; for (Serializable primaryKey : primaryKeys) { AkismetData akismetData = (AkismetData) EntityCacheUtil .getResult(AkismetDataModelImpl.ENTITY_CACHE_ENABLED, AkismetDataImpl.class, primaryKey); if (akismetData == null) { if (uncachedPrimaryKeys == null) { uncachedPrimaryKeys = new HashSet<Serializable>(); } uncachedPrimaryKeys.add(primaryKey); } else { map.put(primaryKey, akismetData); } } if (uncachedPrimaryKeys == null) { return map; } StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1); query.append(_SQL_SELECT_AKISMETDATA_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 (AkismetData akismetData : (List<AkismetData>) q.list()) { map.put(akismetData.getPrimaryKeyObj(), akismetData); cacheResult(akismetData); uncachedPrimaryKeys.remove(akismetData.getPrimaryKeyObj()); } for (Serializable primaryKey : uncachedPrimaryKeys) { EntityCacheUtil.putResult(AkismetDataModelImpl.ENTITY_CACHE_ENABLED, AkismetDataImpl.class, primaryKey, _nullAkismetData); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } return map; }
From source file:com.liferay.alloy.mvc.jsonwebservice.AlloyControllerInvokerManager.java
License:Open Source License
protected byte[] generateAlloyControllerInvokerClassData(Class<?> controllerClass, String alloyControllerInvokerClassName) throws NoClassNecessaryException { boolean jsonWebServiceMethodsPresent = false; ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES); String alloyControllerInvokerClassBinaryName = getClassBinaryName(alloyControllerInvokerClassName); String baseAlloyControllerInvokerClassBinaryName = getClassBinaryName( BaseAlloyControllerInvokerImpl.class.getName()); classWriter.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC | Opcodes.ACC_SUPER, alloyControllerInvokerClassBinaryName, null, baseAlloyControllerInvokerClassBinaryName, null); MethodVisitor methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); methodVisitor.visitCode();//from w w w . j av a 2 s . c o m methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitMethodInsn(Opcodes.INVOKESPECIAL, baseAlloyControllerInvokerClassBinaryName, "<init>", "()V"); methodVisitor.visitInsn(Opcodes.RETURN); methodVisitor.visitMaxs(1, 1); methodVisitor.visitEnd(); Method[] methods = controllerClass.getDeclaredMethods(); for (Method method : methods) { if (!Modifier.isPublic(method.getModifiers())) { continue; } JSONWebServiceMethod jsonWebServiceMethod = method.getAnnotation(JSONWebServiceMethod.class); if (jsonWebServiceMethod == null) { continue; } jsonWebServiceMethodsPresent = true; String methodName = jsonWebServiceMethod.methodName(); if (Validator.isNull(methodName)) { methodName = method.getName(); } Class<?>[] parameterTypes = jsonWebServiceMethod.parameterTypes(); StringBundler sb = new StringBundler(parameterTypes.length + 3); sb.append(StringPool.OPEN_PARENTHESIS); for (Class<?> parameterType : parameterTypes) { sb.append(Type.getDescriptor(parameterType)); } sb.append(StringPool.CLOSE_PARENTHESIS); sb.append(Type.getDescriptor(JSONSerializable.class)); String methodDescriptor = sb.toString(); methodVisitor = classWriter.visitMethod(Opcodes.ACC_PUBLIC, methodName, methodDescriptor, null, new String[] { getClassBinaryName(Exception.class.getName()) }); methodVisitor.visitCode(); for (int i = 0; i < parameterTypes.length; i++) { String parameterName = jsonWebServiceMethod.parameterNames()[i]; Class<?> parameterType = parameterTypes[i]; methodVisitor.visitLocalVariable(parameterName, Type.getDescriptor(parameterType), null, new Label(), new Label(), i + 1); } methodVisitor.visitVarInsn(Opcodes.ALOAD, 0); methodVisitor.visitLdcInsn(jsonWebServiceMethod.lifecycle()); methodVisitor.visitIntInsn(Opcodes.BIPUSH, parameterTypes.length * 2 + 2); methodVisitor.visitTypeInsn(Opcodes.ANEWARRAY, getClassBinaryName(Object.class.getName())); methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitInsn(Opcodes.ICONST_0); methodVisitor.visitLdcInsn("action"); methodVisitor.visitInsn(Opcodes.AASTORE); methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitInsn(Opcodes.ICONST_1); methodVisitor.visitLdcInsn(method.getName()); methodVisitor.visitInsn(Opcodes.AASTORE); for (int i = 0; i < parameterTypes.length; i++) { String parameterName = jsonWebServiceMethod.parameterNames()[i]; methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitIntInsn(Opcodes.BIPUSH, (i + 1) * 2); methodVisitor.visitLdcInsn(parameterName); methodVisitor.visitInsn(Opcodes.AASTORE); methodVisitor.visitInsn(Opcodes.DUP); methodVisitor.visitIntInsn(Opcodes.BIPUSH, (i + 1) * 2 + 1); methodVisitor.visitVarInsn(Opcodes.ALOAD, i + 1); methodVisitor.visitInsn(Opcodes.AASTORE); } sb = new StringBundler(5); sb.append(StringPool.OPEN_PARENTHESIS); sb.append(Type.getDescriptor(String.class)); sb.append(Type.getDescriptor(Object[].class)); sb.append(StringPool.CLOSE_PARENTHESIS); sb.append(Type.getDescriptor(JSONSerializable.class)); methodVisitor.visitMethodInsn(Opcodes.INVOKEVIRTUAL, alloyControllerInvokerClassBinaryName, "invokeAlloyController", sb.toString()); methodVisitor.visitInsn(Opcodes.ARETURN); methodVisitor.visitMaxs(-1, -1); methodVisitor.visitEnd(); } classWriter.visitEnd(); if (!jsonWebServiceMethodsPresent) { throw new NoClassNecessaryException(); } return classWriter.toByteArray(); }
From source file:com.liferay.ams.service.persistence.impl.AssetPersistenceImpl.java
License:Open Source License
@Override public Map<Serializable, Asset> fetchByPrimaryKeys(Set<Serializable> primaryKeys) { if (primaryKeys.isEmpty()) { return Collections.emptyMap(); }// w w w . ja va 2 s.c om Map<Serializable, Asset> map = new HashMap<Serializable, Asset>(); if (primaryKeys.size() == 1) { Iterator<Serializable> iterator = primaryKeys.iterator(); Serializable primaryKey = iterator.next(); Asset asset = fetchByPrimaryKey(primaryKey); if (asset != null) { map.put(primaryKey, asset); } return map; } Set<Serializable> uncachedPrimaryKeys = null; for (Serializable primaryKey : primaryKeys) { Asset asset = (Asset) EntityCacheUtil.getResult(AssetModelImpl.ENTITY_CACHE_ENABLED, AssetImpl.class, primaryKey); if (asset == null) { if (uncachedPrimaryKeys == null) { uncachedPrimaryKeys = new HashSet<Serializable>(); } uncachedPrimaryKeys.add(primaryKey); } else { map.put(primaryKey, asset); } } if (uncachedPrimaryKeys == null) { return map; } StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1); query.append(_SQL_SELECT_ASSET_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 (Asset asset : (List<Asset>) q.list()) { map.put(asset.getPrimaryKeyObj(), asset); cacheResult(asset); uncachedPrimaryKeys.remove(asset.getPrimaryKeyObj()); } for (Serializable primaryKey : uncachedPrimaryKeys) { EntityCacheUtil.putResult(AssetModelImpl.ENTITY_CACHE_ENABLED, AssetImpl.class, primaryKey, _nullAsset); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } return map; }
From source file:com.liferay.ams.service.persistence.impl.CheckoutPersistenceImpl.java
License:Open Source License
@Override public Map<Serializable, Checkout> fetchByPrimaryKeys(Set<Serializable> primaryKeys) { if (primaryKeys.isEmpty()) { return Collections.emptyMap(); }//from w w w .j ava 2 s . c o m Map<Serializable, Checkout> map = new HashMap<Serializable, Checkout>(); if (primaryKeys.size() == 1) { Iterator<Serializable> iterator = primaryKeys.iterator(); Serializable primaryKey = iterator.next(); Checkout checkout = fetchByPrimaryKey(primaryKey); if (checkout != null) { map.put(primaryKey, checkout); } return map; } Set<Serializable> uncachedPrimaryKeys = null; for (Serializable primaryKey : primaryKeys) { Checkout checkout = (Checkout) EntityCacheUtil.getResult(CheckoutModelImpl.ENTITY_CACHE_ENABLED, CheckoutImpl.class, primaryKey); if (checkout == null) { if (uncachedPrimaryKeys == null) { uncachedPrimaryKeys = new HashSet<Serializable>(); } uncachedPrimaryKeys.add(primaryKey); } else { map.put(primaryKey, checkout); } } if (uncachedPrimaryKeys == null) { return map; } StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1); query.append(_SQL_SELECT_CHECKOUT_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 (Checkout checkout : (List<Checkout>) q.list()) { map.put(checkout.getPrimaryKeyObj(), checkout); cacheResult(checkout); uncachedPrimaryKeys.remove(checkout.getPrimaryKeyObj()); } for (Serializable primaryKey : uncachedPrimaryKeys) { EntityCacheUtil.putResult(CheckoutModelImpl.ENTITY_CACHE_ENABLED, CheckoutImpl.class, primaryKey, _nullCheckout); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } return map; }
From source file:com.liferay.ams.service.persistence.impl.DefinitionPersistenceImpl.java
License:Open Source License
@Override public Map<Serializable, Definition> fetchByPrimaryKeys(Set<Serializable> primaryKeys) { if (primaryKeys.isEmpty()) { return Collections.emptyMap(); }//from w w w . j ava 2s .c o m Map<Serializable, Definition> map = new HashMap<Serializable, Definition>(); if (primaryKeys.size() == 1) { Iterator<Serializable> iterator = primaryKeys.iterator(); Serializable primaryKey = iterator.next(); Definition definition = fetchByPrimaryKey(primaryKey); if (definition != null) { map.put(primaryKey, definition); } return map; } Set<Serializable> uncachedPrimaryKeys = null; for (Serializable primaryKey : primaryKeys) { Definition definition = (Definition) EntityCacheUtil.getResult(DefinitionModelImpl.ENTITY_CACHE_ENABLED, DefinitionImpl.class, primaryKey); if (definition == null) { if (uncachedPrimaryKeys == null) { uncachedPrimaryKeys = new HashSet<Serializable>(); } uncachedPrimaryKeys.add(primaryKey); } else { map.put(primaryKey, definition); } } if (uncachedPrimaryKeys == null) { return map; } StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1); query.append(_SQL_SELECT_DEFINITION_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 (Definition definition : (List<Definition>) q.list()) { map.put(definition.getPrimaryKeyObj(), definition); cacheResult(definition); uncachedPrimaryKeys.remove(definition.getPrimaryKeyObj()); } for (Serializable primaryKey : uncachedPrimaryKeys) { EntityCacheUtil.putResult(DefinitionModelImpl.ENTITY_CACHE_ENABLED, DefinitionImpl.class, primaryKey, _nullDefinition); } } catch (Exception e) { throw processException(e); } finally { closeSession(session); } return map; }