Wiki source code of Session.java Addition

Last modified by David Avendasora on 2009/03/26 09:11

Hide last authors
David Avendasora 1.1 1 These additions are based on a more advanced Stateless RMI concept by Florijan Stamenkovic.
2
David Avendasora 6.1 3 {{code 0="java"}}
David Avendasora 5.1 4 public EOFetchSpecification clientSideRequestGetFetchSpecification(String fetchSpecification,
5 String entity) {
6 return getFetchSpecification(fetchSpecification,
7 entity);
David Avendasora 1.1 8 }
David Avendasora 5.1 9
10 /**
11 * Loads and returns an <tt>EOFetchSpecification</tt> objects for the given specification and entity name.
12 *
13 * @param fetchSpecification
14 * Name of the specification
15 * @param entity
16 * Name of the entity
17 * @return A fetch specification, or <tt>null</tt> if it is not found, or an error occurs
18 */
19 public EOFetchSpecification getFetchSpecification(String fetchSpecification,
20 String entity) {
21 try {
22 // NSLog.out.appendln("About to call FetchSpecification " +
23 // fetchSpecification + " on Entity " + entity);
24 return EOFetchSpecification.fetchSpecificationNamed(fetchSpecification,
25 entity);
26 } catch (Exception ex) {
David Avendasora 1.1 27 NSLog.out.appendln(ex);
28 return null;
29 }
30 }
David Avendasora 6.1 31 {{/code}}
David Avendasora 1.1 32
Francis Labrie 4.1 33 {{warning title="Caution"}}
David Avendasora 6.1 34 Due to security concerns you cannot call FetchSpecifications from the client-side that use a Raw SQL Expression without implementing the delegate method [[distributionContextShouldFetchObjectsWithFetchSpecification>>url:http://developer.apple.com/documentation/MacOSXServer/Reference/WO54_Reference/com/webobjects/eodistribution/EODistributionContext.Delegate.html||shape="rect"]] which this code does NOT do.
David Avendasora 3.1 35
36 If you try to, you will get the following exception in the server log:
37
David Avendasora 6.1 38 (% style="color: red;" %)Server exception: The fetchSpecification YourFetchSpecificationWithRawSQLExpression was not allowed to execute on the server. If your application needs to execute this method, the security needs to be relaxed by implementing the delegate method distributionContextShouldFetchObjectsWithFetchSpecification
David Avendasora 3.1 39
40 and this code will return null to the client instead of the expected FetchSpecification.
Francis Labrie 4.1 41 {{/warning}}