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 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_HOSTNAME,
178 new Object[] { virtualHost.getHostname() });
179
180 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_L,
181 new Object[] {
182 Long.valueOf(virtualHost.getCompanyId()),
183 Long.valueOf(virtualHost.getLayoutSetId())
184 });
185 }
186
187
193 public VirtualHost create(long virtualHostId) {
194 VirtualHost virtualHost = new VirtualHostImpl();
195
196 virtualHost.setNew(true);
197 virtualHost.setPrimaryKey(virtualHostId);
198
199 return virtualHost;
200 }
201
202
210 @Override
211 public VirtualHost remove(Serializable primaryKey)
212 throws NoSuchModelException, SystemException {
213 return remove(((Long)primaryKey).longValue());
214 }
215
216
224 public VirtualHost remove(long virtualHostId)
225 throws NoSuchVirtualHostException, SystemException {
226 Session session = null;
227
228 try {
229 session = openSession();
230
231 VirtualHost virtualHost = (VirtualHost)session.get(VirtualHostImpl.class,
232 Long.valueOf(virtualHostId));
233
234 if (virtualHost == null) {
235 if (_log.isWarnEnabled()) {
236 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + virtualHostId);
237 }
238
239 throw new NoSuchVirtualHostException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
240 virtualHostId);
241 }
242
243 return virtualHostPersistence.remove(virtualHost);
244 }
245 catch (NoSuchVirtualHostException nsee) {
246 throw nsee;
247 }
248 catch (Exception e) {
249 throw processException(e);
250 }
251 finally {
252 closeSession(session);
253 }
254 }
255
256
263 @Override
264 public VirtualHost remove(VirtualHost virtualHost)
265 throws SystemException {
266 return super.remove(virtualHost);
267 }
268
269 @Override
270 protected VirtualHost removeImpl(VirtualHost virtualHost)
271 throws SystemException {
272 virtualHost = toUnwrappedModel(virtualHost);
273
274 Session session = null;
275
276 try {
277 session = openSession();
278
279 BatchSessionUtil.delete(session, virtualHost);
280 }
281 catch (Exception e) {
282 throw processException(e);
283 }
284 finally {
285 closeSession(session);
286 }
287
288 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
289 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
290
291 VirtualHostModelImpl virtualHostModelImpl = (VirtualHostModelImpl)virtualHost;
292
293 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_HOSTNAME,
294 new Object[] { virtualHostModelImpl.getHostname() });
295
296 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_L,
297 new Object[] {
298 Long.valueOf(virtualHostModelImpl.getCompanyId()),
299 Long.valueOf(virtualHostModelImpl.getLayoutSetId())
300 });
301
302 EntityCacheUtil.removeResult(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
303 VirtualHostImpl.class, virtualHost.getPrimaryKey());
304
305 return virtualHost;
306 }
307
308 @Override
309 public VirtualHost updateImpl(
310 com.liferay.portal.model.VirtualHost virtualHost, boolean merge)
311 throws SystemException {
312 virtualHost = toUnwrappedModel(virtualHost);
313
314 boolean isNew = virtualHost.isNew();
315
316 VirtualHostModelImpl virtualHostModelImpl = (VirtualHostModelImpl)virtualHost;
317
318 Session session = null;
319
320 try {
321 session = openSession();
322
323 BatchSessionUtil.update(session, virtualHost, merge);
324
325 virtualHost.setNew(false);
326 }
327 catch (Exception e) {
328 throw processException(e);
329 }
330 finally {
331 closeSession(session);
332 }
333
334 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITH_PAGINATION);
335
336 if (isNew || !VirtualHostModelImpl.COLUMN_BITMASK_ENABLED) {
337 FinderCacheUtil.clearCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
338 }
339
340 EntityCacheUtil.putResult(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
341 VirtualHostImpl.class, virtualHost.getPrimaryKey(), virtualHost);
342
343 if (isNew) {
344 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_HOSTNAME,
345 new Object[] { virtualHost.getHostname() }, virtualHost);
346
347 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_L,
348 new Object[] {
349 Long.valueOf(virtualHost.getCompanyId()),
350 Long.valueOf(virtualHost.getLayoutSetId())
351 }, virtualHost);
352 }
353 else {
354 if ((virtualHostModelImpl.getColumnBitmask() &
355 FINDER_PATH_FETCH_BY_HOSTNAME.getColumnBitmask()) != 0) {
356 Object[] args = new Object[] {
357 virtualHostModelImpl.getOriginalHostname()
358 };
359
360 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_HOSTNAME, args);
361 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_HOSTNAME, args);
362
363 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_HOSTNAME,
364 new Object[] { virtualHost.getHostname() }, virtualHost);
365 }
366
367 if ((virtualHostModelImpl.getColumnBitmask() &
368 FINDER_PATH_FETCH_BY_C_L.getColumnBitmask()) != 0) {
369 Object[] args = new Object[] {
370 Long.valueOf(virtualHostModelImpl.getOriginalCompanyId()),
371 Long.valueOf(virtualHostModelImpl.getOriginalLayoutSetId())
372 };
373
374 FinderCacheUtil.removeResult(FINDER_PATH_COUNT_BY_C_L, args);
375 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_L, args);
376
377 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_L,
378 new Object[] {
379 Long.valueOf(virtualHost.getCompanyId()),
380 Long.valueOf(virtualHost.getLayoutSetId())
381 }, virtualHost);
382 }
383 }
384
385 return virtualHost;
386 }
387
388 protected VirtualHost toUnwrappedModel(VirtualHost virtualHost) {
389 if (virtualHost instanceof VirtualHostImpl) {
390 return virtualHost;
391 }
392
393 VirtualHostImpl virtualHostImpl = new VirtualHostImpl();
394
395 virtualHostImpl.setNew(virtualHost.isNew());
396 virtualHostImpl.setPrimaryKey(virtualHost.getPrimaryKey());
397
398 virtualHostImpl.setVirtualHostId(virtualHost.getVirtualHostId());
399 virtualHostImpl.setCompanyId(virtualHost.getCompanyId());
400 virtualHostImpl.setLayoutSetId(virtualHost.getLayoutSetId());
401 virtualHostImpl.setHostname(virtualHost.getHostname());
402
403 return virtualHostImpl;
404 }
405
406
414 @Override
415 public VirtualHost findByPrimaryKey(Serializable primaryKey)
416 throws NoSuchModelException, SystemException {
417 return findByPrimaryKey(((Long)primaryKey).longValue());
418 }
419
420
428 public VirtualHost findByPrimaryKey(long virtualHostId)
429 throws NoSuchVirtualHostException, SystemException {
430 VirtualHost virtualHost = fetchByPrimaryKey(virtualHostId);
431
432 if (virtualHost == null) {
433 if (_log.isWarnEnabled()) {
434 _log.warn(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY + virtualHostId);
435 }
436
437 throw new NoSuchVirtualHostException(_NO_SUCH_ENTITY_WITH_PRIMARY_KEY +
438 virtualHostId);
439 }
440
441 return virtualHost;
442 }
443
444
451 @Override
452 public VirtualHost fetchByPrimaryKey(Serializable primaryKey)
453 throws SystemException {
454 return fetchByPrimaryKey(((Long)primaryKey).longValue());
455 }
456
457
464 public VirtualHost fetchByPrimaryKey(long virtualHostId)
465 throws SystemException {
466 VirtualHost virtualHost = (VirtualHost)EntityCacheUtil.getResult(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
467 VirtualHostImpl.class, virtualHostId);
468
469 if (virtualHost == _nullVirtualHost) {
470 return null;
471 }
472
473 if (virtualHost == null) {
474 Session session = null;
475
476 boolean hasException = false;
477
478 try {
479 session = openSession();
480
481 virtualHost = (VirtualHost)session.get(VirtualHostImpl.class,
482 Long.valueOf(virtualHostId));
483 }
484 catch (Exception e) {
485 hasException = true;
486
487 throw processException(e);
488 }
489 finally {
490 if (virtualHost != null) {
491 cacheResult(virtualHost);
492 }
493 else if (!hasException) {
494 EntityCacheUtil.putResult(VirtualHostModelImpl.ENTITY_CACHE_ENABLED,
495 VirtualHostImpl.class, virtualHostId, _nullVirtualHost);
496 }
497
498 closeSession(session);
499 }
500 }
501
502 return virtualHost;
503 }
504
505
513 public VirtualHost findByHostname(String hostname)
514 throws NoSuchVirtualHostException, SystemException {
515 VirtualHost virtualHost = fetchByHostname(hostname);
516
517 if (virtualHost == null) {
518 StringBundler msg = new StringBundler(4);
519
520 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
521
522 msg.append("hostname=");
523 msg.append(hostname);
524
525 msg.append(StringPool.CLOSE_CURLY_BRACE);
526
527 if (_log.isWarnEnabled()) {
528 _log.warn(msg.toString());
529 }
530
531 throw new NoSuchVirtualHostException(msg.toString());
532 }
533
534 return virtualHost;
535 }
536
537
544 public VirtualHost fetchByHostname(String hostname)
545 throws SystemException {
546 return fetchByHostname(hostname, true);
547 }
548
549
557 public VirtualHost fetchByHostname(String hostname,
558 boolean retrieveFromCache) throws SystemException {
559 Object[] finderArgs = new Object[] { hostname };
560
561 Object result = null;
562
563 if (retrieveFromCache) {
564 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_HOSTNAME,
565 finderArgs, this);
566 }
567
568 if (result == null) {
569 StringBundler query = new StringBundler(2);
570
571 query.append(_SQL_SELECT_VIRTUALHOST_WHERE);
572
573 if (hostname == null) {
574 query.append(_FINDER_COLUMN_HOSTNAME_HOSTNAME_1);
575 }
576 else {
577 if (hostname.equals(StringPool.BLANK)) {
578 query.append(_FINDER_COLUMN_HOSTNAME_HOSTNAME_3);
579 }
580 else {
581 query.append(_FINDER_COLUMN_HOSTNAME_HOSTNAME_2);
582 }
583 }
584
585 String sql = query.toString();
586
587 Session session = null;
588
589 try {
590 session = openSession();
591
592 Query q = session.createQuery(sql);
593
594 QueryPos qPos = QueryPos.getInstance(q);
595
596 if (hostname != null) {
597 qPos.add(hostname);
598 }
599
600 List<VirtualHost> list = q.list();
601
602 result = list;
603
604 VirtualHost virtualHost = null;
605
606 if (list.isEmpty()) {
607 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_HOSTNAME,
608 finderArgs, list);
609 }
610 else {
611 virtualHost = list.get(0);
612
613 cacheResult(virtualHost);
614
615 if ((virtualHost.getHostname() == null) ||
616 !virtualHost.getHostname().equals(hostname)) {
617 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_HOSTNAME,
618 finderArgs, virtualHost);
619 }
620 }
621
622 return virtualHost;
623 }
624 catch (Exception e) {
625 throw processException(e);
626 }
627 finally {
628 if (result == null) {
629 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_HOSTNAME,
630 finderArgs);
631 }
632
633 closeSession(session);
634 }
635 }
636 else {
637 if (result instanceof List<?>) {
638 return null;
639 }
640 else {
641 return (VirtualHost)result;
642 }
643 }
644 }
645
646
655 public VirtualHost findByC_L(long companyId, long layoutSetId)
656 throws NoSuchVirtualHostException, SystemException {
657 VirtualHost virtualHost = fetchByC_L(companyId, layoutSetId);
658
659 if (virtualHost == null) {
660 StringBundler msg = new StringBundler(6);
661
662 msg.append(_NO_SUCH_ENTITY_WITH_KEY);
663
664 msg.append("companyId=");
665 msg.append(companyId);
666
667 msg.append(", layoutSetId=");
668 msg.append(layoutSetId);
669
670 msg.append(StringPool.CLOSE_CURLY_BRACE);
671
672 if (_log.isWarnEnabled()) {
673 _log.warn(msg.toString());
674 }
675
676 throw new NoSuchVirtualHostException(msg.toString());
677 }
678
679 return virtualHost;
680 }
681
682
690 public VirtualHost fetchByC_L(long companyId, long layoutSetId)
691 throws SystemException {
692 return fetchByC_L(companyId, layoutSetId, true);
693 }
694
695
704 public VirtualHost fetchByC_L(long companyId, long layoutSetId,
705 boolean retrieveFromCache) throws SystemException {
706 Object[] finderArgs = new Object[] { companyId, layoutSetId };
707
708 Object result = null;
709
710 if (retrieveFromCache) {
711 result = FinderCacheUtil.getResult(FINDER_PATH_FETCH_BY_C_L,
712 finderArgs, this);
713 }
714
715 if (result == null) {
716 StringBundler query = new StringBundler(3);
717
718 query.append(_SQL_SELECT_VIRTUALHOST_WHERE);
719
720 query.append(_FINDER_COLUMN_C_L_COMPANYID_2);
721
722 query.append(_FINDER_COLUMN_C_L_LAYOUTSETID_2);
723
724 String sql = query.toString();
725
726 Session session = null;
727
728 try {
729 session = openSession();
730
731 Query q = session.createQuery(sql);
732
733 QueryPos qPos = QueryPos.getInstance(q);
734
735 qPos.add(companyId);
736
737 qPos.add(layoutSetId);
738
739 List<VirtualHost> list = q.list();
740
741 result = list;
742
743 VirtualHost virtualHost = null;
744
745 if (list.isEmpty()) {
746 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_L,
747 finderArgs, list);
748 }
749 else {
750 virtualHost = list.get(0);
751
752 cacheResult(virtualHost);
753
754 if ((virtualHost.getCompanyId() != companyId) ||
755 (virtualHost.getLayoutSetId() != layoutSetId)) {
756 FinderCacheUtil.putResult(FINDER_PATH_FETCH_BY_C_L,
757 finderArgs, virtualHost);
758 }
759 }
760
761 return virtualHost;
762 }
763 catch (Exception e) {
764 throw processException(e);
765 }
766 finally {
767 if (result == null) {
768 FinderCacheUtil.removeResult(FINDER_PATH_FETCH_BY_C_L,
769 finderArgs);
770 }
771
772 closeSession(session);
773 }
774 }
775 else {
776 if (result instanceof List<?>) {
777 return null;
778 }
779 else {
780 return (VirtualHost)result;
781 }
782 }
783 }
784
785
791 public List<VirtualHost> findAll() throws SystemException {
792 return findAll(QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);
793 }
794
795
807 public List<VirtualHost> findAll(int start, int end)
808 throws SystemException {
809 return findAll(start, end, null);
810 }
811
812
825 public List<VirtualHost> findAll(int start, int end,
826 OrderByComparator orderByComparator) throws SystemException {
827 FinderPath finderPath = null;
828 Object[] finderArgs = new Object[] { start, end, orderByComparator };
829
830 if ((start == QueryUtil.ALL_POS) && (end == QueryUtil.ALL_POS) &&
831 (orderByComparator == null)) {
832 finderPath = FINDER_PATH_WITH_PAGINATION_FIND_ALL;
833 finderArgs = FINDER_ARGS_EMPTY;
834 }
835 else {
836 finderPath = FINDER_PATH_WITHOUT_PAGINATION_FIND_ALL;
837 finderArgs = new Object[] { start, end, orderByComparator };
838 }
839
840 List<VirtualHost> list = (List<VirtualHost>)FinderCacheUtil.getResult(finderPath,
841 finderArgs, this);
842
843 if (list == null) {
844 StringBundler query = null;
845 String sql = null;
846
847 if (orderByComparator != null) {
848 query = new StringBundler(2 +
849 (orderByComparator.getOrderByFields().length * 3));
850
851 query.append(_SQL_SELECT_VIRTUALHOST);
852
853 appendOrderByComparator(query, _ORDER_BY_ENTITY_ALIAS,
854 orderByComparator);
855
856 sql = query.toString();
857 }
858 else {
859 sql = _SQL_SELECT_VIRTUALHOST;
860 }
861
862 Session session = null;
863
864 try {
865 session = openSession();
866
867 Query q = session.createQuery(sql);
868
869 if (orderByComparator == null) {
870 list = (List<VirtualHost>)QueryUtil.list(q, getDialect(),
871 start, end, false);
872
873 Collections.sort(list);
874 }
875 else {
876 list = (List<VirtualHost>)QueryUtil.list(q, getDialect(),
877 start, end);
878 }
879 }
880 catch (Exception e) {
881 throw processException(e);
882 }
883 finally {
884 if (list == null) {
885 FinderCacheUtil.removeResult(finderPath, finderArgs);
886 }
887 else {
888 cacheResult(list);
889
890 FinderCacheUtil.putResult(finderPath, finderArgs, list);
891 }
892
893 closeSession(session);
894 }
895 }
896
897 return list;
898 }
899
900
906 public void removeByHostname(String hostname)
907 throws NoSuchVirtualHostException, SystemException {
908 VirtualHost virtualHost = findByHostname(hostname);
909
910 virtualHostPersistence.remove(virtualHost);
911 }
912
913
920 public void removeByC_L(long companyId, long layoutSetId)
921 throws NoSuchVirtualHostException, SystemException {
922 VirtualHost virtualHost = findByC_L(companyId, layoutSetId);
923
924 virtualHostPersistence.remove(virtualHost);
925 }
926
927
932 public void removeAll() throws SystemException {
933 for (VirtualHost virtualHost : findAll()) {
934 virtualHostPersistence.remove(virtualHost);
935 }
936 }
937
938
945 public int countByHostname(String hostname) throws SystemException {
946 Object[] finderArgs = new Object[] { hostname };
947
948 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_HOSTNAME,
949 finderArgs, this);
950
951 if (count == null) {
952 StringBundler query = new StringBundler(2);
953
954 query.append(_SQL_COUNT_VIRTUALHOST_WHERE);
955
956 if (hostname == null) {
957 query.append(_FINDER_COLUMN_HOSTNAME_HOSTNAME_1);
958 }
959 else {
960 if (hostname.equals(StringPool.BLANK)) {
961 query.append(_FINDER_COLUMN_HOSTNAME_HOSTNAME_3);
962 }
963 else {
964 query.append(_FINDER_COLUMN_HOSTNAME_HOSTNAME_2);
965 }
966 }
967
968 String sql = query.toString();
969
970 Session session = null;
971
972 try {
973 session = openSession();
974
975 Query q = session.createQuery(sql);
976
977 QueryPos qPos = QueryPos.getInstance(q);
978
979 if (hostname != null) {
980 qPos.add(hostname);
981 }
982
983 count = (Long)q.uniqueResult();
984 }
985 catch (Exception e) {
986 throw processException(e);
987 }
988 finally {
989 if (count == null) {
990 count = Long.valueOf(0);
991 }
992
993 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_HOSTNAME,
994 finderArgs, count);
995
996 closeSession(session);
997 }
998 }
999
1000 return count.intValue();
1001 }
1002
1003
1011 public int countByC_L(long companyId, long layoutSetId)
1012 throws SystemException {
1013 Object[] finderArgs = new Object[] { companyId, layoutSetId };
1014
1015 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_BY_C_L,
1016 finderArgs, this);
1017
1018 if (count == null) {
1019 StringBundler query = new StringBundler(3);
1020
1021 query.append(_SQL_COUNT_VIRTUALHOST_WHERE);
1022
1023 query.append(_FINDER_COLUMN_C_L_COMPANYID_2);
1024
1025 query.append(_FINDER_COLUMN_C_L_LAYOUTSETID_2);
1026
1027 String sql = query.toString();
1028
1029 Session session = null;
1030
1031 try {
1032 session = openSession();
1033
1034 Query q = session.createQuery(sql);
1035
1036 QueryPos qPos = QueryPos.getInstance(q);
1037
1038 qPos.add(companyId);
1039
1040 qPos.add(layoutSetId);
1041
1042 count = (Long)q.uniqueResult();
1043 }
1044 catch (Exception e) {
1045 throw processException(e);
1046 }
1047 finally {
1048 if (count == null) {
1049 count = Long.valueOf(0);
1050 }
1051
1052 FinderCacheUtil.putResult(FINDER_PATH_COUNT_BY_C_L, finderArgs,
1053 count);
1054
1055 closeSession(session);
1056 }
1057 }
1058
1059 return count.intValue();
1060 }
1061
1062
1068 public int countAll() throws SystemException {
1069 Long count = (Long)FinderCacheUtil.getResult(FINDER_PATH_COUNT_ALL,
1070 FINDER_ARGS_EMPTY, this);
1071
1072 if (count == null) {
1073 Session session = null;
1074
1075 try {
1076 session = openSession();
1077
1078 Query q = session.createQuery(_SQL_COUNT_VIRTUALHOST);
1079
1080 count = (Long)q.uniqueResult();
1081 }
1082 catch (Exception e) {
1083 throw processException(e);
1084 }
1085 finally {
1086 if (count == null) {
1087 count = Long.valueOf(0);
1088 }
1089
1090 FinderCacheUtil.putResult(FINDER_PATH_COUNT_ALL,
1091 FINDER_ARGS_EMPTY, count);
1092
1093 closeSession(session);
1094 }
1095 }
1096
1097 return count.intValue();
1098 }
1099
1100
1103 public void afterPropertiesSet() {
1104 String[] listenerClassNames = StringUtil.split(GetterUtil.getString(
1105 com.liferay.portal.util.PropsUtil.get(
1106 "value.object.listener.com.liferay.portal.model.VirtualHost")));
1107
1108 if (listenerClassNames.length > 0) {
1109 try {
1110 List<ModelListener<VirtualHost>> listenersList = new ArrayList<ModelListener<VirtualHost>>();
1111
1112 for (String listenerClassName : listenerClassNames) {
1113 listenersList.add((ModelListener<VirtualHost>)InstanceFactory.newInstance(
1114 listenerClassName));
1115 }
1116
1117 listeners = listenersList.toArray(new ModelListener[listenersList.size()]);
1118 }
1119 catch (Exception e) {
1120 _log.error(e);
1121 }
1122 }
1123 }
1124
1125 public void destroy() {
1126 EntityCacheUtil.removeCache(VirtualHostImpl.class.getName());
1127 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_ENTITY);
1128 FinderCacheUtil.removeCache(FINDER_CLASS_NAME_LIST_WITHOUT_PAGINATION);
1129 }
1130
1131 @BeanReference(type = AccountPersistence.class)
1132 protected AccountPersistence accountPersistence;
1133 @BeanReference(type = AddressPersistence.class)
1134 protected AddressPersistence addressPersistence;
1135 @BeanReference(type = BrowserTrackerPersistence.class)
1136 protected BrowserTrackerPersistence browserTrackerPersistence;
1137 @BeanReference(type = ClassNamePersistence.class)
1138 protected ClassNamePersistence classNamePersistence;
1139 @BeanReference(type = ClusterGroupPersistence.class)
1140 protected ClusterGroupPersistence clusterGroupPersistence;
1141 @BeanReference(type = CompanyPersistence.class)
1142 protected CompanyPersistence companyPersistence;
1143 @BeanReference(type = ContactPersistence.class)
1144 protected ContactPersistence contactPersistence;
1145 @BeanReference(type = CountryPersistence.class)
1146 protected CountryPersistence countryPersistence;
1147 @BeanReference(type = EmailAddressPersistence.class)
1148 protected EmailAddressPersistence emailAddressPersistence;
1149 @BeanReference(type = GroupPersistence.class)
1150 protected GroupPersistence groupPersistence;
1151 @BeanReference(type = ImagePersistence.class)
1152 protected ImagePersistence imagePersistence;
1153 @BeanReference(type = LayoutPersistence.class)
1154 protected LayoutPersistence layoutPersistence;
1155 @BeanReference(type = LayoutBranchPersistence.class)
1156 protected LayoutBranchPersistence layoutBranchPersistence;
1157 @BeanReference(type = LayoutPrototypePersistence.class)
1158 protected LayoutPrototypePersistence layoutPrototypePersistence;
1159 @BeanReference(type = LayoutRevisionPersistence.class)
1160 protected LayoutRevisionPersistence layoutRevisionPersistence;
1161 @BeanReference(type = LayoutSetPersistence.class)
1162 protected LayoutSetPersistence layoutSetPersistence;
1163 @BeanReference(type = LayoutSetBranchPersistence.class)
1164 protected LayoutSetBranchPersistence layoutSetBranchPersistence;
1165 @BeanReference(type = LayoutSetPrototypePersistence.class)
1166 protected LayoutSetPrototypePersistence layoutSetPrototypePersistence;
1167 @BeanReference(type = ListTypePersistence.class)
1168 protected ListTypePersistence listTypePersistence;
1169 @BeanReference(type = LockPersistence.class)
1170 protected LockPersistence lockPersistence;
1171 @BeanReference(type = MembershipRequestPersistence.class)
1172 protected MembershipRequestPersistence membershipRequestPersistence;
1173 @BeanReference(type = OrganizationPersistence.class)
1174 protected OrganizationPersistence organizationPersistence;
1175 @BeanReference(type = OrgGroupPermissionPersistence.class)
1176 protected OrgGroupPermissionPersistence orgGroupPermissionPersistence;
1177 @BeanReference(type = OrgGroupRolePersistence.class)
1178 protected OrgGroupRolePersistence orgGroupRolePersistence;
1179 @BeanReference(type = OrgLaborPersistence.class)
1180 protected OrgLaborPersistence orgLaborPersistence;
1181 @BeanReference(type = PasswordPolicyPersistence.class)
1182 protected PasswordPolicyPersistence passwordPolicyPersistence;
1183 @BeanReference(type = PasswordPolicyRelPersistence.class)
1184 protected PasswordPolicyRelPersistence passwordPolicyRelPersistence;
1185 @BeanReference(type = PasswordTrackerPersistence.class)
1186 protected PasswordTrackerPersistence passwordTrackerPersistence;
1187 @BeanReference(type = PermissionPersistence.class)
1188 protected PermissionPersistence permissionPersistence;
1189 @BeanReference(type = PhonePersistence.class)
1190 protected PhonePersistence phonePersistence;
1191 @BeanReference(type = PluginSettingPersistence.class)
1192 protected PluginSettingPersistence pluginSettingPersistence;
1193 @BeanReference(type = PortalPreferencesPersistence.class)
1194 protected PortalPreferencesPersistence portalPreferencesPersistence;
1195 @BeanReference(type = PortletPersistence.class)
1196 protected PortletPersistence portletPersistence;
1197 @BeanReference(type = PortletItemPersistence.class)
1198 protected PortletItemPersistence portletItemPersistence;
1199 @BeanReference(type = PortletPreferencesPersistence.class)
1200 protected PortletPreferencesPersistence portletPreferencesPersistence;
1201 @BeanReference(type = RegionPersistence.class)
1202 protected RegionPersistence regionPersistence;
1203 @BeanReference(type = ReleasePersistence.class)
1204 protected ReleasePersistence releasePersistence;
1205 @BeanReference(type = RepositoryPersistence.class)
1206 protected RepositoryPersistence repositoryPersistence;
1207 @BeanReference(type = RepositoryEntryPersistence.class)
1208 protected RepositoryEntryPersistence repositoryEntryPersistence;
1209 @BeanReference(type = ResourcePersistence.class)
1210 protected ResourcePersistence resourcePersistence;
1211 @BeanReference(type = ResourceActionPersistence.class)
1212 protected ResourceActionPersistence resourceActionPersistence;
1213 @BeanReference(type = ResourceBlockPersistence.class)
1214 protected ResourceBlockPersistence resourceBlockPersistence;
1215 @BeanReference(type = ResourceBlockPermissionPersistence.class)
1216 protected ResourceBlockPermissionPersistence resourceBlockPermissionPersistence;
1217 @BeanReference(type = ResourceCodePersistence.class)
1218 protected ResourceCodePersistence resourceCodePersistence;
1219 @BeanReference(type = ResourcePermissionPersistence.class)
1220 protected ResourcePermissionPersistence resourcePermissionPersistence;
1221 @BeanReference(type = ResourceTypePermissionPersistence.class)
1222 protected ResourceTypePermissionPersistence resourceTypePermissionPersistence;
1223 @BeanReference(type = RolePersistence.class)
1224 protected RolePersistence rolePersistence;
1225 @BeanReference(type = ServiceComponentPersistence.class)
1226 protected ServiceComponentPersistence serviceComponentPersistence;
1227 @BeanReference(type = ShardPersistence.class)
1228 protected ShardPersistence shardPersistence;
1229 @BeanReference(type = SubscriptionPersistence.class)
1230 protected SubscriptionPersistence subscriptionPersistence;
1231 @BeanReference(type = TeamPersistence.class)
1232 protected TeamPersistence teamPersistence;
1233 @BeanReference(type = TicketPersistence.class)
1234 protected TicketPersistence ticketPersistence;
1235 @BeanReference(type = UserPersistence.class)
1236 protected UserPersistence userPersistence;
1237 @BeanReference(type = UserGroupPersistence.class)
1238 protected UserGroupPersistence userGroupPersistence;
1239 @BeanReference(type = UserGroupGroupRolePersistence.class)
1240 protected UserGroupGroupRolePersistence userGroupGroupRolePersistence;
1241 @BeanReference(type = UserGroupRolePersistence.class)
1242 protected UserGroupRolePersistence userGroupRolePersistence;
1243 @BeanReference(type = UserIdMapperPersistence.class)
1244 protected UserIdMapperPersistence userIdMapperPersistence;
1245 @BeanReference(type = UserNotificationEventPersistence.class)
1246 protected UserNotificationEventPersistence userNotificationEventPersistence;
1247 @BeanReference(type = UserTrackerPersistence.class)
1248 protected UserTrackerPersistence userTrackerPersistence;
1249 @BeanReference(type = UserTrackerPathPersistence.class)
1250 protected UserTrackerPathPersistence userTrackerPathPersistence;
1251 @BeanReference(type = VirtualHostPersistence.class)
1252 protected VirtualHostPersistence virtualHostPersistence;
1253 @BeanReference(type = WebDAVPropsPersistence.class)
1254 protected WebDAVPropsPersistence webDAVPropsPersistence;
1255 @BeanReference(type = WebsitePersistence.class)
1256 protected WebsitePersistence websitePersistence;
1257 @BeanReference(type = WorkflowDefinitionLinkPersistence.class)
1258 protected WorkflowDefinitionLinkPersistence workflowDefinitionLinkPersistence;
1259 @BeanReference(type = WorkflowInstanceLinkPersistence.class)
1260 protected WorkflowInstanceLinkPersistence workflowInstanceLinkPersistence;
1261 private static final String _SQL_SELECT_VIRTUALHOST = "SELECT virtualHost FROM VirtualHost virtualHost";
1262 private static final String _SQL_SELECT_VIRTUALHOST_WHERE = "SELECT virtualHost FROM VirtualHost virtualHost WHERE ";
1263 private static final String _SQL_COUNT_VIRTUALHOST = "SELECT COUNT(virtualHost) FROM VirtualHost virtualHost";
1264 private static final String _SQL_COUNT_VIRTUALHOST_WHERE = "SELECT COUNT(virtualHost) FROM VirtualHost virtualHost WHERE ";
1265 private static final String _FINDER_COLUMN_HOSTNAME_HOSTNAME_1 = "virtualHost.hostname IS NULL";
1266 private static final String _FINDER_COLUMN_HOSTNAME_HOSTNAME_2 = "virtualHost.hostname = ?";
1267 private static final String _FINDER_COLUMN_HOSTNAME_HOSTNAME_3 = "(virtualHost.hostname IS NULL OR virtualHost.hostname = ?)";
1268 private static final String _FINDER_COLUMN_C_L_COMPANYID_2 = "virtualHost.companyId = ? AND ";
1269 private static final String _FINDER_COLUMN_C_L_LAYOUTSETID_2 = "virtualHost.layoutSetId = ?";
1270 private static final String _ORDER_BY_ENTITY_ALIAS = "virtualHost.";
1271 private static final String _NO_SUCH_ENTITY_WITH_PRIMARY_KEY = "No VirtualHost exists with the primary key ";
1272 private static final String _NO_SUCH_ENTITY_WITH_KEY = "No VirtualHost exists with the key {";
1273 private static final boolean _HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE = com.liferay.portal.util.PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE;
1274 private static Log _log = LogFactoryUtil.getLog(VirtualHostPersistenceImpl.class);
1275 private static VirtualHost _nullVirtualHost = new VirtualHostImpl() {
1276 @Override
1277 public Object clone() {
1278 return this;
1279 }
1280
1281 @Override
1282 public CacheModel<VirtualHost> toCacheModel() {
1283 return _nullVirtualHostCacheModel;
1284 }
1285 };
1286
1287 private static CacheModel<VirtualHost> _nullVirtualHostCacheModel = new CacheModel<VirtualHost>() {
1288 public VirtualHost toEntityModel() {
1289 return _nullVirtualHost;
1290 }
1291 };
1292 }