Wiki source code of Session.java Addition

Version 6.1 by David Avendasora on 2009/03/26 09:11

Show last authors
1 These additions are based on a more advanced Stateless RMI concept by Florijan Stamenkovic.
2
3 {{code 0="java"}}
4 public EOFetchSpecification clientSideRequestGetFetchSpecification(String fetchSpecification,
5 String entity) {
6 return getFetchSpecification(fetchSpecification,
7 entity);
8 }
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) {
27 NSLog.out.appendln(ex);
28 return null;
29 }
30 }
31 {{/code}}
32
33 {{warning title="Caution"}}
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.
35
36 If you try to, you will get the following exception in the server log:
37
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
39
40 and this code will return null to the client instead of the expected FetchSpecification.
41 {{/warning}}