db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r499898 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe: client/ direct/ routines/ run/ schema/ test/ util/
Date Thu, 25 Jan 2007 18:50:38 GMT
Author: djd
Date: Thu Jan 25 10:50:37 2007
New Revision: 499898

URL: http://svn.apache.org/viewvc?view=rev&rev=499898
Log:
DERBY-2094 (partial) Add implementation of the payment transaction for the order entry test,
both as
by name and identifier. Clean up some of the testing to make it easier to run tests of just
the transactions
and easier to add scripts.
Fixed an off-by-one error in populating the values for the customer last name.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/routines/
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/routines/Data.java
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/schema/dataroutines.sql
  (with props)
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/client/Display.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/direct/Standard.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Populate.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Schema.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OETest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OperationsTester.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/util/OERandom.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/client/Display.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/client/Display.java?view=diff&rev=499898&r1=499897&r2=499898
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/client/Display.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/client/Display.java
Thu Jan 25 10:50:37 2007
@@ -55,13 +55,13 @@
      *            District (input)
      * @param threshold
      *            Threshold (input)
-     * @param level
+     * @param lowStock
      *            (result)
      * @throws Exception
      *             Error displaying data
      */
     public void displayStockLevel(Object displayData, short w, short d,
-            int threshold, int level) throws Exception;
+            int threshold, int lowStock) throws Exception;
 
     /**
      * Display the result of an order status. Order status terminal i/o is

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/direct/Standard.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/direct/Standard.java?view=diff&rev=499898&r1=499897&r2=499898
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/direct/Standard.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/direct/Standard.java
Thu Jan 25 10:50:37 2007
@@ -28,9 +28,12 @@
 
 import org.apache.derbyTesting.system.oe.client.Display;
 import org.apache.derbyTesting.system.oe.client.Operations;
+import org.apache.derbyTesting.system.oe.model.Address;
 import org.apache.derbyTesting.system.oe.model.Customer;
+import org.apache.derbyTesting.system.oe.model.District;
 import org.apache.derbyTesting.system.oe.model.Order;
 import org.apache.derbyTesting.system.oe.model.OrderLine;
+import org.apache.derbyTesting.system.oe.model.Warehouse;
 
 /**
  * Implement the transactions following the TPC-C specification
@@ -117,7 +120,7 @@
 
                 rs.next();
                 int nextOrder = rs.getInt("D_NEXT_O_ID");
-                rs.close();
+                reset(sl1);
 
                 sl2.setInt(3, nextOrder);
                 sl2.setInt(4, nextOrder - 20);
@@ -125,7 +128,7 @@
                 rs = sl2.executeQuery();
                 rs.next();
                 level = rs.getInt("LOW_STOCK");
-                rs.close();
+                reset(sl2);
 
                 conn.commit();
             } finally {
@@ -204,7 +207,7 @@
                 
                 list.add(customer);
             }
-            rs.close();
+            reset(osCustomerByName);
             if (list.isEmpty())
                 throw new SQLException("Order Status by name - no matching customer "
                         + customerLast);
@@ -248,7 +251,7 @@
             customer.setFirst(rs.getString("C_FIRST"));
             customer.setMiddle(rs.getString("C_MIDDLE"));
             customer.setLast(rs.getString("C_LAST"));    
-            rs.close();
+            reset(osCustomerById);
 
             getOrderStatusForCustomer(display, displayData, false, customer);
         } catch (SQLException e) {
@@ -275,7 +278,7 @@
         ResultSet rs = osLastOrderNumber.executeQuery();
         rs.next();
         order.setId(rs.getInt("LAST_ORDER"));
-        rs.close();
+        reset(osLastOrderNumber);
         
         // Details for the order.
         osOrderDetails.setShort(1, customer.getWarehouse());
@@ -313,23 +316,245 @@
             display.displayOrderStatus(displayData,
                     byName, customer, order, lineItems);
     }
+    
+    private PreparedStatement pyCustomerPayment;
+    private PreparedStatement pyCustomerInfoId;
+    private PreparedStatement pyCustomerByName;
+    private PreparedStatement pyCustomerUpdateBadCredit;
+    private PreparedStatement pyCustomerGetData;
+    private PreparedStatement pyDistrictUpdate;
+    private PreparedStatement pyDistrictInfo;
+    private PreparedStatement pyWarehouseUpdate;
+    private PreparedStatement pyWarehouseInfo;
+    private PreparedStatement pyHistory;
 
     public void setupPayment() throws Exception {
-        // TODO Auto-generated method stub
-
-    }
+        pyCustomerPayment = prepare(
+            "UPDATE CUSTOMER SET C_BALANCE = C_BALANCE - ?, " +
+            "C_YTD_PAYMENT = C_YTD_PAYMENT + ?, " +
+            "C_PAYMENT_CNT = C_PAYMENT_CNT + 1 " +
+            "WHERE C_W_ID = ? AND C_D_ID = ? AND C_ID = ?");
+        
+        pyCustomerInfoId = prepare(
+            "SELECT C_FIRST, C_MIDDLE, C_LAST, C_BALANCE, " +
+            "C_STREET_1, C_STREET_2, C_CITY, C_STATE, C_ZIP, " +
+            "C_PHONE, C_SINCE, C_CREDIT, C_CREDIT_LIM, C_DISCOUNT " +
+            "FROM CUSTOMER WHERE C_W_ID = ? AND C_D_ID = ? AND C_ID = ?");
+        
+        pyCustomerByName = prepare(
+                "SELECT C_ID " +
+                "FROM CUSTOMER WHERE C_W_ID = ? AND C_D_ID = ? AND C_LAST = ? " +
+                "ORDER BY C_FIRST");
+        
+        pyCustomerUpdateBadCredit = prepare(
+            "UPDATE CUSTOMER SET C_DATA = " +
+            " BAD_CREDIT_DATA(C_DATA, ?, ?, C_W_ID, C_W_ID, C_ID, ?) " +
+            "WHERE C_W_ID = ? AND C_D_ID = ? AND C_ID = ?");
+        pyCustomerGetData = prepare(
+            "SELECT SUBSTR(C_DATA, 1, 200) AS C_DATA_200 " +
+            "FROM CUSTOMER WHERE C_W_ID = ? AND C_D_ID = ? AND C_ID = ?");
+        
+        pyDistrictUpdate = prepare(
+            "UPDATE DISTRICT SET D_YTD = D_YTD + ? WHERE D_W_ID = ? AND D_ID = ?");
+        pyDistrictInfo = prepare(
+            "SELECT D_NAME, D_STREET_1, D_STREET_2, D_CITY, D_STATE, D_ZIP FROM DISTRICT
WHERE D_W_ID = ? AND D_ID = ? ");
+        pyWarehouseUpdate = prepare(
+            "UPDATE WAREHOUSE SET W_YTD = W_YTD + ? WHERE W_ID = ?");
+        pyWarehouseInfo = prepare(
+                "SELECT W_NAME, W_STREET_1, W_STREET_2, W_CITY, W_STATE, W_ZIP " +
+                "FROM WAREHOUSE WHERE W_ID = ?");
+        
+        pyHistory = prepare(
+            "INSERT INTO HISTORY(H_C_ID, H_C_D_ID, H_C_W_ID, H_D_ID, H_W_ID, " +
+            "H_DATE, H_AMOUNT, H_DATA) " +
+            "VALUES (?, ?, ?, ?, ?, CURRENT TIMESTAMP, ?, ?)");
+     }
 
+    /**
+     * Payment by customer last name.
+     * Section 2.5.2
+     * The CUSTOMER row will be fetched and then updated.
+     * This is due to the need to select the specific customer
+     * first based upon last name (which will actually fetch and
+     * hence lock a number of customers).
+     */
     public void payment(Display display, Object displayData, short w, short d,
             short cw, short cd, String customerLast, String amount)
             throws Exception {
-        // TODO Auto-generated method stub
+        
+        // Since so much data is needed for the payment transaction
+        // from the customer we don't fill it in as we select the
+        // correct customer. Instead we just fetch the identifier
+        // and then execute a payment by identifier.
+        try {
+            pyCustomerByName.setShort(1, cw);
+            pyCustomerByName.setShort(2, cd);
+            pyCustomerByName.setString(3, customerLast);
+            ResultSet rs = pyCustomerByName.executeQuery();
+            int n = 0;
+            List list = new ArrayList();
+            while (rs.next())
+            {           
+                list.add(rs.getObject("C_ID"));            
+            }
+            reset(pyCustomerByName);
+            if (list.isEmpty())
+                throw new SQLException("Payment by name - no matching customer "
+                        + customerLast);
+            
+            // Customer to use is midpoint (with round up) (see 2.5.2.2)
+            int mid = n/2;
+            if (n%2 == 1)
+                mid++;
+            
+            int c = ((Integer) list.get(mid)).intValue();
 
+            paymentById(display, displayData, w, d, cw, cd, c, amount);
+        } catch (SQLException e) {
+            conn.rollback();
+            throw e;
+        }
+        
+        if (display != null)
+            ;
     }
 
+    /**
+     * Payment by customer identifier.
+     * Section 2.5.2.
+     * The CUSTOMER row is update and then fetched.
+     * 
+     */
     public void payment(Display display, Object displayData, short w, short d,
-            short cw, short cd, int c, String amount) throws Exception {
-        // TODO Auto-generated method stub
+            short cw, short cd, int c, final String amount) throws Exception {
+        
+        try {
+            paymentById(display, displayData, w, d, cw, cd, c, amount);
+        } catch (SQLException e) {
+            conn.rollback();
+            throw e;
+        }
+        
+        if (display != null)
+            ;
+    }
+    
+    private void paymentById(Display display, Object displayData, short w, short d,
+            short cw, short cd, int c, final String amount) throws Exception {
+  
+        
+        Customer customer = new Customer();
+        customer.setWarehouse(cw);
+        customer.setDistrict(cd);
+        customer.setId(c);
+        
+        // Update the customer assuming that they have good credit
+        pyCustomerPayment.setString(1, amount);
+        pyCustomerPayment.setString(2, amount);
+        pyCustomerPayment.setShort(3, cw);
+        pyCustomerPayment.setShort(4, cd);
+        pyCustomerPayment.setInt(5, c);
+        pyCustomerPayment.executeUpdate();
+        
+        // Get the customer information
+        pyCustomerInfoId.setShort(1, cw);
+        pyCustomerInfoId.setShort(2, cd);
+        pyCustomerInfoId.setInt(3, c);
+        ResultSet rs = pyCustomerInfoId.executeQuery();
+        rs.next();
+        
+        customer.setFirst(rs.getString("C_FIRST"));
+        customer.setMiddle(rs.getString("C_MIDDLE"));
+        customer.setLast(rs.getString("C_LAST"));
+        customer.setBalance(rs.getString("C_BALANCE"));
+        
+        customer.setAddress(getAddress(rs, "C_STREET_1"));
+
+        customer.setPhone(rs.getString("C_PHONE"));
+        customer.setSince(rs.getTimestamp("C_SINCE"));
+        customer.setCredit(rs.getString("C_CREDIT"));
+        customer.setCredit_lim(rs.getString("C_CREDIT_LIM"));
+        customer.setDiscount(rs.getString("C_DISCOUNT"));
+        reset(pyCustomerInfoId);
+        
+        // additional work for bad credit customers.
+        if ("BC".equals(customer.getCredit()))
+        {
+            pyCustomerUpdateBadCredit.setShort(1, w);
+            pyCustomerUpdateBadCredit.setShort(2, d);
+            pyCustomerUpdateBadCredit.setString(3, amount);
+            pyCustomerUpdateBadCredit.setShort(4, cw);
+            pyCustomerUpdateBadCredit.setShort(5, cd);
+            pyCustomerUpdateBadCredit.setInt(6, c);         
+            pyCustomerUpdateBadCredit.executeUpdate();
+            reset(pyCustomerUpdateBadCredit);
+            
+            // Need to display the first 200 characters
+            // of C_DATA information if the customer has
+            // bad credit.
+            pyCustomerGetData.setShort(1, cw);
+            pyCustomerGetData.setShort(2, cd);
+            pyCustomerGetData.setInt(3, c);                     
+            rs = pyCustomerGetData.executeQuery();
+            rs.next();
+            customer.setData(rs.getString("C_DATA_200"));
+            reset(pyCustomerGetData);
+        }
 
+        District district = new District();
+        district.setWarehouse(w);
+        district.setId(d);
+
+        // Update DISTRICT
+        pyDistrictUpdate.setString(1, amount);
+        pyDistrictUpdate.setShort(2, w);
+        pyDistrictUpdate.setShort(3, d);
+        pyDistrictUpdate.executeUpdate();
+        reset(pyDistrictUpdate);
+
+        // Get the required information from DISTRICT
+        pyDistrictInfo.setShort(1, w);
+        pyDistrictInfo.setShort(2, d);
+        rs = pyDistrictInfo.executeQuery();
+        rs.next();
+        district.setName(rs.getString("D_NAME"));
+        district.setAddress(getAddress(rs, "D_STREET_1"));
+        reset(pyDistrictInfo);        
+        
+        Warehouse warehouse = new Warehouse();
+        warehouse.setId(w);
+        
+        // Update WAREHOUSE
+        pyWarehouseUpdate.setString(1, amount);
+        pyWarehouseUpdate.setShort(2, w);
+        pyWarehouseUpdate.executeUpdate();
+        reset(pyWarehouseUpdate);
+        
+        // Get the required information from WAREHOUSE
+        pyWarehouseInfo.setShort(1, w);
+        rs = pyWarehouseInfo.executeQuery();
+        rs.next();
+        warehouse.setName(rs.getString("W_NAME"));
+        warehouse.setAddress(getAddress(rs, "W_STREET_1"));
+        reset(pyWarehouseInfo);
+         
+        // Insert HISTORY row
+        pyHistory.setInt(1, c);
+        pyHistory.setShort(2, cd);
+        pyHistory.setShort(3, cw);
+        pyHistory.setShort(4, d);
+        pyHistory.setShort(5, w);
+        pyHistory.setString(6, amount);
+        StringBuffer hData = new StringBuffer(24);
+        hData.append(warehouse.getName());
+        hData.append("    ");
+        hData.append(district.getName());
+        pyHistory.setString(7, hData.toString());
+        pyHistory.executeUpdate();
+        reset(pyHistory);
+        
+        conn.commit();
+  
     }
     
     public void setupNewOrder() throws Exception {
@@ -372,11 +597,56 @@
         close(osOrderDetails);
         close(osOrderLineItems);
         
+        close(pyCustomerPayment);
+        close(pyCustomerInfoId);
+        close(pyCustomerUpdateBadCredit);
+        close(pyDistrictUpdate);
+        close(pyDistrictInfo);
+        close(pyWarehouseUpdate);
+        close(pyWarehouseInfo);
+        close(pyHistory);
+        
     }
+    
+    /**
+     * Reset a PreparedStatement. Closes its open ResultSet
+     * and clears the parameters. While clearing the parameters
+     * is not required since any future execution will override
+     * them, it is done here to reduce the chance of errors.
+     * E.g. using the wrong prepared statement for a operation
+     * or not setting all the parameters.
+     * It is assumed the prepared statement was just executed.
+     * @throws SQLException 
+     */
+    private static void reset(PreparedStatement ps) throws SQLException
+    {
+        ResultSet rs = ps.getResultSet();
+        if (rs != null)
+            rs.close();
+        ps.clearParameters();
+    }
+    
+    /**
+     * Close a PreparedStatement if it was opened.
+     */
     private static void close(PreparedStatement ps)
        throws SQLException
     {
         if (ps != null)
             ps.close();
+    }
+    
+    private Address getAddress(ResultSet rs, String firstColumnName) throws SQLException
+    {
+        Address address = new Address();
+        
+        int col = rs.findColumn(firstColumnName);
+        address.setStreet1(rs.getString(col++));
+        address.setStreet2(rs.getString(col++));
+        address.setCity(rs.getString(col++));
+        address.setState(rs.getString(col++));
+        address.setZip(rs.getString(col));
+        
+        return address;
     }
 }

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/routines/Data.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/routines/Data.java?view=auto&rev=499898
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/routines/Data.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/routines/Data.java
Thu Jan 25 10:50:37 2007
@@ -0,0 +1,56 @@
+/*
+ *
+ * Derby - Class org.apache.derbyTesting.system.oe.routines.Data
+ *
+ * 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.derbyTesting.system.oe.routines;
+
+import java.math.BigDecimal;
+import java.sql.SQLException;
+
+public class Data {
+    
+    /**
+     * Function to provided an updated C_DATA column for a customer account.
+     */
+    public static String dataForBadCredit(String creditData, int w, int d,
+            short cw, short cd, int c, BigDecimal amount) throws SQLException {
+
+        StringBuffer sb = new StringBuffer(600);
+        sb.append(" >");
+        sb.append(c);
+        sb.append(',');
+        sb.append(cd);
+        sb.append(',');
+        sb.append(cw);
+        sb.append(',');
+        sb.append(d);
+        sb.append(',');
+        sb.append(w);
+        sb.append(',');
+        sb.append(amount);
+        sb.append(',');
+        sb.append("< ");
+
+        sb.append(creditData);
+        if (sb.length() > 500)
+            sb.setLength(500);
+
+        return sb.toString();
+    }
+
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/routines/Data.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Populate.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Populate.java?view=diff&rev=499898&r1=499897&r2=499898
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Populate.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Populate.java Thu
Jan 25 10:50:37 2007
@@ -166,7 +166,7 @@
         TestSuite suite = new TestSuite("Order Entry");
 
         // Create Schema
-        suite.addTest(new Schema("testSchema"));
+        Schema.addBaseSchema(suite);
         if (createConstraintsBeforeLoad)
             Schema.addConstraints(suite);
         

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Schema.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Schema.java?view=diff&rev=499898&r1=499897&r2=499898
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Schema.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Schema.java Thu
Jan 25 10:50:37 2007
@@ -54,10 +54,16 @@
         TestSuite suite = new TestSuite("Order Entry- Schema");
 
         // Create Schema
-        suite.addTest(new Schema("testSchema"));
+        addBaseSchema(suite);
         addConstraints(suite);
         return suite;
     }
+    
+    public static void addBaseSchema(TestSuite suite) {
+        // Create Schema
+        suite.addTest(new Schema("schema.sql"));
+        suite.addTest(new Schema("dataroutines.sql"));
+    }
 
     /**
      * Add constraint tests to suite.
@@ -65,51 +71,19 @@
      * @param suite
      */
     static void addConstraints(TestSuite suite) {
-        suite.addTest(new Schema("testPrimaryKey"));
-        suite.addTest(new Schema("testForeignKey"));
-        suite.addTest(new Schema("testIndex"));
-
-    }
-
-    /**
-     * Test setting up the base tables.
-     */
-    public void testSchema() throws UnsupportedEncodingException, SQLException,
-    PrivilegedActionException, IOException {
-        script("schema.sql");
-    }
+        suite.addTest(new Schema("primarykey.sql"));
+        suite.addTest(new Schema("foreignkey.sql"));
+        suite.addTest(new Schema("index.sql"));
 
-    /**
-     * Test setting up the primary keys.
-     */
-    public void testPrimaryKey() throws UnsupportedEncodingException,
-    SQLException, PrivilegedActionException, IOException {
-        script("primarykey.sql");
-    }
-
-    /**
-     * Test setting up the foreign keys.
-     */
-    public void testForeignKey() throws UnsupportedEncodingException,
-    SQLException, PrivilegedActionException, IOException {
-        script("foreignkey.sql");
-    }
-
-    /**
-     * Test setting up the remaining indexes.
-     */
-    public void testIndex() throws UnsupportedEncodingException, SQLException,
-    PrivilegedActionException, IOException {
-        script("index.sql");
     }
 
     /**
      * Run a Order Entry script.
      */
-    private void script(String name) throws UnsupportedEncodingException,
+    public void runTest() throws UnsupportedEncodingException,
     SQLException, PrivilegedActionException, IOException {
 
-        String script = "org/apache/derbyTesting/system/oe/schema/" + name;
+        String script = "org/apache/derbyTesting/system/oe/schema/" + getName();
         int errorCount = runScript(script, "US-ASCII");
         assertEquals("Errors in script ", 0, errorCount);
     }

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/schema/dataroutines.sql
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/schema/dataroutines.sql?view=auto&rev=499898
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/schema/dataroutines.sql
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/schema/dataroutines.sql
Thu Jan 25 10:50:37 2007
@@ -0,0 +1,29 @@
+-- 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.
+;
+
+-- Routines related to the data model;
+
+-- Function to provided an updated C_DATA column for a customer account.
+-- Section 2.5.2.2
+CREATE FUNCTION BAD_CREDIT_DATA(
+    C_DATA VARCHAR(500), W SMALLINT, D SMALLINT,
+    CW SMALLINT, CD SMALLINT, C_ID INTEGER,
+    AMOUNT DECIMAL(6, 2))
+RETURNS VARCHAR(500)
+LANGUAGE JAVA PARAMETER STYLE JAVA
+NO SQL
+EXTERNAL NAME 'org.apache.derbyTesting.system.oe.routines.Data.dataForBadCredit';
+    
\ No newline at end of file

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/schema/dataroutines.sql
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OETest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OETest.java?view=diff&rev=499898&r1=499897&r2=499898
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OETest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OETest.java Thu
Jan 25 10:50:37 2007
@@ -19,18 +19,12 @@
  */
 package org.apache.derbyTesting.system.oe.test;
 
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.security.PrivilegedActionException;
-import java.sql.SQLException;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
 import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
-import org.apache.derbyTesting.system.oe.direct.Standard;
-import org.apache.derbyTesting.system.oe.client.Operations;
 import org.apache.derbyTesting.system.oe.run.Checks;
 import org.apache.derbyTesting.system.oe.run.Populate;
 import org.apache.derbyTesting.system.oe.run.Schema;
@@ -58,29 +52,8 @@
         // perform checks tests.
         suite.addTest(Checks.suite());
 
-        suite.addTest(new OETest("testStandardOperations"));
-        
+        suite.addTestSuite(OperationsTester.class);
+                
         return new CleanDatabaseTestSetup(suite);
     }
-
-    /**
-     * Test the Standard implementations of the business transactions.
-     */
-    public void testStandardOperations() throws Exception
-    {
-        operationsTest(new Standard(getConnection()));
-    }
-    /**
-     * Run a standard set of tests against an implementation
-     * of Operations using the OperationsTester class.
-     */
-    private static void operationsTest(Operations ops) throws Exception
-    {
-        OperationsTester tester = new OperationsTester(ops);
-        tester.test();
-        ops.close();
-    }
-    
-
-
 }

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OperationsTester.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OperationsTester.java?view=diff&rev=499898&r1=499897&r2=499898
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OperationsTester.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OperationsTester.java
Thu Jan 25 10:50:37 2007
@@ -19,8 +19,12 @@
  */
 package org.apache.derbyTesting.system.oe.test;
 
+import java.util.HashMap;
+
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
 import org.apache.derbyTesting.system.oe.client.Display;
 import org.apache.derbyTesting.system.oe.client.Operations;
+import org.apache.derbyTesting.system.oe.direct.Standard;
 import org.apache.derbyTesting.system.oe.model.Customer;
 import org.apache.derbyTesting.system.oe.model.District;
 import org.apache.derbyTesting.system.oe.model.Order;
@@ -34,28 +38,29 @@
  * code is added the implemetations of the transactions
  * will be added.
  */
-class OperationsTester implements Display {
+public class OperationsTester extends BaseJDBCTestCase implements Display {
 
-    private final Operations ops;
+    private Operations ops;
     private final OERandom rand;
     private final short w = 1;
     
-    OperationsTester(Operations ops) {
-        this.ops = ops;
-        this.rand = new OERandom(-1, -1, -1, 3458567);
+    public OperationsTester(String name) {
+        super(name);
+        this.rand = new OERandom(-1, -1, -1);
+    }
+    
+    protected void setUp() throws Exception 
+    {
+        ops = new Standard(getConnection());
     }
     
-    void test() throws Exception
+    protected void tearDown() throws Exception
     {
-        testStockLevel();
-        testOrderStatus();
-        testPayment();
-        testNewOrder();
-        testScheduleDelivery();
-        testDelivery();
+        ops.close();
+        super.tearDown();
     }
     
-    private void testStockLevel() throws Exception
+    public void testStockLevel() throws Exception
     {
         ops.setupStockLevel();
         
@@ -63,9 +68,18 @@
         ops.stockLevel(null, null,
                 w, rand.district(), rand.threshold());
         
-        for (int i = 0; i < 20; i++)
-            ops.stockLevel(this, null,
-                    w, rand.district(), rand.threshold());
+        for (int i = 0; i < 20; i++) {
+           
+            short d = rand.district();
+            int threshold = rand.threshold();
+            
+            HashMap inputData = new HashMap();
+            inputData.put("d", new Short(d));
+            inputData.put("threshold", new Integer(threshold));
+            
+            ops.stockLevel(this, inputData,
+                    w, d, threshold);
+        }
     }
     
     /**
@@ -74,7 +88,7 @@
      * accepts a null display.
      * @throws Exception
      */
-    private void testOrderStatus() throws Exception
+    public void testOrderStatus() throws Exception
     {
         ops.setupOrderStatus();
         
@@ -82,8 +96,15 @@
         ops.orderStatus(null, null,
                 w, rand.district(), rand.NURand1023());
         for (int i = 0; i < 50; i++) {
-            ops.orderStatus(this, null,
-                    w, rand.district(), rand.NURand1023());
+            
+            short d = rand.district();
+            int c = rand.NURand1023();
+            
+            HashMap inputData = new HashMap();
+            inputData.put("d", new Short(d));
+            inputData.put("c", new Integer(c));
+
+            ops.orderStatus(this, inputData, w, d, c);
         }
         
         // By name 
@@ -91,36 +112,74 @@
                 w, rand.district(), rand.randomCLast());
         for (int i = 0; i < 50; i++)
         {
-            ops.orderStatus(this, null,
-                    w, rand.district(), rand.randomCLast());
+            short d = rand.district();
+            String customerLast = rand.randomCLast();
+            
+            HashMap inputData = new HashMap();
+            inputData.put("d", new Short(d));
+            inputData.put("customerLast", customerLast);
+
+            ops.orderStatus(this, inputData, w, d, customerLast);
             
         }
-        //
     }
-    private void testPayment() throws Exception
+    public void testPayment() throws Exception
     {
         ops.setupPayment();
+        
+        //  With no display
+        ops.payment(null, null, w, rand.district(),
+                w, rand.district(), rand.randomCLast(), rand.payment().toString());
+        
+        for (int i = 0; i < 50; i++) {
+            ops.payment(this, null, w, rand.district(),
+                    w, rand.district(), rand.randomCLast(), rand.payment().toString());
+        }  
+        
+        // With no display
+        ops.payment(null, null, w, rand.district(),
+                w, rand.district(), rand.NURand1023(), rand.payment().toString());
+
+        for (int i = 0; i < 50; i++) {
+            
+            ops.payment(this, null, w, rand.district(),
+                    w, rand.district(), rand.NURand1023(), rand.payment().toString());
+        }
     }
-    private void testNewOrder() throws Exception
+    public void testNewOrder() throws Exception
     {
         ops.setupNewOrder();
     }
-    private void testScheduleDelivery() throws Exception
+    public void testScheduleDelivery() throws Exception
     {
         ops.setupScheduleDelivery();
     }
-    private void testDelivery() throws Exception
+    public void testDelivery() throws Exception
     {
         ops.setupDelivery();
     }
 
-    public void displayStockLevel(Object displayData, short w, short d, int threshold, int
level) throws Exception {
-        // TODO: Check expected data is set.  
+    public void displayStockLevel(Object displayData, short w, short d, int threshold, int
lowStock) throws Exception {
+        HashMap inputData = (HashMap) displayData;
+        assertEquals("sl:w", this.w, w);
+        assertEquals("sl:d", ((Short) inputData.get("d")).shortValue(), d);
+        assertEquals("sl:threshold", ((Integer) inputData.get("threshold")).intValue(), threshold);
+        assertTrue("sl:low stock", lowStock >= 0); 
     }
 
     public void displayOrderStatus(Object displayData, boolean byName, Customer customer,
Order order, OrderLine[] lineItems) throws Exception {
-        // TODO: Check expected data is set.   
+        HashMap inputData = (HashMap) displayData;
+        assertEquals("os:w", this.w, customer.getWarehouse());
+        assertEquals("os:d", ((Short) inputData.get("d")).shortValue(), customer.getDistrict());
         
+        if (byName)
+        {
+            assertNotNull(inputData.get("customerLast"));
+        }
+        else
+        {
+            assertNull(inputData.get("customerLast"));
+        }
     }
 
     public void displayPayment(Object displayData, String amount, boolean byName, Warehouse
warehouse, District district, Customer customer) throws Exception {

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/util/OERandom.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/util/OERandom.java?view=diff&rev=499898&r1=499897&r2=499898
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/util/OERandom.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/util/OERandom.java
Thu Jan 25 10:50:37 2007
@@ -81,6 +81,15 @@
 
         return decimalString.toString();
     }
+    
+    /**
+     * Payment amount between 1.00 and 5,000.00
+     * @return Payment amount between 1.00 and 5,000.00
+     */
+    public BigDecimal payment()
+    {
+        return randomDecimal(1, 500000, 2);
+    }
 
     public BigDecimal randomDecimal(int start, int end, int scale) {
         BigInteger bi = BigInteger.valueOf(randomInt(start, end));
@@ -300,8 +309,12 @@
      * in the TPC-C spec. 
      */
     public String randomCLastPopulate(int cid) {
-        if (cid < 1000)
-            return randomCLast(cid); // range 0 - 999
+        
+        // First thousand customers (C_ID is one based)
+        // have a fixed last name based upon the contiguous
+        // values from 0-999, section 4.3.3.1
+        if (cid <= 1000)
+            return randomCLast(cid-1); // range 0 - 999
 
         return randomCLast(NURand255());
     }



Mime
View raw message