RE: Creating beans dynamically from byte code in a byte[]withClassLoader.defineClass - how to do it right?

2002-04-16 Thread Thorbjørn Ravn Andersen (Scandiatransplant)

On Mon, 15 Apr 2002, Niall Pemberton wrote:

> This is exactly what DynaBeans were invented for.

I have spent quite some time looking for such an automatic bean creation
facility, and apparently it is something which is quite unique to the
Struts project in that there is a working solution.

> Using BCEL to generate classes on the fly is impressive, but wouldn't it be
> simpler to just use the DynaBeans, which I believe are in 1.1?

Ah, that's why I didn't see it before.  I have only looked at 1.0.2 since
we need stable software (as in non-changing, not bug-free), so any 1.1
features would have to wait until 1.1 was formally released.

I'll give it a try.  Thanks for your answer.
-- 
  Thorbjørn Ravn Andersen
  Scandiatransplant, c/o Christian Mondrup
  89 49 53 01
  http://biobase.dk/~tra


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>




Creating beans dynamically from byte code in a byte[] withClassLoader.defineClass - how to do it right?

2002-04-15 Thread Thorbjørn Ravn Andersen (Scandiatransplant)


I have spent some time lately figuring out how I can generate beans
on-the-fly with fields completely specified at run-time, since this would
be an enourmeous help when working with JDBC and Struts in an informal
matter (which is why I ask here :-)

I have used Apache Jakarta BCEL to construct the byte-code I need for the
bean (verified by dumping it to disk, and using "java" and 'javap -c' on
the class file), and I would then like to get the SystemClassLoader and
call defineClass on my byte array to get a Class, and then resolve it.

Unfortunately I cannot do this, since the defineClass method is protected
final, so I am a bit at a loss here.  I just need some code which can
instantiate my byte code into a Class, so I can get this working.   I
would prefer not to use physical files, but I have a JSP-environment so
that might be an option.  (Resin+Tomcat).

Is there somebody who have a solution for this problem?  I would
appreciate all pointers.

-- 
  Thorbjørn Ravn Andersen
  Scandiatransplant, c/o Christian Mondrup
  89 49 53 01
  http://biobase.dk/~tra


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>




Struts DataSource object - how much can be taken for given?

2002-01-29 Thread Thorbjørn Ravn Andersen (Scandiatransplant)


I have now progressed further, and run into a few questions which I would
appreciate help with in order to be nudged in the right direction.

After a bit of work with the Struts basic JDBC-connection pooling system
and the struts-config.xml file, I found out that I can get access to my
database from a JSP as follows:

<%@ page 
import="javax.servlet.*,javax.sql.*,java.sql.*,org.apache.struts.*,org.apache.struts.action.*"
  %>
<%
DataSource dataSource = (DataSource)
  getServletContext().getAttribute(Action.DATA_SOURCE_KEY);
Connection conn = dataSource.getConnection();

Statement s = conn.createStatement();
ResultSet rs = s.executeQuery( "select count(*) from recipient");
...

I want to do this in order to provide a set of JSP-pages which test basic
functionality without requiring the whole MVC-system to be functional.

I have written a couple of beans, each of which are to correspond to a
given database table (not much new in that), where they will synchronize
over a Connection-object, and I would like to know how
I should design this for it to be so generic as possible.  The existing
database scheme we are building this application on top, consists of
several hundred tables, so I must recycle resources.

Can I expect that the DataSource object will be the same in the lifetime
of my application (a given bean will only talk to a single database, and
we will most likely not use more than a single database for the whole
application), or should I look in getServletContext() each time I need a
new Connection?

I understand that for connection pools to work correctly I should close my
connection when I am done with it, and request a new one next time.  Will
the above code allow me to choose connection pool managers freely
(provided that it is running correctly), or is this just for the one
provided by Struts?

I have a strong feeling that I should refrain as much as possible from
scriplets in the JSP, so I would also appreciate knowing if there are
beans or taglibs that help manage such an object.  My own beans will be
able to accept the appropriate object (DataSource etc) as a property, but
are there any facilities that help providing what I need as a property?

And a last question.  As part of the work flow of the users they may have
to be presented to a rather long list of persons.  I have considered
whether it would be feasible ressourcewise to simply build an ArrayList of
Beans, where each bean corresponds to a person in the database, and then
have it as a session property.  This also goes very well with the
display:table taglib.   Should I go for a database request per subtable,
and do it all by my self?  I would appreciate comments from people who
have tried this, and have experiences to share.

Some of the tables have many fields, and may be rather large objects.  We
can expect few users, and few simultaneous searches.

If I have missed a FAQ where this is explained in detail, I apologize.  I
am still struggling with learning the framework, and I have tried to
follow and read most of the documentation and the links it contains.

Best Regards,
-- 
  Thorbjørn Ravn Andersen
  Scandiatransplant, c/o Christian Mondrup
  89 49 53 01
  http://biobase.dk/~tra



--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>