001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.expando.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.kernel.bean.BeanReference;
020    import com.liferay.portal.kernel.dao.orm.EntityCache;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCache;
023    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
024    import com.liferay.portal.kernel.dao.orm.FinderPath;
025    import com.liferay.portal.kernel.dao.orm.Query;
026    import com.liferay.portal.kernel.dao.orm.QueryPos;
027    import com.liferay.portal.kernel.dao.orm.QueryUtil;
028    import com.liferay.portal.kernel.dao.orm.SQLQuery;
029    import com.liferay.portal.kernel.dao.orm.Session;
030    import com.liferay.portal.kernel.log.Log;
031    import com.liferay.portal.kernel.log.LogFactoryUtil;
032    import com.liferay.portal.kernel.security.permission.InlineSQLHelperUtil;
033    import com.liferay.portal.kernel.util.ArrayUtil;
034    import com.liferay.portal.kernel.util.OrderByComparator;
035    import com.liferay.portal.kernel.util.SetUtil;
036    import com.liferay.portal.kernel.util.StringBundler;
037    import com.liferay.portal.kernel.util.StringPool;
038    import com.liferay.portal.kernel.util.StringUtil;
039    import com.liferay.portal.kernel.util.Validator;
040    import com.liferay.portal.model.CacheModel;
041    import com.liferay.portal.service.persistence.CompanyProvider;
042    import com.liferay.portal.service.persistence.CompanyProviderWrapper;
043    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044    
045    import com.liferay.portlet.expando.exception.NoSuchColumnException;
046    import com.liferay.portlet.expando.model.ExpandoColumn;
047    import com.liferay.portlet.expando.model.impl.ExpandoColumnImpl;
048    import com.liferay.portlet.expando.model.impl.ExpandoColumnModelImpl;
049    import com.liferay.portlet.expando.service.persistence.ExpandoColumnPersistence;
050    
051    import java.io.Serializable;
052    
053    import java.util.ArrayList;
054    import java.util.Arrays;
055    import java.util.Collections;
056    import java.util.HashMap;
057    import java.util.HashSet;
058    import java.util.Iterator;
059    import java.util.List;
060    import java.util.Map;
061    import java.util.Set;
062    
063    /**
064     * The persistence implementation for the expando column service.
065     *
066     * <p>
067     * Caching information and settings can be found in <code>portal.properties</code>
068     * </p>
069     *
070     * @author Brian Wing Shun Chan
071     * @see ExpandoColumnPersistence
072     * @see com.liferay.portlet.expando.service.persistence.ExpandoColumnUtil
073     * @generated
074     */
075    @ProviderType
076    public class ExpandoColumnPersistenceImpl extends BasePersistenceImpl<ExpandoColumn>
077            implements ExpandoColumnPersistence {
078            /*
079             * NOTE FOR DEVELOPERS:
080             *
081             * Never modify or reference this class directly. Always use {@link ExpandoColumnUtil} to access the expando column persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
082             */
083            public static final String FINDER_CLASS_NAME_ENTITY = ExpandoColumnImpl.class.getName();
084            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
085                    ".List1";
086            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
087                    ".List2";
088            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
089                            ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
090                            ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
091                            "findAll", new String[0]);
092            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
093                            ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
094                            ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
095                            "findAll", new String[0]);
096            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
097                            ExpandoColumnModelImpl.FINDER_CACHE_ENABLED, Long.class,
098                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
099            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_TABLEID = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
100                            ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
101                            ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
102                            "findByTableId",
103                            new String[] {
104                                    Long.class.getName(),
105                                    
106                            Integer.class.getName(), Integer.class.getName(),
107                                    OrderByComparator.class.getName()
108                            });
109            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID =
110                    new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
111                            ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
112                            ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
113                            "findByTableId", new String[] { Long.class.getName() },
114                            ExpandoColumnModelImpl.TABLEID_COLUMN_BITMASK |
115                            ExpandoColumnModelImpl.NAME_COLUMN_BITMASK);
116            public static final FinderPath FINDER_PATH_COUNT_BY_TABLEID = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
117                            ExpandoColumnModelImpl.FINDER_CACHE_ENABLED, Long.class,
118                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByTableId",
119                            new String[] { Long.class.getName() });
120    
121            /**
122             * Returns all the expando columns where tableId = &#63;.
123             *
124             * @param tableId the table ID
125             * @return the matching expando columns
126             */
127            @Override
128            public List<ExpandoColumn> findByTableId(long tableId) {
129                    return findByTableId(tableId, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
130            }
131    
132            /**
133             * Returns a range of all the expando columns where tableId = &#63;.
134             *
135             * <p>
136             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link ExpandoColumnModelImpl}. 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.
137             * </p>
138             *
139             * @param tableId the table ID
140             * @param start the lower bound of the range of expando columns
141             * @param end the upper bound of the range of expando columns (not inclusive)
142             * @return the range of matching expando columns
143             */
144            @Override
145            public List<ExpandoColumn> findByTableId(long tableId, int start, int end) {
146                    return findByTableId(tableId, start, end, null);
147            }
148    
149            /**
150             * Returns an ordered range of all the expando columns where tableId = &#63;.
151             *
152             * <p>
153             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link ExpandoColumnModelImpl}. 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.
154             * </p>
155             *
156             * @param tableId the table ID
157             * @param start the lower bound of the range of expando columns
158             * @param end the upper bound of the range of expando columns (not inclusive)
159             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
160             * @return the ordered range of matching expando columns
161             */
162            @Override
163            public List<ExpandoColumn> findByTableId(long tableId, int start, int end,
164                    OrderByComparator<ExpandoColumn> orderByComparator) {
165                    return findByTableId(tableId, start, end, orderByComparator, true);
166            }
167    
168            /**
169             * Returns an ordered range of all the expando columns where tableId = &#63;.
170             *
171             * <p>
172             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link ExpandoColumnModelImpl}. 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.
173             * </p>
174             *
175             * @param tableId the table ID
176             * @param start the lower bound of the range of expando columns
177             * @param end the upper bound of the range of expando columns (not inclusive)
178             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
179             * @param retrieveFromCache whether to retrieve from the finder cache
180             * @return the ordered range of matching expando columns
181             */
182            @Override
183            public List<ExpandoColumn> findByTableId(long tableId, int start, int end,
184                    OrderByComparator<ExpandoColumn> orderByComparator,
185                    boolean retrieveFromCache) {
186                    boolean pagination = true;
187                    FinderPath finderPath = null;
188                    Object[] finderArgs = null;
189    
190                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
191                                    (orderByComparator == null)) {
192                            pagination = false;
193                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID;
194                            finderArgs = new Object[] { tableId };
195                    }
196                    else {
197                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_TABLEID;
198                            finderArgs = new Object[] { tableId, start, end, orderByComparator };
199                    }
200    
201                    List<ExpandoColumn> list = null;
202    
203                    if (retrieveFromCache) {
204                            list = (List<ExpandoColumn>)finderCache.getResult(finderPath,
205                                            finderArgs, this);
206    
207                            if ((list != null) && !list.isEmpty()) {
208                                    for (ExpandoColumn expandoColumn : list) {
209                                            if ((tableId != expandoColumn.getTableId())) {
210                                                    list = null;
211    
212                                                    break;
213                                            }
214                                    }
215                            }
216                    }
217    
218                    if (list == null) {
219                            StringBundler query = null;
220    
221                            if (orderByComparator != null) {
222                                    query = new StringBundler(3 +
223                                                    (orderByComparator.getOrderByFields().length * 2));
224                            }
225                            else {
226                                    query = new StringBundler(3);
227                            }
228    
229                            query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
230    
231                            query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
232    
233                            if (orderByComparator != null) {
234                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
235                                            orderByComparator);
236                            }
237                            else
238                             if (pagination) {
239                                    query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
240                            }
241    
242                            String sql = query.toString();
243    
244                            Session session = null;
245    
246                            try {
247                                    session = openSession();
248    
249                                    Query q = session.createQuery(sql);
250    
251                                    QueryPos qPos = QueryPos.getInstance(q);
252    
253                                    qPos.add(tableId);
254    
255                                    if (!pagination) {
256                                            list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
257                                                            start, end, false);
258    
259                                            Collections.sort(list);
260    
261                                            list = Collections.unmodifiableList(list);
262                                    }
263                                    else {
264                                            list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
265                                                            start, end);
266                                    }
267    
268                                    cacheResult(list);
269    
270                                    finderCache.putResult(finderPath, finderArgs, list);
271                            }
272                            catch (Exception e) {
273                                    finderCache.removeResult(finderPath, finderArgs);
274    
275                                    throw processException(e);
276                            }
277                            finally {
278                                    closeSession(session);
279                            }
280                    }
281    
282                    return list;
283            }
284    
285            /**
286             * Returns the first expando column in the ordered set where tableId = &#63;.
287             *
288             * @param tableId the table ID
289             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
290             * @return the first matching expando column
291             * @throws NoSuchColumnException if a matching expando column could not be found
292             */
293            @Override
294            public ExpandoColumn findByTableId_First(long tableId,
295                    OrderByComparator<ExpandoColumn> orderByComparator)
296                    throws NoSuchColumnException {
297                    ExpandoColumn expandoColumn = fetchByTableId_First(tableId,
298                                    orderByComparator);
299    
300                    if (expandoColumn != null) {
301                            return expandoColumn;
302                    }
303    
304                    StringBundler msg = new StringBundler(4);
305    
306                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
307    
308                    msg.append("tableId=");
309                    msg.append(tableId);
310    
311                    msg.append(StringPool.CLOSE_CURLY_BRACE);
312    
313                    throw new NoSuchColumnException(msg.toString());
314            }
315    
316            /**
317             * Returns the first expando column in the ordered set where tableId = &#63;.
318             *
319             * @param tableId the table ID
320             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
321             * @return the first matching expando column, or <code>null</code> if a matching expando column could not be found
322             */
323            @Override
324            public ExpandoColumn fetchByTableId_First(long tableId,
325                    OrderByComparator<ExpandoColumn> orderByComparator) {
326                    List<ExpandoColumn> list = findByTableId(tableId, 0, 1,
327                                    orderByComparator);
328    
329                    if (!list.isEmpty()) {
330                            return list.get(0);
331                    }
332    
333                    return null;
334            }
335    
336            /**
337             * Returns the last expando column in the ordered set where tableId = &#63;.
338             *
339             * @param tableId the table ID
340             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
341             * @return the last matching expando column
342             * @throws NoSuchColumnException if a matching expando column could not be found
343             */
344            @Override
345            public ExpandoColumn findByTableId_Last(long tableId,
346                    OrderByComparator<ExpandoColumn> orderByComparator)
347                    throws NoSuchColumnException {
348                    ExpandoColumn expandoColumn = fetchByTableId_Last(tableId,
349                                    orderByComparator);
350    
351                    if (expandoColumn != null) {
352                            return expandoColumn;
353                    }
354    
355                    StringBundler msg = new StringBundler(4);
356    
357                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
358    
359                    msg.append("tableId=");
360                    msg.append(tableId);
361    
362                    msg.append(StringPool.CLOSE_CURLY_BRACE);
363    
364                    throw new NoSuchColumnException(msg.toString());
365            }
366    
367            /**
368             * Returns the last expando column in the ordered set where tableId = &#63;.
369             *
370             * @param tableId the table ID
371             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
372             * @return the last matching expando column, or <code>null</code> if a matching expando column could not be found
373             */
374            @Override
375            public ExpandoColumn fetchByTableId_Last(long tableId,
376                    OrderByComparator<ExpandoColumn> orderByComparator) {
377                    int count = countByTableId(tableId);
378    
379                    if (count == 0) {
380                            return null;
381                    }
382    
383                    List<ExpandoColumn> list = findByTableId(tableId, count - 1, count,
384                                    orderByComparator);
385    
386                    if (!list.isEmpty()) {
387                            return list.get(0);
388                    }
389    
390                    return null;
391            }
392    
393            /**
394             * Returns the expando columns before and after the current expando column in the ordered set where tableId = &#63;.
395             *
396             * @param columnId the primary key of the current expando column
397             * @param tableId the table ID
398             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
399             * @return the previous, current, and next expando column
400             * @throws NoSuchColumnException if a expando column with the primary key could not be found
401             */
402            @Override
403            public ExpandoColumn[] findByTableId_PrevAndNext(long columnId,
404                    long tableId, OrderByComparator<ExpandoColumn> orderByComparator)
405                    throws NoSuchColumnException {
406                    ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
407    
408                    Session session = null;
409    
410                    try {
411                            session = openSession();
412    
413                            ExpandoColumn[] array = new ExpandoColumnImpl[3];
414    
415                            array[0] = getByTableId_PrevAndNext(session, expandoColumn,
416                                            tableId, orderByComparator, true);
417    
418                            array[1] = expandoColumn;
419    
420                            array[2] = getByTableId_PrevAndNext(session, expandoColumn,
421                                            tableId, orderByComparator, false);
422    
423                            return array;
424                    }
425                    catch (Exception e) {
426                            throw processException(e);
427                    }
428                    finally {
429                            closeSession(session);
430                    }
431            }
432    
433            protected ExpandoColumn getByTableId_PrevAndNext(Session session,
434                    ExpandoColumn expandoColumn, long tableId,
435                    OrderByComparator<ExpandoColumn> orderByComparator, boolean previous) {
436                    StringBundler query = null;
437    
438                    if (orderByComparator != null) {
439                            query = new StringBundler(4 +
440                                            (orderByComparator.getOrderByConditionFields().length * 3) +
441                                            (orderByComparator.getOrderByFields().length * 3));
442                    }
443                    else {
444                            query = new StringBundler(3);
445                    }
446    
447                    query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
448    
449                    query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
450    
451                    if (orderByComparator != null) {
452                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
453    
454                            if (orderByConditionFields.length > 0) {
455                                    query.append(WHERE_AND);
456                            }
457    
458                            for (int i = 0; i < orderByConditionFields.length; i++) {
459                                    query.append(_ORDER_BY_ENTITY_ALIAS);
460                                    query.append(orderByConditionFields[i]);
461    
462                                    if ((i + 1) < orderByConditionFields.length) {
463                                            if (orderByComparator.isAscending() ^ previous) {
464                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
465                                            }
466                                            else {
467                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
468                                            }
469                                    }
470                                    else {
471                                            if (orderByComparator.isAscending() ^ previous) {
472                                                    query.append(WHERE_GREATER_THAN);
473                                            }
474                                            else {
475                                                    query.append(WHERE_LESSER_THAN);
476                                            }
477                                    }
478                            }
479    
480                            query.append(ORDER_BY_CLAUSE);
481    
482                            String[] orderByFields = orderByComparator.getOrderByFields();
483    
484                            for (int i = 0; i < orderByFields.length; i++) {
485                                    query.append(_ORDER_BY_ENTITY_ALIAS);
486                                    query.append(orderByFields[i]);
487    
488                                    if ((i + 1) < orderByFields.length) {
489                                            if (orderByComparator.isAscending() ^ previous) {
490                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
491                                            }
492                                            else {
493                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
494                                            }
495                                    }
496                                    else {
497                                            if (orderByComparator.isAscending() ^ previous) {
498                                                    query.append(ORDER_BY_ASC);
499                                            }
500                                            else {
501                                                    query.append(ORDER_BY_DESC);
502                                            }
503                                    }
504                            }
505                    }
506                    else {
507                            query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
508                    }
509    
510                    String sql = query.toString();
511    
512                    Query q = session.createQuery(sql);
513    
514                    q.setFirstResult(0);
515                    q.setMaxResults(2);
516    
517                    QueryPos qPos = QueryPos.getInstance(q);
518    
519                    qPos.add(tableId);
520    
521                    if (orderByComparator != null) {
522                            Object[] values = orderByComparator.getOrderByConditionValues(expandoColumn);
523    
524                            for (Object value : values) {
525                                    qPos.add(value);
526                            }
527                    }
528    
529                    List<ExpandoColumn> list = q.list();
530    
531                    if (list.size() == 2) {
532                            return list.get(1);
533                    }
534                    else {
535                            return null;
536                    }
537            }
538    
539            /**
540             * Returns all the expando columns that the user has permission to view where tableId = &#63;.
541             *
542             * @param tableId the table ID
543             * @return the matching expando columns that the user has permission to view
544             */
545            @Override
546            public List<ExpandoColumn> filterFindByTableId(long tableId) {
547                    return filterFindByTableId(tableId, QueryUtil.ALL_POS,
548                            QueryUtil.ALL_POS, null);
549            }
550    
551            /**
552             * Returns a range of all the expando columns that the user has permission to view where tableId = &#63;.
553             *
554             * <p>
555             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link ExpandoColumnModelImpl}. 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.
556             * </p>
557             *
558             * @param tableId the table ID
559             * @param start the lower bound of the range of expando columns
560             * @param end the upper bound of the range of expando columns (not inclusive)
561             * @return the range of matching expando columns that the user has permission to view
562             */
563            @Override
564            public List<ExpandoColumn> filterFindByTableId(long tableId, int start,
565                    int end) {
566                    return filterFindByTableId(tableId, start, end, null);
567            }
568    
569            /**
570             * Returns an ordered range of all the expando columns that the user has permissions to view where tableId = &#63;.
571             *
572             * <p>
573             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link ExpandoColumnModelImpl}. 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.
574             * </p>
575             *
576             * @param tableId the table ID
577             * @param start the lower bound of the range of expando columns
578             * @param end the upper bound of the range of expando columns (not inclusive)
579             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
580             * @return the ordered range of matching expando columns that the user has permission to view
581             */
582            @Override
583            public List<ExpandoColumn> filterFindByTableId(long tableId, int start,
584                    int end, OrderByComparator<ExpandoColumn> orderByComparator) {
585                    if (!InlineSQLHelperUtil.isEnabled()) {
586                            return findByTableId(tableId, start, end, orderByComparator);
587                    }
588    
589                    StringBundler query = null;
590    
591                    if (orderByComparator != null) {
592                            query = new StringBundler(3 +
593                                            (orderByComparator.getOrderByFields().length * 2));
594                    }
595                    else {
596                            query = new StringBundler(4);
597                    }
598    
599                    if (getDB().isSupportsInlineDistinct()) {
600                            query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
601                    }
602                    else {
603                            query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
604                    }
605    
606                    query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
607    
608                    if (!getDB().isSupportsInlineDistinct()) {
609                            query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
610                    }
611    
612                    if (orderByComparator != null) {
613                            if (getDB().isSupportsInlineDistinct()) {
614                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
615                                            orderByComparator, true);
616                            }
617                            else {
618                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_TABLE,
619                                            orderByComparator, true);
620                            }
621                    }
622                    else {
623                            if (getDB().isSupportsInlineDistinct()) {
624                                    query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
625                            }
626                            else {
627                                    query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
628                            }
629                    }
630    
631                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
632                                    ExpandoColumn.class.getName(),
633                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
634    
635                    Session session = null;
636    
637                    try {
638                            session = openSession();
639    
640                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
641    
642                            if (getDB().isSupportsInlineDistinct()) {
643                                    q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
644                            }
645                            else {
646                                    q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
647                            }
648    
649                            QueryPos qPos = QueryPos.getInstance(q);
650    
651                            qPos.add(tableId);
652    
653                            return (List<ExpandoColumn>)QueryUtil.list(q, getDialect(), start,
654                                    end);
655                    }
656                    catch (Exception e) {
657                            throw processException(e);
658                    }
659                    finally {
660                            closeSession(session);
661                    }
662            }
663    
664            /**
665             * Returns the expando columns before and after the current expando column in the ordered set of expando columns that the user has permission to view where tableId = &#63;.
666             *
667             * @param columnId the primary key of the current expando column
668             * @param tableId the table ID
669             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
670             * @return the previous, current, and next expando column
671             * @throws NoSuchColumnException if a expando column with the primary key could not be found
672             */
673            @Override
674            public ExpandoColumn[] filterFindByTableId_PrevAndNext(long columnId,
675                    long tableId, OrderByComparator<ExpandoColumn> orderByComparator)
676                    throws NoSuchColumnException {
677                    if (!InlineSQLHelperUtil.isEnabled()) {
678                            return findByTableId_PrevAndNext(columnId, tableId,
679                                    orderByComparator);
680                    }
681    
682                    ExpandoColumn expandoColumn = findByPrimaryKey(columnId);
683    
684                    Session session = null;
685    
686                    try {
687                            session = openSession();
688    
689                            ExpandoColumn[] array = new ExpandoColumnImpl[3];
690    
691                            array[0] = filterGetByTableId_PrevAndNext(session, expandoColumn,
692                                            tableId, orderByComparator, true);
693    
694                            array[1] = expandoColumn;
695    
696                            array[2] = filterGetByTableId_PrevAndNext(session, expandoColumn,
697                                            tableId, orderByComparator, false);
698    
699                            return array;
700                    }
701                    catch (Exception e) {
702                            throw processException(e);
703                    }
704                    finally {
705                            closeSession(session);
706                    }
707            }
708    
709            protected ExpandoColumn filterGetByTableId_PrevAndNext(Session session,
710                    ExpandoColumn expandoColumn, long tableId,
711                    OrderByComparator<ExpandoColumn> orderByComparator, boolean previous) {
712                    StringBundler query = null;
713    
714                    if (orderByComparator != null) {
715                            query = new StringBundler(5 +
716                                            (orderByComparator.getOrderByConditionFields().length * 3) +
717                                            (orderByComparator.getOrderByFields().length * 3));
718                    }
719                    else {
720                            query = new StringBundler(4);
721                    }
722    
723                    if (getDB().isSupportsInlineDistinct()) {
724                            query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE);
725                    }
726                    else {
727                            query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1);
728                    }
729    
730                    query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
731    
732                    if (!getDB().isSupportsInlineDistinct()) {
733                            query.append(_FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2);
734                    }
735    
736                    if (orderByComparator != null) {
737                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
738    
739                            if (orderByConditionFields.length > 0) {
740                                    query.append(WHERE_AND);
741                            }
742    
743                            for (int i = 0; i < orderByConditionFields.length; i++) {
744                                    if (getDB().isSupportsInlineDistinct()) {
745                                            query.append(_ORDER_BY_ENTITY_ALIAS);
746                                    }
747                                    else {
748                                            query.append(_ORDER_BY_ENTITY_TABLE);
749                                    }
750    
751                                    query.append(orderByConditionFields[i]);
752    
753                                    if ((i + 1) < orderByConditionFields.length) {
754                                            if (orderByComparator.isAscending() ^ previous) {
755                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
756                                            }
757                                            else {
758                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
759                                            }
760                                    }
761                                    else {
762                                            if (orderByComparator.isAscending() ^ previous) {
763                                                    query.append(WHERE_GREATER_THAN);
764                                            }
765                                            else {
766                                                    query.append(WHERE_LESSER_THAN);
767                                            }
768                                    }
769                            }
770    
771                            query.append(ORDER_BY_CLAUSE);
772    
773                            String[] orderByFields = orderByComparator.getOrderByFields();
774    
775                            for (int i = 0; i < orderByFields.length; i++) {
776                                    if (getDB().isSupportsInlineDistinct()) {
777                                            query.append(_ORDER_BY_ENTITY_ALIAS);
778                                    }
779                                    else {
780                                            query.append(_ORDER_BY_ENTITY_TABLE);
781                                    }
782    
783                                    query.append(orderByFields[i]);
784    
785                                    if ((i + 1) < orderByFields.length) {
786                                            if (orderByComparator.isAscending() ^ previous) {
787                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
788                                            }
789                                            else {
790                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
791                                            }
792                                    }
793                                    else {
794                                            if (orderByComparator.isAscending() ^ previous) {
795                                                    query.append(ORDER_BY_ASC);
796                                            }
797                                            else {
798                                                    query.append(ORDER_BY_DESC);
799                                            }
800                                    }
801                            }
802                    }
803                    else {
804                            if (getDB().isSupportsInlineDistinct()) {
805                                    query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
806                            }
807                            else {
808                                    query.append(ExpandoColumnModelImpl.ORDER_BY_SQL);
809                            }
810                    }
811    
812                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
813                                    ExpandoColumn.class.getName(),
814                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
815    
816                    SQLQuery q = session.createSynchronizedSQLQuery(sql);
817    
818                    q.setFirstResult(0);
819                    q.setMaxResults(2);
820    
821                    if (getDB().isSupportsInlineDistinct()) {
822                            q.addEntity(_FILTER_ENTITY_ALIAS, ExpandoColumnImpl.class);
823                    }
824                    else {
825                            q.addEntity(_FILTER_ENTITY_TABLE, ExpandoColumnImpl.class);
826                    }
827    
828                    QueryPos qPos = QueryPos.getInstance(q);
829    
830                    qPos.add(tableId);
831    
832                    if (orderByComparator != null) {
833                            Object[] values = orderByComparator.getOrderByConditionValues(expandoColumn);
834    
835                            for (Object value : values) {
836                                    qPos.add(value);
837                            }
838                    }
839    
840                    List<ExpandoColumn> list = q.list();
841    
842                    if (list.size() == 2) {
843                            return list.get(1);
844                    }
845                    else {
846                            return null;
847                    }
848            }
849    
850            /**
851             * Removes all the expando columns where tableId = &#63; from the database.
852             *
853             * @param tableId the table ID
854             */
855            @Override
856            public void removeByTableId(long tableId) {
857                    for (ExpandoColumn expandoColumn : findByTableId(tableId,
858                                    QueryUtil.ALL_POS, QueryUtil.ALL_POS, null)) {
859                            remove(expandoColumn);
860                    }
861            }
862    
863            /**
864             * Returns the number of expando columns where tableId = &#63;.
865             *
866             * @param tableId the table ID
867             * @return the number of matching expando columns
868             */
869            @Override
870            public int countByTableId(long tableId) {
871                    FinderPath finderPath = FINDER_PATH_COUNT_BY_TABLEID;
872    
873                    Object[] finderArgs = new Object[] { tableId };
874    
875                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
876    
877                    if (count == null) {
878                            StringBundler query = new StringBundler(2);
879    
880                            query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
881    
882                            query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
883    
884                            String sql = query.toString();
885    
886                            Session session = null;
887    
888                            try {
889                                    session = openSession();
890    
891                                    Query q = session.createQuery(sql);
892    
893                                    QueryPos qPos = QueryPos.getInstance(q);
894    
895                                    qPos.add(tableId);
896    
897                                    count = (Long)q.uniqueResult();
898    
899                                    finderCache.putResult(finderPath, finderArgs, count);
900                            }
901                            catch (Exception e) {
902                                    finderCache.removeResult(finderPath, finderArgs);
903    
904                                    throw processException(e);
905                            }
906                            finally {
907                                    closeSession(session);
908                            }
909                    }
910    
911                    return count.intValue();
912            }
913    
914            /**
915             * Returns the number of expando columns that the user has permission to view where tableId = &#63;.
916             *
917             * @param tableId the table ID
918             * @return the number of matching expando columns that the user has permission to view
919             */
920            @Override
921            public int filterCountByTableId(long tableId) {
922                    if (!InlineSQLHelperUtil.isEnabled()) {
923                            return countByTableId(tableId);
924                    }
925    
926                    StringBundler query = new StringBundler(2);
927    
928                    query.append(_FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE);
929    
930                    query.append(_FINDER_COLUMN_TABLEID_TABLEID_2);
931    
932                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
933                                    ExpandoColumn.class.getName(),
934                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
935    
936                    Session session = null;
937    
938                    try {
939                            session = openSession();
940    
941                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
942    
943                            q.addScalar(COUNT_COLUMN_NAME,
944                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
945    
946                            QueryPos qPos = QueryPos.getInstance(q);
947    
948                            qPos.add(tableId);
949    
950                            Long count = (Long)q.uniqueResult();
951    
952                            return count.intValue();
953                    }
954                    catch (Exception e) {
955                            throw processException(e);
956                    }
957                    finally {
958                            closeSession(session);
959                    }
960            }
961    
962            private static final String _FINDER_COLUMN_TABLEID_TABLEID_2 = "expandoColumn.tableId = ?";
963            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
964                            ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
965                            ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITH_PAGINATION,
966                            "findByT_N",
967                            new String[] {
968                                    Long.class.getName(), String.class.getName(),
969                                    
970                            Integer.class.getName(), Integer.class.getName(),
971                                    OrderByComparator.class.getName()
972                            });
973            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
974                            ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
975                            ExpandoColumnImpl.class, FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION,
976                            "findByT_N",
977                            new String[] { Long.class.getName(), String.class.getName() },
978                            ExpandoColumnModelImpl.TABLEID_COLUMN_BITMASK |
979                            ExpandoColumnModelImpl.NAME_COLUMN_BITMASK);
980            public static final FinderPath FINDER_PATH_FETCH_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
981                            ExpandoColumnModelImpl.FINDER_CACHE_ENABLED,
982                            ExpandoColumnImpl.class, FINDER_CLASS_NAME_ENTITY, "fetchByT_N",
983                            new String[] { Long.class.getName(), String.class.getName() },
984                            ExpandoColumnModelImpl.TABLEID_COLUMN_BITMASK |
985                            ExpandoColumnModelImpl.NAME_COLUMN_BITMASK);
986            public static final FinderPath FINDER_PATH_COUNT_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
987                            ExpandoColumnModelImpl.FINDER_CACHE_ENABLED, Long.class,
988                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByT_N",
989                            new String[] { Long.class.getName(), String.class.getName() });
990            public static final FinderPath FINDER_PATH_WITH_PAGINATION_COUNT_BY_T_N = new FinderPath(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
991                            ExpandoColumnModelImpl.FINDER_CACHE_ENABLED, Long.class,
992                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "countByT_N",
993                            new String[] { Long.class.getName(), String.class.getName() });
994    
995            /**
996             * Returns all the expando columns where tableId = &#63; and name = any &#63;.
997             *
998             * <p>
999             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link ExpandoColumnModelImpl}. 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.
1000             * </p>
1001             *
1002             * @param tableId the table ID
1003             * @param names the names
1004             * @return the matching expando columns
1005             */
1006            @Override
1007            public List<ExpandoColumn> findByT_N(long tableId, String[] names) {
1008                    return findByT_N(tableId, names, QueryUtil.ALL_POS, QueryUtil.ALL_POS,
1009                            null);
1010            }
1011    
1012            /**
1013             * Returns a range of all the expando columns where tableId = &#63; and name = any &#63;.
1014             *
1015             * <p>
1016             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link ExpandoColumnModelImpl}. 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.
1017             * </p>
1018             *
1019             * @param tableId the table ID
1020             * @param names the names
1021             * @param start the lower bound of the range of expando columns
1022             * @param end the upper bound of the range of expando columns (not inclusive)
1023             * @return the range of matching expando columns
1024             */
1025            @Override
1026            public List<ExpandoColumn> findByT_N(long tableId, String[] names,
1027                    int start, int end) {
1028                    return findByT_N(tableId, names, start, end, null);
1029            }
1030    
1031            /**
1032             * Returns an ordered range of all the expando columns where tableId = &#63; and name = any &#63;.
1033             *
1034             * <p>
1035             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link ExpandoColumnModelImpl}. 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.
1036             * </p>
1037             *
1038             * @param tableId the table ID
1039             * @param names the names
1040             * @param start the lower bound of the range of expando columns
1041             * @param end the upper bound of the range of expando columns (not inclusive)
1042             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1043             * @return the ordered range of matching expando columns
1044             */
1045            @Override
1046            public List<ExpandoColumn> findByT_N(long tableId, String[] names,
1047                    int start, int end, OrderByComparator<ExpandoColumn> orderByComparator) {
1048                    return findByT_N(tableId, names, start, end, orderByComparator, true);
1049            }
1050    
1051            /**
1052             * Returns an ordered range of all the expando columns where tableId = &#63; and name = &#63;, optionally using the finder cache.
1053             *
1054             * <p>
1055             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link ExpandoColumnModelImpl}. 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.
1056             * </p>
1057             *
1058             * @param tableId the table ID
1059             * @param name the name
1060             * @param start the lower bound of the range of expando columns
1061             * @param end the upper bound of the range of expando columns (not inclusive)
1062             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1063             * @param retrieveFromCache whether to retrieve from the finder cache
1064             * @return the ordered range of matching expando columns
1065             */
1066            @Override
1067            public List<ExpandoColumn> findByT_N(long tableId, String[] names,
1068                    int start, int end, OrderByComparator<ExpandoColumn> orderByComparator,
1069                    boolean retrieveFromCache) {
1070                    if (names == null) {
1071                            names = new String[0];
1072                    }
1073                    else if (names.length > 1) {
1074                            names = ArrayUtil.distinct(names, NULL_SAFE_STRING_COMPARATOR);
1075    
1076                            Arrays.sort(names, NULL_SAFE_STRING_COMPARATOR);
1077                    }
1078    
1079                    if (names.length == 1) {
1080                            ExpandoColumn expandoColumn = fetchByT_N(tableId, names[0]);
1081    
1082                            if (expandoColumn == null) {
1083                                    return Collections.emptyList();
1084                            }
1085                            else {
1086                                    List<ExpandoColumn> list = new ArrayList<ExpandoColumn>(1);
1087    
1088                                    list.add(expandoColumn);
1089    
1090                                    return list;
1091                            }
1092                    }
1093    
1094                    boolean pagination = true;
1095                    Object[] finderArgs = null;
1096    
1097                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1098                                    (orderByComparator == null)) {
1099                            pagination = false;
1100                            finderArgs = new Object[] { tableId, StringUtil.merge(names) };
1101                    }
1102                    else {
1103                            finderArgs = new Object[] {
1104                                            tableId, StringUtil.merge(names),
1105                                            
1106                                            start, end, orderByComparator
1107                                    };
1108                    }
1109    
1110                    List<ExpandoColumn> list = null;
1111    
1112                    if (retrieveFromCache) {
1113                            list = (List<ExpandoColumn>)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_T_N,
1114                                            finderArgs, this);
1115    
1116                            if ((list != null) && !list.isEmpty()) {
1117                                    for (ExpandoColumn expandoColumn : list) {
1118                                            if ((tableId != expandoColumn.getTableId()) ||
1119                                                            !ArrayUtil.contains(names, expandoColumn.getName())) {
1120                                                    list = null;
1121    
1122                                                    break;
1123                                            }
1124                                    }
1125                            }
1126                    }
1127    
1128                    if (list == null) {
1129                            StringBundler query = new StringBundler();
1130    
1131                            query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1132    
1133                            query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1134    
1135                            if (names.length > 0) {
1136                                    query.append(StringPool.OPEN_PARENTHESIS);
1137    
1138                                    for (int i = 0; i < names.length; i++) {
1139                                            String name = names[i];
1140    
1141                                            if (name == null) {
1142                                                    query.append(_FINDER_COLUMN_T_N_NAME_1);
1143                                            }
1144                                            else if (name.equals(StringPool.BLANK)) {
1145                                                    query.append(_FINDER_COLUMN_T_N_NAME_3);
1146                                            }
1147                                            else {
1148                                                    query.append(_FINDER_COLUMN_T_N_NAME_2);
1149                                            }
1150    
1151                                            if ((i + 1) < names.length) {
1152                                                    query.append(WHERE_OR);
1153                                            }
1154                                    }
1155    
1156                                    query.append(StringPool.CLOSE_PARENTHESIS);
1157                            }
1158    
1159                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
1160                                                    1)), query.index() - 1);
1161    
1162                            if (orderByComparator != null) {
1163                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1164                                            orderByComparator);
1165                            }
1166                            else
1167                             if (pagination) {
1168                                    query.append(ExpandoColumnModelImpl.ORDER_BY_JPQL);
1169                            }
1170    
1171                            String sql = query.toString();
1172    
1173                            Session session = null;
1174    
1175                            try {
1176                                    session = openSession();
1177    
1178                                    Query q = session.createQuery(sql);
1179    
1180                                    QueryPos qPos = QueryPos.getInstance(q);
1181    
1182                                    qPos.add(tableId);
1183    
1184                                    for (String name : names) {
1185                                            if ((name != null) && !name.isEmpty()) {
1186                                                    qPos.add(name);
1187                                            }
1188                                    }
1189    
1190                                    if (!pagination) {
1191                                            list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
1192                                                            start, end, false);
1193    
1194                                            Collections.sort(list);
1195    
1196                                            list = Collections.unmodifiableList(list);
1197                                    }
1198                                    else {
1199                                            list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
1200                                                            start, end);
1201                                    }
1202    
1203                                    cacheResult(list);
1204    
1205                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_T_N,
1206                                            finderArgs, list);
1207                            }
1208                            catch (Exception e) {
1209                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_FIND_BY_T_N,
1210                                            finderArgs);
1211    
1212                                    throw processException(e);
1213                            }
1214                            finally {
1215                                    closeSession(session);
1216                            }
1217                    }
1218    
1219                    return list;
1220            }
1221    
1222            /**
1223             * Returns the expando column where tableId = &#63; and name = &#63; or throws a {@link NoSuchColumnException} if it could not be found.
1224             *
1225             * @param tableId the table ID
1226             * @param name the name
1227             * @return the matching expando column
1228             * @throws NoSuchColumnException if a matching expando column could not be found
1229             */
1230            @Override
1231            public ExpandoColumn findByT_N(long tableId, String name)
1232                    throws NoSuchColumnException {
1233                    ExpandoColumn expandoColumn = fetchByT_N(tableId, name);
1234    
1235                    if (expandoColumn == null) {
1236                            StringBundler msg = new StringBundler(6);
1237    
1238                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
1239    
1240                            msg.append("tableId=");
1241                            msg.append(tableId);
1242    
1243                            msg.append(", name=");
1244                            msg.append(name);
1245    
1246                            msg.append(StringPool.CLOSE_CURLY_BRACE);
1247    
1248                            if (_log.isWarnEnabled()) {
1249                                    _log.warn(msg.toString());
1250                            }
1251    
1252                            throw new NoSuchColumnException(msg.toString());
1253                    }
1254    
1255                    return expandoColumn;
1256            }
1257    
1258            /**
1259             * Returns the expando column where tableId = &#63; and name = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
1260             *
1261             * @param tableId the table ID
1262             * @param name the name
1263             * @return the matching expando column, or <code>null</code> if a matching expando column could not be found
1264             */
1265            @Override
1266            public ExpandoColumn fetchByT_N(long tableId, String name) {
1267                    return fetchByT_N(tableId, name, true);
1268            }
1269    
1270            /**
1271             * Returns the expando column where tableId = &#63; and name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
1272             *
1273             * @param tableId the table ID
1274             * @param name the name
1275             * @param retrieveFromCache whether to retrieve from the finder cache
1276             * @return the matching expando column, or <code>null</code> if a matching expando column could not be found
1277             */
1278            @Override
1279            public ExpandoColumn fetchByT_N(long tableId, String name,
1280                    boolean retrieveFromCache) {
1281                    Object[] finderArgs = new Object[] { tableId, name };
1282    
1283                    Object result = null;
1284    
1285                    if (retrieveFromCache) {
1286                            result = finderCache.getResult(FINDER_PATH_FETCH_BY_T_N,
1287                                            finderArgs, this);
1288                    }
1289    
1290                    if (result instanceof ExpandoColumn) {
1291                            ExpandoColumn expandoColumn = (ExpandoColumn)result;
1292    
1293                            if ((tableId != expandoColumn.getTableId()) ||
1294                                            !Validator.equals(name, expandoColumn.getName())) {
1295                                    result = null;
1296                            }
1297                    }
1298    
1299                    if (result == null) {
1300                            StringBundler query = new StringBundler(4);
1301    
1302                            query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE);
1303    
1304                            query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1305    
1306                            boolean bindName = false;
1307    
1308                            if (name == null) {
1309                                    query.append(_FINDER_COLUMN_T_N_NAME_1);
1310                            }
1311                            else if (name.equals(StringPool.BLANK)) {
1312                                    query.append(_FINDER_COLUMN_T_N_NAME_3);
1313                            }
1314                            else {
1315                                    bindName = true;
1316    
1317                                    query.append(_FINDER_COLUMN_T_N_NAME_2);
1318                            }
1319    
1320                            String sql = query.toString();
1321    
1322                            Session session = null;
1323    
1324                            try {
1325                                    session = openSession();
1326    
1327                                    Query q = session.createQuery(sql);
1328    
1329                                    QueryPos qPos = QueryPos.getInstance(q);
1330    
1331                                    qPos.add(tableId);
1332    
1333                                    if (bindName) {
1334                                            qPos.add(name);
1335                                    }
1336    
1337                                    List<ExpandoColumn> list = q.list();
1338    
1339                                    if (list.isEmpty()) {
1340                                            finderCache.putResult(FINDER_PATH_FETCH_BY_T_N, finderArgs,
1341                                                    list);
1342                                    }
1343                                    else {
1344                                            ExpandoColumn expandoColumn = list.get(0);
1345    
1346                                            result = expandoColumn;
1347    
1348                                            cacheResult(expandoColumn);
1349    
1350                                            if ((expandoColumn.getTableId() != tableId) ||
1351                                                            (expandoColumn.getName() == null) ||
1352                                                            !expandoColumn.getName().equals(name)) {
1353                                                    finderCache.putResult(FINDER_PATH_FETCH_BY_T_N,
1354                                                            finderArgs, expandoColumn);
1355                                            }
1356                                    }
1357                            }
1358                            catch (Exception e) {
1359                                    finderCache.removeResult(FINDER_PATH_FETCH_BY_T_N, finderArgs);
1360    
1361                                    throw processException(e);
1362                            }
1363                            finally {
1364                                    closeSession(session);
1365                            }
1366                    }
1367    
1368                    if (result instanceof List<?>) {
1369                            return null;
1370                    }
1371                    else {
1372                            return (ExpandoColumn)result;
1373                    }
1374            }
1375    
1376            /**
1377             * Removes the expando column where tableId = &#63; and name = &#63; from the database.
1378             *
1379             * @param tableId the table ID
1380             * @param name the name
1381             * @return the expando column that was removed
1382             */
1383            @Override
1384            public ExpandoColumn removeByT_N(long tableId, String name)
1385                    throws NoSuchColumnException {
1386                    ExpandoColumn expandoColumn = findByT_N(tableId, name);
1387    
1388                    return remove(expandoColumn);
1389            }
1390    
1391            /**
1392             * Returns the number of expando columns where tableId = &#63; and name = &#63;.
1393             *
1394             * @param tableId the table ID
1395             * @param name the name
1396             * @return the number of matching expando columns
1397             */
1398            @Override
1399            public int countByT_N(long tableId, String name) {
1400                    FinderPath finderPath = FINDER_PATH_COUNT_BY_T_N;
1401    
1402                    Object[] finderArgs = new Object[] { tableId, name };
1403    
1404                    Long count = (Long)finderCache.getResult(finderPath, finderArgs, this);
1405    
1406                    if (count == null) {
1407                            StringBundler query = new StringBundler(3);
1408    
1409                            query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
1410    
1411                            query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1412    
1413                            boolean bindName = false;
1414    
1415                            if (name == null) {
1416                                    query.append(_FINDER_COLUMN_T_N_NAME_1);
1417                            }
1418                            else if (name.equals(StringPool.BLANK)) {
1419                                    query.append(_FINDER_COLUMN_T_N_NAME_3);
1420                            }
1421                            else {
1422                                    bindName = true;
1423    
1424                                    query.append(_FINDER_COLUMN_T_N_NAME_2);
1425                            }
1426    
1427                            String sql = query.toString();
1428    
1429                            Session session = null;
1430    
1431                            try {
1432                                    session = openSession();
1433    
1434                                    Query q = session.createQuery(sql);
1435    
1436                                    QueryPos qPos = QueryPos.getInstance(q);
1437    
1438                                    qPos.add(tableId);
1439    
1440                                    if (bindName) {
1441                                            qPos.add(name);
1442                                    }
1443    
1444                                    count = (Long)q.uniqueResult();
1445    
1446                                    finderCache.putResult(finderPath, finderArgs, count);
1447                            }
1448                            catch (Exception e) {
1449                                    finderCache.removeResult(finderPath, finderArgs);
1450    
1451                                    throw processException(e);
1452                            }
1453                            finally {
1454                                    closeSession(session);
1455                            }
1456                    }
1457    
1458                    return count.intValue();
1459            }
1460    
1461            /**
1462             * Returns the number of expando columns where tableId = &#63; and name = any &#63;.
1463             *
1464             * @param tableId the table ID
1465             * @param names the names
1466             * @return the number of matching expando columns
1467             */
1468            @Override
1469            public int countByT_N(long tableId, String[] names) {
1470                    if (names == null) {
1471                            names = new String[0];
1472                    }
1473                    else if (names.length > 1) {
1474                            names = ArrayUtil.distinct(names, NULL_SAFE_STRING_COMPARATOR);
1475    
1476                            Arrays.sort(names, NULL_SAFE_STRING_COMPARATOR);
1477                    }
1478    
1479                    Object[] finderArgs = new Object[] { tableId, StringUtil.merge(names) };
1480    
1481                    Long count = (Long)finderCache.getResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_T_N,
1482                                    finderArgs, this);
1483    
1484                    if (count == null) {
1485                            StringBundler query = new StringBundler();
1486    
1487                            query.append(_SQL_COUNT_EXPANDOCOLUMN_WHERE);
1488    
1489                            query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1490    
1491                            if (names.length > 0) {
1492                                    query.append(StringPool.OPEN_PARENTHESIS);
1493    
1494                                    for (int i = 0; i < names.length; i++) {
1495                                            String name = names[i];
1496    
1497                                            if (name == null) {
1498                                                    query.append(_FINDER_COLUMN_T_N_NAME_1);
1499                                            }
1500                                            else if (name.equals(StringPool.BLANK)) {
1501                                                    query.append(_FINDER_COLUMN_T_N_NAME_3);
1502                                            }
1503                                            else {
1504                                                    query.append(_FINDER_COLUMN_T_N_NAME_2);
1505                                            }
1506    
1507                                            if ((i + 1) < names.length) {
1508                                                    query.append(WHERE_OR);
1509                                            }
1510                                    }
1511    
1512                                    query.append(StringPool.CLOSE_PARENTHESIS);
1513                            }
1514    
1515                            query.setStringAt(removeConjunction(query.stringAt(query.index() -
1516                                                    1)), query.index() - 1);
1517    
1518                            String sql = query.toString();
1519    
1520                            Session session = null;
1521    
1522                            try {
1523                                    session = openSession();
1524    
1525                                    Query q = session.createQuery(sql);
1526    
1527                                    QueryPos qPos = QueryPos.getInstance(q);
1528    
1529                                    qPos.add(tableId);
1530    
1531                                    for (String name : names) {
1532                                            if ((name != null) && !name.isEmpty()) {
1533                                                    qPos.add(name);
1534                                            }
1535                                    }
1536    
1537                                    count = (Long)q.uniqueResult();
1538    
1539                                    finderCache.putResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_T_N,
1540                                            finderArgs, count);
1541                            }
1542                            catch (Exception e) {
1543                                    finderCache.removeResult(FINDER_PATH_WITH_PAGINATION_COUNT_BY_T_N,
1544                                            finderArgs);
1545    
1546                                    throw processException(e);
1547                            }
1548                            finally {
1549                                    closeSession(session);
1550                            }
1551                    }
1552    
1553                    return count.intValue();
1554            }
1555    
1556            /**
1557             * Returns the number of expando columns that the user has permission to view where tableId = &#63; and name = &#63;.
1558             *
1559             * @param tableId the table ID
1560             * @param name the name
1561             * @return the number of matching expando columns that the user has permission to view
1562             */
1563            @Override
1564            public int filterCountByT_N(long tableId, String name) {
1565                    if (!InlineSQLHelperUtil.isEnabled()) {
1566                            return countByT_N(tableId, name);
1567                    }
1568    
1569                    StringBundler query = new StringBundler(3);
1570    
1571                    query.append(_FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE);
1572    
1573                    query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1574    
1575                    boolean bindName = false;
1576    
1577                    if (name == null) {
1578                            query.append(_FINDER_COLUMN_T_N_NAME_1);
1579                    }
1580                    else if (name.equals(StringPool.BLANK)) {
1581                            query.append(_FINDER_COLUMN_T_N_NAME_3);
1582                    }
1583                    else {
1584                            bindName = true;
1585    
1586                            query.append(_FINDER_COLUMN_T_N_NAME_2);
1587                    }
1588    
1589                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1590                                    ExpandoColumn.class.getName(),
1591                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1592    
1593                    Session session = null;
1594    
1595                    try {
1596                            session = openSession();
1597    
1598                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
1599    
1600                            q.addScalar(COUNT_COLUMN_NAME,
1601                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1602    
1603                            QueryPos qPos = QueryPos.getInstance(q);
1604    
1605                            qPos.add(tableId);
1606    
1607                            if (bindName) {
1608                                    qPos.add(name);
1609                            }
1610    
1611                            Long count = (Long)q.uniqueResult();
1612    
1613                            return count.intValue();
1614                    }
1615                    catch (Exception e) {
1616                            throw processException(e);
1617                    }
1618                    finally {
1619                            closeSession(session);
1620                    }
1621            }
1622    
1623            /**
1624             * Returns the number of expando columns that the user has permission to view where tableId = &#63; and name = any &#63;.
1625             *
1626             * @param tableId the table ID
1627             * @param names the names
1628             * @return the number of matching expando columns that the user has permission to view
1629             */
1630            @Override
1631            public int filterCountByT_N(long tableId, String[] names) {
1632                    if (!InlineSQLHelperUtil.isEnabled()) {
1633                            return countByT_N(tableId, names);
1634                    }
1635    
1636                    if (names == null) {
1637                            names = new String[0];
1638                    }
1639                    else if (names.length > 1) {
1640                            names = ArrayUtil.distinct(names, NULL_SAFE_STRING_COMPARATOR);
1641    
1642                            Arrays.sort(names, NULL_SAFE_STRING_COMPARATOR);
1643                    }
1644    
1645                    StringBundler query = new StringBundler();
1646    
1647                    query.append(_FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE);
1648    
1649                    query.append(_FINDER_COLUMN_T_N_TABLEID_2);
1650    
1651                    if (names.length > 0) {
1652                            query.append(StringPool.OPEN_PARENTHESIS);
1653    
1654                            for (int i = 0; i < names.length; i++) {
1655                                    String name = names[i];
1656    
1657                                    if (name == null) {
1658                                            query.append(_FINDER_COLUMN_T_N_NAME_1);
1659                                    }
1660                                    else if (name.equals(StringPool.BLANK)) {
1661                                            query.append(_FINDER_COLUMN_T_N_NAME_3);
1662                                    }
1663                                    else {
1664                                            query.append(_FINDER_COLUMN_T_N_NAME_2);
1665                                    }
1666    
1667                                    if ((i + 1) < names.length) {
1668                                            query.append(WHERE_OR);
1669                                    }
1670                            }
1671    
1672                            query.append(StringPool.CLOSE_PARENTHESIS);
1673                    }
1674    
1675                    query.setStringAt(removeConjunction(query.stringAt(query.index() - 1)),
1676                            query.index() - 1);
1677    
1678                    String sql = InlineSQLHelperUtil.replacePermissionCheck(query.toString(),
1679                                    ExpandoColumn.class.getName(),
1680                                    _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN);
1681    
1682                    Session session = null;
1683    
1684                    try {
1685                            session = openSession();
1686    
1687                            SQLQuery q = session.createSynchronizedSQLQuery(sql);
1688    
1689                            q.addScalar(COUNT_COLUMN_NAME,
1690                                    com.liferay.portal.kernel.dao.orm.Type.LONG);
1691    
1692                            QueryPos qPos = QueryPos.getInstance(q);
1693    
1694                            qPos.add(tableId);
1695    
1696                            for (String name : names) {
1697                                    if ((name != null) && !name.isEmpty()) {
1698                                            qPos.add(name);
1699                                    }
1700                            }
1701    
1702                            Long count = (Long)q.uniqueResult();
1703    
1704                            return count.intValue();
1705                    }
1706                    catch (Exception e) {
1707                            throw processException(e);
1708                    }
1709                    finally {
1710                            closeSession(session);
1711                    }
1712            }
1713    
1714            private static final String _FINDER_COLUMN_T_N_TABLEID_2 = "expandoColumn.tableId = ? AND ";
1715            private static final String _FINDER_COLUMN_T_N_NAME_1 = "expandoColumn.name IS NULL";
1716            private static final String _FINDER_COLUMN_T_N_NAME_2 = "expandoColumn.name = ?";
1717            private static final String _FINDER_COLUMN_T_N_NAME_3 = "(expandoColumn.name IS NULL OR expandoColumn.name = '')";
1718    
1719            public ExpandoColumnPersistenceImpl() {
1720                    setModelClass(ExpandoColumn.class);
1721            }
1722    
1723            /**
1724             * Caches the expando column in the entity cache if it is enabled.
1725             *
1726             * @param expandoColumn the expando column
1727             */
1728            @Override
1729            public void cacheResult(ExpandoColumn expandoColumn) {
1730                    entityCache.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
1731                            ExpandoColumnImpl.class, expandoColumn.getPrimaryKey(),
1732                            expandoColumn);
1733    
1734                    finderCache.putResult(FINDER_PATH_FETCH_BY_T_N,
1735                            new Object[] { expandoColumn.getTableId(), expandoColumn.getName() },
1736                            expandoColumn);
1737    
1738                    expandoColumn.resetOriginalValues();
1739            }
1740    
1741            /**
1742             * Caches the expando columns in the entity cache if it is enabled.
1743             *
1744             * @param expandoColumns the expando columns
1745             */
1746            @Override
1747            public void cacheResult(List<ExpandoColumn> expandoColumns) {
1748                    for (ExpandoColumn expandoColumn : expandoColumns) {
1749                            if (entityCache.getResult(
1750                                                    ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
1751                                                    ExpandoColumnImpl.class, expandoColumn.getPrimaryKey()) == null) {
1752                                    cacheResult(expandoColumn);
1753                            }
1754                            else {
1755                                    expandoColumn.resetOriginalValues();
1756                            }
1757                    }
1758            }
1759    
1760            /**
1761             * Clears the cache for all expando columns.
1762             *
1763             * <p>
1764             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
1765             * </p>
1766             */
1767            @Override
1768            public void clearCache() {
1769                    entityCache.clearCache(ExpandoColumnImpl.class);
1770    
1771                    finderCache.clearCache(FINDER_CLASS_NAME_ENTITY);
1772                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1773                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1774            }
1775    
1776            /**
1777             * Clears the cache for the expando column.
1778             *
1779             * <p>
1780             * The {@link EntityCache} and {@link FinderCache} are both cleared by this method.
1781             * </p>
1782             */
1783            @Override
1784            public void clearCache(ExpandoColumn expandoColumn) {
1785                    entityCache.removeResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
1786                            ExpandoColumnImpl.class, expandoColumn.getPrimaryKey());
1787    
1788                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1789                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1790    
1791                    clearUniqueFindersCache((ExpandoColumnModelImpl)expandoColumn);
1792            }
1793    
1794            @Override
1795            public void clearCache(List<ExpandoColumn> expandoColumns) {
1796                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1797                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1798    
1799                    for (ExpandoColumn expandoColumn : expandoColumns) {
1800                            entityCache.removeResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
1801                                    ExpandoColumnImpl.class, expandoColumn.getPrimaryKey());
1802    
1803                            clearUniqueFindersCache((ExpandoColumnModelImpl)expandoColumn);
1804                    }
1805            }
1806    
1807            protected void cacheUniqueFindersCache(
1808                    ExpandoColumnModelImpl expandoColumnModelImpl, boolean isNew) {
1809                    if (isNew) {
1810                            Object[] args = new Object[] {
1811                                            expandoColumnModelImpl.getTableId(),
1812                                            expandoColumnModelImpl.getName()
1813                                    };
1814    
1815                            finderCache.putResult(FINDER_PATH_COUNT_BY_T_N, args,
1816                                    Long.valueOf(1));
1817                            finderCache.putResult(FINDER_PATH_FETCH_BY_T_N, args,
1818                                    expandoColumnModelImpl);
1819                    }
1820                    else {
1821                            if ((expandoColumnModelImpl.getColumnBitmask() &
1822                                            FINDER_PATH_FETCH_BY_T_N.getColumnBitmask()) != 0) {
1823                                    Object[] args = new Object[] {
1824                                                    expandoColumnModelImpl.getTableId(),
1825                                                    expandoColumnModelImpl.getName()
1826                                            };
1827    
1828                                    finderCache.putResult(FINDER_PATH_COUNT_BY_T_N, args,
1829                                            Long.valueOf(1));
1830                                    finderCache.putResult(FINDER_PATH_FETCH_BY_T_N, args,
1831                                            expandoColumnModelImpl);
1832                            }
1833                    }
1834            }
1835    
1836            protected void clearUniqueFindersCache(
1837                    ExpandoColumnModelImpl expandoColumnModelImpl) {
1838                    Object[] args = new Object[] {
1839                                    expandoColumnModelImpl.getTableId(),
1840                                    expandoColumnModelImpl.getName()
1841                            };
1842    
1843                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_N, args);
1844                    finderCache.removeResult(FINDER_PATH_FETCH_BY_T_N, args);
1845    
1846                    if ((expandoColumnModelImpl.getColumnBitmask() &
1847                                    FINDER_PATH_FETCH_BY_T_N.getColumnBitmask()) != 0) {
1848                            args = new Object[] {
1849                                            expandoColumnModelImpl.getOriginalTableId(),
1850                                            expandoColumnModelImpl.getOriginalName()
1851                                    };
1852    
1853                            finderCache.removeResult(FINDER_PATH_COUNT_BY_T_N, args);
1854                            finderCache.removeResult(FINDER_PATH_FETCH_BY_T_N, args);
1855                    }
1856            }
1857    
1858            /**
1859             * Creates a new expando column with the primary key. Does not add the expando column to the database.
1860             *
1861             * @param columnId the primary key for the new expando column
1862             * @return the new expando column
1863             */
1864            @Override
1865            public ExpandoColumn create(long columnId) {
1866                    ExpandoColumn expandoColumn = new ExpandoColumnImpl();
1867    
1868                    expandoColumn.setNew(true);
1869                    expandoColumn.setPrimaryKey(columnId);
1870    
1871                    expandoColumn.setCompanyId(companyProvider.getCompanyId());
1872    
1873                    return expandoColumn;
1874            }
1875    
1876            /**
1877             * Removes the expando column with the primary key from the database. Also notifies the appropriate model listeners.
1878             *
1879             * @param columnId the primary key of the expando column
1880             * @return the expando column that was removed
1881             * @throws NoSuchColumnException if a expando column with the primary key could not be found
1882             */
1883            @Override
1884            public ExpandoColumn remove(long columnId) throws NoSuchColumnException {
1885                    return remove((Serializable)columnId);
1886            }
1887    
1888            /**
1889             * Removes the expando column with the primary key from the database. Also notifies the appropriate model listeners.
1890             *
1891             * @param primaryKey the primary key of the expando column
1892             * @return the expando column that was removed
1893             * @throws NoSuchColumnException if a expando column with the primary key could not be found
1894             */
1895            @Override
1896            public ExpandoColumn remove(Serializable primaryKey)
1897                    throws NoSuchColumnException {
1898                    Session session = null;
1899    
1900                    try {
1901                            session = openSession();
1902    
1903                            ExpandoColumn expandoColumn = (ExpandoColumn)session.get(ExpandoColumnImpl.class,
1904                                            primaryKey);
1905    
1906                            if (expandoColumn == null) {
1907                                    if (_log.isWarnEnabled()) {
1908                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
1909                                    }
1910    
1911                                    throw new NoSuchColumnException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
1912                                            primaryKey);
1913                            }
1914    
1915                            return remove(expandoColumn);
1916                    }
1917                    catch (NoSuchColumnException nsee) {
1918                            throw nsee;
1919                    }
1920                    catch (Exception e) {
1921                            throw processException(e);
1922                    }
1923                    finally {
1924                            closeSession(session);
1925                    }
1926            }
1927    
1928            @Override
1929            protected ExpandoColumn removeImpl(ExpandoColumn expandoColumn) {
1930                    expandoColumn = toUnwrappedModel(expandoColumn);
1931    
1932                    Session session = null;
1933    
1934                    try {
1935                            session = openSession();
1936    
1937                            if (!session.contains(expandoColumn)) {
1938                                    expandoColumn = (ExpandoColumn)session.get(ExpandoColumnImpl.class,
1939                                                    expandoColumn.getPrimaryKeyObj());
1940                            }
1941    
1942                            if (expandoColumn != null) {
1943                                    session.delete(expandoColumn);
1944                            }
1945                    }
1946                    catch (Exception e) {
1947                            throw processException(e);
1948                    }
1949                    finally {
1950                            closeSession(session);
1951                    }
1952    
1953                    if (expandoColumn != null) {
1954                            clearCache(expandoColumn);
1955                    }
1956    
1957                    return expandoColumn;
1958            }
1959    
1960            @Override
1961            public ExpandoColumn updateImpl(ExpandoColumn expandoColumn) {
1962                    expandoColumn = toUnwrappedModel(expandoColumn);
1963    
1964                    boolean isNew = expandoColumn.isNew();
1965    
1966                    ExpandoColumnModelImpl expandoColumnModelImpl = (ExpandoColumnModelImpl)expandoColumn;
1967    
1968                    Session session = null;
1969    
1970                    try {
1971                            session = openSession();
1972    
1973                            if (expandoColumn.isNew()) {
1974                                    session.save(expandoColumn);
1975    
1976                                    expandoColumn.setNew(false);
1977                            }
1978                            else {
1979                                    expandoColumn = (ExpandoColumn)session.merge(expandoColumn);
1980                            }
1981                    }
1982                    catch (Exception e) {
1983                            throw processException(e);
1984                    }
1985                    finally {
1986                            closeSession(session);
1987                    }
1988    
1989                    finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
1990    
1991                    if (isNew || !ExpandoColumnModelImpl.COLUMN_BITMASK_ENABLED) {
1992                            finderCache.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1993                    }
1994    
1995                    else {
1996                            if ((expandoColumnModelImpl.getColumnBitmask() &
1997                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID.getColumnBitmask()) != 0) {
1998                                    Object[] args = new Object[] {
1999                                                    expandoColumnModelImpl.getOriginalTableId()
2000                                            };
2001    
2002                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
2003                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
2004                                            args);
2005    
2006                                    args = new Object[] { expandoColumnModelImpl.getTableId() };
2007    
2008                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_TABLEID, args);
2009                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_TABLEID,
2010                                            args);
2011                            }
2012    
2013                            if ((expandoColumnModelImpl.getColumnBitmask() &
2014                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N.getColumnBitmask()) != 0) {
2015                                    Object[] args = new Object[] {
2016                                                    expandoColumnModelImpl.getOriginalTableId(),
2017                                                    expandoColumnModelImpl.getOriginalName()
2018                                            };
2019    
2020                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_N, args);
2021                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N,
2022                                            args);
2023    
2024                                    args = new Object[] {
2025                                                    expandoColumnModelImpl.getTableId(),
2026                                                    expandoColumnModelImpl.getName()
2027                                            };
2028    
2029                                    finderCache.removeResult(FINDER_PATH_COUNT_BY_T_N, args);
2030                                    finderCache.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_T_N,
2031                                            args);
2032                            }
2033                    }
2034    
2035                    entityCache.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
2036                            ExpandoColumnImpl.class, expandoColumn.getPrimaryKey(),
2037                            expandoColumn, false);
2038    
2039                    clearUniqueFindersCache(expandoColumnModelImpl);
2040                    cacheUniqueFindersCache(expandoColumnModelImpl, isNew);
2041    
2042                    expandoColumn.resetOriginalValues();
2043    
2044                    return expandoColumn;
2045            }
2046    
2047            protected ExpandoColumn toUnwrappedModel(ExpandoColumn expandoColumn) {
2048                    if (expandoColumn instanceof ExpandoColumnImpl) {
2049                            return expandoColumn;
2050                    }
2051    
2052                    ExpandoColumnImpl expandoColumnImpl = new ExpandoColumnImpl();
2053    
2054                    expandoColumnImpl.setNew(expandoColumn.isNew());
2055                    expandoColumnImpl.setPrimaryKey(expandoColumn.getPrimaryKey());
2056    
2057                    expandoColumnImpl.setColumnId(expandoColumn.getColumnId());
2058                    expandoColumnImpl.setCompanyId(expandoColumn.getCompanyId());
2059                    expandoColumnImpl.setTableId(expandoColumn.getTableId());
2060                    expandoColumnImpl.setName(expandoColumn.getName());
2061                    expandoColumnImpl.setType(expandoColumn.getType());
2062                    expandoColumnImpl.setDefaultData(expandoColumn.getDefaultData());
2063                    expandoColumnImpl.setTypeSettings(expandoColumn.getTypeSettings());
2064    
2065                    return expandoColumnImpl;
2066            }
2067    
2068            /**
2069             * Returns the expando column with the primary key or throws a {@link com.liferay.portal.exception.NoSuchModelException} if it could not be found.
2070             *
2071             * @param primaryKey the primary key of the expando column
2072             * @return the expando column
2073             * @throws NoSuchColumnException if a expando column with the primary key could not be found
2074             */
2075            @Override
2076            public ExpandoColumn findByPrimaryKey(Serializable primaryKey)
2077                    throws NoSuchColumnException {
2078                    ExpandoColumn expandoColumn = fetchByPrimaryKey(primaryKey);
2079    
2080                    if (expandoColumn == null) {
2081                            if (_log.isWarnEnabled()) {
2082                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
2083                            }
2084    
2085                            throw new NoSuchColumnException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
2086                                    primaryKey);
2087                    }
2088    
2089                    return expandoColumn;
2090            }
2091    
2092            /**
2093             * Returns the expando column with the primary key or throws a {@link NoSuchColumnException} if it could not be found.
2094             *
2095             * @param columnId the primary key of the expando column
2096             * @return the expando column
2097             * @throws NoSuchColumnException if a expando column with the primary key could not be found
2098             */
2099            @Override
2100            public ExpandoColumn findByPrimaryKey(long columnId)
2101                    throws NoSuchColumnException {
2102                    return findByPrimaryKey((Serializable)columnId);
2103            }
2104    
2105            /**
2106             * Returns the expando column with the primary key or returns <code>null</code> if it could not be found.
2107             *
2108             * @param primaryKey the primary key of the expando column
2109             * @return the expando column, or <code>null</code> if a expando column with the primary key could not be found
2110             */
2111            @Override
2112            public ExpandoColumn fetchByPrimaryKey(Serializable primaryKey) {
2113                    ExpandoColumn expandoColumn = (ExpandoColumn)entityCache.getResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
2114                                    ExpandoColumnImpl.class, primaryKey);
2115    
2116                    if (expandoColumn == _nullExpandoColumn) {
2117                            return null;
2118                    }
2119    
2120                    if (expandoColumn == null) {
2121                            Session session = null;
2122    
2123                            try {
2124                                    session = openSession();
2125    
2126                                    expandoColumn = (ExpandoColumn)session.get(ExpandoColumnImpl.class,
2127                                                    primaryKey);
2128    
2129                                    if (expandoColumn != null) {
2130                                            cacheResult(expandoColumn);
2131                                    }
2132                                    else {
2133                                            entityCache.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
2134                                                    ExpandoColumnImpl.class, primaryKey, _nullExpandoColumn);
2135                                    }
2136                            }
2137                            catch (Exception e) {
2138                                    entityCache.removeResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
2139                                            ExpandoColumnImpl.class, primaryKey);
2140    
2141                                    throw processException(e);
2142                            }
2143                            finally {
2144                                    closeSession(session);
2145                            }
2146                    }
2147    
2148                    return expandoColumn;
2149            }
2150    
2151            /**
2152             * Returns the expando column with the primary key or returns <code>null</code> if it could not be found.
2153             *
2154             * @param columnId the primary key of the expando column
2155             * @return the expando column, or <code>null</code> if a expando column with the primary key could not be found
2156             */
2157            @Override
2158            public ExpandoColumn fetchByPrimaryKey(long columnId) {
2159                    return fetchByPrimaryKey((Serializable)columnId);
2160            }
2161    
2162            @Override
2163            public Map<Serializable, ExpandoColumn> fetchByPrimaryKeys(
2164                    Set<Serializable> primaryKeys) {
2165                    if (primaryKeys.isEmpty()) {
2166                            return Collections.emptyMap();
2167                    }
2168    
2169                    Map<Serializable, ExpandoColumn> map = new HashMap<Serializable, ExpandoColumn>();
2170    
2171                    if (primaryKeys.size() == 1) {
2172                            Iterator<Serializable> iterator = primaryKeys.iterator();
2173    
2174                            Serializable primaryKey = iterator.next();
2175    
2176                            ExpandoColumn expandoColumn = fetchByPrimaryKey(primaryKey);
2177    
2178                            if (expandoColumn != null) {
2179                                    map.put(primaryKey, expandoColumn);
2180                            }
2181    
2182                            return map;
2183                    }
2184    
2185                    Set<Serializable> uncachedPrimaryKeys = null;
2186    
2187                    for (Serializable primaryKey : primaryKeys) {
2188                            ExpandoColumn expandoColumn = (ExpandoColumn)entityCache.getResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
2189                                            ExpandoColumnImpl.class, primaryKey);
2190    
2191                            if (expandoColumn == null) {
2192                                    if (uncachedPrimaryKeys == null) {
2193                                            uncachedPrimaryKeys = new HashSet<Serializable>();
2194                                    }
2195    
2196                                    uncachedPrimaryKeys.add(primaryKey);
2197                            }
2198                            else {
2199                                    map.put(primaryKey, expandoColumn);
2200                            }
2201                    }
2202    
2203                    if (uncachedPrimaryKeys == null) {
2204                            return map;
2205                    }
2206    
2207                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
2208                                    1);
2209    
2210                    query.append(_SQL_SELECT_EXPANDOCOLUMN_WHERE_PKS_IN);
2211    
2212                    for (Serializable primaryKey : uncachedPrimaryKeys) {
2213                            query.append(String.valueOf(primaryKey));
2214    
2215                            query.append(StringPool.COMMA);
2216                    }
2217    
2218                    query.setIndex(query.index() - 1);
2219    
2220                    query.append(StringPool.CLOSE_PARENTHESIS);
2221    
2222                    String sql = query.toString();
2223    
2224                    Session session = null;
2225    
2226                    try {
2227                            session = openSession();
2228    
2229                            Query q = session.createQuery(sql);
2230    
2231                            for (ExpandoColumn expandoColumn : (List<ExpandoColumn>)q.list()) {
2232                                    map.put(expandoColumn.getPrimaryKeyObj(), expandoColumn);
2233    
2234                                    cacheResult(expandoColumn);
2235    
2236                                    uncachedPrimaryKeys.remove(expandoColumn.getPrimaryKeyObj());
2237                            }
2238    
2239                            for (Serializable primaryKey : uncachedPrimaryKeys) {
2240                                    entityCache.putResult(ExpandoColumnModelImpl.ENTITY_CACHE_ENABLED,
2241                                            ExpandoColumnImpl.class, primaryKey, _nullExpandoColumn);
2242                            }
2243                    }
2244                    catch (Exception e) {
2245                            throw processException(e);
2246                    }
2247                    finally {
2248                            closeSession(session);
2249                    }
2250    
2251                    return map;
2252            }
2253    
2254            /**
2255             * Returns all the expando columns.
2256             *
2257             * @return the expando columns
2258             */
2259            @Override
2260            public List<ExpandoColumn> findAll() {
2261                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
2262            }
2263    
2264            /**
2265             * Returns a range of all the expando columns.
2266             *
2267             * <p>
2268             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link ExpandoColumnModelImpl}. 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.
2269             * </p>
2270             *
2271             * @param start the lower bound of the range of expando columns
2272             * @param end the upper bound of the range of expando columns (not inclusive)
2273             * @return the range of expando columns
2274             */
2275            @Override
2276            public List<ExpandoColumn> findAll(int start, int end) {
2277                    return findAll(start, end, null);
2278            }
2279    
2280            /**
2281             * Returns an ordered range of all the expando columns.
2282             *
2283             * <p>
2284             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link ExpandoColumnModelImpl}. 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.
2285             * </p>
2286             *
2287             * @param start the lower bound of the range of expando columns
2288             * @param end the upper bound of the range of expando columns (not inclusive)
2289             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2290             * @return the ordered range of expando columns
2291             */
2292            @Override
2293            public List<ExpandoColumn> findAll(int start, int end,
2294                    OrderByComparator<ExpandoColumn> orderByComparator) {
2295                    return findAll(start, end, orderByComparator, true);
2296            }
2297    
2298            /**
2299             * Returns an ordered range of all the expando columns.
2300             *
2301             * <p>
2302             * 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 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 QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link ExpandoColumnModelImpl}. 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.
2303             * </p>
2304             *
2305             * @param start the lower bound of the range of expando columns
2306             * @param end the upper bound of the range of expando columns (not inclusive)
2307             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
2308             * @param retrieveFromCache whether to retrieve from the finder cache
2309             * @return the ordered range of expando columns
2310             */
2311            @Override
2312            public List<ExpandoColumn> findAll(int start, int end,
2313                    OrderByComparator<ExpandoColumn> orderByComparator,
2314                    boolean retrieveFromCache) {
2315                    boolean pagination = true;
2316                    FinderPath finderPath = null;
2317                    Object[] finderArgs = null;
2318    
2319                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
2320                                    (orderByComparator == null)) {
2321                            pagination = false;
2322                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
2323                            finderArgs = FINDER_ARGS_EMPTY;
2324                    }
2325                    else {
2326                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
2327                            finderArgs = new Object[] { start, end, orderByComparator };
2328                    }
2329    
2330                    List<ExpandoColumn> list = null;
2331    
2332                    if (retrieveFromCache) {
2333                            list = (List<ExpandoColumn>)finderCache.getResult(finderPath,
2334                                            finderArgs, this);
2335                    }
2336    
2337                    if (list == null) {
2338                            StringBundler query = null;
2339                            String sql = null;
2340    
2341                            if (orderByComparator != null) {
2342                                    query = new StringBundler(2 +
2343                                                    (orderByComparator.getOrderByFields().length * 2));
2344    
2345                                    query.append(_SQL_SELECT_EXPANDOCOLUMN);
2346    
2347                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
2348                                            orderByComparator);
2349    
2350                                    sql = query.toString();
2351                            }
2352                            else {
2353                                    sql = _SQL_SELECT_EXPANDOCOLUMN;
2354    
2355                                    if (pagination) {
2356                                            sql = sql.concat(ExpandoColumnModelImpl.ORDER_BY_JPQL);
2357                                    }
2358                            }
2359    
2360                            Session session = null;
2361    
2362                            try {
2363                                    session = openSession();
2364    
2365                                    Query q = session.createQuery(sql);
2366    
2367                                    if (!pagination) {
2368                                            list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
2369                                                            start, end, false);
2370    
2371                                            Collections.sort(list);
2372    
2373                                            list = Collections.unmodifiableList(list);
2374                                    }
2375                                    else {
2376                                            list = (List<ExpandoColumn>)QueryUtil.list(q, getDialect(),
2377                                                            start, end);
2378                                    }
2379    
2380                                    cacheResult(list);
2381    
2382                                    finderCache.putResult(finderPath, finderArgs, list);
2383                            }
2384                            catch (Exception e) {
2385                                    finderCache.removeResult(finderPath, finderArgs);
2386    
2387                                    throw processException(e);
2388                            }
2389                            finally {
2390                                    closeSession(session);
2391                            }
2392                    }
2393    
2394                    return list;
2395            }
2396    
2397            /**
2398             * Removes all the expando columns from the database.
2399             *
2400             */
2401            @Override
2402            public void removeAll() {
2403                    for (ExpandoColumn expandoColumn : findAll()) {
2404                            remove(expandoColumn);
2405                    }
2406            }
2407    
2408            /**
2409             * Returns the number of expando columns.
2410             *
2411             * @return the number of expando columns
2412             */
2413            @Override
2414            public int countAll() {
2415                    Long count = (Long)finderCache.getResult(FINDER_PATH_COUNT_ALL,
2416                                    FINDER_ARGS_EMPTY, this);
2417    
2418                    if (count == null) {
2419                            Session session = null;
2420    
2421                            try {
2422                                    session = openSession();
2423    
2424                                    Query q = session.createQuery(_SQL_COUNT_EXPANDOCOLUMN);
2425    
2426                                    count = (Long)q.uniqueResult();
2427    
2428                                    finderCache.putResult(FINDER_PATH_COUNT_ALL, FINDER_ARGS_EMPTY,
2429                                            count);
2430                            }
2431                            catch (Exception e) {
2432                                    finderCache.removeResult(FINDER_PATH_COUNT_ALL,
2433                                            FINDER_ARGS_EMPTY);
2434    
2435                                    throw processException(e);
2436                            }
2437                            finally {
2438                                    closeSession(session);
2439                            }
2440                    }
2441    
2442                    return count.intValue();
2443            }
2444    
2445            @Override
2446            public Set<String> getBadColumnNames() {
2447                    return _badColumnNames;
2448            }
2449    
2450            @Override
2451            protected Map<String, Integer> getTableColumnsMap() {
2452                    return ExpandoColumnModelImpl.TABLE_COLUMNS_MAP;
2453            }
2454    
2455            /**
2456             * Initializes the expando column persistence.
2457             */
2458            public void afterPropertiesSet() {
2459            }
2460    
2461            public void destroy() {
2462                    entityCache.removeCache(ExpandoColumnImpl.class.getName());
2463                    finderCache.removeCache(FINDER_CLASS_NAME_ENTITY);
2464                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
2465                    finderCache.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
2466            }
2467    
2468            @BeanReference(type = CompanyProviderWrapper.class)
2469            protected CompanyProvider companyProvider;
2470            protected EntityCache entityCache = EntityCacheUtil.getEntityCache();
2471            protected FinderCache finderCache = FinderCacheUtil.getFinderCache();
2472            private static final String _SQL_SELECT_EXPANDOCOLUMN = "SELECT expandoColumn FROM ExpandoColumn expandoColumn";
2473            private static final String _SQL_SELECT_EXPANDOCOLUMN_WHERE_PKS_IN = "SELECT expandoColumn FROM ExpandoColumn expandoColumn WHERE columnId IN (";
2474            private static final String _SQL_SELECT_EXPANDOCOLUMN_WHERE = "SELECT expandoColumn FROM ExpandoColumn expandoColumn WHERE ";
2475            private static final String _SQL_COUNT_EXPANDOCOLUMN = "SELECT COUNT(expandoColumn) FROM ExpandoColumn expandoColumn";
2476            private static final String _SQL_COUNT_EXPANDOCOLUMN_WHERE = "SELECT COUNT(expandoColumn) FROM ExpandoColumn expandoColumn WHERE ";
2477            private static final String _FILTER_ENTITY_TABLE_FILTER_PK_COLUMN = "expandoColumn.columnId";
2478            private static final String _FILTER_SQL_SELECT_EXPANDOCOLUMN_WHERE = "SELECT DISTINCT {expandoColumn.*} FROM ExpandoColumn expandoColumn WHERE ";
2479            private static final String _FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_1 =
2480                    "SELECT {ExpandoColumn.*} FROM (SELECT DISTINCT expandoColumn.columnId FROM ExpandoColumn expandoColumn WHERE ";
2481            private static final String _FILTER_SQL_SELECT_EXPANDOCOLUMN_NO_INLINE_DISTINCT_WHERE_2 =
2482                    ") TEMP_TABLE INNER JOIN ExpandoColumn ON TEMP_TABLE.columnId = ExpandoColumn.columnId";
2483            private static final String _FILTER_SQL_COUNT_EXPANDOCOLUMN_WHERE = "SELECT COUNT(DISTINCT expandoColumn.columnId) AS COUNT_VALUE FROM ExpandoColumn expandoColumn WHERE ";
2484            private static final String _FILTER_ENTITY_ALIAS = "expandoColumn";
2485            private static final String _FILTER_ENTITY_TABLE = "ExpandoColumn";
2486            private static final String _ORDER_BY_ENTITY_ALIAS = "expandoColumn.";
2487            private static final String _ORDER_BY_ENTITY_TABLE = "ExpandoColumn.";
2488            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoColumn exists with the primary key ";
2489            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoColumn exists with the key {";
2490            private static final Log _log = LogFactoryUtil.getLog(ExpandoColumnPersistenceImpl.class);
2491            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
2492                                    "type"
2493                            });
2494            private static final ExpandoColumn _nullExpandoColumn = new ExpandoColumnImpl() {
2495                            @Override
2496                            public Object clone() {
2497                                    return this;
2498                            }
2499    
2500                            @Override
2501                            public CacheModel<ExpandoColumn> toCacheModel() {
2502                                    return _nullExpandoColumnCacheModel;
2503                            }
2504                    };
2505    
2506            private static final CacheModel<ExpandoColumn> _nullExpandoColumnCacheModel = new CacheModel<ExpandoColumn>() {
2507                            @Override
2508                            public ExpandoColumn toEntityModel() {
2509                                    return _nullExpandoColumn;
2510                            }
2511                    };
2512    }