1. Run the SQL statement directly // to use Basepeer.executeQuery (SQLSTR) int RECount = ("Select Count (*) as rightcount from tbluser_right_def"). Get (0)). GetValue (1) .asint (); List list = basepeer.executeQuery (strsql);
2, according to the ID found recorded performing operations related tblcredef = TblcreDefPeer.retrieveByPK (intCreDefID); tblcredef.setCreName (strCreDefName); tblcredef.setCreNote (strCreDefNote); tblcredef.setCreClsid (intCreClsID); tblcredef.save ();
3, transaction processing try {conn.rollback ();} catch (Exception E) {debug.println ("rollback error" e.tostring ());} return;} try {conn.commit ();} catch Exception E) {MessageDispatch (Infostring.err_addproflowdef); try {conn.rollback ();} catch (exception ex) {debug.println ("rollback error" ex.totring ());}
4 Infostring.err_dbconn; return;} ... // transaction TBLbook.save (conn); TBLREC.SAVE (CONN); Transaction.Rollback (conn);
5. Descending crit.addDescendingorderByColumn (TBLProflopeer.Begin_Time);
6, a combination of the SQL statement SELECT TBLPRO_INFO.ACCOUNTA, TBLPRO_FLO.PFID, TBLOUTERUSER_INFO.USER_NAME, TBLPRO_INFO.PROID, TBLPRO_INFO.PRO_ACC_CODE, TBLPRO_INFO.PRO_TITLE, TBLPRO_FLO.PRO_FLO_DEF_NAME, TBLPRO_FLO_ZS_DEF.ZS_DEFID, TBLZS_DEF.ZS_DEF_NAME FROM TBLPRO_INFO, TBLPRO_FLO, TBLOUTERUSER_INFO, TBLPRO_FLO_ZS_DEF, TBLZS_DEF WHERE TBLPRO_FLO.DEP_CODE = '00000001' AND ((TBLPRO_INFO.STATUS> = 2048 AND TBLPRO_INFO.STATUS <4096) AND TBLPRO_INFO.STATUS & 64 = 64) AND TBLPRO_INFO.PROID = TBLPRO_FLO.PROID AND TBLPRO_FLO.PFDID = TBLPRO_FLO_ZS_DEF.PFDID AND TBLPRO_FLO_ZS_DEF.ZS_DEFID = TBLZS_DEF.ZS_DEFID AND TBLPRO_INFO.ACCOUNTA = TBLOUTERUSER_INFO.ACCOUNT // // set equal to a particular query data TBLPRO_FLO.DEP_CODE = '00000001' crit.add (TblproFloPeer.DEP_CODE, InterSiteSession.getDepCode (m_request)); // Combined complex SQL, multi-judgment conditions crit.add (TBLPROINFOPEER.STATUS, New Integer (status.numbertostatus (12)), criteria.greater_equal ;
crit.getcriterion (TBLPROINFOPEER.STATUS) .and (crit.getnewcriterion (tblProinfopeer.Status,
New Integer (status.numbertostatus (13)), criteria.less_than);
crit.getCriterion (TblproInfoPeer.STATUS) .and (crit.getNewCriterion (TblproInfoPeer.STATUS, (Object) strObject, Criteria.CUSTOM)); // simple SQL, both sides are fields: TBLPRO_INFO.PROID = TBLPRO_FLO.PROID crit. addJoin (TblproInfoPeer.PROID, TblproFloPeer.PROID); crit.addJoin (TblproFloPeer.PFDID, TblproFloZsDefPeer.PFDID); crit.addJoin (TblproFloZsDefPeer.ZS_DEFID, TblzsDefPeer.ZS_DEFID); crit.addJoin (TblproInfoPeer.ACCOUNTA, TblouteruserInfoPeer.ACCOUNT); // select field crit.addSelectColumn (TblproInfoPeer.ACCOUNTA) to be outputted; crit.addSelectColumn (TblproFloPeer.PFID); crit.addSelectColumn (TblouteruserInfoPeer.USER_NAME); crit.addSelectColumn (TblproInfoPeer.PROID); crit.addSelectColumn (TblproInfoPeer.PRO_ACC_CODE ); crit.addSelectColumn (TblproInfoPeer.PRO_TITLE); crit.addSelectColumn (TblproFloPeer.PRO_FLO_DEF_NAME); crit.addSelectColumn (TblproFloZsDefPeer.ZS_DEFID); crit.addSelectColumn (TblzsDefPeer.ZS_DEF_NAME); // use BasePeer.doSelect (crit)
5, Record transforms to the ObjBean object instance
// First get list (Records) with Basepeer
List list = basepeer.doselect (crit);
RECORD RECORD = (record) list.get (0);
// Single RECORD object transforms into objbean
TBLOBJ OBJ = NULL;
Obj = tblobjpeer.populateObject (Record, 1, New Tblobj ()); // offset is calculated from the first field
// Obj = tblobjpeer.row2Object (Record, 1, TBLOBJ.CLASS); // This is also possible, it calls populateObject
// list records translates into list objBeans
List = tblobjpeer.populateObjects (list);
6, irregular (cannot be converted into a single objbean) Record transforms to the Rundata object instance
// Single RECORD object transforms into RD
Rundata rd = rundata.getInstance (record); // Because RD is stored in an instance of a Record object
// List records translates into List RDS
List = rd.recordlisttorundatAlist (list);
/ ************************************************** ********************** * 2003-9-17 Torque application summary (LM & Me) ************* *********************************************************** ****** / 1, (1) Problems involving crit.addselectColumn can only use basepeer.doselect (crit), without using the peer.doselect (crit) method corresponding to the relevant class; (2) About Along all Select operations are also to be verified, and if you sort cring type fields, crit.addscendColumn (Peer.StrColunm), the generated SQL query is only "select Upper (peer.strcolunm) ", Other fields are lost, is it only Baser? (3) When you handle a certain field of a record, you need to force the basepeer.doselect (crit) .GET (0) to convert BasePeer.Doselect (0) to the RECORD type, and then Call getValue (i) to get the variable of the value type, then transform it into a corresponding data type (call asint (), asstring (), etc.), note that i is starting from "1"; 2. For when to use Basepeer, when to conclusions to PEER in this class: (1) When a function (such as count, max, min), only BasePeer; (2) can only be used when involving addselectColumn (*), only Basepeer; (3) When the recording (including all fields) involves the recording (including all fields), only the peer of this class;
3, there are many useful tool methods in the peer of this class, such as "1 pair N" relational object, transforming RECORD and TBLOBJECT, etc.
4, using Torque multi-construction view VPeer (especially when the table and table is complex), the view VPEER is only responsible for query operation, and the PEER of this class is only responsible for adding deletion of modification.
5. When writing DB-Schema.xml, if there is a "one-to-one" or "multi-to-many" relationship between the table and the table, the foreign key is equipped with the SQL of the ANT to generate the table. Remove the foreign key related SQL, so that you can keep Torque automatically generate simple tool methods, do not affect the use of the database. The code example of the tool method is as follows: list userlist = tbllevel.gettblusers (crit, conn); TBLLEVEL Level = tbluser.gettbllevel () L; // Large amount reduction This time Torque defaults to "lazy" mode, that is, TORQUE query database formation LIST is placed in memory when the first densitic List is first depleted.
6. About field variable name naming rules: Write down, don't go down. such as:
Reconfigure, the generated Java class is in line with the standard JavaBean specification, making it easier for us to use the Rundata class and other third-party tool classes.
7. When performing a DB-Schema.xml configuration, if you feel some unclear options, such as what is the value of the properties, you can view http://jakarta.apache.org/turbine/dtd/Database.dtd files . If you want to learn more about the type of field configuration, such as "longvarchar", which data types corresponding to different databases can be viewed and modified "D: /torque-3.0/templates/sql/base/db2/db.props" This configuration file is.
8. When performing Linux DB2 Torque Tomcat JNDI configuration, pay attention to some JAR package conflicts, such as Tomcat-Naming.jar, because Torque and Tomcat have corresponding JNDI package, but the version is Different; also pay attention to the DB2 default in Linux is a JCC driver service, but Torque currently only supports NET and APP drivers, so you have to open the DB2 NET driver service, just execute "# / db2 / bin / db2jstrt in Linux DB2 instance users 6789 "You can start the Java DB2 JDBC Applet server, the specified port is 6789, you can drive with NET. 9. The JNDI steps in Tomcat in Torque are as follows: (1) Configure Torque.properties to open the four lines below "## using jndi"; other can't open; pay attention to "Path" to write ("Java: com / env / jdbc / course "), for example: ## Using jnditorque.dsfactory.bookstore.factory = org.apache.torque.dsfactory.JndiDataSourceFactorytorque.dsfactory.bookstore.jndi.path = java: com / env / jdbc / bookstoretorque .dsfactory.bookstore.jndi.java.naming.factory.initial = org.apache.naming.java.javaURLContextFactorytorque.dsfactory.bookstore.jndi.java.naming.factory.url.pkgs = org.apache.naming (2) configuration Tomcat / conf / server.xml, added; (3) Configuration /Web-inf/web.xml, add;
10, TORQUE3.0 JNDI ORACLE9I WebSphere5.1 Configuration: (1) WebShpere Oracle Drive Using Oracle JDBC Driver (or XA); will drive OJDBC14.jar to copy to WebSphere; (2) JNDI Name in WebSphere is named "JDBC / Course"; (3) If JDBC programming calls WebSphere JNDI gets connecting CONN, just lookup ("JDBC / Course"); without having to use full name ("Java: COM / ENV / JDBC / "); (4) TORQUE When the JNDI in WebSphere is called, just open the two sentences under" ## using jndi ": torque.dsfactory.bookStore.Factory = org.Apache.torque.dsfactory.jndidataSourceFactorytorQue.dsFactorytorQue.dsFactory .bookstore.jndi.path = jdbc / bookstore (None "Java: COM / ENV /" in PATH) (5) WEB.XML is also required to be configured.