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