File: T_RowSource.java

package info (click to toggle)
derby 10.14.2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 79,056 kB
  • sloc: java: 691,961; sql: 42,686; xml: 20,512; sh: 3,373; sed: 96; makefile: 60
file content (277 lines) | stat: -rw-r--r-- 7,521 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/*

   Derby - Class org.apache.derbyTesting.unitTests.store.T_RowSource

   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.unitTests.store;

import org.apache.derby.iapi.store.access.*;

import org.apache.derby.iapi.types.SQLInteger;

import org.apache.derby.iapi.services.io.FormatableBitSet;

import org.apache.derby.iapi.error.StandardException;

import org.apache.derby.iapi.store.raw.Transaction;

import org.apache.derby.iapi.types.DataValueDescriptor;

import org.apache.derby.iapi.types.RowLocation;


/**
  A RowSource is the mechanism for iterating over a set of rows.  The RowSource
  is the interface through which access recieved a set of rows from the client
  for the purpose of inserting into a single container.

  <p>
  A RowSource can come from many sources - from rows that are from fast path
  import, to rows coming out of a sort for index creation.

  @see org.apache.derby.iapi.store.access.RowSource
*/ 
public class T_RowSource implements RowSource {

	static public final int INTEGER_ROW_TYPE = 1;
	static public final int STRING_ROW_TYPE = 2;

	static protected final String REC_001 = "McLaren";
	static protected final String REC_002 = "Ferrari";
	static protected final String REC_003 = "Benetton";
	static protected final String REC_004 = "Prost";
	static protected final String REC_005 = "Tyrell";
	static protected final String REC_006 = "012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
	static protected final String REC_007 = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
	static protected final String REC_008 = "z";

	static protected final int DEFAULT_ROW_COUNT = 500000;
	static protected final int DEFAULT_COLUMN_COUNT = 13;
	static protected final int DEFAULT_SEED = 53;	// some random number

	private int rowCount;
	private int columnCount;
	private DataValueDescriptor row[];
	private FormatableBitSet validColumns;
	private boolean forceAbort;
	private Transaction t;

	/*
	 *	constructor
	 */
	public T_RowSource() {

		// default will create DEFAULT_ROW_COUNT rows,
		// of DEFAULT_COLUMN_COUNT columns string type rows
		// validColumns will be set to null.
		this.rowCount = DEFAULT_ROW_COUNT;
		this.columnCount = DEFAULT_COLUMN_COUNT;
		this.row = new DataValueDescriptor[DEFAULT_COLUMN_COUNT];
		row = setStringRow();
	}

	// if the caller does not pass in a validColumn, we will set it here
	public T_RowSource(int count, int columnCount, int rowType, boolean forceAbort, Transaction t) {

		this.rowCount = count;
		this.columnCount = columnCount;
		validColumns = new FormatableBitSet(columnCount);
		for (int i = 0; i < columnCount; i++)
			validColumns.set(i);

		this.row = new DataValueDescriptor[columnCount];
		if (rowType == INTEGER_ROW_TYPE)
			setIntegerRow();
		else
			row = setStringRow();

		this.forceAbort = forceAbort;
		this.t = t;
	}

	// the caller has a chance to set the valisColumns to anything they want.
	public T_RowSource(int count, int columnCount, int rowType, FormatableBitSet validColumns) {

		this.rowCount = count;
		this.columnCount = columnCount;
		this.validColumns = validColumns;

		this.row = new DataValueDescriptor[columnCount];
		if (rowType == INTEGER_ROW_TYPE)
			setIntegerRow();
		else
			row = setStringRow();
	}

	/*
	 *	methods for RowSource
	 */

	/**
	    @return true if more rows are coming, false if there is no more rows
		in the RowSource
	 * @exception StandardException		Thrown on error
	 */
	public boolean hasMoreRows() throws StandardException {
		if (rowCount > 0)
			return true;
		else
			return false;
	}

	/**
		Get the next row as an array of column objects. The column objects can
		be a JBMS Storable or any
		Serializable/Externalizable/Formattable/Streaming type.  

		@exception StandardException Derby Standard Error Policy
	 */
	public DataValueDescriptor[] getNextRowFromRowSource() 
        throws StandardException {

		if (this.rowCount <= 0)
			return null;

		// if we are testing error condition, force an abort now
		if (forceAbort && (this.rowCount < 3))
			t.abort();

		this.rowCount--;
		return row;
	}

	/**
	  getValidColumns describes the DataValueDescriptor[] returned by all calls
      to the getNextRowFromRowSource() call. 
	*/
	public FormatableBitSet getValidColumns() {
		return validColumns;
	} 

	/**
		closeRowSource tells the RowSource that it will no longer need to
		return any rows and it can release any resource it may have.
		Subsequent call to any method on the RowSource will result in undefined
		behavior.  A closed rowSource can be closed again.
	*/
	public void closeRowSource() {

		this.rowCount = 0;
	}


	/**
		needsRowLocation returns true iff this the row source expects the
		drainer of the row source to call rowLocation after getting a row from
		getNextRowFromRowSource.

		@return true iff this row source expects some row location to be
		returned 
		@see #rowLocation
	 */
	public boolean needsRowLocation() {
		return false;
	}

	/**
	 * @see RowSource#needsToClone
	 */
	public boolean needsToClone()
	{
		return true;
	}

	/**
		rowLocation  is not implemented here
	 */
	public void rowLocation(RowLocation rl) {

		rl = null;
	}

	/**
		Get a copy of the template row.  Cast each column to
		a CloneableObject and clone it.

		@exception StandardException Derby Standard Error Policy
	**/
	public DataValueDescriptor[] getTemplate() throws StandardException {

		return row;

	}

	// set all column of the row to integer object
	private void setIntegerRow() {
		for (int i = 0; i < columnCount; i++)
			this.row[i] = new SQLInteger(i + DEFAULT_SEED);
	}

	private DataValueDescriptor[] setStringRow() {

		T_RawStoreRow row = new T_RawStoreRow(columnCount);

		for (int i = 0; i < columnCount; i++) {
			switch (i % 13) {
			case 0:
				row.setColumn(i, (String) null);
				break;
			case 1:			
				row.setColumn(i, REC_001);
				break;
			case 2:
				row.setColumn(i, REC_002);
				break;
			case 3:
				row.setColumn(i, REC_003);
				break;
			case 4:
				row.setColumn(i, REC_004);
				break;
			case 5:
				row.setColumn(i, REC_005);
				break;
			case 6:
				row.setColumn(i, REC_006);
				break;
			case 7:
				row.setColumn(i, REC_007);
				break;
			case 8:
				row.setColumn(i, (String) null);
				break;
			case 9:
				row.setColumn(i, REC_008);
				break;
			case 10:
				row.setColumn(i, REC_007);
				break;
			case 11:
				row.setColumn(i, (String) null);
				break;
			case 12:
				row.setColumn(i, REC_006);
				break;
			default:
				row.setColumn(i, REC_008);
			}
		}
		return row.getRow();
	}
}