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