Revision c8d37de7
Added by Cherian Mathew almost 9 years ago
eu.etaxonomy.taxeditor.cdmlib/src/main/java/org/hibernate/collection/internal/AbstractPersistentCollection.java | ||
---|---|---|
26 | 26 |
package org.hibernate.collection.internal; |
27 | 27 |
|
28 | 28 |
import java.io.Serializable; |
29 |
import java.lang.reflect.Field; |
|
30 | 29 |
import java.util.ArrayList; |
31 | 30 |
import java.util.Collection; |
32 | 31 |
import java.util.Collections; |
... | ... | |
78 | 77 |
private static final Logger log = Logger.getLogger( AbstractPersistentCollection.class ); |
79 | 78 |
|
80 | 79 |
private static final long serialVersionUID = -7238232378593030571L; |
81 |
|
|
80 |
|
|
82 | 81 |
private transient SessionImplementor session; |
83 | 82 |
private boolean initialized; |
84 | 83 |
private transient List<DelayedOperation> operationQueue; |
... | ... | |
97 | 96 |
private String sessionFactoryUuid; |
98 | 97 |
private boolean specjLazyLoad = false; |
99 | 98 |
|
100 |
public final String getRole() { |
|
99 |
@Override |
|
100 |
public final String getRole() { |
|
101 | 101 |
return role; |
102 | 102 |
} |
103 | 103 |
|
104 |
public final Serializable getKey() { |
|
104 |
@Override |
|
105 |
public final Serializable getKey() { |
|
105 | 106 |
return key; |
106 | 107 |
} |
107 | 108 |
|
108 |
public final boolean isUnreferenced() { |
|
109 |
@Override |
|
110 |
public final boolean isUnreferenced() { |
|
109 | 111 |
return role == null; |
110 | 112 |
} |
111 | 113 |
|
112 |
public final boolean isDirty() { |
|
114 |
@Override |
|
115 |
public final boolean isDirty() { |
|
113 | 116 |
return dirty; |
114 | 117 |
} |
115 | 118 |
|
116 |
public final void clearDirty() { |
|
119 |
@Override |
|
120 |
public final void clearDirty() { |
|
117 | 121 |
dirty = false; |
118 | 122 |
} |
119 | 123 |
|
120 |
public final void dirty() { |
|
124 |
@Override |
|
125 |
public final void dirty() { |
|
121 | 126 |
dirty = true; |
122 | 127 |
} |
123 | 128 |
|
124 |
public final Serializable getStoredSnapshot() { |
|
129 |
@Override |
|
130 |
public final Serializable getStoredSnapshot() { |
|
125 | 131 |
return storedSnapshot; |
126 | 132 |
} |
127 | 133 |
|
... | ... | |
130 | 136 |
/** |
131 | 137 |
* Is the initialized collection empty? |
132 | 138 |
*/ |
133 |
public abstract boolean empty(); |
|
139 |
@Override |
|
140 |
public abstract boolean empty(); |
|
134 | 141 |
|
135 | 142 |
/** |
136 | 143 |
* Called by any read-only method of the collection interface |
... | ... | |
151 | 158 |
else { |
152 | 159 |
// In remoting we are sure that session is null |
153 | 160 |
// both when using property paths and switching off conversations |
154 |
if(session == null && remoting) {
|
|
161 |
if(session == null && remoting) { |
|
155 | 162 |
log.info("--> readSize, of " + getRole() + " with key " + getKey()); |
156 |
read();
|
|
163 |
read(); |
|
157 | 164 |
} else { |
158 | 165 |
boolean isExtraLazy = withTemporarySessionIfNeeded( |
159 | 166 |
new LazyInitializationWork<Boolean>() { |
... | ... | |
236 | 243 |
.getTransactionContext().getTransactionEnvironment() |
237 | 244 |
.getTransactionFactory() |
238 | 245 |
.compatibleWithJtaSynchronization(); |
239 |
|
|
246 |
|
|
240 | 247 |
if ( !isJTA ) { |
241 | 248 |
// Explicitly handle the transactions only if we're not in |
242 | 249 |
// a JTA environment. A lazy loading temporary session can |
... | ... | |
245 | 252 |
// multiple transactions. |
246 | 253 |
( ( Session) session ).beginTransaction(); |
247 | 254 |
} |
248 |
|
|
255 |
|
|
249 | 256 |
session.getPersistenceContext().addUninitializedDetachedCollection( |
250 | 257 |
session.getFactory().getCollectionPersister( getRole() ), |
251 | 258 |
this |
... | ... | |
286 | 293 |
if ( !initialized ) { |
287 | 294 |
// In remoting we are sure that session is null |
288 | 295 |
// both when using property paths and switching off conversations |
289 |
if(session == null && remoting) {
|
|
296 |
if(session == null && remoting) { |
|
290 | 297 |
log.info("--> readIndexExistence, of " + getRole() + " with key " + getKey()); |
291 |
read();
|
|
298 |
read(); |
|
292 | 299 |
} else { |
293 | 300 |
Boolean extraLazyExistenceCheck = withTemporarySessionIfNeeded( |
294 | 301 |
new LazyInitializationWork<Boolean>() { |
... | ... | |
323 | 330 |
// both when using property paths and switching off conversations |
324 | 331 |
if(session == null && remoting) { |
325 | 332 |
log.info("--> readElementExistence, of " + getRole() + " with key " + getKey()); |
326 |
read();
|
|
327 |
|
|
333 |
read(); |
|
334 |
|
|
328 | 335 |
} else { |
329 | 336 |
Boolean extraLazyExistenceCheck = withTemporarySessionIfNeeded( |
330 | 337 |
new LazyInitializationWork<Boolean>() { |
... | ... | |
359 | 366 |
if ( !initialized ) { |
360 | 367 |
// In remoting we are sure that session is null |
361 | 368 |
// both when using property paths and switching off conversations |
362 |
if(session == null && remoting) {
|
|
369 |
if(session == null && remoting) { |
|
363 | 370 |
log.info("--> readElementByIndex, of " + getRole() + " with key " + getKey()); |
364 |
read();
|
|
365 |
|
|
371 |
read(); |
|
372 |
|
|
366 | 373 |
} else { |
367 | 374 |
class ExtraLazyElementByIndexReader implements LazyInitializationWork { |
368 | 375 |
private boolean isExtraLazy; |
... | ... | |
510 | 517 |
/** |
511 | 518 |
* After flushing, re-init snapshot state. |
512 | 519 |
*/ |
513 |
public void setSnapshot(Serializable key, String role, Serializable snapshot) { |
|
520 |
@Override |
|
521 |
public void setSnapshot(Serializable key, String role, Serializable snapshot) { |
|
514 | 522 |
this.key = key; |
515 | 523 |
this.role = role; |
516 | 524 |
this.storedSnapshot = snapshot; |
... | ... | |
520 | 528 |
* After flushing, clear any "queued" additions, since the |
521 | 529 |
* database state is now synchronized with the memory state. |
522 | 530 |
*/ |
523 |
public void postAction() { |
|
531 |
@Override |
|
532 |
public void postAction() { |
|
524 | 533 |
operationQueue = null; |
525 | 534 |
cachedSize = -1; |
526 | 535 |
clearDirty(); |
... | ... | |
540 | 549 |
/** |
541 | 550 |
* return the user-visible collection (or array) instance |
542 | 551 |
*/ |
543 |
public Object getValue() { |
|
552 |
@Override |
|
553 |
public Object getValue() { |
|
544 | 554 |
return this; |
545 | 555 |
} |
546 | 556 |
|
547 | 557 |
/** |
548 | 558 |
* Called just before reading any rows from the JDBC result set |
549 | 559 |
*/ |
550 |
public void beginRead() { |
|
560 |
@Override |
|
561 |
public void beginRead() { |
|
551 | 562 |
// override on some subclasses |
552 | 563 |
initializing = true; |
553 | 564 |
} |
... | ... | |
555 | 566 |
/** |
556 | 567 |
* Called after reading all rows from the JDBC result set |
557 | 568 |
*/ |
558 |
public boolean endRead() { |
|
569 |
@Override |
|
570 |
public boolean endRead() { |
|
559 | 571 |
//override on some subclasses |
560 | 572 |
return afterInitialize(); |
561 | 573 |
} |
562 | 574 |
|
563 |
public boolean afterInitialize() { |
|
575 |
@Override |
|
576 |
public boolean afterInitialize() { |
|
564 | 577 |
setInitialized(); |
565 | 578 |
//do this bit after setting initialized to true or it will recurse |
566 | 579 |
if ( operationQueue != null ) { |
... | ... | |
586 | 599 |
// In remoting we are sure that session is null |
587 | 600 |
// both when using property paths and switching off conversations |
588 | 601 |
if(session == null && remoting) { |
589 |
remoteInitialize();
|
|
602 |
remoteInitialize(); |
|
590 | 603 |
} |
591 |
|
|
604 |
|
|
592 | 605 |
if ( initialized ) { |
593 | 606 |
return; |
594 | 607 |
} |
595 | 608 |
|
596 |
|
|
609 |
|
|
597 | 610 |
withTemporarySessionIfNeeded( |
598 | 611 |
new LazyInitializationWork<Object>() { |
599 | 612 |
@Override |
... | ... | |
635 | 648 |
* Could the application possibly have a direct reference to |
636 | 649 |
* the underlying collection implementation? |
637 | 650 |
*/ |
638 |
public boolean isDirectlyAccessible() { |
|
651 |
@Override |
|
652 |
public boolean isDirectlyAccessible() { |
|
639 | 653 |
return directlyAccessible; |
640 | 654 |
} |
641 | 655 |
|
... | ... | |
644 | 658 |
* |
645 | 659 |
* @return true if this was currently associated with the given session |
646 | 660 |
*/ |
647 |
public final boolean unsetSession(SessionImplementor currentSession) { |
|
661 |
@Override |
|
662 |
public final boolean unsetSession(SessionImplementor currentSession) { |
|
648 | 663 |
prepareForPossibleSpecialSpecjInitialization(); |
649 | 664 |
if ( currentSession == this.session ) { |
650 | 665 |
this.session = null; |
... | ... | |
679 | 694 |
* @throws HibernateException if the collection was already associated |
680 | 695 |
* with another open session |
681 | 696 |
*/ |
682 |
public final boolean setCurrentSession(SessionImplementor session) throws HibernateException { |
|
697 |
@Override |
|
698 |
public final boolean setCurrentSession(SessionImplementor session) throws HibernateException { |
|
683 | 699 |
if ( session == this.session ) { |
684 | 700 |
return false; |
685 | 701 |
} |
... | ... | |
711 | 727 |
/** |
712 | 728 |
* Do we need to completely recreate this collection when it changes? |
713 | 729 |
*/ |
714 |
public boolean needsRecreate(CollectionPersister persister) { |
|
730 |
@Override |
|
731 |
public boolean needsRecreate(CollectionPersister persister) { |
|
715 | 732 |
return false; |
716 | 733 |
} |
717 | 734 |
|
... | ... | |
719 | 736 |
* To be called internally by the session, forcing |
720 | 737 |
* immediate initialization. |
721 | 738 |
*/ |
722 |
public final void forceInitialization() throws HibernateException { |
|
739 |
@Override |
|
740 |
public final void forceInitialization() throws HibernateException { |
|
723 | 741 |
if ( !initialized ) { |
724 | 742 |
if ( initializing ) { |
725 | 743 |
throw new AssertionFailure( "force initialize loading collection" ); |
... | ... | |
746 | 764 |
/** |
747 | 765 |
* Is this instance initialized? |
748 | 766 |
*/ |
749 |
public final boolean wasInitialized() { |
|
767 |
@Override |
|
768 |
public final boolean wasInitialized() { |
|
750 | 769 |
return initialized; |
751 | 770 |
} |
752 | 771 |
|
753 |
public boolean isRowUpdatePossible() { |
|
772 |
@Override |
|
773 |
public boolean isRowUpdatePossible() { |
|
754 | 774 |
return true; |
755 | 775 |
} |
756 | 776 |
|
757 | 777 |
/** |
758 | 778 |
* Does this instance have any "queued" additions? |
759 | 779 |
*/ |
760 |
public final boolean hasQueuedOperations() { |
|
780 |
@Override |
|
781 |
public final boolean hasQueuedOperations() { |
|
761 | 782 |
return operationQueue != null; |
762 | 783 |
} |
763 | 784 |
|
764 | 785 |
/** |
765 | 786 |
* Iterate the "queued" additions |
766 | 787 |
*/ |
767 |
public final Iterator queuedAdditionIterator() { |
|
788 |
@Override |
|
789 |
public final Iterator queuedAdditionIterator() { |
|
768 | 790 |
if ( hasQueuedOperations() ) { |
769 | 791 |
return new Iterator() { |
770 | 792 |
int i = 0; |
771 | 793 |
|
772 |
public Object next() { |
|
794 |
@Override |
|
795 |
public Object next() { |
|
773 | 796 |
return operationQueue.get( i++ ).getAddedInstance(); |
774 | 797 |
} |
775 | 798 |
|
776 |
public boolean hasNext() { |
|
799 |
@Override |
|
800 |
public boolean hasNext() { |
|
777 | 801 |
return i < operationQueue.size(); |
778 | 802 |
} |
779 | 803 |
|
780 |
public void remove() { |
|
804 |
@Override |
|
805 |
public void remove() { |
|
781 | 806 |
throw new UnsupportedOperationException(); |
782 | 807 |
} |
783 | 808 |
}; |
... | ... | |
790 | 815 |
/** |
791 | 816 |
* Iterate the "queued" additions |
792 | 817 |
*/ |
793 |
@SuppressWarnings({"unchecked"}) |
|
818 |
@Override |
|
819 |
@SuppressWarnings({"unchecked"}) |
|
794 | 820 |
public final Collection getQueuedOrphans(String entityName) { |
795 | 821 |
if ( hasQueuedOperations() ) { |
796 | 822 |
Collection additions = new ArrayList( operationQueue.size() ); |
... | ... | |
810 | 836 |
* Called before inserting rows, to ensure that any surrogate keys |
811 | 837 |
* are fully generated |
812 | 838 |
*/ |
813 |
public void preInsert(CollectionPersister persister) throws HibernateException { |
|
839 |
@Override |
|
840 |
public void preInsert(CollectionPersister persister) throws HibernateException { |
|
814 | 841 |
} |
815 | 842 |
|
816 | 843 |
/** |
817 | 844 |
* Called after inserting a row, to fetch the natively generated id |
818 | 845 |
*/ |
819 |
public void afterRowInsert(CollectionPersister persister, Object entry, int i) throws HibernateException { |
|
846 |
@Override |
|
847 |
public void afterRowInsert(CollectionPersister persister, Object entry, int i) throws HibernateException { |
|
820 | 848 |
} |
821 | 849 |
|
822 | 850 |
/** |
823 | 851 |
* get all "orphaned" elements |
824 | 852 |
*/ |
825 |
public abstract Collection getOrphans(Serializable snapshot, String entityName) throws HibernateException; |
|
853 |
@Override |
|
854 |
public abstract Collection getOrphans(Serializable snapshot, String entityName) throws HibernateException; |
|
826 | 855 |
|
827 | 856 |
/** |
828 | 857 |
* Get the current session |
... | ... | |
839 | 868 |
this.itr = itr; |
840 | 869 |
} |
841 | 870 |
|
842 |
public boolean hasNext() { |
|
871 |
@Override |
|
872 |
public boolean hasNext() { |
|
843 | 873 |
return itr.hasNext(); |
844 | 874 |
} |
845 | 875 |
|
846 |
public Object next() { |
|
876 |
@Override |
|
877 |
public Object next() { |
|
847 | 878 |
return itr.next(); |
848 | 879 |
} |
849 | 880 |
|
850 |
public void remove() { |
|
881 |
@Override |
|
882 |
public void remove() { |
|
851 | 883 |
write(); |
852 | 884 |
itr.remove(); |
853 | 885 |
} |
... | ... | |
861 | 893 |
this.itr = itr; |
862 | 894 |
} |
863 | 895 |
|
864 |
@SuppressWarnings({"unchecked"}) |
|
896 |
@Override |
|
897 |
@SuppressWarnings({"unchecked"}) |
|
865 | 898 |
public void add(Object o) { |
866 | 899 |
write(); |
867 | 900 |
itr.add( o ); |
868 | 901 |
} |
869 | 902 |
|
870 |
public boolean hasNext() { |
|
903 |
@Override |
|
904 |
public boolean hasNext() { |
|
871 | 905 |
return itr.hasNext(); |
872 | 906 |
} |
873 | 907 |
|
874 |
public boolean hasPrevious() { |
|
908 |
@Override |
|
909 |
public boolean hasPrevious() { |
|
875 | 910 |
return itr.hasPrevious(); |
876 | 911 |
} |
877 | 912 |
|
878 |
public Object next() { |
|
913 |
@Override |
|
914 |
public Object next() { |
|
879 | 915 |
return itr.next(); |
880 | 916 |
} |
881 | 917 |
|
882 |
public int nextIndex() { |
|
918 |
@Override |
|
919 |
public int nextIndex() { |
|
883 | 920 |
return itr.nextIndex(); |
884 | 921 |
} |
885 | 922 |
|
886 |
public Object previous() { |
|
923 |
@Override |
|
924 |
public Object previous() { |
|
887 | 925 |
return itr.previous(); |
888 | 926 |
} |
889 | 927 |
|
890 |
public int previousIndex() { |
|
928 |
@Override |
|
929 |
public int previousIndex() { |
|
891 | 930 |
return itr.previousIndex(); |
892 | 931 |
} |
893 | 932 |
|
894 |
public void remove() { |
|
933 |
@Override |
|
934 |
public void remove() { |
|
895 | 935 |
write(); |
896 | 936 |
itr.remove(); |
897 | 937 |
} |
898 | 938 |
|
899 |
@SuppressWarnings({"unchecked"}) |
|
939 |
@Override |
|
940 |
@SuppressWarnings({"unchecked"}) |
|
900 | 941 |
public void set(Object o) { |
901 | 942 |
write(); |
902 | 943 |
itr.set( o ); |
... | ... | |
911 | 952 |
this.set = set; |
912 | 953 |
} |
913 | 954 |
|
914 |
@SuppressWarnings({"unchecked"}) |
|
955 |
@Override |
|
956 |
@SuppressWarnings({"unchecked"}) |
|
915 | 957 |
public boolean add(Object o) { |
916 | 958 |
write(); |
917 | 959 |
return set.add( o ); |
918 | 960 |
} |
919 | 961 |
|
920 |
@SuppressWarnings({"unchecked"}) |
|
962 |
@Override |
|
963 |
@SuppressWarnings({"unchecked"}) |
|
921 | 964 |
public boolean addAll(Collection c) { |
922 | 965 |
write(); |
923 | 966 |
return set.addAll( c ); |
924 | 967 |
} |
925 | 968 |
|
926 |
public void clear() { |
|
969 |
@Override |
|
970 |
public void clear() { |
|
927 | 971 |
write(); |
928 | 972 |
set.clear(); |
929 | 973 |
} |
930 | 974 |
|
931 |
public boolean contains(Object o) { |
|
975 |
@Override |
|
976 |
public boolean contains(Object o) { |
|
932 | 977 |
return set.contains( o ); |
933 | 978 |
} |
934 | 979 |
|
935 |
public boolean containsAll(Collection c) { |
|
980 |
@Override |
|
981 |
public boolean containsAll(Collection c) { |
|
936 | 982 |
return set.containsAll( c ); |
937 | 983 |
} |
938 | 984 |
|
939 |
public boolean isEmpty() { |
|
985 |
@Override |
|
986 |
public boolean isEmpty() { |
|
940 | 987 |
return set.isEmpty(); |
941 | 988 |
} |
942 | 989 |
|
943 |
public Iterator iterator() { |
|
990 |
@Override |
|
991 |
public Iterator iterator() { |
|
944 | 992 |
return new IteratorProxy( set.iterator() ); |
945 | 993 |
} |
946 | 994 |
|
947 |
public boolean remove(Object o) { |
|
995 |
@Override |
|
996 |
public boolean remove(Object o) { |
|
948 | 997 |
write(); |
949 | 998 |
return set.remove( o ); |
950 | 999 |
} |
951 | 1000 |
|
952 |
public boolean removeAll(Collection c) { |
|
1001 |
@Override |
|
1002 |
public boolean removeAll(Collection c) { |
|
953 | 1003 |
write(); |
954 | 1004 |
return set.removeAll( c ); |
955 | 1005 |
} |
956 | 1006 |
|
957 |
public boolean retainAll(Collection c) { |
|
1007 |
@Override |
|
1008 |
public boolean retainAll(Collection c) { |
|
958 | 1009 |
write(); |
959 | 1010 |
return set.retainAll( c ); |
960 | 1011 |
} |
961 | 1012 |
|
962 |
public int size() { |
|
1013 |
@Override |
|
1014 |
public int size() { |
|
963 | 1015 |
return set.size(); |
964 | 1016 |
} |
965 | 1017 |
|
966 |
public Object[] toArray() { |
|
1018 |
@Override |
|
1019 |
public Object[] toArray() { |
|
967 | 1020 |
return set.toArray(); |
968 | 1021 |
} |
969 | 1022 |
|
970 |
@SuppressWarnings({"unchecked"}) |
|
1023 |
@Override |
|
1024 |
@SuppressWarnings({"unchecked"}) |
|
971 | 1025 |
public Object[] toArray(Object[] array) { |
972 | 1026 |
return set.toArray( array ); |
973 | 1027 |
} |
... | ... | |
1207 | 1261 |
} |
1208 | 1262 |
} |
1209 | 1263 |
|
1210 |
public Object getIdentifier(Object entry, int i) { |
|
1264 |
@Override |
|
1265 |
public Object getIdentifier(Object entry, int i) { |
|
1211 | 1266 |
throw new UnsupportedOperationException(); |
1212 | 1267 |
} |
1213 | 1268 |
|
1214 |
public Object getOwner() { |
|
1269 |
@Override |
|
1270 |
public Object getOwner() { |
|
1215 | 1271 |
return owner; |
1216 | 1272 |
} |
1217 | 1273 |
|
1218 |
public void setOwner(Object owner) { |
|
1274 |
@Override |
|
1275 |
public void setOwner(Object owner) { |
|
1219 | 1276 |
this.owner = owner; |
1220 | 1277 |
} |
1221 | 1278 |
|
1222 | 1279 |
/** ------ Below is section of code which makes remote service calls ----- */ |
1223 |
// The affected methods are :
|
|
1280 |
// The affected methods are : |
|
1224 | 1281 |
// initialize(final boolean writing) |
1225 | 1282 |
// readSize() |
1226 | 1283 |
// readIndexExistence(final Object index) |
1227 | 1284 |
// readElementExistence(final Object element) |
1228 |
// readElementByIndex(final Object index)
|
|
1229 |
|
|
1285 |
// readElementByIndex(final Object index) |
|
1286 |
|
|
1230 | 1287 |
private static ICdmApplicationConfiguration configuration; |
1231 | 1288 |
private static boolean remoting = false; |
1232 |
|
|
1289 |
|
|
1233 | 1290 |
public static void setConfiguration(ICdmApplicationConfiguration conf) { |
1234 | 1291 |
configuration = conf; |
1235 |
|
|
1292 |
|
|
1236 | 1293 |
if(conf instanceof CdmApplicationRemoteController) { |
1237 | 1294 |
remoting = true; |
1238 | 1295 |
} else { |
1239 | 1296 |
remoting = false; |
1240 | 1297 |
} |
1241 | 1298 |
} |
1242 |
|
|
1243 |
|
|
1299 |
|
|
1300 |
|
|
1244 | 1301 |
private void remoteInitialize() { |
1245 |
|
|
1246 |
if (getOwner() != null && !initialized) {
|
|
1247 |
|
|
1302 |
|
|
1303 |
if (getOwner() != null && !initialized) { |
|
1304 |
|
|
1248 | 1305 |
try { |
1249 | 1306 |
String role = getRole(); |
1250 | 1307 |
String fieldName = role.substring(role.lastIndexOf(".") + 1); |
1251 | 1308 |
log.info("--> Remote Lazy Initializing " + getRole() + " , key : " + getKey() + " , field : " + fieldName); |
1252 | 1309 |
Object owner = getOwner(); |
1253 |
|
|
1310 |
|
|
1254 | 1311 |
if(configuration == null) { |
1255 | 1312 |
throw new HibernateException("CdmApplicationRemoteConfiguration not initialized (null)"); |
1256 | 1313 |
} |
... | ... | |
1258 | 1315 |
if(commonService == null) { |
1259 | 1316 |
throw new HibernateException("commonService not initialized (null)"); |
1260 | 1317 |
} |
1261 |
|
|
1262 |
PersistentCollection col = commonService.initializeCollection(this);
|
|
1263 |
afterInitialize(); |
|
1264 |
|
|
1265 |
Class<?> clazz = getClass(); |
|
1266 |
if (clazz != null) {
|
|
1267 |
CollectionField cf = getCollectionField(col); |
|
1268 |
Field field = clazz.getDeclaredField(cf.getFieldName()); |
|
1269 |
field.setAccessible(true); |
|
1270 |
field.set(this, cf.getCollection());
|
|
1271 |
}
|
|
1318 |
|
|
1319 |
// PersistentCollection col = commonService.initializeCollection(this);
|
|
1320 |
// afterInitialize();
|
|
1321 |
// |
|
1322 |
// Class<?> clazz = getClass();
|
|
1323 |
// if (clazz != null) {
|
|
1324 |
// CollectionField cf = getCollectionField(col);
|
|
1325 |
// Field field = clazz.getDeclaredField(cf.getFieldName());
|
|
1326 |
// field.setAccessible(true);
|
|
1327 |
// field.set(this, cf.getCollection());
|
|
1328 |
// }
|
|
1272 | 1329 |
} catch (Exception ex) { |
1273 | 1330 |
log.warn(ex.getMessage()); |
1274 |
} |
|
1331 |
} |
|
1332 |
log.warn("This code is invalid"); |
|
1275 | 1333 |
} |
1276 | 1334 |
} |
1277 |
|
|
1278 |
|
|
1335 |
|
|
1336 |
|
|
1279 | 1337 |
private CollectionField getCollectionField(PersistentCollection pc) { |
1280 | 1338 |
if(pc != null) { |
1281 | 1339 |
if(pc instanceof PersistentSet) { |
... | ... | |
1296 | 1354 |
} |
1297 | 1355 |
return null; |
1298 | 1356 |
} |
1299 |
|
|
1357 |
|
|
1300 | 1358 |
private String getCollectionFieldName(PersistentCollection pc) { |
1301 | 1359 |
if(pc != null) { |
1302 | 1360 |
if(pc instanceof PersistentSet || pc instanceof PersistentSortedSet) { |
1303 | 1361 |
return "set"; |
1304 |
}
|
|
1362 |
} |
|
1305 | 1363 |
if(pc instanceof PersistentList) { |
1306 | 1364 |
return "list"; |
1307 | 1365 |
} |
... | ... | |
1311 | 1369 |
} |
1312 | 1370 |
return null; |
1313 | 1371 |
} |
1314 |
|
|
1372 |
|
|
1315 | 1373 |
private class CollectionField { |
1316 |
private Object col; |
|
1317 |
private String fieldName; |
|
1374 |
private final Object col;
|
|
1375 |
private final String fieldName;
|
|
1318 | 1376 |
public CollectionField(Object col, String fieldName) { |
1319 | 1377 |
this.col = col; |
1320 | 1378 |
this.fieldName = fieldName; |
1321 | 1379 |
} |
1322 |
|
|
1380 |
|
|
1323 | 1381 |
public Object getCollection() { |
1324 | 1382 |
return this.col; |
1325 | 1383 |
} |
1326 |
|
|
1384 |
|
|
1327 | 1385 |
public String getFieldName() { |
1328 | 1386 |
return this.fieldName; |
1329 | 1387 |
} |
1330 | 1388 |
} |
1331 |
|
|
1389 |
|
|
1332 | 1390 |
public static boolean isInitialized(List list) { |
1333 | 1391 |
return ((AbstractPersistentCollection)list).initialized; |
1334 | 1392 |
} |
1335 |
|
|
1393 |
|
|
1336 | 1394 |
public static boolean isInitialized(Map map) { |
1337 | 1395 |
return ((AbstractPersistentCollection)map).initialized; |
1338 | 1396 |
} |
1339 |
|
|
1397 |
|
|
1340 | 1398 |
public static boolean isInitialized(Set set) { |
1341 | 1399 |
return ((AbstractPersistentCollection)set).initialized; |
1342 | 1400 |
} |
1343 |
|
|
1344 |
//FIXME:Remoting These methods may no longer be required since we are |
|
1345 |
// initialising collections as default behaviour |
|
1346 |
private int remoteSize() { |
|
1347 |
int size = configuration.getCommonService().size(this); |
|
1348 |
log.debug("--> Remote Lazy Initializing size of " + getRole() + " to " + size); |
|
1349 |
if(size == -1) { |
|
1350 |
throw new HibernateException("size of " + getClass() + " could not be retrieved from remote service"); |
|
1351 |
} |
|
1352 |
return size; |
|
1353 |
} |
|
1354 |
|
|
1355 |
private Object remoteReadElementByIndex(int index) { |
|
1356 |
Object element = configuration.getCommonService().get(this,index); |
|
1357 |
log.debug("--> Remote Lazy Initializing element from " + getRole() + " at index " + index); |
|
1358 |
return element; |
|
1359 |
} |
|
1360 |
|
|
1361 |
private boolean remoteReadElementExistence(Object element) { |
|
1362 |
return configuration.getCommonService().contains(this,element); |
|
1363 |
} |
|
1364 |
|
|
1365 |
private boolean remoteReadIndexExistence(Object index) { |
|
1366 |
return false; |
|
1367 |
} |
|
1401 |
|
|
1402 |
|
|
1368 | 1403 |
} |
1369 | 1404 |
|
Also available in: Unified diff
Fix remoting code compilation errors