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