cayenne-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Lindesay <>
Subject Re: New features in Select API
Date Tue, 07 Apr 2015 18:15:24 GMT
Hello Savva;

Thank you for that update.  I had some thoughts on the "selectOne" 
> selectOne(ObjectContext);

I often find myself needing to assert that a single object is present 
after querying for it.  A good example would be querying for an item of 
reference data by some 'code'.  In this example there are three 

1) I get nothing --> runtime exception
2) I get one object --> return it
3) I get more than one object --> runtime exception

The "selectOne(..)" method will (as-built) take care of dealing with the 
#3 runtime exception for me, but still leaves me to handle the runtime 
exception for #1.  I wonder if...

T selectOne(context)

...should throw a runtime exception if it finds no result instead of 
returning null.  An additional signature...

T selectOne(context, T fallbackValue)

Could take a fallback value that could be presented in the case that the 
query yielded no results.  This would provide the functionality 
as-implemented now.

Although it is not an option because of the language level of the 
project, returning an Optional<T> (Java 8 / guava) would also provide a 
good way to provide this functionality.


Andrew Lindesay

View raw message