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.bean.BeanReference;
019    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
020    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
021    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderPath;
023    import com.liferay.portal.kernel.dao.orm.Query;
024    import com.liferay.portal.kernel.dao.orm.QueryPos;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
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.GetterUtil;
031    import com.liferay.portal.kernel.util.InstanceFactory;
032    import com.liferay.portal.kernel.util.OrderByComparator;
033    import com.liferay.portal.kernel.util.StringBundler;
034    import com.liferay.portal.kernel.util.StringPool;
035    import com.liferay.portal.kernel.util.StringUtil;
036    import com.liferay.portal.kernel.util.Validator;
037    import com.liferay.portal.model.CacheModel;
038    import com.liferay.portal.model.ModelListener;
039    import com.liferay.portal.service.persistence.UserPersistence;
040    import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
041    
042    import com.liferay.portlet.expando.NoSuchTableException;
043    import com.liferay.portlet.expando.model.ExpandoTable;
044    import com.liferay.portlet.expando.model.impl.ExpandoTableImpl;
045    import com.liferay.portlet.expando.model.impl.ExpandoTableModelImpl;
046    
047    import java.io.Serializable;
048    
049    import java.util.ArrayList;
050    import java.util.Collections;
051    import java.util.List;
052    
053    /**
054     * The persistence implementation for the expando table service.
055     *
056     * <p>
057     * Caching information and settings can be found in <code>portal.properties</code>
058     * </p>
059     *
060     * @author Brian Wing Shun Chan
061     * @see ExpandoTablePersistence
062     * @see ExpandoTableUtil
063     * @generated
064     */
065    public class ExpandoTablePersistenceImpl extends BasePersistenceImpl<ExpandoTable>
066            implements ExpandoTablePersistence {
067            /*
068             * NOTE FOR DEVELOPERS:
069             *
070             * Never modify or reference this class directly. Always use {@link ExpandoTableUtil} to access the expando table persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
071             */
072            public static final String FINDER_CLASS_NAME_ENTITY = ExpandoTableImpl.class.getName();
073            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074                    ".List1";
075            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
076                    ".List2";
077            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
078                            ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
079                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findByC_C",
080                            new String[] {
081                                    Long.class.getName(), Long.class.getName(),
082                                    
083                            "java.lang.Integer", "java.lang.Integer",
084                                    "com.liferay.portal.kernel.util.OrderByComparator"
085                            });
086            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
087                            ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
088                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findByC_C",
089                            new String[] { Long.class.getName(), Long.class.getName() },
090                            ExpandoTableModelImpl.COMPANYID_COLUMN_BITMASK |
091                            ExpandoTableModelImpl.CLASSNAMEID_COLUMN_BITMASK);
092            public static final FinderPath FINDER_PATH_COUNT_BY_C_C = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
093                            ExpandoTableModelImpl.FINDER_CACHE_ENABLED, Long.class,
094                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C",
095                            new String[] { Long.class.getName(), Long.class.getName() });
096            public static final FinderPath FINDER_PATH_FETCH_BY_C_C_N = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
097                            ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
098                            FINDER_CLASS_NAME_ENTITY, "fetchByC_C_N",
099                            new String[] {
100                                    Long.class.getName(), Long.class.getName(),
101                                    String.class.getName()
102                            },
103                            ExpandoTableModelImpl.COMPANYID_COLUMN_BITMASK |
104                            ExpandoTableModelImpl.CLASSNAMEID_COLUMN_BITMASK |
105                            ExpandoTableModelImpl.NAME_COLUMN_BITMASK);
106            public static final FinderPath FINDER_PATH_COUNT_BY_C_C_N = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
107                            ExpandoTableModelImpl.FINDER_CACHE_ENABLED, Long.class,
108                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_C_N",
109                            new String[] {
110                                    Long.class.getName(), Long.class.getName(),
111                                    String.class.getName()
112                            });
113            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
114                            ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
115                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
116            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
117                            ExpandoTableModelImpl.FINDER_CACHE_ENABLED, ExpandoTableImpl.class,
118                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
119            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
120                            ExpandoTableModelImpl.FINDER_CACHE_ENABLED, Long.class,
121                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
122    
123            /**
124             * Caches the expando table in the entity cache if it is enabled.
125             *
126             * @param expandoTable the expando table
127             */
128            public void cacheResult(ExpandoTable expandoTable) {
129                    EntityCacheUtil.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
130                            ExpandoTableImpl.class, expandoTable.getPrimaryKey(), expandoTable);
131    
132                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
133                            new Object[] {
134                                    Long.valueOf(expandoTable.getCompanyId()),
135                                    Long.valueOf(expandoTable.getClassNameId()),
136                                    
137                            expandoTable.getName()
138                            }, expandoTable);
139    
140                    expandoTable.resetOriginalValues();
141            }
142    
143            /**
144             * Caches the expando tables in the entity cache if it is enabled.
145             *
146             * @param expandoTables the expando tables
147             */
148            public void cacheResult(List<ExpandoTable> expandoTables) {
149                    for (ExpandoTable expandoTable : expandoTables) {
150                            if (EntityCacheUtil.getResult(
151                                                    ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
152                                                    ExpandoTableImpl.class, expandoTable.getPrimaryKey()) == null) {
153                                    cacheResult(expandoTable);
154                            }
155                            else {
156                                    expandoTable.resetOriginalValues();
157                            }
158                    }
159            }
160    
161            /**
162             * Clears the cache for all expando tables.
163             *
164             * <p>
165             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
166             * </p>
167             */
168            @Override
169            public void clearCache() {
170                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
171                            CacheRegistryUtil.clear(ExpandoTableImpl.class.getName());
172                    }
173    
174                    EntityCacheUtil.clearCache(ExpandoTableImpl.class.getName());
175    
176                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
177                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
178                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
179            }
180    
181            /**
182             * Clears the cache for the expando table.
183             *
184             * <p>
185             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
186             * </p>
187             */
188            @Override
189            public void clearCache(ExpandoTable expandoTable) {
190                    EntityCacheUtil.removeResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
191                            ExpandoTableImpl.class, expandoTable.getPrimaryKey());
192    
193                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
194                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
195    
196                    clearUniqueFindersCache(expandoTable);
197            }
198    
199            @Override
200            public void clearCache(List<ExpandoTable> expandoTables) {
201                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
202                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
203    
204                    for (ExpandoTable expandoTable : expandoTables) {
205                            EntityCacheUtil.removeResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
206                                    ExpandoTableImpl.class, expandoTable.getPrimaryKey());
207    
208                            clearUniqueFindersCache(expandoTable);
209                    }
210            }
211    
212            protected void clearUniqueFindersCache(ExpandoTable expandoTable) {
213                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N,
214                            new Object[] {
215                                    Long.valueOf(expandoTable.getCompanyId()),
216                                    Long.valueOf(expandoTable.getClassNameId()),
217                                    
218                            expandoTable.getName()
219                            });
220            }
221    
222            /**
223             * Creates a new expando table with the primary key. Does not add the expando table to the database.
224             *
225             * @param tableId the primary key for the new expando table
226             * @return the new expando table
227             */
228            public ExpandoTable create(long tableId) {
229                    ExpandoTable expandoTable = new ExpandoTableImpl();
230    
231                    expandoTable.setNew(true);
232                    expandoTable.setPrimaryKey(tableId);
233    
234                    return expandoTable;
235            }
236    
237            /**
238             * Removes the expando table with the primary key from the database. Also notifies the appropriate model listeners.
239             *
240             * @param tableId the primary key of the expando table
241             * @return the expando table that was removed
242             * @throws com.liferay.portlet.expando.NoSuchTableException if a expando table with the primary key could not be found
243             * @throws SystemException if a system exception occurred
244             */
245            public ExpandoTable remove(long tableId)
246                    throws NoSuchTableException, SystemException {
247                    return remove(Long.valueOf(tableId));
248            }
249    
250            /**
251             * Removes the expando table with the primary key from the database. Also notifies the appropriate model listeners.
252             *
253             * @param primaryKey the primary key of the expando table
254             * @return the expando table that was removed
255             * @throws com.liferay.portlet.expando.NoSuchTableException if a expando table with the primary key could not be found
256             * @throws SystemException if a system exception occurred
257             */
258            @Override
259            public ExpandoTable remove(Serializable primaryKey)
260                    throws NoSuchTableException, SystemException {
261                    Session session = null;
262    
263                    try {
264                            session = openSession();
265    
266                            ExpandoTable expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
267                                            primaryKey);
268    
269                            if (expandoTable == null) {
270                                    if (_log.isWarnEnabled()) {
271                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
272                                    }
273    
274                                    throw new NoSuchTableException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
275                                            primaryKey);
276                            }
277    
278                            return remove(expandoTable);
279                    }
280                    catch (NoSuchTableException nsee) {
281                            throw nsee;
282                    }
283                    catch (Exception e) {
284                            throw processException(e);
285                    }
286                    finally {
287                            closeSession(session);
288                    }
289            }
290    
291            @Override
292            protected ExpandoTable removeImpl(ExpandoTable expandoTable)
293                    throws SystemException {
294                    expandoTable = toUnwrappedModel(expandoTable);
295    
296                    Session session = null;
297    
298                    try {
299                            session = openSession();
300    
301                            if (expandoTable.isCachedModel()) {
302                                    expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
303                                                    expandoTable.getPrimaryKeyObj());
304                            }
305    
306                            session.delete(expandoTable);
307                    }
308                    catch (Exception e) {
309                            throw processException(e);
310                    }
311                    finally {
312                            closeSession(session);
313                    }
314    
315                    clearCache(expandoTable);
316    
317                    return expandoTable;
318            }
319    
320            @Override
321            public ExpandoTable updateImpl(
322                    com.liferay.portlet.expando.model.ExpandoTable expandoTable)
323                    throws SystemException {
324                    expandoTable = toUnwrappedModel(expandoTable);
325    
326                    boolean isNew = expandoTable.isNew();
327    
328                    ExpandoTableModelImpl expandoTableModelImpl = (ExpandoTableModelImpl)expandoTable;
329    
330                    Session session = null;
331    
332                    try {
333                            session = openSession();
334    
335                            if (expandoTable.isNew()) {
336                                    session.save(expandoTable);
337    
338                                    expandoTable.setNew(false);
339                            }
340                            else {
341                                    session.merge(expandoTable);
342                            }
343                    }
344                    catch (Exception e) {
345                            throw processException(e);
346                    }
347                    finally {
348                            closeSession(session);
349                    }
350    
351                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
352    
353                    if (isNew || !ExpandoTableModelImpl.COLUMN_BITMASK_ENABLED) {
354                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
355                    }
356    
357                    else {
358                            if ((expandoTableModelImpl.getColumnBitmask() &
359                                            FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C.getColumnBitmask()) != 0) {
360                                    Object[] args = new Object[] {
361                                                    Long.valueOf(expandoTableModelImpl.getOriginalCompanyId()),
362                                                    Long.valueOf(expandoTableModelImpl.getOriginalClassNameId())
363                                            };
364    
365                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
366                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
367                                            args);
368    
369                                    args = new Object[] {
370                                                    Long.valueOf(expandoTableModelImpl.getCompanyId()),
371                                                    Long.valueOf(expandoTableModelImpl.getClassNameId())
372                                            };
373    
374                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C, args);
375                                    FinderCacheUtil.removeResult(FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C,
376                                            args);
377                            }
378                    }
379    
380                    EntityCacheUtil.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
381                            ExpandoTableImpl.class, expandoTable.getPrimaryKey(), expandoTable);
382    
383                    if (isNew) {
384                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
385                                    new Object[] {
386                                            Long.valueOf(expandoTable.getCompanyId()),
387                                            Long.valueOf(expandoTable.getClassNameId()),
388                                            
389                                    expandoTable.getName()
390                                    }, expandoTable);
391                    }
392                    else {
393                            if ((expandoTableModelImpl.getColumnBitmask() &
394                                            FINDER_PATH_FETCH_BY_C_C_N.getColumnBitmask()) != 0) {
395                                    Object[] args = new Object[] {
396                                                    Long.valueOf(expandoTableModelImpl.getOriginalCompanyId()),
397                                                    Long.valueOf(expandoTableModelImpl.getOriginalClassNameId()),
398                                                    
399                                                    expandoTableModelImpl.getOriginalName()
400                                            };
401    
402                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_C_N, args);
403    
404                                    FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N, args);
405    
406                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
407                                            new Object[] {
408                                                    Long.valueOf(expandoTable.getCompanyId()),
409                                                    Long.valueOf(expandoTable.getClassNameId()),
410                                                    
411                                            expandoTable.getName()
412                                            }, expandoTable);
413                            }
414                    }
415    
416                    return expandoTable;
417            }
418    
419            protected ExpandoTable toUnwrappedModel(ExpandoTable expandoTable) {
420                    if (expandoTable instanceof ExpandoTableImpl) {
421                            return expandoTable;
422                    }
423    
424                    ExpandoTableImpl expandoTableImpl = new ExpandoTableImpl();
425    
426                    expandoTableImpl.setNew(expandoTable.isNew());
427                    expandoTableImpl.setPrimaryKey(expandoTable.getPrimaryKey());
428    
429                    expandoTableImpl.setTableId(expandoTable.getTableId());
430                    expandoTableImpl.setCompanyId(expandoTable.getCompanyId());
431                    expandoTableImpl.setClassNameId(expandoTable.getClassNameId());
432                    expandoTableImpl.setName(expandoTable.getName());
433    
434                    return expandoTableImpl;
435            }
436    
437            /**
438             * Returns the expando table with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
439             *
440             * @param primaryKey the primary key of the expando table
441             * @return the expando table
442             * @throws com.liferay.portal.NoSuchModelException if a expando table with the primary key could not be found
443             * @throws SystemException if a system exception occurred
444             */
445            @Override
446            public ExpandoTable findByPrimaryKey(Serializable primaryKey)
447                    throws NoSuchModelException, SystemException {
448                    return findByPrimaryKey(((Long)primaryKey).longValue());
449            }
450    
451            /**
452             * Returns the expando table with the primary key or throws a {@link com.liferay.portlet.expando.NoSuchTableException} if it could not be found.
453             *
454             * @param tableId the primary key of the expando table
455             * @return the expando table
456             * @throws com.liferay.portlet.expando.NoSuchTableException if a expando table with the primary key could not be found
457             * @throws SystemException if a system exception occurred
458             */
459            public ExpandoTable findByPrimaryKey(long tableId)
460                    throws NoSuchTableException, SystemException {
461                    ExpandoTable expandoTable = fetchByPrimaryKey(tableId);
462    
463                    if (expandoTable == null) {
464                            if (_log.isWarnEnabled()) {
465                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + tableId);
466                            }
467    
468                            throw new NoSuchTableException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
469                                    tableId);
470                    }
471    
472                    return expandoTable;
473            }
474    
475            /**
476             * Returns the expando table with the primary key or returns <code>null</code> if it could not be found.
477             *
478             * @param primaryKey the primary key of the expando table
479             * @return the expando table, or <code>null</code> if a expando table with the primary key could not be found
480             * @throws SystemException if a system exception occurred
481             */
482            @Override
483            public ExpandoTable fetchByPrimaryKey(Serializable primaryKey)
484                    throws SystemException {
485                    return fetchByPrimaryKey(((Long)primaryKey).longValue());
486            }
487    
488            /**
489             * Returns the expando table with the primary key or returns <code>null</code> if it could not be found.
490             *
491             * @param tableId the primary key of the expando table
492             * @return the expando table, or <code>null</code> if a expando table with the primary key could not be found
493             * @throws SystemException if a system exception occurred
494             */
495            public ExpandoTable fetchByPrimaryKey(long tableId)
496                    throws SystemException {
497                    ExpandoTable expandoTable = (ExpandoTable)EntityCacheUtil.getResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
498                                    ExpandoTableImpl.class, tableId);
499    
500                    if (expandoTable == _nullExpandoTable) {
501                            return null;
502                    }
503    
504                    if (expandoTable == null) {
505                            Session session = null;
506    
507                            boolean hasException = false;
508    
509                            try {
510                                    session = openSession();
511    
512                                    expandoTable = (ExpandoTable)session.get(ExpandoTableImpl.class,
513                                                    Long.valueOf(tableId));
514                            }
515                            catch (Exception e) {
516                                    hasException = true;
517    
518                                    throw processException(e);
519                            }
520                            finally {
521                                    if (expandoTable != null) {
522                                            cacheResult(expandoTable);
523                                    }
524                                    else if (!hasException) {
525                                            EntityCacheUtil.putResult(ExpandoTableModelImpl.ENTITY_CACHE_ENABLED,
526                                                    ExpandoTableImpl.class, tableId, _nullExpandoTable);
527                                    }
528    
529                                    closeSession(session);
530                            }
531                    }
532    
533                    return expandoTable;
534            }
535    
536            /**
537             * Returns all the expando tables where companyId = &#63; and classNameId = &#63;.
538             *
539             * @param companyId the company ID
540             * @param classNameId the class name ID
541             * @return the matching expando tables
542             * @throws SystemException if a system exception occurred
543             */
544            public List<ExpandoTable> findByC_C(long companyId, long classNameId)
545                    throws SystemException {
546                    return findByC_C(companyId, classNameId, QueryUtil.ALL_POS,
547                            QueryUtil.ALL_POS, null);
548            }
549    
550            /**
551             * Returns a range of all the expando tables where companyId = &#63; and classNameId = &#63;.
552             *
553             * <p>
554             * 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.
555             * </p>
556             *
557             * @param companyId the company ID
558             * @param classNameId the class name ID
559             * @param start the lower bound of the range of expando tables
560             * @param end the upper bound of the range of expando tables (not inclusive)
561             * @return the range of matching expando tables
562             * @throws SystemException if a system exception occurred
563             */
564            public List<ExpandoTable> findByC_C(long companyId, long classNameId,
565                    int start, int end) throws SystemException {
566                    return findByC_C(companyId, classNameId, start, end, null);
567            }
568    
569            /**
570             * Returns an ordered range of all the expando tables where companyId = &#63; and classNameId = &#63;.
571             *
572             * <p>
573             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set.
574             * </p>
575             *
576             * @param companyId the company ID
577             * @param classNameId the class name ID
578             * @param start the lower bound of the range of expando tables
579             * @param end the upper bound of the range of expando tables (not inclusive)
580             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
581             * @return the ordered range of matching expando tables
582             * @throws SystemException if a system exception occurred
583             */
584            public List<ExpandoTable> findByC_C(long companyId, long classNameId,
585                    int start, int end, OrderByComparator orderByComparator)
586                    throws SystemException {
587                    FinderPath finderPath = null;
588                    Object[] finderArgs = null;
589    
590                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
591                                    (orderByComparator == null)) {
592                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_BY_C_C;
593                            finderArgs = new Object[] { companyId, classNameId };
594                    }
595                    else {
596                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_BY_C_C;
597                            finderArgs = new Object[] {
598                                            companyId, classNameId,
599                                            
600                                            start, end, orderByComparator
601                                    };
602                    }
603    
604                    List<ExpandoTable> list = (List<ExpandoTable>)FinderCacheUtil.getResult(finderPath,
605                                    finderArgs, this);
606    
607                    if ((list != null) && !list.isEmpty()) {
608                            for (ExpandoTable expandoTable : list) {
609                                    if ((companyId != expandoTable.getCompanyId()) ||
610                                                    (classNameId != expandoTable.getClassNameId())) {
611                                            list = null;
612    
613                                            break;
614                                    }
615                            }
616                    }
617    
618                    if (list == null) {
619                            StringBundler query = null;
620    
621                            if (orderByComparator != null) {
622                                    query = new StringBundler(4 +
623                                                    (orderByComparator.getOrderByFields().length * 3));
624                            }
625                            else {
626                                    query = new StringBundler(3);
627                            }
628    
629                            query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
630    
631                            query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
632    
633                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
634    
635                            if (orderByComparator != null) {
636                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
637                                            orderByComparator);
638                            }
639    
640                            String sql = query.toString();
641    
642                            Session session = null;
643    
644                            try {
645                                    session = openSession();
646    
647                                    Query q = session.createQuery(sql);
648    
649                                    QueryPos qPos = QueryPos.getInstance(q);
650    
651                                    qPos.add(companyId);
652    
653                                    qPos.add(classNameId);
654    
655                                    list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
656                                                    start, end);
657                            }
658                            catch (Exception e) {
659                                    throw processException(e);
660                            }
661                            finally {
662                                    if (list == null) {
663                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
664                                    }
665                                    else {
666                                            cacheResult(list);
667    
668                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
669                                    }
670    
671                                    closeSession(session);
672                            }
673                    }
674    
675                    return list;
676            }
677    
678            /**
679             * Returns the first expando table in the ordered set where companyId = &#63; and classNameId = &#63;.
680             *
681             * @param companyId the company ID
682             * @param classNameId the class name ID
683             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
684             * @return the first matching expando table
685             * @throws com.liferay.portlet.expando.NoSuchTableException if a matching expando table could not be found
686             * @throws SystemException if a system exception occurred
687             */
688            public ExpandoTable findByC_C_First(long companyId, long classNameId,
689                    OrderByComparator orderByComparator)
690                    throws NoSuchTableException, SystemException {
691                    ExpandoTable expandoTable = fetchByC_C_First(companyId, classNameId,
692                                    orderByComparator);
693    
694                    if (expandoTable != null) {
695                            return expandoTable;
696                    }
697    
698                    StringBundler msg = new StringBundler(6);
699    
700                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
701    
702                    msg.append("companyId=");
703                    msg.append(companyId);
704    
705                    msg.append(", classNameId=");
706                    msg.append(classNameId);
707    
708                    msg.append(StringPool.CLOSE_CURLY_BRACE);
709    
710                    throw new NoSuchTableException(msg.toString());
711            }
712    
713            /**
714             * Returns the first expando table in the ordered set where companyId = &#63; and classNameId = &#63;.
715             *
716             * @param companyId the company ID
717             * @param classNameId the class name ID
718             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
719             * @return the first matching expando table, or <code>null</code> if a matching expando table could not be found
720             * @throws SystemException if a system exception occurred
721             */
722            public ExpandoTable fetchByC_C_First(long companyId, long classNameId,
723                    OrderByComparator orderByComparator) throws SystemException {
724                    List<ExpandoTable> list = findByC_C(companyId, classNameId, 0, 1,
725                                    orderByComparator);
726    
727                    if (!list.isEmpty()) {
728                            return list.get(0);
729                    }
730    
731                    return null;
732            }
733    
734            /**
735             * Returns the last expando table in the ordered set where companyId = &#63; and classNameId = &#63;.
736             *
737             * @param companyId the company ID
738             * @param classNameId the class name ID
739             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
740             * @return the last matching expando table
741             * @throws com.liferay.portlet.expando.NoSuchTableException if a matching expando table could not be found
742             * @throws SystemException if a system exception occurred
743             */
744            public ExpandoTable findByC_C_Last(long companyId, long classNameId,
745                    OrderByComparator orderByComparator)
746                    throws NoSuchTableException, SystemException {
747                    ExpandoTable expandoTable = fetchByC_C_Last(companyId, classNameId,
748                                    orderByComparator);
749    
750                    if (expandoTable != null) {
751                            return expandoTable;
752                    }
753    
754                    StringBundler msg = new StringBundler(6);
755    
756                    msg.append(_NO_SUCH_ENTITY_WITH_KEY);
757    
758                    msg.append("companyId=");
759                    msg.append(companyId);
760    
761                    msg.append(", classNameId=");
762                    msg.append(classNameId);
763    
764                    msg.append(StringPool.CLOSE_CURLY_BRACE);
765    
766                    throw new NoSuchTableException(msg.toString());
767            }
768    
769            /**
770             * Returns the last expando table in the ordered set where companyId = &#63; and classNameId = &#63;.
771             *
772             * @param companyId the company ID
773             * @param classNameId the class name ID
774             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
775             * @return the last matching expando table, or <code>null</code> if a matching expando table could not be found
776             * @throws SystemException if a system exception occurred
777             */
778            public ExpandoTable fetchByC_C_Last(long companyId, long classNameId,
779                    OrderByComparator orderByComparator) throws SystemException {
780                    int count = countByC_C(companyId, classNameId);
781    
782                    List<ExpandoTable> list = findByC_C(companyId, classNameId, count - 1,
783                                    count, orderByComparator);
784    
785                    if (!list.isEmpty()) {
786                            return list.get(0);
787                    }
788    
789                    return null;
790            }
791    
792            /**
793             * Returns the expando tables before and after the current expando table in the ordered set where companyId = &#63; and classNameId = &#63;.
794             *
795             * @param tableId the primary key of the current expando table
796             * @param companyId the company ID
797             * @param classNameId the class name ID
798             * @param orderByComparator the comparator to order the set by (optionally <code>null</code>)
799             * @return the previous, current, and next expando table
800             * @throws com.liferay.portlet.expando.NoSuchTableException if a expando table with the primary key could not be found
801             * @throws SystemException if a system exception occurred
802             */
803            public ExpandoTable[] findByC_C_PrevAndNext(long tableId, long companyId,
804                    long classNameId, OrderByComparator orderByComparator)
805                    throws NoSuchTableException, SystemException {
806                    ExpandoTable expandoTable = findByPrimaryKey(tableId);
807    
808                    Session session = null;
809    
810                    try {
811                            session = openSession();
812    
813                            ExpandoTable[] array = new ExpandoTableImpl[3];
814    
815                            array[0] = getByC_C_PrevAndNext(session, expandoTable, companyId,
816                                            classNameId, orderByComparator, true);
817    
818                            array[1] = expandoTable;
819    
820                            array[2] = getByC_C_PrevAndNext(session, expandoTable, companyId,
821                                            classNameId, orderByComparator, false);
822    
823                            return array;
824                    }
825                    catch (Exception e) {
826                            throw processException(e);
827                    }
828                    finally {
829                            closeSession(session);
830                    }
831            }
832    
833            protected ExpandoTable getByC_C_PrevAndNext(Session session,
834                    ExpandoTable expandoTable, long companyId, long classNameId,
835                    OrderByComparator orderByComparator, boolean previous) {
836                    StringBundler query = null;
837    
838                    if (orderByComparator != null) {
839                            query = new StringBundler(6 +
840                                            (orderByComparator.getOrderByFields().length * 6));
841                    }
842                    else {
843                            query = new StringBundler(3);
844                    }
845    
846                    query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
847    
848                    query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
849    
850                    query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
851    
852                    if (orderByComparator != null) {
853                            String[] orderByConditionFields = orderByComparator.getOrderByConditionFields();
854    
855                            if (orderByConditionFields.length > 0) {
856                                    query.append(WHERE_AND);
857                            }
858    
859                            for (int i = 0; i < orderByConditionFields.length; i++) {
860                                    query.append(_ORDER_BY_ENTITY_ALIAS);
861                                    query.append(orderByConditionFields[i]);
862    
863                                    if ((i + 1) < orderByConditionFields.length) {
864                                            if (orderByComparator.isAscending() ^ previous) {
865                                                    query.append(WHERE_GREATER_THAN_HAS_NEXT);
866                                            }
867                                            else {
868                                                    query.append(WHERE_LESSER_THAN_HAS_NEXT);
869                                            }
870                                    }
871                                    else {
872                                            if (orderByComparator.isAscending() ^ previous) {
873                                                    query.append(WHERE_GREATER_THAN);
874                                            }
875                                            else {
876                                                    query.append(WHERE_LESSER_THAN);
877                                            }
878                                    }
879                            }
880    
881                            query.append(ORDER_BY_CLAUSE);
882    
883                            String[] orderByFields = orderByComparator.getOrderByFields();
884    
885                            for (int i = 0; i < orderByFields.length; i++) {
886                                    query.append(_ORDER_BY_ENTITY_ALIAS);
887                                    query.append(orderByFields[i]);
888    
889                                    if ((i + 1) < orderByFields.length) {
890                                            if (orderByComparator.isAscending() ^ previous) {
891                                                    query.append(ORDER_BY_ASC_HAS_NEXT);
892                                            }
893                                            else {
894                                                    query.append(ORDER_BY_DESC_HAS_NEXT);
895                                            }
896                                    }
897                                    else {
898                                            if (orderByComparator.isAscending() ^ previous) {
899                                                    query.append(ORDER_BY_ASC);
900                                            }
901                                            else {
902                                                    query.append(ORDER_BY_DESC);
903                                            }
904                                    }
905                            }
906                    }
907    
908                    String sql = query.toString();
909    
910                    Query q = session.createQuery(sql);
911    
912                    q.setFirstResult(0);
913                    q.setMaxResults(2);
914    
915                    QueryPos qPos = QueryPos.getInstance(q);
916    
917                    qPos.add(companyId);
918    
919                    qPos.add(classNameId);
920    
921                    if (orderByComparator != null) {
922                            Object[] values = orderByComparator.getOrderByConditionValues(expandoTable);
923    
924                            for (Object value : values) {
925                                    qPos.add(value);
926                            }
927                    }
928    
929                    List<ExpandoTable> list = q.list();
930    
931                    if (list.size() == 2) {
932                            return list.get(1);
933                    }
934                    else {
935                            return null;
936                    }
937            }
938    
939            /**
940             * Returns the expando table where companyId = &#63; and classNameId = &#63; and name = &#63; or throws a {@link com.liferay.portlet.expando.NoSuchTableException} if it could not be found.
941             *
942             * @param companyId the company ID
943             * @param classNameId the class name ID
944             * @param name the name
945             * @return the matching expando table
946             * @throws com.liferay.portlet.expando.NoSuchTableException if a matching expando table could not be found
947             * @throws SystemException if a system exception occurred
948             */
949            public ExpandoTable findByC_C_N(long companyId, long classNameId,
950                    String name) throws NoSuchTableException, SystemException {
951                    ExpandoTable expandoTable = fetchByC_C_N(companyId, classNameId, name);
952    
953                    if (expandoTable == null) {
954                            StringBundler msg = new StringBundler(8);
955    
956                            msg.append(_NO_SUCH_ENTITY_WITH_KEY);
957    
958                            msg.append("companyId=");
959                            msg.append(companyId);
960    
961                            msg.append(", classNameId=");
962                            msg.append(classNameId);
963    
964                            msg.append(", name=");
965                            msg.append(name);
966    
967                            msg.append(StringPool.CLOSE_CURLY_BRACE);
968    
969                            if (_log.isWarnEnabled()) {
970                                    _log.warn(msg.toString());
971                            }
972    
973                            throw new NoSuchTableException(msg.toString());
974                    }
975    
976                    return expandoTable;
977            }
978    
979            /**
980             * Returns the expando table where companyId = &#63; and classNameId = &#63; and name = &#63; or returns <code>null</code> if it could not be found. Uses the finder cache.
981             *
982             * @param companyId the company ID
983             * @param classNameId the class name ID
984             * @param name the name
985             * @return the matching expando table, or <code>null</code> if a matching expando table could not be found
986             * @throws SystemException if a system exception occurred
987             */
988            public ExpandoTable fetchByC_C_N(long companyId, long classNameId,
989                    String name) throws SystemException {
990                    return fetchByC_C_N(companyId, classNameId, name, true);
991            }
992    
993            /**
994             * Returns the expando table where companyId = &#63; and classNameId = &#63; and name = &#63; or returns <code>null</code> if it could not be found, optionally using the finder cache.
995             *
996             * @param companyId the company ID
997             * @param classNameId the class name ID
998             * @param name the name
999             * @param retrieveFromCache whether to use the finder cache
1000             * @return the matching expando table, or <code>null</code> if a matching expando table could not be found
1001             * @throws SystemException if a system exception occurred
1002             */
1003            public ExpandoTable fetchByC_C_N(long companyId, long classNameId,
1004                    String name, boolean retrieveFromCache) throws SystemException {
1005                    Object[] finderArgs = new Object[] { companyId, classNameId, name };
1006    
1007                    Object result = null;
1008    
1009                    if (retrieveFromCache) {
1010                            result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_C_N,
1011                                            finderArgs, this);
1012                    }
1013    
1014                    if (result instanceof ExpandoTable) {
1015                            ExpandoTable expandoTable = (ExpandoTable)result;
1016    
1017                            if ((companyId != expandoTable.getCompanyId()) ||
1018                                            (classNameId != expandoTable.getClassNameId()) ||
1019                                            !Validator.equals(name, expandoTable.getName())) {
1020                                    result = null;
1021                            }
1022                    }
1023    
1024                    if (result == null) {
1025                            StringBundler query = new StringBundler(4);
1026    
1027                            query.append(_SQL_SELECT_EXPANDOTABLE_WHERE);
1028    
1029                            query.append(_FINDER_COLUMN_C_C_N_COMPANYID_2);
1030    
1031                            query.append(_FINDER_COLUMN_C_C_N_CLASSNAMEID_2);
1032    
1033                            if (name == null) {
1034                                    query.append(_FINDER_COLUMN_C_C_N_NAME_1);
1035                            }
1036                            else {
1037                                    if (name.equals(StringPool.BLANK)) {
1038                                            query.append(_FINDER_COLUMN_C_C_N_NAME_3);
1039                                    }
1040                                    else {
1041                                            query.append(_FINDER_COLUMN_C_C_N_NAME_2);
1042                                    }
1043                            }
1044    
1045                            String sql = query.toString();
1046    
1047                            Session session = null;
1048    
1049                            try {
1050                                    session = openSession();
1051    
1052                                    Query q = session.createQuery(sql);
1053    
1054                                    QueryPos qPos = QueryPos.getInstance(q);
1055    
1056                                    qPos.add(companyId);
1057    
1058                                    qPos.add(classNameId);
1059    
1060                                    if (name != null) {
1061                                            qPos.add(name);
1062                                    }
1063    
1064                                    List<ExpandoTable> list = q.list();
1065    
1066                                    result = list;
1067    
1068                                    ExpandoTable expandoTable = null;
1069    
1070                                    if (list.isEmpty()) {
1071                                            FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
1072                                                    finderArgs, list);
1073                                    }
1074                                    else {
1075                                            expandoTable = list.get(0);
1076    
1077                                            cacheResult(expandoTable);
1078    
1079                                            if ((expandoTable.getCompanyId() != companyId) ||
1080                                                            (expandoTable.getClassNameId() != classNameId) ||
1081                                                            (expandoTable.getName() == null) ||
1082                                                            !expandoTable.getName().equals(name)) {
1083                                                    FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_C_N,
1084                                                            finderArgs, expandoTable);
1085                                            }
1086                                    }
1087    
1088                                    return expandoTable;
1089                            }
1090                            catch (Exception e) {
1091                                    throw processException(e);
1092                            }
1093                            finally {
1094                                    if (result == null) {
1095                                            FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_C_N,
1096                                                    finderArgs);
1097                                    }
1098    
1099                                    closeSession(session);
1100                            }
1101                    }
1102                    else {
1103                            if (result instanceof List<?>) {
1104                                    return null;
1105                            }
1106                            else {
1107                                    return (ExpandoTable)result;
1108                            }
1109                    }
1110            }
1111    
1112            /**
1113             * Returns all the expando tables.
1114             *
1115             * @return the expando tables
1116             * @throws SystemException if a system exception occurred
1117             */
1118            public List<ExpandoTable> findAll() throws SystemException {
1119                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
1120            }
1121    
1122            /**
1123             * Returns a range of all the expando tables.
1124             *
1125             * <p>
1126             * 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.
1127             * </p>
1128             *
1129             * @param start the lower bound of the range of expando tables
1130             * @param end the upper bound of the range of expando tables (not inclusive)
1131             * @return the range of expando tables
1132             * @throws SystemException if a system exception occurred
1133             */
1134            public List<ExpandoTable> findAll(int start, int end)
1135                    throws SystemException {
1136                    return findAll(start, end, null);
1137            }
1138    
1139            /**
1140             * Returns an ordered range of all the expando tables.
1141             *
1142             * <p>
1143             * 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.
1144             * </p>
1145             *
1146             * @param start the lower bound of the range of expando tables
1147             * @param end the upper bound of the range of expando tables (not inclusive)
1148             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
1149             * @return the ordered range of expando tables
1150             * @throws SystemException if a system exception occurred
1151             */
1152            public List<ExpandoTable> findAll(int start, int end,
1153                    OrderByComparator orderByComparator) throws SystemException {
1154                    FinderPath finderPath = null;
1155                    Object[] finderArgs = new Object[] { start, end, orderByComparator };
1156    
1157                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
1158                                    (orderByComparator == null)) {
1159                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
1160                            finderArgs = FINDER_ARGS_EMPTY;
1161                    }
1162                    else {
1163                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
1164                            finderArgs = new Object[] { start, end, orderByComparator };
1165                    }
1166    
1167                    List<ExpandoTable> list = (List<ExpandoTable>)FinderCacheUtil.getResult(finderPath,
1168                                    finderArgs, this);
1169    
1170                    if (list == null) {
1171                            StringBundler query = null;
1172                            String sql = null;
1173    
1174                            if (orderByComparator != null) {
1175                                    query = new StringBundler(2 +
1176                                                    (orderByComparator.getOrderByFields().length * 3));
1177    
1178                                    query.append(_SQL_SELECT_EXPANDOTABLE);
1179    
1180                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
1181                                            orderByComparator);
1182    
1183                                    sql = query.toString();
1184                            }
1185                            else {
1186                                    sql = _SQL_SELECT_EXPANDOTABLE;
1187                            }
1188    
1189                            Session session = null;
1190    
1191                            try {
1192                                    session = openSession();
1193    
1194                                    Query q = session.createQuery(sql);
1195    
1196                                    if (orderByComparator == null) {
1197                                            list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
1198                                                            start, end, false);
1199    
1200                                            Collections.sort(list);
1201                                    }
1202                                    else {
1203                                            list = (List<ExpandoTable>)QueryUtil.list(q, getDialect(),
1204                                                            start, end);
1205                                    }
1206                            }
1207                            catch (Exception e) {
1208                                    throw processException(e);
1209                            }
1210                            finally {
1211                                    if (list == null) {
1212                                            FinderCacheUtil.removeResult(finderPath, finderArgs);
1213                                    }
1214                                    else {
1215                                            cacheResult(list);
1216    
1217                                            FinderCacheUtil.putResult(finderPath, finderArgs, list);
1218                                    }
1219    
1220                                    closeSession(session);
1221                            }
1222                    }
1223    
1224                    return list;
1225            }
1226    
1227            /**
1228             * Removes all the expando tables where companyId = &#63; and classNameId = &#63; from the database.
1229             *
1230             * @param companyId the company ID
1231             * @param classNameId the class name ID
1232             * @throws SystemException if a system exception occurred
1233             */
1234            public void removeByC_C(long companyId, long classNameId)
1235                    throws SystemException {
1236                    for (ExpandoTable expandoTable : findByC_C(companyId, classNameId)) {
1237                            remove(expandoTable);
1238                    }
1239            }
1240    
1241            /**
1242             * Removes the expando table where companyId = &#63; and classNameId = &#63; and name = &#63; from the database.
1243             *
1244             * @param companyId the company ID
1245             * @param classNameId the class name ID
1246             * @param name the name
1247             * @return the expando table that was removed
1248             * @throws SystemException if a system exception occurred
1249             */
1250            public ExpandoTable removeByC_C_N(long companyId, long classNameId,
1251                    String name) throws NoSuchTableException, SystemException {
1252                    ExpandoTable expandoTable = findByC_C_N(companyId, classNameId, name);
1253    
1254                    return remove(expandoTable);
1255            }
1256    
1257            /**
1258             * Removes all the expando tables from the database.
1259             *
1260             * @throws SystemException if a system exception occurred
1261             */
1262            public void removeAll() throws SystemException {
1263                    for (ExpandoTable expandoTable : findAll()) {
1264                            remove(expandoTable);
1265                    }
1266            }
1267    
1268            /**
1269             * Returns the number of expando tables where companyId = &#63; and classNameId = &#63;.
1270             *
1271             * @param companyId the company ID
1272             * @param classNameId the class name ID
1273             * @return the number of matching expando tables
1274             * @throws SystemException if a system exception occurred
1275             */
1276            public int countByC_C(long companyId, long classNameId)
1277                    throws SystemException {
1278                    Object[] finderArgs = new Object[] { companyId, classNameId };
1279    
1280                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C,
1281                                    finderArgs, this);
1282    
1283                    if (count == null) {
1284                            StringBundler query = new StringBundler(3);
1285    
1286                            query.append(_SQL_COUNT_EXPANDOTABLE_WHERE);
1287    
1288                            query.append(_FINDER_COLUMN_C_C_COMPANYID_2);
1289    
1290                            query.append(_FINDER_COLUMN_C_C_CLASSNAMEID_2);
1291    
1292                            String sql = query.toString();
1293    
1294                            Session session = null;
1295    
1296                            try {
1297                                    session = openSession();
1298    
1299                                    Query q = session.createQuery(sql);
1300    
1301                                    QueryPos qPos = QueryPos.getInstance(q);
1302    
1303                                    qPos.add(companyId);
1304    
1305                                    qPos.add(classNameId);
1306    
1307                                    count = (Long)q.uniqueResult();
1308                            }
1309                            catch (Exception e) {
1310                                    throw processException(e);
1311                            }
1312                            finally {
1313                                    if (count == null) {
1314                                            count = Long.valueOf(0);
1315                                    }
1316    
1317                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C, finderArgs,
1318                                            count);
1319    
1320                                    closeSession(session);
1321                            }
1322                    }
1323    
1324                    return count.intValue();
1325            }
1326    
1327            /**
1328             * Returns the number of expando tables where companyId = &#63; and classNameId = &#63; and name = &#63;.
1329             *
1330             * @param companyId the company ID
1331             * @param classNameId the class name ID
1332             * @param name the name
1333             * @return the number of matching expando tables
1334             * @throws SystemException if a system exception occurred
1335             */
1336            public int countByC_C_N(long companyId, long classNameId, String name)
1337                    throws SystemException {
1338                    Object[] finderArgs = new Object[] { companyId, classNameId, name };
1339    
1340                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_C_N,
1341                                    finderArgs, this);
1342    
1343                    if (count == null) {
1344                            StringBundler query = new StringBundler(4);
1345    
1346                            query.append(_SQL_COUNT_EXPANDOTABLE_WHERE);
1347    
1348                            query.append(_FINDER_COLUMN_C_C_N_COMPANYID_2);
1349    
1350                            query.append(_FINDER_COLUMN_C_C_N_CLASSNAMEID_2);
1351    
1352                            if (name == null) {
1353                                    query.append(_FINDER_COLUMN_C_C_N_NAME_1);
1354                            }
1355                            else {
1356                                    if (name.equals(StringPool.BLANK)) {
1357                                            query.append(_FINDER_COLUMN_C_C_N_NAME_3);
1358                                    }
1359                                    else {
1360                                            query.append(_FINDER_COLUMN_C_C_N_NAME_2);
1361                                    }
1362                            }
1363    
1364                            String sql = query.toString();
1365    
1366                            Session session = null;
1367    
1368                            try {
1369                                    session = openSession();
1370    
1371                                    Query q = session.createQuery(sql);
1372    
1373                                    QueryPos qPos = QueryPos.getInstance(q);
1374    
1375                                    qPos.add(companyId);
1376    
1377                                    qPos.add(classNameId);
1378    
1379                                    if (name != null) {
1380                                            qPos.add(name);
1381                                    }
1382    
1383                                    count = (Long)q.uniqueResult();
1384                            }
1385                            catch (Exception e) {
1386                                    throw processException(e);
1387                            }
1388                            finally {
1389                                    if (count == null) {
1390                                            count = Long.valueOf(0);
1391                                    }
1392    
1393                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_C_N,
1394                                            finderArgs, count);
1395    
1396                                    closeSession(session);
1397                            }
1398                    }
1399    
1400                    return count.intValue();
1401            }
1402    
1403            /**
1404             * Returns the number of expando tables.
1405             *
1406             * @return the number of expando tables
1407             * @throws SystemException if a system exception occurred
1408             */
1409            public int countAll() throws SystemException {
1410                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1411                                    FINDER_ARGS_EMPTY, this);
1412    
1413                    if (count == null) {
1414                            Session session = null;
1415    
1416                            try {
1417                                    session = openSession();
1418    
1419                                    Query q = session.createQuery(_SQL_COUNT_EXPANDOTABLE);
1420    
1421                                    count = (Long)q.uniqueResult();
1422                            }
1423                            catch (Exception e) {
1424                                    throw processException(e);
1425                            }
1426                            finally {
1427                                    if (count == null) {
1428                                            count = Long.valueOf(0);
1429                                    }
1430    
1431                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1432                                            FINDER_ARGS_EMPTY, count);
1433    
1434                                    closeSession(session);
1435                            }
1436                    }
1437    
1438                    return count.intValue();
1439            }
1440    
1441            /**
1442             * Initializes the expando table persistence.
1443             */
1444            public void afterPropertiesSet() {
1445                    String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1446                                            com.liferay.portal.util.PropsUtil.get(
1447                                                    "value.object.listener.com.liferay.portlet.expando.model.ExpandoTable")));
1448    
1449                    if (listenerClassNames.length > 0) {
1450                            try {
1451                                    List<ModelListener<ExpandoTable>> listenersList = new ArrayList<ModelListener<ExpandoTable>>();
1452    
1453                                    for (String listenerClassName : listenerClassNames) {
1454                                            listenersList.add((ModelListener<ExpandoTable>)InstanceFactory.newInstance(
1455                                                            listenerClassName));
1456                                    }
1457    
1458                                    listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1459                            }
1460                            catch (Exception e) {
1461                                    _log.error(e);
1462                            }
1463                    }
1464            }
1465    
1466            public void destroy() {
1467                    EntityCacheUtil.removeCache(ExpandoTableImpl.class.getName());
1468                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1469                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1470            }
1471    
1472            @BeanReference(type = ExpandoColumnPersistence.class)
1473            protected ExpandoColumnPersistence expandoColumnPersistence;
1474            @BeanReference(type = ExpandoRowPersistence.class)
1475            protected ExpandoRowPersistence expandoRowPersistence;
1476            @BeanReference(type = ExpandoTablePersistence.class)
1477            protected ExpandoTablePersistence expandoTablePersistence;
1478            @BeanReference(type = ExpandoValuePersistence.class)
1479            protected ExpandoValuePersistence expandoValuePersistence;
1480            @BeanReference(type = UserPersistence.class)
1481            protected UserPersistence userPersistence;
1482            private static final String _SQL_SELECT_EXPANDOTABLE = "SELECT expandoTable FROM ExpandoTable expandoTable";
1483            private static final String _SQL_SELECT_EXPANDOTABLE_WHERE = "SELECT expandoTable FROM ExpandoTable expandoTable WHERE ";
1484            private static final String _SQL_COUNT_EXPANDOTABLE = "SELECT COUNT(expandoTable) FROM ExpandoTable expandoTable";
1485            private static final String _SQL_COUNT_EXPANDOTABLE_WHERE = "SELECT COUNT(expandoTable) FROM ExpandoTable expandoTable WHERE ";
1486            private static final String _FINDER_COLUMN_C_C_COMPANYID_2 = "expandoTable.companyId = ? AND ";
1487            private static final String _FINDER_COLUMN_C_C_CLASSNAMEID_2 = "expandoTable.classNameId = ?";
1488            private static final String _FINDER_COLUMN_C_C_N_COMPANYID_2 = "expandoTable.companyId = ? AND ";
1489            private static final String _FINDER_COLUMN_C_C_N_CLASSNAMEID_2 = "expandoTable.classNameId = ? AND ";
1490            private static final String _FINDER_COLUMN_C_C_N_NAME_1 = "expandoTable.name IS NULL";
1491            private static final String _FINDER_COLUMN_C_C_N_NAME_2 = "expandoTable.name = ?";
1492            private static final String _FINDER_COLUMN_C_C_N_NAME_3 = "(expandoTable.name IS NULL OR expandoTable.name = ?)";
1493            private static final String _ORDER_BY_ENTITY_ALIAS = "expandoTable.";
1494            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No ExpandoTable exists with the primary key ";
1495            private static final String _NO_SUCH_ENTITY_WITH_KEY = "No ExpandoTable exists with the key {";
1496            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1497            private static Log _log = LogFactoryUtil.getLog(ExpandoTablePersistenceImpl.class);
1498            private static ExpandoTable _nullExpandoTable = new ExpandoTableImpl() {
1499                            @Override
1500                            public Object clone() {
1501                                    return this;
1502                            }
1503    
1504                            @Override
1505                            public CacheModel<ExpandoTable> toCacheModel() {
1506                                    return _nullExpandoTableCacheModel;
1507                            }
1508                    };
1509    
1510            private static CacheModel<ExpandoTable> _nullExpandoTableCacheModel = new CacheModel<ExpandoTable>() {
1511                            public ExpandoTable toEntityModel() {
1512                                    return _nullExpandoTable;
1513                            }
1514                    };
1515    }