RE: confused about how to port some sql queries...
Jason -- For my answer, I'll assume that you have a class-descriptor for the class "Timeclock" that is 'mapped' to the 'timeclock' table, and that this class-descriptor has the following field-descriptors attributeName mappedToColumn = == tSin tsin refEmployee ref_employee tsOut tsout With those assumptions, here's how you would accomplish your query: // Assemble the criteria Criteria criteria = new Criteria(); criteria.addEqualTo("refEmployee",someValueForRefEmployee); criteria.addEqualTo("tsOut",someValueForTsOut); // What columns should be included? String columns[] = new String[1]{"min(tSin)"}; ReportQueryByCriteria query = QueryFactory.newReportQuery(Timeclock.class,columns,criteria,true); The last argument (true in my example) tell OJB whether or not you want distinct rows returned. Setting it to true causes OJB to insert the DISTINCT keyword in the generated sql. As far as the 'targetClass' is concerned, this identifies the class-descriptor that is the basis for which the various attributes (i.e. "refEmployee", "tsOut" and "tSin") that are found in the criteria/column list are resolved to actual table/column names. HTH Ron Gallagher Atlanta, GA [EMAIL PROTECTED] -Original Message- From: Jason Pyeron [mailto:[EMAIL PROTECTED] Sent: Saturday, November 22, 2003 9:03 PM To: OJB Users List Subject: confused about how to port some sql queries... I have a prepared statement like so: "SELECT min(tsin) FROM timeclock WHERE ref_employee= ? AND tsout=0;" I use this to decide what to query next, it sounds like I should use the "report" feature in OJB but I have no idea how. I looked at ReportQueryByCriteria(java.lang.Class targetClass, java.lang.String[] columns, Criteria criteria) what is this targetClass? Sincerely, Jason Pyeron -- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- - - - Jason Pyeron http://www.pyerotechnics.com - - Partner & Sr. Manager Pyerotechnics Development, Inc. - - +1 (443) 451-2697 500 West University Parkway #1S - - +1 (410) 808-6646 (c) Baltimore, Maryland 21210-3253 - - - -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, purge the message from your system and notify the sender immediately. Any other use of the email by you is prohibited. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: confused about how to port some sql queries...
Jason -- For my answer, I'll assume that you have a class-descriptor for the class "Timeclock" that is 'mapped' to the 'timeclock' table, and that this class-descriptor has the following field-descriptors attributeName mappedToColumn = == tSin tsin refEmployee ref_employee tsOut tsout With those assumptions, here's how you would accomplish your query: // Assemble the criteria Criteria criteria = new Criteria(); criteria.addEqualTo("refEmployee",someValueForRefEmployee); criteria.addEqualTo("tsOut",someValueForTsOut); // What columns should be included? String columns[] = new String[1]{"min(tSin)"}; ReportQueryByCriteria query = QueryFactory.newReportQuery(Timeclock.class,columns,criteria,true); The last argument (true in my example) tell OJB whether or not you want distinct rows returned. Setting it to true causes OJB to insert the DISTINCT keyword in the generated sql. As far as the 'targetClass' is concerned, this identifies the class-descriptor that is the basis for which the various attributes (i.e. "refEmployee", "tsOut" and "tSin") that are found in the criteria/column list are resolved to actual table/column names. HTH Ron Gallagher Atlanta, GA [EMAIL PROTECTED] -Original Message- From: Jason Pyeron [mailto:[EMAIL PROTECTED] Sent: Saturday, November 22, 2003 9:03 PM To: OJB Users List Subject: confused about how to port some sql queries... I have a prepared statement like so: "SELECT min(tsin) FROM timeclock WHERE ref_employee= ? AND tsout=0;" I use this to decide what to query next, it sounds like I should use the "report" feature in OJB but I have no idea how. I looked at ReportQueryByCriteria(java.lang.Class targetClass, java.lang.String[] columns, Criteria criteria) what is this targetClass? Sincerely, Jason Pyeron -- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- - - - Jason Pyeron http://www.pyerotechnics.com - - Partner & Sr. Manager Pyerotechnics Development, Inc. - - +1 (443) 451-2697 500 West University Parkway #1S - - +1 (410) 808-6646 (c) Baltimore, Maryland 21210-3253 - - - -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, purge the message from your system and notify the sender immediately. Any other use of the email by you is prohibited. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: confused about how to port some sql queries...
btw, this is what I am doing for now: PersistenceBroker broker=PersistenceBrokerFactory.defaultPersistenceBroker(); Connection C=broker.serviceConnectionManager().getConnection(); PreparedStatement stmt=C.prepareStatement("SELECT min(tsin) FROM timeclock WHERE ref_employee= ? AND tsout=0;"); stmt.setInt(1,emp.getId()); ResultSet rs=stmt.executeQuery(); min=rs.getDate(1); rs.close(); stmt.close(); C.close(); broker.close(); On Sat, 22 Nov 2003, Jason Pyeron wrote: > > I have a prepared statement like so: > > "SELECT min(tsin) FROM timeclock WHERE ref_employee= ? AND tsout=0;" > > > I use this to decide what to query next, it sounds like I should use the > "report" feature in OJB but I have no idea how. > > I looked at > > ReportQueryByCriteria(java.lang.Class targetClass, java.lang.String[] columns, > Criteria criteria) > > what is this targetClass? > > Sincerely, > > Jason Pyeron > > -- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- - - - Jason Pyeron http://www.pyerotechnics.com - - Partner & Sr. Manager Pyerotechnics Development, Inc. - - +1 (443) 451-2697 500 West University Parkway #1S - - +1 (410) 808-6646 (c) Baltimore, Maryland 21210-3253 - - - -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, purge the message from your system and notify the sender immediately. Any other use of the email by you is prohibited. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
confused about how to port some sql queries...
I have a prepared statement like so: "SELECT min(tsin) FROM timeclock WHERE ref_employee= ? AND tsout=0;" I use this to decide what to query next, it sounds like I should use the "report" feature in OJB but I have no idea how. I looked at ReportQueryByCriteria(java.lang.Class targetClass, java.lang.String[] columns, Criteria criteria) what is this targetClass? Sincerely, Jason Pyeron -- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- - - - Jason Pyeron http://www.pyerotechnics.com - - Partner & Sr. Manager Pyerotechnics Development, Inc. - - +1 (443) 451-2697 500 West University Parkway #1S - - +1 (410) 808-6646 (c) Baltimore, Maryland 21210-3253 - - - -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- This message is for the designated recipient only and may contain privileged, proprietary, or otherwise private information. If you have received it in error, purge the message from your system and notify the sender immediately. Any other use of the email by you is prohibited. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]