001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.service.persistence.impl;
016    
017    import aQute.bnd.annotation.ProviderType;
018    
019    import com.liferay.portal.NoSuchAccountException;
020    import com.liferay.portal.kernel.cache.CacheRegistryUtil;
021    import com.liferay.portal.kernel.dao.orm.EntityCacheUtil;
022    import com.liferay.portal.kernel.dao.orm.FinderCacheUtil;
023    import com.liferay.portal.kernel.dao.orm.FinderPath;
024    import com.liferay.portal.kernel.dao.orm.Query;
025    import com.liferay.portal.kernel.dao.orm.QueryUtil;
026    import com.liferay.portal.kernel.dao.orm.Session;
027    import com.liferay.portal.kernel.log.Log;
028    import com.liferay.portal.kernel.log.LogFactoryUtil;
029    import com.liferay.portal.kernel.util.OrderByComparator;
030    import com.liferay.portal.kernel.util.SetUtil;
031    import com.liferay.portal.kernel.util.StringBundler;
032    import com.liferay.portal.kernel.util.StringPool;
033    import com.liferay.portal.model.Account;
034    import com.liferay.portal.model.CacheModel;
035    import com.liferay.portal.model.MVCCModel;
036    import com.liferay.portal.model.impl.AccountImpl;
037    import com.liferay.portal.model.impl.AccountModelImpl;
038    import com.liferay.portal.service.persistence.AccountPersistence;
039    
040    import java.io.Serializable;
041    
042    import java.util.Collections;
043    import java.util.HashMap;
044    import java.util.HashSet;
045    import java.util.Iterator;
046    import java.util.List;
047    import java.util.Map;
048    import java.util.Set;
049    
050    /**
051     * The persistence implementation for the account service.
052     *
053     * <p>
054     * Caching information and settings can be found in <code>portal.properties</code>
055     * </p>
056     *
057     * @author Brian Wing Shun Chan
058     * @see AccountPersistence
059     * @see AccountUtil
060     * @generated
061     */
062    @ProviderType
063    public class AccountPersistenceImpl extends BasePersistenceImpl<Account>
064            implements AccountPersistence {
065            /*
066             * NOTE FOR DEVELOPERS:
067             *
068             * Never modify or reference this class directly. Always use {@link AccountUtil} to access the account persistence. Modify <code>service.xml</code> and rerun ServiceBuilder to regenerate this class.
069             */
070            public static final String FINDER_CLASS_NAME_ENTITY = AccountImpl.class.getName();
071            public static final String FINDER_CLASS_NAME_LIST_WITH_PAGINATION = FINDER_CLASS_NAME_ENTITY +
072                    ".List1";
073            public static final String FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION = FINDER_CLASS_NAME_ENTITY +
074                    ".List2";
075            public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(AccountModelImpl.ENTITY_CACHE_ENABLED,
076                            AccountModelImpl.FINDER_CACHE_ENABLED, AccountImpl.class,
077                            FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
078            public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(AccountModelImpl.ENTITY_CACHE_ENABLED,
079                            AccountModelImpl.FINDER_CACHE_ENABLED, AccountImpl.class,
080                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
081            public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(AccountModelImpl.ENTITY_CACHE_ENABLED,
082                            AccountModelImpl.FINDER_CACHE_ENABLED, Long.class,
083                            FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
084    
085            public AccountPersistenceImpl() {
086                    setModelClass(Account.class);
087            }
088    
089            /**
090             * Caches the account in the entity cache if it is enabled.
091             *
092             * @param account the account
093             */
094            @Override
095            public void cacheResult(Account account) {
096                    EntityCacheUtil.putResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
097                            AccountImpl.class, account.getPrimaryKey(), account);
098    
099                    account.resetOriginalValues();
100            }
101    
102            /**
103             * Caches the accounts in the entity cache if it is enabled.
104             *
105             * @param accounts the accounts
106             */
107            @Override
108            public void cacheResult(List<Account> accounts) {
109                    for (Account account : accounts) {
110                            if (EntityCacheUtil.getResult(
111                                                    AccountModelImpl.ENTITY_CACHE_ENABLED,
112                                                    AccountImpl.class, account.getPrimaryKey()) == null) {
113                                    cacheResult(account);
114                            }
115                            else {
116                                    account.resetOriginalValues();
117                            }
118                    }
119            }
120    
121            /**
122             * Clears the cache for all accounts.
123             *
124             * <p>
125             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
126             * </p>
127             */
128            @Override
129            public void clearCache() {
130                    if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
131                            CacheRegistryUtil.clear(AccountImpl.class.getName());
132                    }
133    
134                    EntityCacheUtil.clearCache(AccountImpl.class);
135    
136                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
137                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
138                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
139            }
140    
141            /**
142             * Clears the cache for the account.
143             *
144             * <p>
145             * The {@link com.liferay.portal.kernel.dao.orm.EntityCache} and {@link com.liferay.portal.kernel.dao.orm.FinderCache} are both cleared by this method.
146             * </p>
147             */
148            @Override
149            public void clearCache(Account account) {
150                    EntityCacheUtil.removeResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
151                            AccountImpl.class, account.getPrimaryKey());
152    
153                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
154                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
155            }
156    
157            @Override
158            public void clearCache(List<Account> accounts) {
159                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
160                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
161    
162                    for (Account account : accounts) {
163                            EntityCacheUtil.removeResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
164                                    AccountImpl.class, account.getPrimaryKey());
165                    }
166            }
167    
168            /**
169             * Creates a new account with the primary key. Does not add the account to the database.
170             *
171             * @param accountId the primary key for the new account
172             * @return the new account
173             */
174            @Override
175            public Account create(long accountId) {
176                    Account account = new AccountImpl();
177    
178                    account.setNew(true);
179                    account.setPrimaryKey(accountId);
180    
181                    return account;
182            }
183    
184            /**
185             * Removes the account with the primary key from the database. Also notifies the appropriate model listeners.
186             *
187             * @param accountId the primary key of the account
188             * @return the account that was removed
189             * @throws com.liferay.portal.NoSuchAccountException if a account with the primary key could not be found
190             */
191            @Override
192            public Account remove(long accountId) throws NoSuchAccountException {
193                    return remove((Serializable)accountId);
194            }
195    
196            /**
197             * Removes the account with the primary key from the database. Also notifies the appropriate model listeners.
198             *
199             * @param primaryKey the primary key of the account
200             * @return the account that was removed
201             * @throws com.liferay.portal.NoSuchAccountException if a account with the primary key could not be found
202             */
203            @Override
204            public Account remove(Serializable primaryKey)
205                    throws NoSuchAccountException {
206                    Session session = null;
207    
208                    try {
209                            session = openSession();
210    
211                            Account account = (Account)session.get(AccountImpl.class, primaryKey);
212    
213                            if (account == null) {
214                                    if (_log.isWarnEnabled()) {
215                                            _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
216                                    }
217    
218                                    throw new NoSuchAccountException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
219                                            primaryKey);
220                            }
221    
222                            return remove(account);
223                    }
224                    catch (NoSuchAccountException nsee) {
225                            throw nsee;
226                    }
227                    catch (Exception e) {
228                            throw processException(e);
229                    }
230                    finally {
231                            closeSession(session);
232                    }
233            }
234    
235            @Override
236            protected Account removeImpl(Account account) {
237                    account = toUnwrappedModel(account);
238    
239                    Session session = null;
240    
241                    try {
242                            session = openSession();
243    
244                            if (!session.contains(account)) {
245                                    account = (Account)session.get(AccountImpl.class,
246                                                    account.getPrimaryKeyObj());
247                            }
248    
249                            if (account != null) {
250                                    session.delete(account);
251                            }
252                    }
253                    catch (Exception e) {
254                            throw processException(e);
255                    }
256                    finally {
257                            closeSession(session);
258                    }
259    
260                    if (account != null) {
261                            clearCache(account);
262                    }
263    
264                    return account;
265            }
266    
267            @Override
268            public Account updateImpl(com.liferay.portal.model.Account account) {
269                    account = toUnwrappedModel(account);
270    
271                    boolean isNew = account.isNew();
272    
273                    Session session = null;
274    
275                    try {
276                            session = openSession();
277    
278                            if (account.isNew()) {
279                                    session.save(account);
280    
281                                    account.setNew(false);
282                            }
283                            else {
284                                    session.merge(account);
285                            }
286                    }
287                    catch (Exception e) {
288                            throw processException(e);
289                    }
290                    finally {
291                            closeSession(session);
292                    }
293    
294                    FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
295    
296                    if (isNew) {
297                            FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
298                    }
299    
300                    EntityCacheUtil.putResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
301                            AccountImpl.class, account.getPrimaryKey(), account, false);
302    
303                    account.resetOriginalValues();
304    
305                    return account;
306            }
307    
308            protected Account toUnwrappedModel(Account account) {
309                    if (account instanceof AccountImpl) {
310                            return account;
311                    }
312    
313                    AccountImpl accountImpl = new AccountImpl();
314    
315                    accountImpl.setNew(account.isNew());
316                    accountImpl.setPrimaryKey(account.getPrimaryKey());
317    
318                    accountImpl.setMvccVersion(account.getMvccVersion());
319                    accountImpl.setAccountId(account.getAccountId());
320                    accountImpl.setCompanyId(account.getCompanyId());
321                    accountImpl.setUserId(account.getUserId());
322                    accountImpl.setUserName(account.getUserName());
323                    accountImpl.setCreateDate(account.getCreateDate());
324                    accountImpl.setModifiedDate(account.getModifiedDate());
325                    accountImpl.setParentAccountId(account.getParentAccountId());
326                    accountImpl.setName(account.getName());
327                    accountImpl.setLegalName(account.getLegalName());
328                    accountImpl.setLegalId(account.getLegalId());
329                    accountImpl.setLegalType(account.getLegalType());
330                    accountImpl.setSicCode(account.getSicCode());
331                    accountImpl.setTickerSymbol(account.getTickerSymbol());
332                    accountImpl.setIndustry(account.getIndustry());
333                    accountImpl.setType(account.getType());
334                    accountImpl.setSize(account.getSize());
335    
336                    return accountImpl;
337            }
338    
339            /**
340             * Returns the account with the primary key or throws a {@link com.liferay.portal.NoSuchModelException} if it could not be found.
341             *
342             * @param primaryKey the primary key of the account
343             * @return the account
344             * @throws com.liferay.portal.NoSuchAccountException if a account with the primary key could not be found
345             */
346            @Override
347            public Account findByPrimaryKey(Serializable primaryKey)
348                    throws NoSuchAccountException {
349                    Account account = fetchByPrimaryKey(primaryKey);
350    
351                    if (account == null) {
352                            if (_log.isWarnEnabled()) {
353                                    _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
354                            }
355    
356                            throw new NoSuchAccountException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
357                                    primaryKey);
358                    }
359    
360                    return account;
361            }
362    
363            /**
364             * Returns the account with the primary key or throws a {@link com.liferay.portal.NoSuchAccountException} if it could not be found.
365             *
366             * @param accountId the primary key of the account
367             * @return the account
368             * @throws com.liferay.portal.NoSuchAccountException if a account with the primary key could not be found
369             */
370            @Override
371            public Account findByPrimaryKey(long accountId)
372                    throws NoSuchAccountException {
373                    return findByPrimaryKey((Serializable)accountId);
374            }
375    
376            /**
377             * Returns the account with the primary key or returns <code>null</code> if it could not be found.
378             *
379             * @param primaryKey the primary key of the account
380             * @return the account, or <code>null</code> if a account with the primary key could not be found
381             */
382            @Override
383            public Account fetchByPrimaryKey(Serializable primaryKey) {
384                    Account account = (Account)EntityCacheUtil.getResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
385                                    AccountImpl.class, primaryKey);
386    
387                    if (account == _nullAccount) {
388                            return null;
389                    }
390    
391                    if (account == null) {
392                            Session session = null;
393    
394                            try {
395                                    session = openSession();
396    
397                                    account = (Account)session.get(AccountImpl.class, primaryKey);
398    
399                                    if (account != null) {
400                                            cacheResult(account);
401                                    }
402                                    else {
403                                            EntityCacheUtil.putResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
404                                                    AccountImpl.class, primaryKey, _nullAccount);
405                                    }
406                            }
407                            catch (Exception e) {
408                                    EntityCacheUtil.removeResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
409                                            AccountImpl.class, primaryKey);
410    
411                                    throw processException(e);
412                            }
413                            finally {
414                                    closeSession(session);
415                            }
416                    }
417    
418                    return account;
419            }
420    
421            /**
422             * Returns the account with the primary key or returns <code>null</code> if it could not be found.
423             *
424             * @param accountId the primary key of the account
425             * @return the account, or <code>null</code> if a account with the primary key could not be found
426             */
427            @Override
428            public Account fetchByPrimaryKey(long accountId) {
429                    return fetchByPrimaryKey((Serializable)accountId);
430            }
431    
432            @Override
433            public Map<Serializable, Account> fetchByPrimaryKeys(
434                    Set<Serializable> primaryKeys) {
435                    if (primaryKeys.isEmpty()) {
436                            return Collections.emptyMap();
437                    }
438    
439                    Map<Serializable, Account> map = new HashMap<Serializable, Account>();
440    
441                    if (primaryKeys.size() == 1) {
442                            Iterator<Serializable> iterator = primaryKeys.iterator();
443    
444                            Serializable primaryKey = iterator.next();
445    
446                            Account account = fetchByPrimaryKey(primaryKey);
447    
448                            if (account != null) {
449                                    map.put(primaryKey, account);
450                            }
451    
452                            return map;
453                    }
454    
455                    Set<Serializable> uncachedPrimaryKeys = null;
456    
457                    for (Serializable primaryKey : primaryKeys) {
458                            Account account = (Account)EntityCacheUtil.getResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
459                                            AccountImpl.class, primaryKey);
460    
461                            if (account == null) {
462                                    if (uncachedPrimaryKeys == null) {
463                                            uncachedPrimaryKeys = new HashSet<Serializable>();
464                                    }
465    
466                                    uncachedPrimaryKeys.add(primaryKey);
467                            }
468                            else {
469                                    map.put(primaryKey, account);
470                            }
471                    }
472    
473                    if (uncachedPrimaryKeys == null) {
474                            return map;
475                    }
476    
477                    StringBundler query = new StringBundler((uncachedPrimaryKeys.size() * 2) +
478                                    1);
479    
480                    query.append(_SQL_SELECT_ACCOUNT_WHERE_PKS_IN);
481    
482                    for (Serializable primaryKey : uncachedPrimaryKeys) {
483                            query.append(String.valueOf(primaryKey));
484    
485                            query.append(StringPool.COMMA);
486                    }
487    
488                    query.setIndex(query.index() - 1);
489    
490                    query.append(StringPool.CLOSE_PARENTHESIS);
491    
492                    String sql = query.toString();
493    
494                    Session session = null;
495    
496                    try {
497                            session = openSession();
498    
499                            Query q = session.createQuery(sql);
500    
501                            for (Account account : (List<Account>)q.list()) {
502                                    map.put(account.getPrimaryKeyObj(), account);
503    
504                                    cacheResult(account);
505    
506                                    uncachedPrimaryKeys.remove(account.getPrimaryKeyObj());
507                            }
508    
509                            for (Serializable primaryKey : uncachedPrimaryKeys) {
510                                    EntityCacheUtil.putResult(AccountModelImpl.ENTITY_CACHE_ENABLED,
511                                            AccountImpl.class, primaryKey, _nullAccount);
512                            }
513                    }
514                    catch (Exception e) {
515                            throw processException(e);
516                    }
517                    finally {
518                            closeSession(session);
519                    }
520    
521                    return map;
522            }
523    
524            /**
525             * Returns all the accounts.
526             *
527             * @return the accounts
528             */
529            @Override
530            public List<Account> findAll() {
531                    return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
532            }
533    
534            /**
535             * Returns a range of all the accounts.
536             *
537             * <p>
538             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.AccountModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
539             * </p>
540             *
541             * @param start the lower bound of the range of accounts
542             * @param end the upper bound of the range of accounts (not inclusive)
543             * @return the range of accounts
544             */
545            @Override
546            public List<Account> findAll(int start, int end) {
547                    return findAll(start, end, null);
548            }
549    
550            /**
551             * Returns an ordered range of all the accounts.
552             *
553             * <p>
554             * Useful when paginating results. Returns a maximum of <code>end - start</code> instances. <code>start</code> and <code>end</code> are not primary keys, they are indexes in the result set. Thus, <code>0</code> refers to the first result in the set. Setting both <code>start</code> and <code>end</code> to {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS} will return the full result set. If <code>orderByComparator</code> is specified, then the query will include the given ORDER BY logic. If <code>orderByComparator</code> is absent and pagination is required (<code>start</code> and <code>end</code> are not {@link com.liferay.portal.kernel.dao.orm.QueryUtil#ALL_POS}), then the query will include the default ORDER BY logic from {@link com.liferay.portal.model.impl.AccountModelImpl}. If both <code>orderByComparator</code> and pagination are absent, for performance reasons, the query will not have an ORDER BY clause and the returned result set will be sorted on by the primary key in an ascending order.
555             * </p>
556             *
557             * @param start the lower bound of the range of accounts
558             * @param end the upper bound of the range of accounts (not inclusive)
559             * @param orderByComparator the comparator to order the results by (optionally <code>null</code>)
560             * @return the ordered range of accounts
561             */
562            @Override
563            public List<Account> findAll(int start, int end,
564                    OrderByComparator<Account> orderByComparator) {
565                    boolean pagination = true;
566                    FinderPath finderPath = null;
567                    Object[] finderArgs = null;
568    
569                    if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
570                                    (orderByComparator == null)) {
571                            pagination = false;
572                            finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
573                            finderArgs = FINDER_ARGS_EMPTY;
574                    }
575                    else {
576                            finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
577                            finderArgs = new Object[] { start, end, orderByComparator };
578                    }
579    
580                    List<Account> list = (List<Account>)FinderCacheUtil.getResult(finderPath,
581                                    finderArgs, this);
582    
583                    if (list == null) {
584                            StringBundler query = null;
585                            String sql = null;
586    
587                            if (orderByComparator != null) {
588                                    query = new StringBundler(2 +
589                                                    (orderByComparator.getOrderByFields().length * 3));
590    
591                                    query.append(_SQL_SELECT_ACCOUNT);
592    
593                                    appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
594                                            orderByComparator);
595    
596                                    sql = query.toString();
597                            }
598                            else {
599                                    sql = _SQL_SELECT_ACCOUNT;
600    
601                                    if (pagination) {
602                                            sql = sql.concat(AccountModelImpl.ORDER_BY_JPQL);
603                                    }
604                            }
605    
606                            Session session = null;
607    
608                            try {
609                                    session = openSession();
610    
611                                    Query q = session.createQuery(sql);
612    
613                                    if (!pagination) {
614                                            list = (List<Account>)QueryUtil.list(q, getDialect(),
615                                                            start, end, false);
616    
617                                            Collections.sort(list);
618    
619                                            list = Collections.unmodifiableList(list);
620                                    }
621                                    else {
622                                            list = (List<Account>)QueryUtil.list(q, getDialect(),
623                                                            start, end);
624                                    }
625    
626                                    cacheResult(list);
627    
628                                    FinderCacheUtil.putResult(finderPath, finderArgs, list);
629                            }
630                            catch (Exception e) {
631                                    FinderCacheUtil.removeResult(finderPath, finderArgs);
632    
633                                    throw processException(e);
634                            }
635                            finally {
636                                    closeSession(session);
637                            }
638                    }
639    
640                    return list;
641            }
642    
643            /**
644             * Removes all the accounts from the database.
645             *
646             */
647            @Override
648            public void removeAll() {
649                    for (Account account : findAll()) {
650                            remove(account);
651                    }
652            }
653    
654            /**
655             * Returns the number of accounts.
656             *
657             * @return the number of accounts
658             */
659            @Override
660            public int countAll() {
661                    Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
662                                    FINDER_ARGS_EMPTY, this);
663    
664                    if (count == null) {
665                            Session session = null;
666    
667                            try {
668                                    session = openSession();
669    
670                                    Query q = session.createQuery(_SQL_COUNT_ACCOUNT);
671    
672                                    count = (Long)q.uniqueResult();
673    
674                                    FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
675                                            FINDER_ARGS_EMPTY, count);
676                            }
677                            catch (Exception e) {
678                                    FinderCacheUtil.removeResult(FINDER_PATH_COUNT_ALL,
679                                            FINDER_ARGS_EMPTY);
680    
681                                    throw processException(e);
682                            }
683                            finally {
684                                    closeSession(session);
685                            }
686                    }
687    
688                    return count.intValue();
689            }
690    
691            @Override
692            protected Set<String> getBadColumnNames() {
693                    return _badColumnNames;
694            }
695    
696            /**
697             * Initializes the account persistence.
698             */
699            public void afterPropertiesSet() {
700            }
701    
702            public void destroy() {
703                    EntityCacheUtil.removeCache(AccountImpl.class.getName());
704                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
705                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
706                    FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
707            }
708    
709            private static final String _SQL_SELECT_ACCOUNT = "SELECT account FROM Account account";
710            private static final String _SQL_SELECT_ACCOUNT_WHERE_PKS_IN = "SELECT account FROM Account account WHERE accountId IN (";
711            private static final String _SQL_COUNT_ACCOUNT = "SELECT COUNT(account) FROM Account account";
712            private static final String _ORDER_BY_ENTITY_ALIAS = "account.";
713            private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No Account exists with the primary key ";
714            private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
715            private static final Log _log = LogFactoryUtil.getLog(AccountPersistenceImpl.class);
716            private static final Set<String> _badColumnNames = SetUtil.fromArray(new String[] {
717                                    "type", "size"
718                            });
719            private static final Account _nullAccount = new AccountImpl() {
720                            @Override
721                            public Object clone() {
722                                    return this;
723                            }
724    
725                            @Override
726                            public CacheModel<Account> toCacheModel() {
727                                    return _nullAccountCacheModel;
728                            }
729                    };
730    
731            private static final CacheModel<Account> _nullAccountCacheModel = new NullCacheModel();
732    
733            private static class NullCacheModel implements CacheModel<Account>,
734                    MVCCModel {
735                    @Override
736                    public long getMvccVersion() {
737                            return -1;
738                    }
739    
740                    @Override
741                    public void setMvccVersion(long mvccVersion) {
742                    }
743    
744                    @Override
745                    public Account toEntityModel() {
746                            return _nullAccount;
747                    }
748            }
749    }