📄 t_qualifiertest.java
字号:
/* Derby - Class org.apache.derbyTesting.unitTests.store.T_QualifierTest Copyright 1997, 2005 The Apache Software Foundation or its licensors, as applicable. Licensed 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.unitTests.store;import org.apache.derbyTesting.unitTests.harness.T_Fail;import org.apache.derby.impl.store.access.conglomerate.*;import java.util.Properties;import java.util.HashSet;import java.io.PrintWriter;import org.apache.derby.iapi.services.stream.HeaderPrintWriter;import org.apache.derby.iapi.error.StandardException;import org.apache.derby.iapi.store.access.ConglomerateController;import org.apache.derby.iapi.store.access.GroupFetchScanController;import org.apache.derby.iapi.store.access.Qualifier;import org.apache.derby.iapi.store.access.RowUtil;import org.apache.derby.iapi.store.access.ScanController;import org.apache.derby.iapi.store.access.TransactionController;import org.apache.derby.iapi.types.DataValueDescriptor;import org.apache.derby.iapi.types.Orderable;import org.apache.derby.iapi.types.RowLocation;import org.apache.derby.iapi.types.SQLLongint;import org.apache.derby.iapi.store.access.BackingStoreHashtable;import org.apache.derby.iapi.services.io.FormatableBitSet;import java.util.Enumeration;import java.util.Vector;public class T_QualifierTest { private String init_conglomerate_type; private Properties init_properties; private boolean init_temporary; private HeaderPrintWriter init_out; private int init_order = ORDER_NONE; public static final int ORDER_FORWARD = 1; public static final int ORDER_BACKWARD = 2; public static final int ORDER_NONE = 3; public static final int ORDER_DESC = 4; // ordered in descending order /* Constructor */ public T_QualifierTest( String conglomerate_type, Properties properties, boolean temporary, HeaderPrintWriter out, int order) { this.init_conglomerate_type = conglomerate_type; this.init_properties = properties; this.init_temporary = temporary; this.init_out = out; this.init_order = order; return; } /************************************************************************** * Private/Protected methods of This class: ************************************************************************** */ private static HashSet create_hash_set( int expect_key, int expect_numrows, int order) { HashSet set = new HashSet(10, 0.8f); int key_val = expect_key; for (int i = 0; i < expect_numrows; i++) { set.add(new Long(key_val)); if (order == ORDER_DESC) key_val--; else key_val++; } return(set); } private static int flip_scan_op(int op) { int ret_op = -42; if (op == ScanController.GE) ret_op = ScanController.GT; else if (op == ScanController.GT) ret_op = ScanController.GE; return(ret_op); } /** * Test a single scan. */ public static boolean t_scan( TransactionController tc, long conglomid, DataValueDescriptor[] init_scan_template, DataValueDescriptor[] fetch_template, DataValueDescriptor[] start_key, int start_op, Qualifier qualifier[][], DataValueDescriptor[] stop_key, int stop_op, int expect_numrows, int lowest_expect_key, int order) throws StandardException, T_Fail { boolean ret_val; // call scan which does next(), fetch(row) ret_val = t_scanNext(tc, conglomid, fetch_template, start_key, start_op, qualifier, stop_key, stop_op, expect_numrows, lowest_expect_key, order); if (!ret_val) return(ret_val); // call scan which does fetchNext(row), fetch(row) ret_val = t_scanFetchNext(tc, conglomid, init_scan_template, fetch_template, start_key, start_op, qualifier, stop_key, stop_op, expect_numrows, lowest_expect_key, order); if (!ret_val) return(ret_val); // call scan which does fetchNext(partial_row), fetch(partial_row) ret_val = t_scanFetchNextPartial(tc, conglomid, fetch_template, start_key, start_op, qualifier, stop_key, stop_op, expect_numrows, lowest_expect_key, order); if (!ret_val) return(ret_val); // call scan which does createBackingStoreHashtable() ret_val = t_scanFetchHashtable(tc, conglomid, fetch_template, start_key, start_op, qualifier, stop_key, stop_op, expect_numrows, lowest_expect_key, order); if (!ret_val) return(ret_val); // call scan which does fetchNextGroup() - fetching 1 at a time. // this tests the edge case. ret_val = t_scanFetchNextGroup(tc, 1, conglomid, fetch_template, start_key, start_op, qualifier, stop_key, stop_op, expect_numrows, lowest_expect_key, order); if (!ret_val) return(ret_val); // call scan which does fetchNextGroup() - fetching 2 at a time. // this tests the general case of fetching N rows which is usually // less than the remaining rows in the result set. ret_val = t_scanFetchNextGroup(tc, 2, conglomid, fetch_template, start_key, start_op, qualifier, stop_key, stop_op, expect_numrows, lowest_expect_key, order); if (!ret_val) return(ret_val); // call scan which does fetchNextGroup() - fetching 1000 at a time. // this will get the entire result set in one fetch. ret_val = t_scanFetchNextGroup(tc, 1000, conglomid, fetch_template, start_key, start_op, qualifier, stop_key, stop_op, expect_numrows, lowest_expect_key, order); if (!ret_val) return(ret_val); return(ret_val); } private static boolean t_scanNext( TransactionController tc, long conglomid, DataValueDescriptor[] fetch_template, DataValueDescriptor[] start_key, int start_op, Qualifier qualifier[][], DataValueDescriptor[] stop_key, int stop_op, int expect_numrows, int input_expect_key, int order) throws StandardException, T_Fail { HashSet set = null; boolean ordered = (order == T_QualifierTest.ORDER_FORWARD || order == T_QualifierTest.ORDER_DESC); int expect_key = input_expect_key; if (!ordered) { set = create_hash_set(input_expect_key, expect_numrows, order); } /********************************************************************** * Forward scan test case ********************************************************************** */ ScanController scan = tc.openScan( conglomid, false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, start_key, start_op, qualifier, stop_key, stop_op); long key = -42; int numrows = 0; while (scan.next()) { scan.fetch(fetch_template); key = ((SQLLongint)(fetch_template[2])).getLong(); if (ordered) { if (key != expect_key) { return( fail("(t_scanNext) wrong key, expected (" + expect_key + ")" + "but got (" + key + ").")); } else { if (order == ORDER_DESC) expect_key--; else expect_key++; } } else { if (!set.remove(new Long(key))) { return( fail("(t_scanNext) wrong key, expected (" + expect_key + ")" + "but got (" + key + ").")); } } numrows++; } scan.close(); if (numrows != expect_numrows) { return(fail("(t_scanNext) wrong number of rows. Expected " + expect_numrows + " rows, but got " + numrows + "rows.")); } /********************************************************************** * Backward scan test case ********************************************************************** */ /* if (!ordered) { set = create_hash_set(input_expect_key, expect_numrows, order); } // flip start and stop keys for backward scan and also flip // start and stop operators (ie. GE->GT and GT->GE). scan = tc.openBackwardScan( conglomid, false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, stop_key, flip_scan_op(stop_op), qualifier, start_key, flip_scan_op(start_op)); key = -42; numrows = 0; // rows are going to come back in reverse order in the ordered case. expect_key = input_expect_key + expect_numrows - 1; while (scan.next()) { scan.fetch(fetch_template); key = ((SQLLongint)(fetch_template[2])).getLong(); if (ordered) { if (key != expect_key) { return( fail("(t_scanNext-backward) wrong key, expected (" + expect_key + ")" + "but got (" + key + ").")); } else { expect_key--; } } else { if (!set.remove(new Long(key))) { return( fail("(t_scanNext-backward) wrong key, expected (" + expect_key + ")" + "but got (" + key + ").")); } } numrows++; } if (numrows != expect_numrows) { return(fail("(t_scanNext-backward) wrong num of rows. Expected " + expect_numrows + " rows, but got " + numrows + "rows.")); } scan.close(); */ return(true); } /** * Test scan which does FetchNext with all of the fields. * <p> * FetchNext() may be optimized by the underlying scan code to try and * not do multiple fetches of the same row for the user, but if the user * asks for one column, but the stop position depends on the whole row * this optimization is not possible. * <p> * * @return Whether the test succeeded or not. * * @exception StandardException Standard exception policy. **/ public static boolean t_scanFetchNext( TransactionController tc, long conglomid, DataValueDescriptor[] init_scan_template, DataValueDescriptor[] fetch_template, DataValueDescriptor[] start_key, int start_op, Qualifier qualifier[][], DataValueDescriptor[] stop_key, int stop_op, int expect_numrows, int input_expect_key, int order) throws StandardException, T_Fail { HashSet set = null; boolean ordered = (order == ORDER_FORWARD || order == ORDER_DESC); if (!ordered) { set = create_hash_set(input_expect_key, expect_numrows, order); } /********************************************************************** * Forward scan test case ********************************************************************** */ ScanController scan = tc.openScan( conglomid, false, 0, TransactionController.MODE_RECORD, TransactionController.ISOLATION_SERIALIZABLE, (FormatableBitSet) null, start_key, start_op, qualifier, stop_key, stop_op); int expect_key = input_expect_key; long key = -42; long numrows = 0; while (scan.fetchNext(fetch_template)) { scan.fetch(init_scan_template); // make sure all columns from fetchNext() match subsequent fetch(). for (int i = 0; i < init_scan_template.length; i++) { if ((fetch_template[i]).compare( (init_scan_template[i])) != 0) { return( fail("(t_scanFetchNext) wrong key, expected (" + fetch_template[i] + ")" + "but got (" + init_scan_template[i] + ").")); } } // see if we are getting the right keys. key = ((SQLLongint)(init_scan_template[2])).getLong();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -