Example usage for com.liferay.portal.kernel.util StringPool CLOSE_PARENTHESIS

List of usage examples for com.liferay.portal.kernel.util StringPool CLOSE_PARENTHESIS

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util StringPool CLOSE_PARENTHESIS.

Prototype

String CLOSE_PARENTHESIS

To view the source code for com.liferay.portal.kernel.util StringPool CLOSE_PARENTHESIS.

Click Source Link

Usage

From source file:com.liferay.osb.scv.user.mapper.service.persistence.impl.UserMappingRulePersistenceImpl.java

License:Open Source License

@Override
public Map<Serializable, UserMappingRule> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }/*from  www. j  a v a  2  s.  c  om*/

    Map<Serializable, UserMappingRule> map = new HashMap<Serializable, UserMappingRule>();

    if (primaryKeys.size() == 1) {
        Iterator<Serializable> iterator = primaryKeys.iterator();

        Serializable primaryKey = iterator.next();

        UserMappingRule userMappingRule = fetchByPrimaryKey(primaryKey);

        if (userMappingRule != null) {
            map.put(primaryKey, userMappingRule);
        }

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        Serializable serializable = entityCache.getResult(UserMappingRuleModelImpl.ENTITY_CACHE_ENABLED,
                UserMappingRuleImpl.class, primaryKey);

        if (serializable != nullModel) {
            if (serializable == null) {
                if (uncachedPrimaryKeys == null) {
                    uncachedPrimaryKeys = new HashSet<Serializable>();
                }

                uncachedPrimaryKeys.add(primaryKey);
            } else {
                map.put(primaryKey, (UserMappingRule) serializable);
            }
        }
    }

    if (uncachedPrimaryKeys == null) {
        return map;
    }

    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1);

    query.append(_SQL_SELECT_USERMAPPINGRULE_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 (UserMappingRule userMappingRule : (List<UserMappingRule>) q.list()) {
            map.put(userMappingRule.getPrimaryKeyObj(), userMappingRule);

            cacheResult(userMappingRule);

            uncachedPrimaryKeys.remove(userMappingRule.getPrimaryKeyObj());
        }

        for (Serializable primaryKey : uncachedPrimaryKeys) {
            entityCache.putResult(UserMappingRuleModelImpl.ENTITY_CACHE_ENABLED, UserMappingRuleImpl.class,
                    primaryKey, nullModel);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    return map;
}

From source file:com.liferay.osgi.util.ComponentUtil.java

License:Open Source License

public static <T> void enableComponents(Class<T> referenceClass, String filterString,
        ComponentContext componentContext, Class<?>... componentClasses) {

    AwaitReferenceServiceTrackerCustomizer<T> awaitReferenceServiceTrackerCustomizer = new AwaitReferenceServiceTrackerCustomizer<>(
            componentContext, componentClasses);

    ServiceTracker<T, T> serviceTracker = null;

    if (Validator.isNull(filterString)) {
        serviceTracker = ServiceTrackerFactory.create(componentContext.getBundleContext(), referenceClass,
                awaitReferenceServiceTrackerCustomizer);
    } else {/*from ww w.  ja v  a 2s  . c o m*/
        StringBundler sb = new StringBundler(5);

        sb.append("(&(objectClass=");
        sb.append(referenceClass.getName());
        sb.append(StringPool.CLOSE_PARENTHESIS);
        sb.append(filterString);
        sb.append(StringPool.CLOSE_PARENTHESIS);

        serviceTracker = ServiceTrackerFactory.create(componentContext.getBundleContext(), sb.toString(),
                awaitReferenceServiceTrackerCustomizer);
    }

    awaitReferenceServiceTrackerCustomizer.setServiceTracker(serviceTracker);

    serviceTracker.open();
}

From source file:com.liferay.pokedex.service.persistence.impl.PokemonPersistenceImpl.java

License:Open Source License

@Override
public Map<Serializable, Pokemon> fetchByPrimaryKeys(Set<Serializable> primaryKeys) {
    if (primaryKeys.isEmpty()) {
        return Collections.emptyMap();
    }/*w w  w.  ja  v a  2s  .c  o  m*/

    Map<Serializable, Pokemon> map = new HashMap<Serializable, Pokemon>();

    if (primaryKeys.size() == 1) {
        Iterator<Serializable> iterator = primaryKeys.iterator();

        Serializable primaryKey = iterator.next();

        Pokemon pokemon = fetchByPrimaryKey(primaryKey);

        if (pokemon != null) {
            map.put(primaryKey, pokemon);
        }

        return map;
    }

    Set<Serializable> uncachedPrimaryKeys = null;

    for (Serializable primaryKey : primaryKeys) {
        Serializable serializable = entityCache.getResult(PokemonModelImpl.ENTITY_CACHE_ENABLED,
                PokemonImpl.class, primaryKey);

        if (serializable != nullModel) {
            if (serializable == null) {
                if (uncachedPrimaryKeys == null) {
                    uncachedPrimaryKeys = new HashSet<Serializable>();
                }

                uncachedPrimaryKeys.add(primaryKey);
            } else {
                map.put(primaryKey, (Pokemon) serializable);
            }
        }
    }

    if (uncachedPrimaryKeys == null) {
        return map;
    }

    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) + 1);

    query.append(_SQL_SELECT_POKEMON_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 (Pokemon pokemon : (List<Pokemon>) q.list()) {
            map.put(pokemon.getPrimaryKeyObj(), pokemon);

            cacheResult(pokemon);

            uncachedPrimaryKeys.remove(pokemon.getPrimaryKeyObj());
        }

        for (Serializable primaryKey : uncachedPrimaryKeys) {
            entityCache.putResult(PokemonModelImpl.ENTITY_CACHE_ENABLED, PokemonImpl.class, primaryKey,
                    nullModel);
        }
    } catch (Exception e) {
        throw processException(e);
    } finally {
        closeSession(session);
    }

    return map;
}

From source file:com.liferay.portlet.asset.service.persistence.AssetEntryFinderImpl.java

License:Open Source License

protected void buildAllCategoriesSQL(String sqlId, long[] categoryIds, StringBundler sb) {

    sb.append(" AND AssetEntry.entryId IN (");

    for (int i = 0; i < categoryIds.length; i++) {
        sb.append(CustomSQLUtil.get(sqlId));

        if ((i + 1) < categoryIds.length) {
            sb.append(" AND AssetEntry.entryId IN (");
        }// w w  w  . j  av a  2  s .  c o  m
    }

    for (int i = 0; i < categoryIds.length; i++) {
        if ((i + 1) < categoryIds.length) {
            sb.append(StringPool.CLOSE_PARENTHESIS);
        }
    }

    sb.append(StringPool.CLOSE_PARENTHESIS);
}

From source file:com.liferay.portlet.asset.service.persistence.AssetEntryFinderImpl.java

License:Open Source License

protected void buildAllTagsSQL(long[] tagIds, StringBundler sb) {
    sb.append(" AND AssetEntry.entryId IN (");

    for (int i = 0; i < tagIds.length; i++) {
        sb.append(CustomSQLUtil.get(FIND_BY_AND_TAG_IDS));

        if ((i + 1) < tagIds.length) {
            sb.append(" AND AssetEntry.entryId IN (");
        }/* w  w  w  . jav  a  2 s . c  om*/
    }

    for (int i = 0; i < tagIds.length; i++) {
        if ((i + 1) < tagIds.length) {
            sb.append(StringPool.CLOSE_PARENTHESIS);
        }
    }

    sb.append(StringPool.CLOSE_PARENTHESIS);
}

From source file:com.liferay.portlet.asset.service.persistence.AssetEntryFinderImpl.java

License:Open Source License

protected void buildClassTypeIdsSQL(long[] classTypeIds, StringBundler sb) {
    sb.append(" AND (");

    for (int i = 0; i < classTypeIds.length; i++) {
        sb.append(" AssetEntry.classTypeId = ");
        sb.append(classTypeIds[i]);//from w w  w  .j  a v a2s.com

        if ((i + 1) < classTypeIds.length) {
            sb.append(" OR ");
        } else {
            sb.append(StringPool.CLOSE_PARENTHESIS);
        }
    }
}

From source file:com.liferay.portlet.asset.service.persistence.AssetEntryFinderImpl.java

License:Open Source License

protected void buildNotAnyCategoriesSQL(String sqlId, long[] categoryIds, StringBundler sb) {

    sb.append(" AND (");

    for (int i = 0; i < categoryIds.length; i++) {
        sb.append("AssetEntry.entryId NOT IN (");
        sb.append(CustomSQLUtil.get(sqlId));
        sb.append(StringPool.CLOSE_PARENTHESIS);

        if ((i + 1) < categoryIds.length) {
            sb.append(" OR ");
        }//from w w w  .  j  av  a  2  s.  co m
    }

    sb.append(StringPool.CLOSE_PARENTHESIS);
}

From source file:com.liferay.portlet.asset.service.persistence.AssetEntryFinderImpl.java

License:Open Source License

protected void buildNotAnyTagsSQL(long[] tagIds, StringBundler sb) {
    sb.append(" AND (");

    for (int i = 0; i < tagIds.length; i++) {
        sb.append("AssetEntry.entryId NOT IN (");
        sb.append(CustomSQLUtil.get(FIND_BY_AND_TAG_IDS));
        sb.append(StringPool.CLOSE_PARENTHESIS);

        if ((i + 1) < tagIds.length) {
            sb.append(" OR ");
        }//from  w w  w.j ava2s .  c  o m
    }

    sb.append(StringPool.CLOSE_PARENTHESIS);
}

From source file:com.liferay.portlet.asset.service.persistence.AssetEntryFinderImpl.java

License:Open Source License

protected String getCategoryIds(String sqlId, long[] categoryIds) {
    StringBundler sb = new StringBundler();

    sb.append(" AND (");

    for (int i = 0; i < categoryIds.length; i++) {
        sb.append("AssetEntry.entryId IN (");
        sb.append(CustomSQLUtil.get(sqlId));
        sb.append(StringPool.CLOSE_PARENTHESIS);

        if ((i + 1) < categoryIds.length) {
            sb.append(" OR ");
        }/*w ww. j  ava  2  s  .  com*/
    }

    sb.append(StringPool.CLOSE_PARENTHESIS);

    return sb.toString();
}

From source file:com.liferay.portlet.asset.service.persistence.AssetEntryFinderImpl.java

License:Open Source License

protected String getNotCategoryIds(String sqlId, long[] notCategoryIds) {
    if (notCategoryIds.length == 0) {
        return StringPool.BLANK;
    }/*from   ww w  .ja  va  2 s .  c om*/

    StringBundler sb = new StringBundler(notCategoryIds.length * 4 - 1);

    for (int i = 0; i < notCategoryIds.length; i++) {
        sb.append("AssetEntry.entryId NOT IN (");
        sb.append(CustomSQLUtil.get(sqlId));
        sb.append(StringPool.CLOSE_PARENTHESIS);

        if ((i + 1) < notCategoryIds.length) {
            sb.append(" AND ");
        }
    }

    return sb.toString();
}