Creating and deploying your own entity Bean with Orion:

Creating and deploying an entity Bean on the Orion Server is very easy to
do.  The first thing you should do before you get started is to make sure
that the data-sources.xml file is setup to use an existing database, so it
should look something like this (this uses the Hypersonic database):

<data-source class="com.evermind.sql.ConnectionDataSource"
location="jdbc/DefaultDS">
        <name>Default data-source</name>
        <description>
                Hypersonic SQL source.
        </description>
        <url>jdbc:HypersonicSQL:defaultdb</url>
        <connection-driver>hSql.hDriver</connection-driver>
        <username>sa</username>
        <password></password>
</data-source>

If you don't have a database to use, you can get the Hypersonic database
here: http://www.lynx.ch/Contacts/~/ThomasM/hypersql.html
And just follow the download/install directions.

And, if you haven't played with Orion already, make sure that the necessary
.jars (orion.jar, ejb.jar, jndi.jar) are in your classpath.

Next, make sure you have uncommented the <ejb-config> and <rmi-config> tags
in the server.xml file.

And finally, makre sure that there is an <ejb-jar> tag in the ejb.xml file
that specifies the path to this EJB we are creating.

Now we're ready to create our bean.

I found this "EJBMaker How-to" in the email archives, and it is very nice.
EJBMaker is used to create a deployable entity bean.

1) Start up EJB-maker. This is done by either double-clicking ejbmaker.jar
in the Orion dir or typing "java -jar ejbmaker.jar" in the console (in the
Orion dir).

2) The first thing I did, is rename the "Default" bean name to DanTest.
Next, I added a few fields (methods) to the bean field table on the lower
half of the screen:
I chose firstName, lastName, age;

3) Go to "Export" on the File menu, and choose a directory that you want
EJBMaker to create your entity Bean in (c:\orion\beantest), and press save
when you�re done.

Now you should see DanTest.java, DanTestEJB.java, and DanTestHome.java in
the c:\orion\beantest directory.  EJBMaker also created the
META-INF/ejb-jar.xml file for you as well, so all you have to do is put the
path to your EJB (c:\orion\beantest) in the <ejb-jar> tag in config/ejb.xml,
and your bean will be deployed when you restart the Orion server.
To create a client to access the bean, you can just copy the CartClient.java
(c:\orion\demo\ejb\cart) to the beantest directory, edit the necessary
lookup, home and remote references, use your new method calls
(setFirstName(), setLastName(), etc..) and you�ll be up and running in no
time.

After you restart your server, you should see output similar to this to
verify that your new bean has been deployed:

C:\orion>java -jar orion.jar
Auto-deploying file:/C:/orion/beantest/...
Auto-creating table: create table DanTest (id integer primary key, firstName
varchar (255), lastName varchar (255), age integer)
done.
Orion/0.8.2 initialized

The above output shows that the EJB in the c:\orion\beantest directory has
been deployed, and that a database table DanTest has been created in the
database.  And remember, the database name (defaultdb) was specified in the
data-sources.xml file.

Also, if you just want to see the generic raw data in the database, the
database is written to the file system in c:\orion\defaultdb, so you can use
Hypersonic's DatabaseManager tool (Java application) to run simple select
statements to query the database whether the Orion application server is
running or not, just to show you that your data is in the database.


Dan
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com

Reply via email to