• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Java Client RawRows Query
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Java Client RawRows Query


  • Subject: Re: Java Client RawRows Query
  • From: David Avendasora <email@hidden>
  • Date: Mon, 28 Apr 2008 07:02:27 -0400

Hi Neil,

In addition to what Flor is suggesting, you can use key-path constructs to sum values as well as doing RMI (stateless or stateful). A key-path example would be:

valueForKeyPath("email@hiddenbute")

Now, what this is going to do is retrieve all the EOs from the server then iterate through them on the client and sum the "attributeToSum" and return that value. So this one command does a _lot_ of EO work (ain't WO great?). If there are a lot of EOs in the relationship and you don't need all of them on the client for other things, then you should probably perform this in the server-side class instead of the client-side one. The way I normally do this is using regular stateful Remote Method Invocation that is built into every EO.

On the client side you replace the body of your method that ruturns the sum like so:

public BigDecimal attributeSum() {
return (BigDecimal) invokeRemoteMethod("clientSideRequestAttributeSum", null, null);
}


Then on the server side you'd add the following methods:

public BigDecimal clientSideRequestAttributeSum() {
	return attributeSum();
}

public BigDecimal attributeSum() {
return (BigDecimal) valueForKeyPath("email@hiddenbute");
}


Any method called by the client-side classes, MUST be prefixed with "clientSideRequest" in order for WO to let it execute on the server- side.

By using the "Stateful" version of RMI, WO will automatically synchronize the client and server-side Editing Contexts so any changes you've made on the client side will be copied back to the server along with the RMI request. It's all transparent which makes keeping the client and server in sync ridiculously easy.

The Stateless RMI that Flor refers to will not copy any of the Editing Context information back to the server, so it is possible to end up with two different sets of data. However, if you were going to perform a SQL query anyway (are you sure you need to do it this way?) then what you are doing _is_ stateless anyway.

Are you absolutely sure you need to go to the DB yourself? Why can't you use WO to manage the fetching of the DB records?

Dave


On Apr 27, 2008, at 8:15 PM, Florijan Stamenkovic wrote:

Neil,


EOUtilities is a part of EOAccess, which is not a part of the client libraries. If you managed to get it in your client side code you must be including the server side only libraries into your client application. You are not allowed to distribute these with your client application! I do mention this in the tutorial, please check out:


http://web.mac.com/flor385/eSwamp/software/wojc_tutorial.html#client_libs

To solve your problem I would use stateless RMI to access a server side method that does the EOUtilities call... If you need help with this I can explain how off list...

Also I'd like to notify you that I have in the beginning of this month updated the tutorial, nothing significant, but it now points to JBND for more info on how to bind a Swing GUI (which I assume you are doing) to EOF. If you are not familiar with JBND, it is a library I made specially for this purpose, and it can be found at:

http://web.mac.com/flor385/JBND/

And finally, welcome to the WOJC club (I assume you are new to it since I don't recall seeing your name before, and I do try to keep track of JC users out there), and do not hesitate to ask if you need any help...

Best regards,
Flor

On Apr 27, 2008, at 17:00, Neil MacLennan wrote:

I'm running a JavaClient application (and surprised how easy it is to connect to my EOModel on the server :-) Thanks to Florijan's walkthrough [http://web.mac.com/flor385/eSwamp/software/wojc_tutorial.html ]).

I'm trying to run a simple SQL query that performs a SQL sum on a table, and I thought of using EOUtilities.rawRowsForSQL to do this read operation rather than return a full set of EOs and sum them in code. However I got this error:

[AWT-EventQueue-0] DEBUG uk.org.cwwresources.TicketSearch - An error occurred: modelGroup: an EOEditingContext's root object store must be an EOObjectStoreCoordinator for this method to function.
java.lang.IllegalArgumentException: modelGroup: an EOEditingContext's root object store must be an EOObjectStoreCoordinator for this method to function.
at com.webobjects.eoaccess.EOUtilities.modelGroup(EOUtilities.java: 1004)
at com .webobjects .eoaccess.EOUtilities.databaseContextForModelNamed(EOUtilities.java: 766)
at com.webobjects.eoaccess.EOUtilities.rawRowsForSQL(EOUtilities.java: 547)
at uk .org.cwwresources.TicketSearch.fetchCountTallies(TicketSearch.java: 125)
at uk.org.cwwresources.ScanIt$1.actionPerformed(ScanIt.java:80)
at javax.swing.Timer.fireActionPerformed(Timer.java:271)
at javax.swing.Timer$DoPostEvent.run(Timer.java:201)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at java .awt .EventDispatchThread .pumpOneEventForHierarchy(EventDispatchThread.java:269)
at java .awt .EventDispatchThread .pumpEventsForHierarchy(EventDispatchThread.java:190)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:184)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:176)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)


The calling code was:
EOEditingContext ec = new EOEditingContext();
String sql = "SELECT sum(*) AS overallTotal FROM tickets";
NSArray result1 = EOUtilities.rawRowsForSQL(ec,"Shop", sql, null);

I know that my JC<->Server link is working as I can retrieve EOs fine in another method in the same class.

What I don't know is (i) whether or not this is "fixable"/"possible" and if it is I don't have enough knowledge to fix it; and (ii) is there an alternative way to access something like "SELECT sum(*) AS overallTotal FROM tickets" using JavaClient and EOs or otherwise.

Thanks in advance for any pointers...

.neilmac

PS OSX10.5/WO5.3/MySQL5/Eclipse/WOLips/No_Wonder (but have it installed -- can I use it with JavaClient?)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden



_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
  • Follow-Ups:
    • Re: Java Client RawRows Query
      • From: Florijan Stamenkovic <email@hidden>
References: 
 >Java Client RawRows Query (From: Neil MacLennan <email@hidden>)
 >Re: Java Client RawRows Query (From: Florijan Stamenkovic <email@hidden>)

  • Prev by Date: Re: Batching creation of primary keys with Oracle
  • Next by Date: Forms changed to http with Eclipse/WOLips?
  • Previous by thread: Re: Java Client RawRows Query
  • Next by thread: Re: Java Client RawRows Query
  • Index(es):
    • Date
    • Thread