Hi All!
I'm developing a little application for Oracle8-Cocoon2
my system PC1 win2000,Tomcat4,jdk1.3
end data souce is in PC2
cocon.xconf
<datasources>
<component-instance name="test_oracle_pool"
class="org.apache.avalon.util.datasource.JdbcDataSource">
<!-- Don't forget the oradb parameter for Oracle!!! -->
<pool-controller min="5" max="10" oradb="true"/>
<dburl>jdbc:oracle:thin:@2000server.asa.ned.dmroma.it:1521:oras</dburl>
<user>de</user>
<password>gi</password>
</component-instance>
</datasources>
*******How to Use the Data Source Component?****
*******How to implement class name? *************
No matter how you defined your DataSourceComponent, you access it the same
way.
Because The DataSourceComponent is a Component, your class needs to implement
the Avalon Composer interface.
The Avalon Framework will give your class a ComponentManager. At that point,
it is up to you how and when you pull the DataSourceComponent out of the
ComponentManager.
import org.apache.avalon.ComponentManager;
import org.apache.avalon.ComponentSelector;
import org.apache.cocoon.Roles;
import org.apache.cocoon.component.datasource.DataSourceComponent;
import java.sql.Connection;
// .... Skip a lot of lines until we are in the method you use
// to initialize the DataSourceComponent ....
private DataSourceComponent datasource;
public void compose(ComponentManager manager) {
ComponentSelector selector = (ComponentSelector)
manager.lookup(Roles.DB_CONNECTION);
this.datasource = (DataSourceComponent) selector.select("MyConnectionName");
}
// .... Skip more lines until we actually need to use the datasource
private void meMethod() {
Connection myConnection = this.datasource.getConnection();
// .... perform SQL code here
myConnection.close();
}
Notice that once you obtained your connection, you did nothing out of the
ordinary to return the connection to the pool? This is by design, and a
result of the JDBC specification. Basically the JDBC specification states
that if a driver implements pooled connections, then it should not alter
the way those connections are used. This maintains the portability of your
code.
Bye & Thank's
Giuseppe
__________________________________________________________________
Abbonati a Tiscali!
Con Tiscali By Phone puoi anche ascoltare ed inviare email al telefono.
Chiama Tiscali By Phone all' 892 800 http://byphone.tiscali.it
---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
To unsubscribe, e-mail: <[EMAIL PROTECTED]>
For additional commands, e-mail: <[EMAIL PROTECTED]>