Saturday, April 29, 2006

command-line tool for fetching with EOF

There are too many things to write about. If I think about all the things I want to say about WebObjects, the things I think people should know, my head threatens to explode.

Additionally, I do not know which of these things are important. Being inside the WebObjects group for so long has given me an odd perspective. There are things I care about that I think will seem arcane and inconsequential to others. It is hard to tell.

So, let us just start. There is a question which comes up occasionally, year after year, on the mailing lists. How does one create a tool for fetching with EOF? Let me just start with this. It is not complex, or even very interesting. But it is a start.


import com.webobjects.eoaccess.EOModelGroup;
import com.webobjects.eoaccess.EOUtilities;
import com.webobjects.eocontrol.EOEditingContext;

public class fetch {

public static void main(String[] arg) {
(new fetch()).fetch();

public void fetch() {
EOModelGroup group = EOModelGroup.defaultGroup();
try {
catch ( mue) { System.out.println(mue.getMessage()); }
EOEditingContext ec = new EOEditingContext();
NSArray rows = EOUtilities.objectsForEntityNamed(ec, "Movie");
System.out.println("retrieved rows # "+rows.count());


<project name="fetch" default="compile" basedir=".">

<target name="setup"><mkdir dir="classes/com/foo" /></target>

<property name="SLF" value="/System/Library/Frameworks" />
<property name="fRJ" value="framework/Resources/Java" />
<property name="Foundation" value="${SLF}/JavaFoundation.${fRJ}/javafoundation.jar" />
<property name="EOAccess" value="${SLF}/JavaEOAccess.${fRJ}/javaeoaccess.jar" />
<property name="EOControl" value="${SLF}/JavaEOControl.${fRJ}/javaeocontrol.jar" />
<property name="XML" value="${SLF}/JavaXML.${fRJ}/javaxml.jar" />
<property name="JDBC" value="${SLF}/JavaJDBCAdaptor.${fRJ}/javajdbcadaptor.jar" />

<path id="build.path">
<pathelement path="${Foundation}" />
<pathelement path="${EOAccess}" />
<pathelement path="${EOControl}" />
<path id="exec.path">
<path refid="build.path" />
<pathelement path="${XML}" />
<pathelement path="${JDBC}" />
<pathelement path="classes" />

<target name="compile" depends="setup">
<javac srcdir="." destdir="classes" classpathref="build.path">
<include name="" />

<target name="exec" depends="compile"><java classname="" fork="true" classpathref="exec.path" /></target>


At 11:57 PM , Anonymous Anonymous said...

Hi Tau, I just stumbled across your blog looking for information on loading EOModels from web servers (I recently tested it in XCode 2.1 and it worked, but in XCode 2.3 it seems to be broken).

Anyway, I for one would sure welcome more blogging from you about WO. I take it you work for Apple?

Bernard Devlin


Post a Comment

Subscribe to Post Comments [Atom]

<< Home