Re: How can I stream blobs to/from entities?
Re: How can I stream blobs to/from entities?
- Subject: Re: How can I stream blobs to/from entities?
- From: Jonathan Rochkind <email@hidden>
- Date: Mon, 12 Apr 2004 16:15:38 -0500
Oh, sorry, I missed your question.
Well, I'm not sure it's a good idea, but I'll show you how to get a
JDBCContext .
I'm not sure it's a good idea, because I'm not sure how to
lock/unlock the JDBCContext properly, to make sure there isn't some
part of EOF in the middle of using it at the same time you are trying
to use it. There's probably a way to do that, that sort of stuff
just makes me nervous. Although I suppose you could lock() the whole
EOObjectStoreCoordinator, which should do it, but might be overkill.
Another option would be creating your own JDBCConnection and ignoring
EOF entirely---but you don't need to create a JDBC Connection every
time you want to connect, you could create one once, and put it in a
static or Application scoped variable somewhere, and then take care
of synchronizing it's access yourself. Or create a pool of them for
use with your code only, for that matter. I might do that, if it's
relatively simple to do, to avoid dealing with the sometimes
mysterious underbelly of EOF.
But as far as finding a JDBCContext: You need to specify an entity
name (there might be a different connection for different entities)
and an EOEditingContext (any should do in a standard EOF
configuration).
EOEditingContext ec; //assume exists
String entityName; //assume exists
EOFetchSpecification fs = new EOFetchSpecification(entityName, null, null);
EOObjectStoreCoordinator rootStore =
(EOObjectStoreCoordinator)ec.rootObjectStore();
//good to lock the object store before messing with it
rootStore.lock();
try {
EODatabaseContext dbContext =
(EODatabaseContext)rootStore.objectStoreForFetchSpecification(fs);
EOAdaptor adaptor = dbContext.database().adaptor();
EOAdaptorContext adContext = dbContext.adaptorContext();
}
finally {
rootStore.unlock();
}
That EOAdaptorContext there should pretty much always be a
JDBCContext, in a modern WO application that isn't doing anything
especially funky.
At 4:44 PM -0400 4/12/04, Serge Froment wrote:
Hi Jonathan,
Thanks for your quick response.
I am actually trying to do it at JDBC level. The problem I have is
reaching the JDBC connection that WebObjects maintains so I can talk
to the database without creating a new connection, because this is
costly. I guess com.webobjects.jdbcadaptor.JDBCContext.connection()
is the method I need to call, but I don't know how to get my hands
on the JDBCConect instance.
Le 12 avr. 04, ` 16:29, Jonathan Rochkind a icrit :
I don't believe EOF supports that, unfortunately. You need to do
it with JDBC API directly. Don't model the myBlobAttribute at all,
but perhaps write those methods to use JDBC API to do what you
want, by referencing the primary key of the EO to make sure you are
getting/setting from the right row.
Serge Froment
http://www.serge-froment.com
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.