001
014
015 package com.liferay.portal.service.persistence;
016
017 import com.liferay.portal.NoSuchModelException;
018 import com.liferay.portal.NoSuchVirtualHostException;
019 import com.liferay.portal.kernel.bean.BeanReference;
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.QueryPos;
026 import com.liferay.portal.kernel.dao.orm.QueryUtil;
027 import com.liferay.portal.kernel.dao.orm.Session;
028 import com.liferay.portal.kernel.exception.SystemException;
029 import com.liferay.portal.kernel.log.Log;
030 import com.liferay.portal.kernel.log.LogFactoryUtil;
031 import com.liferay.portal.kernel.util.GetterUtil;
032 import com.liferay.portal.kernel.util.InstanceFactory;
033 import com.liferay.portal.kernel.util.OrderByComparator;
034 import com.liferay.portal.kernel.util.StringBundler;
035 import com.liferay.portal.kernel.util.StringPool;
036 import com.liferay.portal.kernel.util.StringUtil;
037 import com.liferay.portal.kernel.util.Validator;
038 import com.liferay.portal.model.CacheModel;
039 import com.liferay.portal.model.ModelListener;
040 import com.liferay.portal.model.VirtualHost;
041 import com.liferay.portal.model.impl.VirtualHostImpl;
042 import com.liferay.portal.model.impl.VirtualHostModelImpl;
043 import com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
044
045 import java.io.Serializable;
046
047 import java.util.ArrayList;
048 import java.util.Collections;
049 import java.util.List;
050
051
063 public class VirtualHostPersistenceImpl extends BasePersistenceImpl<VirtualHost>
064 implements VirtualHostPersistence {
065
070 public static final String FINDER_CLASS_NAME_ENTITY = VirtualHostImpl.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_FETCH_BY_HOSTNAME = new FinderPath(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
076 VirtualHostModelImpl.FINDER_CACHE_ENABLED, VirtualHostImpl.class,
077 FINDER_CLASS_NAME_ENTITY, "fetchByHostname",
078 new String[] { String.class.getName() },
079 VirtualHostModelImpl.HOSTNAME_COLUMN_BITMASK);
080 public static final FinderPath FINDER_PATH_COUNT_BY_HOSTNAME = new FinderPath(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
081 VirtualHostModelImpl.FINDER_CACHE_ENABLED, Long.class,
082 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByHostname",
083 new String[] { String.class.getName() });
084 public static final FinderPath FINDER_PATH_FETCH_BY_C_L = new FinderPath(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
085 VirtualHostModelImpl.FINDER_CACHE_ENABLED, VirtualHostImpl.class,
086 FINDER_CLASS_NAME_ENTITY, "fetchByC_L",
087 new String[] { Long.class.getName(), Long.class.getName() },
088 VirtualHostModelImpl.COMPANYID_COLUMN_BITMASK |
089 VirtualHostModelImpl.LAYOUTSETID_COLUMN_BITMASK);
090 public static final FinderPath FINDER_PATH_COUNT_BY_C_L = new FinderPath(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
091 VirtualHostModelImpl.FINDER_CACHE_ENABLED, Long.class,
092 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countByC_L",
093 new String[] { Long.class.getName(), Long.class.getName() });
094 public static final FinderPath FINDER_PATH_WITH_PAGINATION_FIND_ALL = new FinderPath(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
095 VirtualHostModelImpl.FINDER_CACHE_ENABLED, VirtualHostImpl.class,
096 FINDER_CLASS_NAME_LIST_WITH_PAGINATION, "findAll", new String[0]);
097 public static final FinderPath FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL = new FinderPath(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
098 VirtualHostModelImpl.FINDER_CACHE_ENABLED, VirtualHostImpl.class,
099 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "findAll", new String[0]);
100 public static final FinderPath FINDER_PATH_COUNT_ALL = new FinderPath(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
101 VirtualHostModelImpl.FINDER_CACHE_ENABLED, Long.class,
102 FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION, "countAll", new String[0]);
103
104
109 public void cacheResult(VirtualHost virtualHost) {
110 EntityCacheUtil.putResult(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
111 VirtualHostImpl.class, virtualHost.getPrimaryKey(), virtualHost);
112
113 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_HOSTNAME,
114 new Object[] { virtualHost.getHostname() }, virtualHost);
115
116 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_L,
117 new Object[] {
118 Long.valueOf(virtualHost.getCompanyId()),
119 Long.valueOf(virtualHost.getLayoutSetId())
120 }, virtualHost);
121
122 virtualHost.resetOriginalValues();
123 }
124
125
130 public void cacheResult(List<VirtualHost> virtualHosts) {
131 for (VirtualHost virtualHost : virtualHosts) {
132 if (EntityCacheUtil.getResult(
133 VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
134 VirtualHostImpl.class, virtualHost.getPrimaryKey()) == null) {
135 cacheResult(virtualHost);
136 }
137 else {
138 virtualHost.resetOriginalValues();
139 }
140 }
141 }
142
143
150 @Override
151 public void clearCache() {
152 if (_HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
153 CacheRegistryUtil.clear(VirtualHostImpl.class.getName());
154 }
155
156 EntityCacheUtil.clearCache(VirtualHostImpl.class.getName());
157
158 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_ENTITY);
159 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
160 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
161 }
162
163
170 @Override
171 public void clearCache(VirtualHost virtualHost) {
172 EntityCacheUtil.removeResult(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
173 VirtualHostImpl.class, virtualHost.getPrimaryKey());
174
175 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
176 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
177
178 clearUniqueFindersCache(virtualHost);
179 }
180
181 @Override
182 public void clearCache(List<VirtualHost> virtualHosts) {
183 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
184 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
185
186 for (VirtualHost virtualHost : virtualHosts) {
187 EntityCacheUtil.removeResult(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
188 VirtualHostImpl.class, virtualHost.getPrimaryKey());
189
190 clearUniqueFindersCache(virtualHost);
191 }
192 }
193
194 protected void clearUniqueFindersCache(VirtualHost virtualHost) {
195 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_HOSTNAME,
196 new Object[] { virtualHost.getHostname() });
197
198 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_L,
199 new Object[] {
200 Long.valueOf(virtualHost.getCompanyId()),
201 Long.valueOf(virtualHost.getLayoutSetId())
202 });
203 }
204
205
211 public VirtualHost create(long virtualHostId) {
212 VirtualHost virtualHost = new VirtualHostImpl();
213
214 virtualHost.setNew(true);
215 virtualHost.setPrimaryKey(virtualHostId);
216
217 return virtualHost;
218 }
219
220
228 public VirtualHost remove(long virtualHostId)
229 throws NoSuchVirtualHostException, SystemException {
230 return remove(Long.valueOf(virtualHostId));
231 }
232
233
241 @Override
242 public VirtualHost remove(Serializable primaryKey)
243 throws NoSuchVirtualHostException, SystemException {
244 Session session = null;
245
246 try {
247 session = openSession();
248
249 VirtualHost virtualHost = (VirtualHost)session.get(VirtualHostImpl.class,
250 primaryKey);
251
252 if (virtualHost == null) {
253 if (_log.isWarnEnabled()) {
254 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + primaryKey);
255 }
256
257 throw new NoSuchVirtualHostException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
258 primaryKey);
259 }
260
261 return remove(virtualHost);
262 }
263 catch (NoSuchVirtualHostException nsee) {
264 throw nsee;
265 }
266 catch (Exception e) {
267 throw processException(e);
268 }
269 finally {
270 closeSession(session);
271 }
272 }
273
274 @Override
275 protected VirtualHost removeImpl(VirtualHost virtualHost)
276 throws SystemException {
277 virtualHost = toUnwrappedModel(virtualHost);
278
279 Session session = null;
280
281 try {
282 session = openSession();
283
284 BatchSessionUtil.delete(session, virtualHost);
285 }
286 catch (Exception e) {
287 throw processException(e);
288 }
289 finally {
290 closeSession(session);
291 }
292
293 clearCache(virtualHost);
294
295 return virtualHost;
296 }
297
298 @Override
299 public VirtualHost updateImpl(
300 com.liferay.portal.model.VirtualHost virtualHost, boolean merge)
301 throws SystemException {
302 virtualHost = toUnwrappedModel(virtualHost);
303
304 boolean isNew = virtualHost.isNew();
305
306 VirtualHostModelImpl virtualHostModelImpl = (VirtualHostModelImpl)virtualHost;
307
308 Session session = null;
309
310 try {
311 session = openSession();
312
313 BatchSessionUtil.update(session, virtualHost, merge);
314
315 virtualHost.setNew(false);
316 }
317 catch (Exception e) {
318 throw processException(e);
319 }
320 finally {
321 closeSession(session);
322 }
323
324 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
325
326 if (isNew || !VirtualHostModelImpl.COLUMN_BITMASK_ENABLED) {
327 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
328 }
329
330 EntityCacheUtil.putResult(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
331 VirtualHostImpl.class, virtualHost.getPrimaryKey(), virtualHost);
332
333 if (isNew) {
334 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_HOSTNAME,
335 new Object[] { virtualHost.getHostname() }, virtualHost);
336
337 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_L,
338 new Object[] {
339 Long.valueOf(virtualHost.getCompanyId()),
340 Long.valueOf(virtualHost.getLayoutSetId())
341 }, virtualHost);
342 }
343 else {
344 if ((virtualHostModelImpl.getColumnBitmask() &
345 FINDER_PATH_FETCH_BY_HOSTNAME.getColumnBitmask()) != 0) {
346 Object[] args = new Object[] {
347 virtualHostModelImpl.getOriginalHostname()
348 };
349
350 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_HOSTNAME, args);
351 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_HOSTNAME, args);
352
353 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_HOSTNAME,
354 new Object[] { virtualHost.getHostname() }, virtualHost);
355 }
356
357 if ((virtualHostModelImpl.getColumnBitmask() &
358 FINDER_PATH_FETCH_BY_C_L.getColumnBitmask()) != 0) {
359 Object[] args = new Object[] {
360 Long.valueOf(virtualHostModelImpl.getOriginalCompanyId()),
361 Long.valueOf(virtualHostModelImpl.getOriginalLayoutSetId())
362 };
363
364 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_L, args);
365 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_L, args);
366
367 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_L,
368 new Object[] {
369 Long.valueOf(virtualHost.getCompanyId()),
370 Long.valueOf(virtualHost.getLayoutSetId())
371 }, virtualHost);
372 }
373 }
374
375 return virtualHost;
376 }
377
378 protected VirtualHost toUnwrappedModel(VirtualHost virtualHost) {
379 if (virtualHost instanceof VirtualHostImpl) {
380 return virtualHost;
381 }
382
383 VirtualHostImpl virtualHostImpl = new VirtualHostImpl();
384
385 virtualHostImpl.setNew(virtualHost.isNew());
386 virtualHostImpl.setPrimaryKey(virtualHost.getPrimaryKey());
387
388 virtualHostImpl.setVirtualHostId(virtualHost.getVirtualHostId());
389 virtualHostImpl.setCompanyId(virtualHost.getCompanyId());
390 virtualHostImpl.setLayoutSetId(virtualHost.getLayoutSetId());
391 virtualHostImpl.setHostname(virtualHost.getHostname());
392
393 return virtualHostImpl;
394 }
395
396
404 @Override
405 public VirtualHost findByPrimaryKey(Serializable primaryKey)
406 throws NoSuchModelException, SystemException {
407 return findByPrimaryKey(((Long)primaryKey).longValue());
408 }
409
410
418 public VirtualHost findByPrimaryKey(long virtualHostId)
419 throws NoSuchVirtualHostException, SystemException {
420 VirtualHost virtualHost = fetchByPrimaryKey(virtualHostId);
421
422 if (virtualHost == null) {
423 if (_log.isWarnEnabled()) {
424 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + virtualHostId);
425 }
426
427 throw new NoSuchVirtualHostException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
428 virtualHostId);
429 }
430
431 return virtualHost;
432 }
433
434
441 @Override
442 public VirtualHost fetchByPrimaryKey(Serializable primaryKey)
443 throws SystemException {
444 return fetchByPrimaryKey(((Long)primaryKey).longValue());
445 }
446
447
454 public VirtualHost fetchByPrimaryKey(long virtualHostId)
455 throws SystemException {
456 VirtualHost virtualHost = (VirtualHost)EntityCacheUtil.getResult(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
457 VirtualHostImpl.class, virtualHostId);
458
459 if (virtualHost == _nullVirtualHost) {
460 return null;
461 }
462
463 if (virtualHost == null) {
464 Session session = null;
465
466 boolean hasException = false;
467
468 try {
469 session = openSession();
470
471 virtualHost = (VirtualHost)session.get(VirtualHostImpl.class,
472 Long.valueOf(virtualHostId));
473 }
474 catch (Exception e) {
475 hasException = true;
476
477 throw processException(e);
478 }
479 finally {
480 if (virtualHost != null) {
481 cacheResult(virtualHost);
482 }
483 else if (!hasException) {
484 EntityCacheUtil.putResult(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
485 VirtualHostImpl.class, virtualHostId, _nullVirtualHost);
486 }
487
488 closeSession(session);
489 }
490 }
491
492 return virtualHost;
493 }
494
495
503 public VirtualHost findByHostname(String hostname)
504 throws NoSuchVirtualHostException, SystemException {
505 VirtualHost virtualHost = fetchByHostname(hostname);
506
507 if (virtualHost == null) {
508 StringBundler msg = new StringBundler(4);
509
510 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
511
512 msg.append("hostname=");
513 msg.append(hostname);
514
515 msg.append(StringPool.CLOSE_CURLY_BRACE);
516
517 if (_log.isWarnEnabled()) {
518 _log.warn(msg.toString());
519 }
520
521 throw new NoSuchVirtualHostException(msg.toString());
522 }
523
524 return virtualHost;
525 }
526
527
534 public VirtualHost fetchByHostname(String hostname)
535 throws SystemException {
536 return fetchByHostname(hostname, true);
537 }
538
539
547 public VirtualHost fetchByHostname(String hostname,
548 boolean retrieveFromCache) throws SystemException {
549 Object[] finderArgs = new Object[] { hostname };
550
551 Object result = null;
552
553 if (retrieveFromCache) {
554 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_HOSTNAME,
555 finderArgs, this);
556 }
557
558 if (result instanceof VirtualHost) {
559 VirtualHost virtualHost = (VirtualHost)result;
560
561 if (!Validator.equals(hostname, virtualHost.getHostname())) {
562 result = null;
563 }
564 }
565
566 if (result == null) {
567 StringBundler query = new StringBundler(2);
568
569 query.append(_SQL_SELECT_VIRTUALHOST_WHERE);
570
571 if (hostname == null) {
572 query.append(_FINDER_COLUMN_HOSTNAME_HOSTNAME_1);
573 }
574 else {
575 if (hostname.equals(StringPool.BLANK)) {
576 query.append(_FINDER_COLUMN_HOSTNAME_HOSTNAME_3);
577 }
578 else {
579 query.append(_FINDER_COLUMN_HOSTNAME_HOSTNAME_2);
580 }
581 }
582
583 String sql = query.toString();
584
585 Session session = null;
586
587 try {
588 session = openSession();
589
590 Query q = session.createQuery(sql);
591
592 QueryPos qPos = QueryPos.getInstance(q);
593
594 if (hostname != null) {
595 qPos.add(hostname);
596 }
597
598 List<VirtualHost> list = q.list();
599
600 result = list;
601
602 VirtualHost virtualHost = null;
603
604 if (list.isEmpty()) {
605 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_HOSTNAME,
606 finderArgs, list);
607 }
608 else {
609 virtualHost = list.get(0);
610
611 cacheResult(virtualHost);
612
613 if ((virtualHost.getHostname() == null) ||
614 !virtualHost.getHostname().equals(hostname)) {
615 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_HOSTNAME,
616 finderArgs, virtualHost);
617 }
618 }
619
620 return virtualHost;
621 }
622 catch (Exception e) {
623 throw processException(e);
624 }
625 finally {
626 if (result == null) {
627 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_HOSTNAME,
628 finderArgs);
629 }
630
631 closeSession(session);
632 }
633 }
634 else {
635 if (result instanceof List<?>) {
636 return null;
637 }
638 else {
639 return (VirtualHost)result;
640 }
641 }
642 }
643
644
653 public VirtualHost findByC_L(long companyId, long layoutSetId)
654 throws NoSuchVirtualHostException, SystemException {
655 VirtualHost virtualHost = fetchByC_L(companyId, layoutSetId);
656
657 if (virtualHost == null) {
658 StringBundler msg = new StringBundler(6);
659
660 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
661
662 msg.append("companyId=");
663 msg.append(companyId);
664
665 msg.append(", layoutSetId=");
666 msg.append(layoutSetId);
667
668 msg.append(StringPool.CLOSE_CURLY_BRACE);
669
670 if (_log.isWarnEnabled()) {
671 _log.warn(msg.toString());
672 }
673
674 throw new NoSuchVirtualHostException(msg.toString());
675 }
676
677 return virtualHost;
678 }
679
680
688 public VirtualHost fetchByC_L(long companyId, long layoutSetId)
689 throws SystemException {
690 return fetchByC_L(companyId, layoutSetId, true);
691 }
692
693
702 public VirtualHost fetchByC_L(long companyId, long layoutSetId,
703 boolean retrieveFromCache) throws SystemException {
704 Object[] finderArgs = new Object[] { companyId, layoutSetId };
705
706 Object result = null;
707
708 if (retrieveFromCache) {
709 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_L,
710 finderArgs, this);
711 }
712
713 if (result instanceof VirtualHost) {
714 VirtualHost virtualHost = (VirtualHost)result;
715
716 if ((companyId != virtualHost.getCompanyId()) ||
717 (layoutSetId != virtualHost.getLayoutSetId())) {
718 result = null;
719 }
720 }
721
722 if (result == null) {
723 StringBundler query = new StringBundler(3);
724
725 query.append(_SQL_SELECT_VIRTUALHOST_WHERE);
726
727 query.append(_FINDER_COLUMN_C_L_COMPANYID_2);
728
729 query.append(_FINDER_COLUMN_C_L_LAYOUTSETID_2);
730
731 String sql = query.toString();
732
733 Session session = null;
734
735 try {
736 session = openSession();
737
738 Query q = session.createQuery(sql);
739
740 QueryPos qPos = QueryPos.getInstance(q);
741
742 qPos.add(companyId);
743
744 qPos.add(layoutSetId);
745
746 List<VirtualHost> list = q.list();
747
748 result = list;
749
750 VirtualHost virtualHost = null;
751
752 if (list.isEmpty()) {
753 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_L,
754 finderArgs, list);
755 }
756 else {
757 virtualHost = list.get(0);
758
759 cacheResult(virtualHost);
760
761 if ((virtualHost.getCompanyId() != companyId) ||
762 (virtualHost.getLayoutSetId() != layoutSetId)) {
763 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_L,
764 finderArgs, virtualHost);
765 }
766 }
767
768 return virtualHost;
769 }
770 catch (Exception e) {
771 throw processException(e);
772 }
773 finally {
774 if (result == null) {
775 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_L,
776 finderArgs);
777 }
778
779 closeSession(session);
780 }
781 }
782 else {
783 if (result instanceof List<?>) {
784 return null;
785 }
786 else {
787 return (VirtualHost)result;
788 }
789 }
790 }
791
792
798 public List<VirtualHost> findAll() throws SystemException {
799 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
800 }
801
802
814 public List<VirtualHost> findAll(int start, int end)
815 throws SystemException {
816 return findAll(start, end, null);
817 }
818
819
832 public List<VirtualHost> findAll(int start, int end,
833 OrderByComparator orderByComparator) throws SystemException {
834 FinderPath finderPath = null;
835 Object[] finderArgs = new Object[] { start, end, orderByComparator };
836
837 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
838 (orderByComparator == null)) {
839 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
840 finderArgs = FINDER_ARGS_EMPTY;
841 }
842 else {
843 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
844 finderArgs = new Object[] { start, end, orderByComparator };
845 }
846
847 List<VirtualHost> list = (List<VirtualHost>)FinderCacheUtil.getResult(finderPath,
848 finderArgs, this);
849
850 if (list == null) {
851 StringBundler query = null;
852 String sql = null;
853
854 if (orderByComparator != null) {
855 query = new StringBundler(2 +
856 (orderByComparator.getOrderByFields().length * 3));
857
858 query.append(_SQL_SELECT_VIRTUALHOST);
859
860 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
861 orderByComparator);
862
863 sql = query.toString();
864 }
865 else {
866 sql = _SQL_SELECT_VIRTUALHOST;
867 }
868
869 Session session = null;
870
871 try {
872 session = openSession();
873
874 Query q = session.createQuery(sql);
875
876 if (orderByComparator == null) {
877 list = (List<VirtualHost>)QueryUtil.list(q, getDialect(),
878 start, end, false);
879
880 Collections.sort(list);
881 }
882 else {
883 list = (List<VirtualHost>)QueryUtil.list(q, getDialect(),
884 start, end);
885 }
886 }
887 catch (Exception e) {
888 throw processException(e);
889 }
890 finally {
891 if (list == null) {
892 FinderCacheUtil.removeResult(finderPath, finderArgs);
893 }
894 else {
895 cacheResult(list);
896
897 FinderCacheUtil.putResult(finderPath, finderArgs, list);
898 }
899
900 closeSession(session);
901 }
902 }
903
904 return list;
905 }
906
907
913 public void removeByHostname(String hostname)
914 throws NoSuchVirtualHostException, SystemException {
915 VirtualHost virtualHost = findByHostname(hostname);
916
917 remove(virtualHost);
918 }
919
920
927 public void removeByC_L(long companyId, long layoutSetId)
928 throws NoSuchVirtualHostException, SystemException {
929 VirtualHost virtualHost = findByC_L(companyId, layoutSetId);
930
931 remove(virtualHost);
932 }
933
934
939 public void removeAll() throws SystemException {
940 for (VirtualHost virtualHost : findAll()) {
941 remove(virtualHost);
942 }
943 }
944
945
952 public int countByHostname(String hostname) throws SystemException {
953 Object[] finderArgs = new Object[] { hostname };
954
955 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_HOSTNAME,
956 finderArgs, this);
957
958 if (count == null) {
959 StringBundler query = new StringBundler(2);
960
961 query.append(_SQL_COUNT_VIRTUALHOST_WHERE);
962
963 if (hostname == null) {
964 query.append(_FINDER_COLUMN_HOSTNAME_HOSTNAME_1);
965 }
966 else {
967 if (hostname.equals(StringPool.BLANK)) {
968 query.append(_FINDER_COLUMN_HOSTNAME_HOSTNAME_3);
969 }
970 else {
971 query.append(_FINDER_COLUMN_HOSTNAME_HOSTNAME_2);
972 }
973 }
974
975 String sql = query.toString();
976
977 Session session = null;
978
979 try {
980 session = openSession();
981
982 Query q = session.createQuery(sql);
983
984 QueryPos qPos = QueryPos.getInstance(q);
985
986 if (hostname != null) {
987 qPos.add(hostname);
988 }
989
990 count = (Long)q.uniqueResult();
991 }
992 catch (Exception e) {
993 throw processException(e);
994 }
995 finally {
996 if (count == null) {
997 count = Long.valueOf(0);
998 }
999
1000 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_HOSTNAME,
1001 finderArgs, count);
1002
1003 closeSession(session);
1004 }
1005 }
1006
1007 return count.intValue();
1008 }
1009
1010
1018 public int countByC_L(long companyId, long layoutSetId)
1019 throws SystemException {
1020 Object[] finderArgs = new Object[] { companyId, layoutSetId };
1021
1022 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_L,
1023 finderArgs, this);
1024
1025 if (count == null) {
1026 StringBundler query = new StringBundler(3);
1027
1028 query.append(_SQL_COUNT_VIRTUALHOST_WHERE);
1029
1030 query.append(_FINDER_COLUMN_C_L_COMPANYID_2);
1031
1032 query.append(_FINDER_COLUMN_C_L_LAYOUTSETID_2);
1033
1034 String sql = query.toString();
1035
1036 Session session = null;
1037
1038 try {
1039 session = openSession();
1040
1041 Query q = session.createQuery(sql);
1042
1043 QueryPos qPos = QueryPos.getInstance(q);
1044
1045 qPos.add(companyId);
1046
1047 qPos.add(layoutSetId);
1048
1049 count = (Long)q.uniqueResult();
1050 }
1051 catch (Exception e) {
1052 throw processException(e);
1053 }
1054 finally {
1055 if (count == null) {
1056 count = Long.valueOf(0);
1057 }
1058
1059 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_L, finderArgs,
1060 count);
1061
1062 closeSession(session);
1063 }
1064 }
1065
1066 return count.intValue();
1067 }
1068
1069
1075 public int countAll() throws SystemException {
1076 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1077 FINDER_ARGS_EMPTY, this);
1078
1079 if (count == null) {
1080 Session session = null;
1081
1082 try {
1083 session = openSession();
1084
1085 Query q = session.createQuery(_SQL_COUNT_VIRTUALHOST);
1086
1087 count = (Long)q.uniqueResult();
1088 }
1089 catch (Exception e) {
1090 throw processException(e);
1091 }
1092 finally {
1093 if (count == null) {
1094 count = Long.valueOf(0);
1095 }
1096
1097 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1098 FINDER_ARGS_EMPTY, count);
1099
1100 closeSession(session);
1101 }
1102 }
1103
1104 return count.intValue();
1105 }
1106
1107
1110 public void afterPropertiesSet() {
1111 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1112 com.liferay.portal.util.PropsUtil.get(
1113 "value.object.listener.com.liferay.portal.model.VirtualHost")));
1114
1115 if (listenerClassNames.length > 0) {
1116 try {
1117 List<ModelListener<VirtualHost>> listenersList = new ArrayList<ModelListener<VirtualHost>>();
1118
1119 for (String listenerClassName : listenerClassNames) {
1120 listenersList.add((ModelListener<VirtualHost>)InstanceFactory.newInstance(
1121 listenerClassName));
1122 }
1123
1124 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1125 }
1126 catch (Exception e) {
1127 _log.error(e);
1128 }
1129 }
1130 }
1131
1132 public void destroy() {
1133 EntityCacheUtil.removeCache(VirtualHostImpl.class.getName());
1134 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1135 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1136 }
1137
1138 @BeanReference(type = AccountPersistence.class)
1139 protected AccountPersistence accountPersistence;
1140 @BeanReference(type = AddressPersistence.class)
1141 protected AddressPersistence addressPersistence;
1142 @BeanReference(type = BrowserTrackerPersistence.class)
1143 protected BrowserTrackerPersistence browserTrackerPersistence;
1144 @BeanReference(type = ClassNamePersistence.class)
1145 protected ClassNamePersistence classNamePersistence;
1146 @BeanReference(type = ClusterGroupPersistence.class)
1147 protected ClusterGroupPersistence clusterGroupPersistence;
1148 @BeanReference(type = CompanyPersistence.class)
1149 protected CompanyPersistence companyPersistence;
1150 @BeanReference(type = ContactPersistence.class)
1151 protected ContactPersistence contactPersistence;
1152 @BeanReference(type = CountryPersistence.class)
1153 protected CountryPersistence countryPersistence;
1154 @BeanReference(type = EmailAddressPersistence.class)
1155 protected EmailAddressPersistence emailAddressPersistence;
1156 @BeanReference(type = GroupPersistence.class)
1157 protected GroupPersistence groupPersistence;
1158 @BeanReference(type = ImagePersistence.class)
1159 protected ImagePersistence imagePersistence;
1160 @BeanReference(type = LayoutPersistence.class)
1161 protected LayoutPersistence layoutPersistence;
1162 @BeanReference(type = LayoutBranchPersistence.class)
1163 protected LayoutBranchPersistence layoutBranchPersistence;
1164 @BeanReference(type = LayoutPrototypePersistence.class)
1165 protected LayoutPrototypePersistence layoutPrototypePersistence;
1166 @BeanReference(type = LayoutRevisionPersistence.class)
1167 protected LayoutRevisionPersistence layoutRevisionPersistence;
1168 @BeanReference(type = LayoutSetPersistence.class)
1169 protected LayoutSetPersistence layoutSetPersistence;
1170 @BeanReference(type = LayoutSetBranchPersistence.class)
1171 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1172 @BeanReference(type = LayoutSetPrototypePersistence.class)
1173 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1174 @BeanReference(type = ListTypePersistence.class)
1175 protected ListTypePersistence listTypePersistence;
1176 @BeanReference(type = LockPersistence.class)
1177 protected LockPersistence lockPersistence;
1178 @BeanReference(type = MembershipRequestPersistence.class)
1179 protected MembershipRequestPersistence membershipRequestPersistence;
1180 @BeanReference(type = OrganizationPersistence.class)
1181 protected OrganizationPersistence organizationPersistence;
1182 @BeanReference(type = OrgGroupPermissionPersistence.class)
1183 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1184 @BeanReference(type = OrgGroupRolePersistence.class)
1185 protected OrgGroupRolePersistence orgGroupRolePersistence;
1186 @BeanReference(type = OrgLaborPersistence.class)
1187 protected OrgLaborPersistence orgLaborPersistence;
1188 @BeanReference(type = PasswordPolicyPersistence.class)
1189 protected PasswordPolicyPersistence passwordPolicyPersistence;
1190 @BeanReference(type = PasswordPolicyRelPersistence.class)
1191 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1192 @BeanReference(type = PasswordTrackerPersistence.class)
1193 protected PasswordTrackerPersistence passwordTrackerPersistence;
1194 @BeanReference(type = PermissionPersistence.class)
1195 protected PermissionPersistence permissionPersistence;
1196 @BeanReference(type = PhonePersistence.class)
1197 protected PhonePersistence phonePersistence;
1198 @BeanReference(type = PluginSettingPersistence.class)
1199 protected PluginSettingPersistence pluginSettingPersistence;
1200 @BeanReference(type = PortalPreferencesPersistence.class)
1201 protected PortalPreferencesPersistence portalPreferencesPersistence;
1202 @BeanReference(type = PortletPersistence.class)
1203 protected PortletPersistence portletPersistence;
1204 @BeanReference(type = PortletItemPersistence.class)
1205 protected PortletItemPersistence portletItemPersistence;
1206 @BeanReference(type = PortletPreferencesPersistence.class)
1207 protected PortletPreferencesPersistence portletPreferencesPersistence;
1208 @BeanReference(type = RegionPersistence.class)
1209 protected RegionPersistence regionPersistence;
1210 @BeanReference(type = ReleasePersistence.class)
1211 protected ReleasePersistence releasePersistence;
1212 @BeanReference(type = RepositoryPersistence.class)
1213 protected RepositoryPersistence repositoryPersistence;
1214 @BeanReference(type = RepositoryEntryPersistence.class)
1215 protected RepositoryEntryPersistence repositoryEntryPersistence;
1216 @BeanReference(type = ResourcePersistence.class)
1217 protected ResourcePersistence resourcePersistence;
1218 @BeanReference(type = ResourceActionPersistence.class)
1219 protected ResourceActionPersistence resourceActionPersistence;
1220 @BeanReference(type = ResourceBlockPersistence.class)
1221 protected ResourceBlockPersistence resourceBlockPersistence;
1222 @BeanReference(type = ResourceBlockPermissionPersistence.class)
1223 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
1224 @BeanReference(type = ResourceCodePersistence.class)
1225 protected ResourceCodePersistence resourceCodePersistence;
1226 @BeanReference(type = ResourcePermissionPersistence.class)
1227 protected ResourcePermissionPersistence resourcePermissionPersistence;
1228 @BeanReference(type = ResourceTypePermissionPersistence.class)
1229 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
1230 @BeanReference(type = RolePersistence.class)
1231 protected RolePersistence rolePersistence;
1232 @BeanReference(type = ServiceComponentPersistence.class)
1233 protected ServiceComponentPersistence serviceComponentPersistence;
1234 @BeanReference(type = ShardPersistence.class)
1235 protected ShardPersistence shardPersistence;
1236 @BeanReference(type = SubscriptionPersistence.class)
1237 protected SubscriptionPersistence subscriptionPersistence;
1238 @BeanReference(type = TeamPersistence.class)
1239 protected TeamPersistence teamPersistence;
1240 @BeanReference(type = TicketPersistence.class)
1241 protected TicketPersistence ticketPersistence;
1242 @BeanReference(type = UserPersistence.class)
1243 protected UserPersistence userPersistence;
1244 @BeanReference(type = UserGroupPersistence.class)
1245 protected UserGroupPersistence userGroupPersistence;
1246 @BeanReference(type = UserGroupGroupRolePersistence.class)
1247 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1248 @BeanReference(type = UserGroupRolePersistence.class)
1249 protected UserGroupRolePersistence userGroupRolePersistence;
1250 @BeanReference(type = UserIdMapperPersistence.class)
1251 protected UserIdMapperPersistence userIdMapperPersistence;
1252 @BeanReference(type = UserNotificationEventPersistence.class)
1253 protected UserNotificationEventPersistence userNotificationEventPersistence;
1254 @BeanReference(type = UserTrackerPersistence.class)
1255 protected UserTrackerPersistence userTrackerPersistence;
1256 @BeanReference(type = UserTrackerPathPersistence.class)
1257 protected UserTrackerPathPersistence userTrackerPathPersistence;
1258 @BeanReference(type = VirtualHostPersistence.class)
1259 protected VirtualHostPersistence virtualHostPersistence;
1260 @BeanReference(type = WebDAVPropsPersistence.class)
1261 protected WebDAVPropsPersistence webDAVPropsPersistence;
1262 @BeanReference(type = WebsitePersistence.class)
1263 protected WebsitePersistence websitePersistence;
1264 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1265 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1266 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1267 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1268 private static final String _SQL_SELECT_VIRTUALHOST = "SELECT virtualHost FROM VirtualHost virtualHost";
1269 private static final String _SQL_SELECT_VIRTUALHOST_WHERE = "SELECT virtualHost FROM VirtualHost virtualHost WHERE ";
1270 private static final String _SQL_COUNT_VIRTUALHOST = "SELECT COUNT(virtualHost) FROM VirtualHost virtualHost";
1271 private static final String _SQL_COUNT_VIRTUALHOST_WHERE = "SELECT COUNT(virtualHost) FROM VirtualHost virtualHost WHERE ";
1272 private static final String _FINDER_COLUMN_HOSTNAME_HOSTNAME_1 = "virtualHost.hostname IS NULL";
1273 private static final String _FINDER_COLUMN_HOSTNAME_HOSTNAME_2 = "virtualHost.hostname = ?";
1274 private static final String _FINDER_COLUMN_HOSTNAME_HOSTNAME_3 = "(virtualHost.hostname IS NULL OR virtualHost.hostname = ?)";
1275 private static final String _FINDER_COLUMN_C_L_COMPANYID_2 = "virtualHost.companyId = ? AND ";
1276 private static final String _FINDER_COLUMN_C_L_LAYOUTSETID_2 = "virtualHost.layoutSetId = ?";
1277 private static final String _ORDER_BY_ENTITY_ALIAS = "virtualHost.";
1278 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No VirtualHost exists with the primary key ";
1279 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No VirtualHost exists with the key {";
1280 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1281 private static Log _log = LogFactoryUtil.getLog(VirtualHostPersistenceImpl.class);
1282 private static VirtualHost _nullVirtualHost = new VirtualHostImpl() {
1283 @Override
1284 public Object clone() {
1285 return this;
1286 }
1287
1288 @Override
1289 public CacheModel<VirtualHost> toCacheModel() {
1290 return _nullVirtualHostCacheModel;
1291 }
1292 };
1293
1294 private static CacheModel<VirtualHost> _nullVirtualHostCacheModel = new CacheModel<VirtualHost>() {
1295 public VirtualHost toEntityModel() {
1296 return _nullVirtualHost;
1297 }
1298 };
1299 }