• 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: EnterpriseObjects in a regular Java application
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EnterpriseObjects in a regular Java application


  • Subject: Re: EnterpriseObjects in a regular Java application
  • From: Michael DeMan <email@hidden>
  • Date: Thu, 2 Feb 2006 01:51:57 -0800

Yeah, this question is always a weird one and I have a whole new twist on the entire thing.

For our batch jobs I do it in a completely screwball way with WO 5.2.4. I need a WOSession and context because we e-mail out WOComponents and things during some of the batch jobs for billing and other stuff. Basically I start up and then have the application send itself a request and use that to generate a context via a direction action.

Totally insane but the only way I could actually get a WOApplication without an infinite main() runloop AND have a legitimate WOContext.

This is probably different than the original post here about just firing up an EOF-enabled application, but I'm darn curious about the proper way to programmatically instantiate a full WO application with a valid WOContext because what seem to be the obvious ways just don't work. So if anybody knows how to do that I would love to clean up the mess below...


PCEngine - subclassed from WOApplication Other PCxx classes similarly subclassed from WOxx


// engine - the batch job engine to be created
// realm - the database realm it wants to connect to, handled with custom code in createSessionForRequest
// method - the engine has a method called job<METHOD>, and that is the work to be done


following is the bizarre code in my subclass of WOApplication to be able to do what I would think would be a simple thing, start up a WebObjects application that can access EOF and WO frameworks (like HTML web pages for e-mail) on the command line, have it do something useful and exit gracefully when it is done.


public PCEngine createEngineInRealm(String engineName, String realm) {
NSLog.out.appendln("PCApplication::createEngineInRealm - "+engineName+", " + realm);
NSMutableDictionary headers = new NSMutableDictionary();
headers.setObjectForKey(realm, "realm");
NSData content = new NSData();
NSMutableDictionary info = new NSMutableDictionary();
WORequest r = createRequest("GET", "", "HTTP/1.1", headers, content, info) ;
NSLog.out.appendln("PCApplication::createEngineInRealm - Request created: " + r);
WOContext context = new WOContext(r);
NSLog.out.appendln("PCApplication::createEngineInRealm - Context created: " + context);
PCDirectAction da = new PCDirectAction(r);
PCSession newSession = (PCSession) da.pcSession();
newSession.setPageWrapperName("PageWrapperForMail");
PCEngine engine = (PCEngine) pageWithName(engineName, newSession.context()); // the engine itself is actually a WOComponent
newSession.setCurrentUser(Employee.findBy(<<WHOEVER THE BATCH JOB IS RUNNING AS>>);
return engine;
}



public static void main(String argv[]) { String dbRealm = argv[0]; String engineName = argv[1] + "Engine"; String method = "job" + argv[2];

PCEngineApplication myApp = new PCEngineApplication();
myApp.setSMTPHost("localhost");
PCEngine engine = myApp.createEngineInRealm(engineName, dbRealm);
engine.valueForKey(method); // have the engine execute the job to be run
}



On Jan 30, 2006, at 5:02 PM, John Lennard wrote:

Hi,

I followed the stepwise article, but found that a few things in it were no longer relevant or api's had changed.

This is how i got my editingContext etc.

<snip>

		//gets a url for the model
		modelUrl = new URL("file:holidaybook.eomodeld");

		EOModel model = new EOModel(modelUrl);

		EOModelGroup mg = EOModelGroup.defaultGroup();
		mg.addModel( model );

		//use lewo stuff to specify the db to connect to
		LEEOHelper.setDBConnectionForNamedModel("file:holidaybook",
			LEConfig.stringForKey(WTConstants.KEY_CONFIG_WT_MAIN_JDBCDRIVER),
			LEConfig.stringForKey(WTConstants.KEY_CONFIG_WT_MAIN_JDBCURL),
			LEConfig.stringForKey(WTConstants.KEY_CONFIG_WT_MAIN_JDBCUSERNAME),
			LEConfig.stringForKey(WTConstants.KEY_CONFIG_WT_MAIN_JDBCPASSWD));

</snip>

and due to general laziness, this is how i created my editing context as a class variable (i know, very lazy :-)

<snip>
	protected static EOEditingContext ec = new EOEditingContext();
</snip>

with this, i used the lewostuff framework from http:// www.lindesay.co.nz to alter the connection properties of the model.

and this is the list of the jar files that are needed

<snip>
/System/Library/Frameworks/JavaEOControl.framework/Resources/Java/ javaeocontrol.jar
/System/Library/Frameworks/JavaFoundation.framework/Resources/Java/ javafoundation.jar
/System/Library/Frameworks/JavaEOAccess.framework/Resources/Java/ javaeoaccess.jar
/System/Library/Frameworks/JavaXML.framework/Resources/Java/ javaxml.jar
/System/Library/Frameworks/JavaJDBCAdaptor.framework/Resources/Java/ javajdbcadaptor.jar
</snip>


I was then happy to run EOF stuff to my hearts content and avoid those horrid Java collection classes too.

This example was used in a highly threaded application used to process images and i didn't run into any problems other than those of my own doing anyway.


The only gotchas are that you need to make sure that xcode has the jars specified in the project in order to build, and then for debugging/running you need to add


<snip>
-cp "EOFImageMunger.jar:/System/Library/Frameworks/ JavaEOControl.framework/Resources/Java/javaeocontrol.jar:/System/ Library/Frameworks/JavaFoundation.framework/Resources/Java/ javafoundation.jar:/System/Library/Frameworks/ JavaEOAccess.framework/Resources/Java/javaeoaccess.jar:/System/ Library/Frameworks/JavaXML.framework/Resources/Java/javaxml.jar:/ Library/Frameworks/LEWOStuff.framework/Resources/Java/ lewostuff.jar:/System/Library/Frameworks/JavaJDBCAdaptor.framework/ Resources/Java/javajdbcadaptor.jar:."


</snip>

as a run time argument to the java run target so that every thing can be found, like wise, this needs to be specified if you are running from a command line.

I can possibly provide a more complete example, but this should be enough to get it all running, as it was surprisingly simple once the class paths were correct.



regards

john.



On 30/01/2006, at 10:24 PM, Ruenagel, Frank wrote:

Hi,

there is a little bit outdated stepwise article about this issue:
http://www.stepwise.com/Articles/Technical/2001-07-01.01.html

It has helped me to create a java console app.

HTH
Frank


-----Original Message-----
From: webobjects-dev-bounces+webobjects=email@hidden
[mailto:webobjects-dev-bounces+webobjects=symposion.de@lists.a
pple.com]O
n Behalf Of John Huss
Sent: Friday, January 27, 2006 9:35 PM
To: email@hidden
Subject: EnterpriseObjects in a regular Java application


Is it possible to use my EnterpriseObjects classes and EOModel in a regular Java application without any web interface?

How do I get a connection to the database and get an editing context?

My ultimate goal is to write a little command-line program
that will import
text files into a database at scheduled times.  If this is a
bad approach
I'm open to other ideas.

Thanks,
John

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

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:
40yakmoose.org.nz


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:
40geminisolutions.com


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
  • Prev by Date: Re: Creating indexes from EOModeler?
  • Next by Date: Re: WebObjects Licensing
  • Previous by thread: Re: EnterpriseObjects in a regular Java application
  • Next by thread: Re: EnterpriseObjects in a regular Java application
  • Index(es):
    • Date
    • Thread