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