Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 95389 invoked from network); 2 Nov 2006 14:26:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Nov 2006 14:26:38 -0000 Received: (qmail 87928 invoked by uid 500); 2 Nov 2006 14:26:50 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 87869 invoked by uid 500); 2 Nov 2006 14:26:50 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 87857 invoked by uid 99); 2 Nov 2006 14:26:50 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Nov 2006 06:26:50 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Nov 2006 06:26:38 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id A35F21A984D; Thu, 2 Nov 2006 06:26:13 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r470372 [2/2] - in /db/derby/code/trunk/java/demo/scores: ./ java/ java/client/ java/client/org/ java/client/org/apache/ java/client/org/apache/derbyDemo/ java/client/org/apache/derbyDemo/scores/ java/client/org/apache/derbyDemo/scores/app/... Date: Thu, 02 Nov 2006 14:26:12 -0000 To: derby-commits@db.apache.org From: rhillegas@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061102142613.A35F21A984D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: db/derby/code/trunk/java/demo/scores/java/server/org/apache/derbyDemo/scores/proc/Procedures.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/demo/scores/java/server/org/apache/derbyDemo/scores/proc/Procedures.java?view=auto&rev=470372 ============================================================================== --- db/derby/code/trunk/java/demo/scores/java/server/org/apache/derbyDemo/scores/proc/Procedures.java (added) +++ db/derby/code/trunk/java/demo/scores/java/server/org/apache/derbyDemo/scores/proc/Procedures.java Thu Nov 2 06:26:09 2006 @@ -0,0 +1,136 @@ +/* + + Derby - Class org.apache.derbyDemo.scores.proc.Procedures + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ + +package org.apache.derbyDemo.scores.proc; + +import java.sql.*; + +import org.apache.derbyDemo.scores.util.*; + +/** + *

+ * Procedures used by the Scores application. + *

+ * + * @author Rick Hillegas + */ +public class Procedures +{ + //////////////////////////////////////////////////////// + // + // CONSTANTS + // + //////////////////////////////////////////////////////// + + //////////////////////////////////////////////////////// + // + // STATE + // + //////////////////////////////////////////////////////// + + private static int _scoringCount = 0; + + //////////////////////////////////////////////////////// + // + // STATIC BEHAVIOR + // + //////////////////////////////////////////////////////// + + /** + *

+ * Score a test run and update TestTaking with the score. + *

+ */ + public static void ScoreTestTaking( int takingID ) + throws SQLException + { + Connection conn = Functions.getDefaultConnection(); + Logger log = Logger.getLogger(); + boolean loggingEnabled = log.isLoggingEnabled(); + + try { + // + // Only print out the first test taking. + // They all look alike. + // + if ( _scoringCount > 0 ) { log.enableLogging( false ); } + + log.log + ( + "Trigger has just fired and started " + + "the ScoreTestTaking procedure.\n" + ); + + PreparedStatement ps = Utils.prepare + ( + conn, + "select \n" + + " sum( weighQuestion( q.difficulty ) ),\n" + + " sum( scoreAnswer( q.difficulty, q.numberOfChoices," + + " q.correctChoice, qt.actualChoice ) )\n" + + "from Question q, QuestionTaking qt\n" + + "where q.questionID = qt.questionID\n" + + "and qt.takingID = ?\n" + ); + ps.setInt( 1, takingID ); + + ResultSet rs = ps.executeQuery(); + + rs.next(); + + int column = 1; + double allCorrect = rs.getDouble( column++ ); + double actual = rs.getDouble( column++ ); + double score = Utils.finishScore + ( allCorrect, actual ); + + Utils.close( rs ); + Utils.close( ps ); + + int param = 1; + ps = Utils.prepare + ( + conn, + "update TestTaking set score = ? where takingID = ?\n" + ); + ps.setDouble( param++, score ); + ps.setInt( param++, takingID ); + ps.executeUpdate(); + + Utils.close( ps ); + + } + finally + { + log.enableLogging( loggingEnabled ); + } + + _scoringCount++; + } + + //////////////////////////////////////////////////////// + // + // MINIONS + // + //////////////////////////////////////////////////////// + + +} Propchange: db/derby/code/trunk/java/demo/scores/java/server/org/apache/derbyDemo/scores/proc/Procedures.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: db/derby/code/trunk/java/demo/scores/java/server/org/apache/derbyDemo/scores/proc/Procedures.java ------------------------------------------------------------------------------ svn:executable = *