return true;
}
else {
- boolean isExtraLazy = withTemporarySessionIfNeeded(
- new LazyInitializationWork<Boolean>() {
- @Override
- public Boolean doWork() {
- CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this );
-
- if ( entry != null ) {
- CollectionPersister persister = entry.getLoadedPersister();
- if ( persister.isExtraLazy() ) {
- if ( hasQueuedOperations() ) {
- session.flush();
+ // In remoting we are sure that session is null
+ // both when using property paths and switching off conversations
+ if(session == null && remoting) {
+ log.info("--> readSize, of " + getRole() + " with key " + getKey());
+ read();
+ } else {
+ boolean isExtraLazy = withTemporarySessionIfNeeded(
+ new LazyInitializationWork<Boolean>() {
+ @Override
+ public Boolean doWork() {
+ CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this );
+
+ if ( entry != null ) {
+ CollectionPersister persister = entry.getLoadedPersister();
+ if ( persister.isExtraLazy() ) {
+ if ( hasQueuedOperations() ) {
+ session.flush();
+ }
+ cachedSize = persister.getSize( entry.getLoadedKey(), session );
+ return true;
+ }
+ else {
+ read();
}
- cachedSize = persister.getSize( entry.getLoadedKey(), session );
- return true;
}
- else {
- read();
+ else{
+ throwLazyInitializationExceptionIfNotConnected();
}
+ return false;
}
- else{
- throwLazyInitializationExceptionIfNotConnected();
- }
- return false;
}
- }
- );
- if ( isExtraLazy ) {
- return true;
+ );
+ if ( isExtraLazy ) {
+ return true;
+ }
}
}
}
protected Boolean readIndexExistence(final Object index) {
if ( !initialized ) {
- Boolean extraLazyExistenceCheck = withTemporarySessionIfNeeded(
- new LazyInitializationWork<Boolean>() {
- @Override
- public Boolean doWork() {
- CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this );
- CollectionPersister persister = entry.getLoadedPersister();
- if ( persister.isExtraLazy() ) {
- if ( hasQueuedOperations() ) {
- session.flush();
+ // In remoting we are sure that session is null
+ // both when using property paths and switching off conversations
+ if(session == null && remoting) {
+ log.info("--> readIndexExistence, of " + getRole() + " with key " + getKey());
+ read();
+ } else {
+ Boolean extraLazyExistenceCheck = withTemporarySessionIfNeeded(
+ new LazyInitializationWork<Boolean>() {
+ @Override
+ public Boolean doWork() {
+ CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this );
+ CollectionPersister persister = entry.getLoadedPersister();
+ if ( persister.isExtraLazy() ) {
+ if ( hasQueuedOperations() ) {
+ session.flush();
+ }
+ return persister.indexExists( entry.getLoadedKey(), index, session );
}
- return persister.indexExists( entry.getLoadedKey(), index, session );
- }
- else {
- read();
+ else {
+ read();
+ }
+ return null;
}
- return null;
}
- }
- );
- if ( extraLazyExistenceCheck != null ) {
- return extraLazyExistenceCheck;
+ );
+ if ( extraLazyExistenceCheck != null ) {
+ return extraLazyExistenceCheck;
+ }
}
}
return null;
protected Boolean readElementExistence(final Object element) {
if ( !initialized ) {
- Boolean extraLazyExistenceCheck = withTemporarySessionIfNeeded(
- new LazyInitializationWork<Boolean>() {
- @Override
- public Boolean doWork() {
- CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this );
- CollectionPersister persister = entry.getLoadedPersister();
- if ( persister.isExtraLazy() ) {
- if ( hasQueuedOperations() ) {
- session.flush();
+ // In remoting we are sure that session is null
+ // both when using property paths and switching off conversations
+ if(session == null && remoting) {
+ log.info("--> readElementExistence, of " + getRole() + " with key " + getKey());
+ read();
+
+ } else {
+ Boolean extraLazyExistenceCheck = withTemporarySessionIfNeeded(
+ new LazyInitializationWork<Boolean>() {
+ @Override
+ public Boolean doWork() {
+ CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this );
+ CollectionPersister persister = entry.getLoadedPersister();
+ if ( persister.isExtraLazy() ) {
+ if ( hasQueuedOperations() ) {
+ session.flush();
+ }
+ return persister.elementExists( entry.getLoadedKey(), element, session );
}
- return persister.elementExists( entry.getLoadedKey(), element, session );
- }
- else {
- read();
+ else {
+ read();
+ }
+ return null;
}
- return null;
}
- }
- );
- if ( extraLazyExistenceCheck != null ) {
- return extraLazyExistenceCheck;
+ );
+ if ( extraLazyExistenceCheck != null ) {
+ return extraLazyExistenceCheck;
+ }
}
}
return null;
protected Object readElementByIndex(final Object index) {
if ( !initialized ) {
- class ExtraLazyElementByIndexReader implements LazyInitializationWork {
- private boolean isExtraLazy;
- private Object element;
-
- @Override
- public Object doWork() {
- CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this );
- CollectionPersister persister = entry.getLoadedPersister();
- isExtraLazy = persister.isExtraLazy();
- if ( isExtraLazy ) {
- if ( hasQueuedOperations() ) {
- session.flush();
+ // In remoting we are sure that session is null
+ // both when using property paths and switching off conversations
+ if(session == null && remoting) {
+ log.info("--> readElementByIndex, of " + getRole() + " with key " + getKey());
+ read();
+
+ } else {
+ class ExtraLazyElementByIndexReader implements LazyInitializationWork {
+ private boolean isExtraLazy;
+ private Object element;
+
+ @Override
+ public Object doWork() {
+ CollectionEntry entry = session.getPersistenceContext().getCollectionEntry( AbstractPersistentCollection.this );
+ CollectionPersister persister = entry.getLoadedPersister();
+ isExtraLazy = persister.isExtraLazy();
+ if ( isExtraLazy ) {
+ if ( hasQueuedOperations() ) {
+ session.flush();
+ }
+ element = persister.getElementByIndex( entry.getLoadedKey(), index, session, owner );
}
- element = persister.getElementByIndex( entry.getLoadedKey(), index, session, owner );
- }
- else {
- read();
+ else {
+ read();
+ }
+ return null;
}
- return null;
}
- }
- ExtraLazyElementByIndexReader reader = new ExtraLazyElementByIndexReader();
- //noinspection unchecked
- withTemporarySessionIfNeeded( reader );
- if ( reader.isExtraLazy ) {
- return reader.element;
+ ExtraLazyElementByIndexReader reader = new ExtraLazyElementByIndexReader();
+ //noinspection unchecked
+ withTemporarySessionIfNeeded( reader );
+ if ( reader.isExtraLazy ) {
+ return reader.element;
+ }
}
}
return UNKNOWN;
protected final void initialize(final boolean writing) {
// In remoting we are sure that session is null
// both when using property paths and switching off conversations
- if(session == null) {
- remoteInitialize();
+ if(session == null && remoting) {
+ remoteInitialize();
}
if ( initialized ) {
this.owner = owner;
}
- /** Below is section of code which makes remote service calls */
+ /** ------ Below is section of code which makes remote service calls ----- */
+ // The affected methods are :
+ // initialize(final boolean writing)
+ // readSize()
+ // readIndexExistence(final Object index)
+ // readElementExistence(final Object element)
+ // readElementByIndex(final Object index)
private static ICdmApplicationConfiguration configuration;
-
+ private static boolean remoting = false;
public static void setConfiguration(ICdmApplicationConfiguration conf) {
configuration = conf;
+ Boolean isRemoting = (Boolean)configuration.getBean("isRemoting");
+ if(isRemoting != null) {
+ remoting = isRemoting.booleanValue();
+ } else {
+ remoting = false;
+ }
}
+
private void remoteInitialize() {
if (getOwner() != null && !initialized) {
try {
String role = getRole();
String fieldName = role.substring(role.lastIndexOf(".") + 1);
- log.info("--> Remote Lazy Initializing " + getRole() + " , field : " + fieldName);
+ log.info("--> Remote Lazy Initializing " + getRole() + " , key : " + getKey() + " , field : " + fieldName);
Object owner = getOwner();
if(configuration == null) {
}
}
+
private CollectionField getCollectionField(PersistentCollection pc) {
if(pc != null) {
if(pc instanceof PersistentSet) {
}
}
+ public static boolean isInitialized(List list) {
+ return ((AbstractPersistentCollection)list).initialized;
+ }
+
+ public static boolean isInitialized(Map map) {
+ return ((AbstractPersistentCollection)map).initialized;
+ }
+
+ //FIXME:Remoting These methods may no longer be required since we are
+ // initialising collections as default behaviour
+ private int remoteSize() {
+ int size = configuration.getCommonService().size(this);
+ log.debug("--> Remote Lazy Initializing size of " + getRole() + " to " + size);
+ if(size == -1) {
+ throw new HibernateException("size of " + getClass() + " could not be retrieved from remote service");
+ }
+ return size;
+ }
+
+ private Object remoteReadElementByIndex(int index) {
+ Object element = configuration.getCommonService().get(this,index);
+ log.debug("--> Remote Lazy Initializing element from " + getRole() + " at index " + index);
+ return element;
+ }
+
+ private boolean remoteReadElementExistence(Object element) {
+ return configuration.getCommonService().contains(this,element);
+ }
+
+ private boolean remoteReadIndexExistence(Object index) {
+ return false;
+ }
}