On creating trigger,set the information in java code loaded in weblogic application server
I have a oracle database table. When a row is inserted then I want to create a trigger. Till now the problem is ok,but after creating trigger I want to call weblogic application server code(means I want to set this information(new database row) in a java class which is loaded on other weblogic application server.) Any help is appreciated. I have spent hours looking for tutorials on Google. However I cannot seem to find anything that holds the hand. Can you recommend a tutorial, or set of tutorials or examples that cover this.
Like Java class is :
import java.util.Random;
public class Person
{
public String getId()
{
retur开发者_如何学运维n id;
}
public void setId(String id)
{
this.id = id;
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
Where id
and name
are columns of db table. I want a java object on weblogic application server holding the new values of row which is inserted in db.
EDIT:
Thanks for your reply....
data to be defined :-A machine on which oracle 11g is installed and weblogic application server is installed on other machine.There is static hashmap hm on weblogic server which is readed by some other application on weblogic server.Value of this hashmap is object of Person class(as described above)
Now my requirement is whenever a new row is added in database table,then it set the values of this row in person class(by firing oracle trigger) and store this object in hashmap value field(Treat one column of db table as hashmap key).
For eg id and name are columns of db.whenever a new row(id=1, name=xyz) is inserted in this table then put this values in hashmap hm as {hm.put("1",object of person class)}
name field will be set in object of person class.
There are probably several ways to do what you want, but to have Oracle return a java object is probably the most convoluted of them all. The simplest solution would be to have the weblogic application that makes the call to insert the record into the database then create the Person class object and put it into the hashmap. If the application doesn't control the id (e.g. the id is created from a sequence on the database, you can insert the record through a function and have the function return the id to the web application:
CREATE SEQUENCE person_id_seq START WITH 1;
CREATE FUNCTION insert_person ( p_name IN VARCHAR2 )
RETURN NUMBER
IS
retval NUMBER := -1;
BEGIN
INSERT INTO person ( id, name )
VALUES ( person_id_seq.NEXTVAL, p_name )
RETURNING id INTO retval;
RETURN retval;
END insert_person;
Additionally, I'm not sure if you fully understand what Oracle triggers do. Triggers are usually used to either do logic/data validation before an insert/update/delete or to do some post-insert/update/delete action (e.g. create a record in an audit/history table of changes made, update other records). While Oracle does support triggers written in Java, I've never used them nor am I sure how the trigger would communicate with your weblogic application.
If you must return a java object from Oracle to your weblogic application, you can declare an Oracle object type and have your insert function/procedure return that, or you can return a ref cursor with the data elements. Depending upon how you return the Oracle object type, you might need to have a Java class defined to which the Oracle OJDBC drivers can map the pl/sql object.
Do a web search on SQLData or ORAData. A great reference book is R.A. Menon's Expert Oracle JDBC Programming : http://www.amazon.com/Expert-Oracle-JDBC-Programming-Menon/dp/159059407X
精彩评论