You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by rh...@apache.org on 2006/11/02 15:26:12 UTC
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/...
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.*;
+
+/**
+ * <p>
+ * Procedures used by the Scores application.
+ * </p>
+ *
+ * @author Rick Hillegas
+ */
+public class Procedures
+{
+ ////////////////////////////////////////////////////////
+ //
+ // CONSTANTS
+ //
+ ////////////////////////////////////////////////////////
+
+ ////////////////////////////////////////////////////////
+ //
+ // STATE
+ //
+ ////////////////////////////////////////////////////////
+
+ private static int _scoringCount = 0;
+
+ ////////////////////////////////////////////////////////
+ //
+ // STATIC BEHAVIOR
+ //
+ ////////////////////////////////////////////////////////
+
+ /**
+ * <p>
+ * Score a test run and update TestTaking with the score.
+ * </p>
+ */
+ 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 = *