Transactional EJB TIMER

O

oliviergir

Hi,
I would like to make a transactional operation every x minute.
What I am trying to figure out, is the behavior in case of a violent
shutdown of the server in the middle of a transaction.

My application server is wepshere 6.0.2.
My datasource 's implementation class name =
oracle.jdbc.xa.client.OracleXADataSource.

Thus, I did an session ejb and implemented the ejbTimedout method like
following.




public void ejbTimeout(Timer arg0) {
// TODO Auto-generated method stub
System.out.println("deb timer");
Connection con=null;

try {
InitialContext context = new InitialContext();
javax.sql.DataSource ds1 = (javax.sql.DataSource)
context.lookup("jdbc/ds1");
con=ds1.getConnection();
Statement st=con.createStatement();
int i=st.executeUpdate("update TESTJAVA2 set COL2=6 where COL1=1");
System.out.println(i +" ligne mise a jour");

// this will raise an
exception as the table TESTgJAVA2 does not exist
i=st.executeUpdate("update TESTgJAVA2 set COL2=0 where COL1=1");
System.out.println(i +" ligne mise a jour");



} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println(""+e.getMessage());

//e.printStackTrace();
}
finally {
try {
System.out.println("finally");
con.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
System.out.println("fin timer");

}






The method is declared transactional like this
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>MonTimer</ejb-name>
<method-intf>Local</method-intf>
<method-name>ejbTimeout</method-name>
<method-params>
<method-param>javax.ejb.Timer</method-param>
</method-params>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>

(I tried RequiresNew in vain as well)

I was hoping that, as the second update raises an exception, the
transaction would be rollbacked and the first update would be canceled.
That is not the case, the first update is commited every x minute.
It seems I don't have any transaction at all.
What's wrong with all that ?

Here, the server 's log :
[7/25/06 16:55:51:353 CEST] 00000041 SystemOut O 1 ligne mise a
jour
[7/25/06 16:55:51:353 CEST] 00000041 SystemOut O ORA-00942: table
or view does not exist

[7/25/06 16:55:51:353 CEST] 00000041 SystemOut O finally
[7/25/06 16:55:51:353 CEST] 00000041 SystemOut O fin timer
[7/25/06 16:56:11:322 CEST] 00000041 SystemOut O deb timer
[7/25/06 16:56:11:322 CEST] 00000041 ConnectionFac W J2CA0294W:
Deprecated usage of direct JNDI lookup of resource jdbc/ds1. The
following default values are used: [Resource-ref settings]

res-auth: 1 (APPLICATION)
res-isolation-level: 0 (TRANSACTION_NONE)
res-sharing-scope: true (SHAREABLE)
loginConfigurationName: null
loginConfigProperties: null
[Other attributes]

res-resolution-control: 999 (undefined)
isCMP1_x: false (not CMP1.x)
isJMS: false (not JMS)

[7/25/06 16:56:11:338 CEST] 00000041 SystemOut O 1 ligne mise a
jour
[7/25/06 16:56:11:338 CEST] 00000041 SystemOut O ORA-00942: table
or view does not exist

[7/25/06 16:56:11:338 CEST] 00000041 SystemOut O finally
[7/25/06 16:56:11:338 CEST] 00000041 SystemOut O fin timer
[7/25/06 16:56:31:322 CEST] 00000041 SystemOut O deb timer
[7/25/06 16:56:31:322 CEST] 00000041 ConnectionFac W J2CA0294W:
Deprecated usage of direct JNDI lookup of resource jdbc/ds1. The
following default values are used: [Resource-ref settings]

res-auth: 1 (APPLICATION)
res-isolation-level: 0 (TRANSACTION_NONE)
res-sharing-scope: true (SHAREABLE)
loginConfigurationName: null
loginConfigProperties: null
[Other attributes]

res-resolution-control: 999 (undefined)
isCMP1_x: false (not CMP1.x)
isJMS: false (not JMS)

[7/25/06 16:56:31:369 CEST] 00000041 SystemOut O 1 ligne mise a
jour
[7/25/06 16:56:31:369 CEST] 00000041 SystemOut O ORA-00942: table
or view does not exist

[7/25/06 16:56:31:369 CEST] 00000041 SystemOut O finally
[7/25/06 16:56:31:369 CEST] 00000041 SystemOut O fin timer
 
O

oliviergir

well, that seems to be solved.
I added a reference toward the datasource
with an isolation level : TRANSACTION_SERIALIZABLE
and it seems to work..

(e-mail address removed) a écrit :
Hi,
I would like to make a transactional operation every x minute.
What I am trying to figure out, is the behavior in case of a violent
shutdown of the server in the middle of a transaction.

My application server is wepshere 6.0.2.
My datasource 's implementation class name =
oracle.jdbc.xa.client.OracleXADataSource.

Thus, I did an session ejb and implemented the ejbTimedout method like
following.




public void ejbTimeout(Timer arg0) {
// TODO Auto-generated method stub
System.out.println("deb timer");
Connection con=null;

try {
InitialContext context = new InitialContext();
javax.sql.DataSource ds1 = (javax.sql.DataSource)
context.lookup("jdbc/ds1");
con=ds1.getConnection();
Statement st=con.createStatement();
int i=st.executeUpdate("update TESTJAVA2 set COL2=6 where COL1=1");
System.out.println(i +" ligne mise a jour");

// this will raise an
exception as the table TESTgJAVA2 does not exist
i=st.executeUpdate("update TESTgJAVA2 set COL2=0 where COL1=1");
System.out.println(i +" ligne mise a jour");



} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println(""+e.getMessage());

//e.printStackTrace();
}
finally {
try {
System.out.println("finally");
con.close();
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
System.out.println("fin timer");

}






The method is declared transactional like this
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>MonTimer</ejb-name>
<method-intf>Local</method-intf>
<method-name>ejbTimeout</method-name>
<method-params>
<method-param>javax.ejb.Timer</method-param>
</method-params>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>

(I tried RequiresNew in vain as well)

I was hoping that, as the second update raises an exception, the
transaction would be rollbacked and the first update would be canceled.
That is not the case, the first update is commited every x minute.
It seems I don't have any transaction at all.
What's wrong with all that ?

Here, the server 's log :
[7/25/06 16:55:51:353 CEST] 00000041 SystemOut O 1 ligne mise a
jour
[7/25/06 16:55:51:353 CEST] 00000041 SystemOut O ORA-00942: table
or view does not exist

[7/25/06 16:55:51:353 CEST] 00000041 SystemOut O finally
[7/25/06 16:55:51:353 CEST] 00000041 SystemOut O fin timer
[7/25/06 16:56:11:322 CEST] 00000041 SystemOut O deb timer
[7/25/06 16:56:11:322 CEST] 00000041 ConnectionFac W J2CA0294W:
Deprecated usage of direct JNDI lookup of resource jdbc/ds1. The
following default values are used: [Resource-ref settings]

res-auth: 1 (APPLICATION)
res-isolation-level: 0 (TRANSACTION_NONE)
res-sharing-scope: true (SHAREABLE)
loginConfigurationName: null
loginConfigProperties: null
[Other attributes]

res-resolution-control: 999 (undefined)
isCMP1_x: false (not CMP1.x)
isJMS: false (not JMS)

[7/25/06 16:56:11:338 CEST] 00000041 SystemOut O 1 ligne mise a
jour
[7/25/06 16:56:11:338 CEST] 00000041 SystemOut O ORA-00942: table
or view does not exist

[7/25/06 16:56:11:338 CEST] 00000041 SystemOut O finally
[7/25/06 16:56:11:338 CEST] 00000041 SystemOut O fin timer
[7/25/06 16:56:31:322 CEST] 00000041 SystemOut O deb timer
[7/25/06 16:56:31:322 CEST] 00000041 ConnectionFac W J2CA0294W:
Deprecated usage of direct JNDI lookup of resource jdbc/ds1. The
following default values are used: [Resource-ref settings]

res-auth: 1 (APPLICATION)
res-isolation-level: 0 (TRANSACTION_NONE)
res-sharing-scope: true (SHAREABLE)
loginConfigurationName: null
loginConfigProperties: null
[Other attributes]

res-resolution-control: 999 (undefined)
isCMP1_x: false (not CMP1.x)
isJMS: false (not JMS)

[7/25/06 16:56:31:369 CEST] 00000041 SystemOut O 1 ligne mise a
jour
[7/25/06 16:56:31:369 CEST] 00000041 SystemOut O ORA-00942: table
or view does not exist

[7/25/06 16:56:31:369 CEST] 00000041 SystemOut O finally
[7/25/06 16:56:31:369 CEST] 00000041 SystemOut O fin timer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top