You are viewing a plain text version of this content. The canonical link for it is here.
Posted to torque-dev@db.apache.org by to...@db.apache.org on 2004/03/04 04:11:52 UTC
[DB Torque Wiki] New: FrequentlyAskedQuestions
Date: 2004-03-03T19:11:51
Editor: ScottEade <se...@backstagetech.com.au>
Wiki: DB Torque Wiki
Page: FrequentlyAskedQuestions
URL: http://wiki.apache.org/db-torque/FrequentlyAskedQuestions
Converted from Usemod wiki - content could do with review.
New Page:
Question: What is Village?
Answer: See the [http://share.whichever.com/index.php?SCREEN=village Village] homepage for that information.
----
Question: Torque uses Village 2.0. I can't find any reference to that version on the Village page.
Answer: Village 2.0 has not been released. You can get the source by getting the latest CVS version. Instructions for doing this are on the [http://share.whichever.com/index.php?SCREEN=village Village] homepage. When you build the project, you will have a village-2.0-dev jar file.
----
Question: How can I configure Torque to use a JNDI connection
Answer: Read the Torque Howto for indepth information. However, here is the short howto!
* Torque.properties:
{{{ torque.database.default.adapter=mssql
torque.dsfactory.default.factory=org.apache.torque.dsfactory.JndiDataSourceFactory
torque.dsfactory.default.jndi.path=java:comp/env/jdbc/fortius }}}
* web.xml (In the right order according to the servlet spec):
{{{
<resource-ref>
<description>
Resource reference to a factory for java.sql.Connection
instances that may be used for talking to a particular
database that is configured in the server.xml file.
</description>
<res-ref-name>
jdbc/fortius
</res-ref-name>
<res-type>
org.apache.torque.pool.TorqueClassicDataSource
</res-type>
<res-auth>
Container
</res-auth>
</resource-ref>
}}}
* server.xml (inside your Context):
{{{
<Resource name="jdbc/fortius" scope="Shareable" type="javax.sql.DataSource"/>
<ResourceParams name="jdbc/fortius">
<parameter>
<name>validationQuery>/name>
<value>SELECT 1>/value>
</parameter>
<parameter>
<name>maxWait>/name>
<value>5000>/value>
</parameter>
<parameter>
<name>maxActive>/name>
<value>4>/value>
</parameter>
<parameter>
<name>password>/name>
<value>mypassword;/value>
</parameter>
<parameter>
<name>url>/name>
<value>jdbc:microsoft:sqlserver://cuzco:1433;DatabaseName=fortius;SelectMethod=cursor>/value>
</parameter>
<parameter>
<name>driverClassName>/name>
<value>com.microsoft.jdbc.sqlserver.SQLServerDriver>/value>
</parameter>
<parameter>
<name>maxIdle>/name>
<value>2>/value>
</parameter>
<parameter>
<name>username>/name>
<value>SilverUserLogin>/value>
</parameter>
</ResourceParams> }}}
* Libraries. Make sure you put your Jar's that are need for the driver where they can be reached. For Tomcat, put them in /common/lib, otherwise Tomcat can not create the connection.
* Debugging
If all else fails, first try and verify that you are able to directly create the datasource. I wrote a little action called DB.java that I could call from torque with a single action:
{{{ public void doPerform(RunData data, Context context)
throws Exception {
try {
Log.debug("DB.doPerform called");
String foo = '''''';
javax.naming.Context initCtx = new InitialContext();
javax.naming.Context envCtx = (javax.naming.Context) initCtx.lookup("java:comp/env");
DataSource ds =
(DataSource) envCtx.lookup("jdbc/fortius");
if (ds != null) {
Connection conn = ds.getConnection();
if (conn != null) {
System.out.println("Got Connection " + conn.toString());
Statement stmt = conn.createStatement();
ResultSet rst =
stmt.executeQuery(
"select * from kinase");
if (rst.next()) {
foo = rst.getString(2);
System.out.println("foo:" + foo);
}
conn.close();
}
}
}
catch (Exception e) {
Log.error(e);
throw e;
}
} }}}
-- EricPugh
----
Question: How can I execute a stored procedure
Answer: You can use some of the functionality exposed by the Village library to execute and deal with the result set of your stored procedure:
{{{ import com.workingdogs.village.Record;
String SQL = "exec myStroedProc 4, 'hello'";
List records = WorkorderPeer.executeQuery(SQL);
Vector kinaseATPConcs = new Vector();
for (Iterator i = records.iterator(); i.hasNext();) {
Record record = (Record) i.next();
["KinaseATPConc"] kinaseATPConc = new ["KinaseATPConc"]();
kinaseATPConc.setKinaseId(record.getValue("kinase_id").asString());
kinaseATPConc.setAtpConc(record.getValue("atp_conc").asDouble());
kinaseATPConcs.add(kinaseATPConc);
} }}}
What else you may notice is that if you do something similar with a complex sql query:
{{{String SQL = "select top 50 distinct kinase_id,atp_conc from reaction where workorder_id = "
+ workorder.getWorkorderId()
+ " and reaction.result is null and reaction.daughterboard_id is null");
}}}
-- EricPugh
----
Question: How to add !P6Spy for printing SQL
Answer:
1. add the p6spy.jar to your application classpath
1. copy the "spy.properties" into your classpath (e.g. same location as log4j.properties)
1. set the "realdriver" in spy.properties, e.g. realdriver=oracle.jdbc.driver.OracleDriver for Oracle
1. change the Torque.properties, e.g. "torque.dsfactory.XXX.connection.driver = com.p6spy.engine.spy.P6SpyDriver" to use the proxy JDBC drivers
1. run your application
1. !P6Spy creates a spy.log in your current directory
-- Siegfried Goeschl
----
Question: doDelete() is throwing a !TorqueException. What's up?
Answer: doDelete() throws a !TorqueException with message "You must specify Key''''''Def attributes for this Table''''''Data''''''Set in order to delete a Record" when the schema for the table does not contain a primary key. If the table has no primary key, doDelete() may not be used to delete from it.
-- Gary Shea
---------------------------------------------------------------------
To unsubscribe, e-mail: torque-dev-unsubscribe@db.apache.org
For additional commands, e-mail: torque-dev-help@db.apache.org