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