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