Closed bloodgain closed 7 years ago
Thank you for your feedback, we are currently reviewing the issues. Will update the issue as soon as we have the explanation or fix ready to post.
Here is the code example for preload:
//Functionality Test for pre-load
int index=0;
Resource preLoadResource = setHasTerms.member(index);
while(preLoadResource != null)
{
if(index%2 != 0) {
preLoadResource.setLoaded(true);
}
Util.jsonPrettyPrinter(preLoadResource.toJSON());
preLoadResource = setHasTerms.member(++index);
}
Util.jsonPrettyPrinter(setHasTerms.count());
It is available in Git and Maven.
The
ResourceSet
methodsfetchMember
andcreate
return aResource
object created from JSON obtained from the server within the same function call. However, they do not set theisLoaded
flag in the returnedResource
object totrue
. An examination of the code reveals the same issue with other methods, includingsync
andmergeSync
(possibly others).Subsequent method calls on the
Resource
object (notablytoJSON
) initiate aload
call on theResource
object before returning a value. This creates an extraneous call to the web service and discardsproperties
arguments passed to the original loading method. As a result, the user is unable to get a reduced-scope JSON object fromResource
objects when using these methods, while also generating unexpected calls to the server.Possible solutions:
isLoaded
variable inResource
through package-private methods or constructors, allowing partner classes to create "pre-loaded"Resource
objects.isLoaded
totrue
by default in theResource
constructors that takeJsonObject
parameters. Make the constructors package-private.Neither solution exposes the
isLoaded
variable to the public interface, but Solution 2 seems superior. It is simpler to implement and requires no extra work withinResourceSet
or other partner classes. The current library design offers no obvious reason for users to constructResource
objects directly. If that need arises, static factory methods could be added to enable controlled construction.