0001: /*
0002:
0003: Derby - Class org.apache.derbyTesting.unitTests.store.T_Util
0004:
0005: Licensed to the Apache Software Foundation (ASF) under one or more
0006: contributor license agreements. See the NOTICE file distributed with
0007: this work for additional information regarding copyright ownership.
0008: The ASF licenses this file to You under the Apache License, Version 2.0
0009: (the "License"); you may not use this file except in compliance with
0010: the License. You may obtain a copy of the License at
0011:
0012: http://www.apache.org/licenses/LICENSE-2.0
0013:
0014: Unless required by applicable law or agreed to in writing, software
0015: distributed under the License is distributed on an "AS IS" BASIS,
0016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0017: See the License for the specific language governing permissions and
0018: limitations under the License.
0019:
0020: */
0021:
0022: package org.apache.derbyTesting.unitTests.store;
0023:
0024: import org.apache.derby.iapi.store.raw.*;
0025:
0026: import org.apache.derby.iapi.services.io.FormatableBitSet;
0027:
0028: import org.apache.derby.iapi.reference.Property;
0029:
0030: // impl imports are the preferred way to create unit tests.
0031: import org.apache.derbyTesting.unitTests.harness.T_MultiThreadedIterations;
0032: import org.apache.derbyTesting.unitTests.harness.T_Fail;
0033:
0034: import org.apache.derby.iapi.services.context.ContextService;
0035: import org.apache.derby.iapi.services.context.ContextManager;
0036: import org.apache.derby.iapi.services.locks.*;
0037: import org.apache.derby.iapi.services.sanity.SanityManager;
0038:
0039: import org.apache.derby.iapi.error.StandardException;
0040:
0041: import org.apache.derby.iapi.store.access.AccessFactoryGlobals;
0042: import org.apache.derby.iapi.store.access.Qualifier;
0043:
0044: import org.apache.derby.iapi.store.access.conglomerate.LogicalUndo;
0045:
0046: import org.apache.derby.iapi.types.DataValueDescriptor;
0047:
0048: import org.apache.derby.iapi.reference.Attribute;
0049: import org.apache.derby.iapi.services.property.PropertyUtil;
0050: import org.apache.derby.iapi.error.ExceptionSeverity;
0051: import java.io.*;
0052: import java.util.Properties;
0053: import org.apache.derby.iapi.types.SQLChar;
0054:
0055: /*
0056: Utility class to help test raw store functionality.
0057:
0058: If you write a raw store unit test, be that a protocol test or an
0059: implementation test, and find youself needing to do certain operations over
0060: and over again, chances are that functionality is either in here or should be
0061: added. This class is here entirely for the convenience of people writing
0062: unit tests for the RawStore.
0063: */
0064: public class T_Util {
0065:
0066: RawStoreFactory rsFactory;
0067: LockFactory lFactory;
0068: ContextService csFactory;
0069:
0070: private int openContainerMode; // mode flags used in openContainer
0071:
0072: public T_Util(RawStoreFactory rsf, LockFactory lf,
0073: ContextService csf) {
0074: rsFactory = rsf;
0075: lFactory = lf;
0076: csFactory = csf;
0077:
0078: openContainerMode = 0; // logged by default
0079: }
0080:
0081: public void setOpenMode(int newMode) {
0082: openContainerMode = newMode;
0083: }
0084:
0085: /*
0086: * function that checks for a condition, throws T_Fail exception if the condition
0087: * is not met.
0088: */
0089:
0090: /*
0091: * check that transaction does not hold any lock
0092: */
0093: public void t_checkNullLockCount(Transaction t) throws T_Fail {
0094: if (lFactory.areLocksHeld(t))
0095: throw T_Fail
0096: .testFailMsg("Previous action did not clean up all locks.");
0097: }
0098:
0099: /*
0100: * check that page number on the page matches the input page number
0101: */
0102: public static void t_checkPageNumber(Page page, long pageNumber)
0103: throws T_Fail {
0104: if (page.getPageNumber() != pageNumber)
0105: throw T_Fail.testFailMsg("page number expected to be "
0106: + pageNumber + ", is " + page.getPageNumber());
0107: }
0108:
0109: /*
0110: * check that the number of record on the page matches input.
0111: * @param page the page in question
0112: * @param count the total number of record - this include deleted as well as non-deleted
0113: * @param nonDeleted the number of non-deleted record
0114: */
0115: public static void t_checkRecordCount(Page page, int count,
0116: int nonDeleted) throws T_Fail, StandardException {
0117: if (page.recordCount() != count)
0118: throw T_Fail.testFailMsg("recordCount() expected to be "
0119: + count + ", is " + page.recordCount());
0120:
0121: if (page.nonDeletedRecordCount() != nonDeleted)
0122: throw T_Fail
0123: .testFailMsg("nonDeletedRecordCount() expected to be "
0124: + nonDeleted
0125: + ", is "
0126: + page.nonDeletedRecordCount());
0127: }
0128:
0129: /*
0130: * check the number of fields in the slot
0131: */
0132: public static void t_checkFieldCount(Page page, int slot, int count)
0133: throws T_Fail, StandardException {
0134: if (page.fetchNumFieldsAtSlot(slot) != count)
0135: throw T_Fail.testFailMsg("number of fields at slot " + slot
0136: + " expected to be " + count + ", is "
0137: + page.fetchNumFieldsAtSlot(slot));
0138: }
0139:
0140: /**
0141: Fetch a record that is expected to exist using a record handle.
0142: The record has a T_RawStoreRow of 1 column and this column as value as
0143: specified by data, which could be null.
0144:
0145: Calls recordExists() before fetch to ensure that the record
0146: is there.
0147:
0148: @param page the page in question
0149: @param rh the record handle
0150: @param data the string value that is expected in the row
0151:
0152: @exception T_Fail Implementation failed expectation
0153: @exception StandardException Unexpected exception from the implementation
0154:
0155: @see Page#recordExists
0156: @see Page#fetch
0157: */
0158: public static void t_checkFetch(Page page, RecordHandle rh,
0159: String data, int stringLen) throws T_Fail,
0160: StandardException {
0161:
0162: t_checkFetch(page, rh, T_Util
0163: .getStringFromData(data, stringLen));
0164: }
0165:
0166: public static void t_checkFetch(Page page, RecordHandle rh,
0167: String data) throws T_Fail, StandardException {
0168:
0169: if (!page.recordExists(rh, false))
0170: throw T_Fail.testFailMsg("Record does not exist");
0171:
0172: T_RawStoreRow readRow = new T_RawStoreRow((String) null);
0173:
0174: int slot = page.getSlotNumber(rh);
0175:
0176: RecordHandle rhf = page.fetchFromSlot(rh, slot, readRow
0177: .getRow(), (FetchDescriptor) null, false);
0178:
0179: if (rhf == null)
0180: throw T_Fail.testFailMsg("Failed to read record");
0181:
0182: if ((data == null) || readRow.getStorableColumn(0).isNull()) {
0183:
0184: if ((data == null) && readRow.getStorableColumn(0).isNull())
0185: return;
0186:
0187: throw T_Fail.testFailMsg("Record's value incorrect");
0188: }
0189:
0190: if (!readRow.toString().equals(data))
0191: throw T_Fail
0192: .testFailMsg("Record's value incorrect, expected :"
0193: + data + ": - got :" + readRow.toString());
0194: }
0195:
0196: /**
0197: Fetch a record from a container that is expected to exist using a record handle.
0198: Calls recordExists() before fetch to ensure that the record
0199: is there.
0200:
0201: @exception T_Fail Implementation failed expectation
0202: @exception StandardException Unexpected exception from the implementation
0203:
0204: @see Page#recordExists
0205: @see Page#fetch
0206: */
0207: public void t_checkFetch(ContainerHandle c, RecordHandle rh,
0208: String data) throws T_Fail, StandardException {
0209:
0210: Page page = t_getPage(c, rh.getPageNumber());
0211:
0212: try {
0213: t_checkFetch(page, rh, data);
0214: } finally {
0215: page.unlatch();
0216: }
0217: }
0218:
0219: /**
0220: Check to make sure record is NOT there
0221:
0222: @exception T_Fail Implementation failed expectation
0223: @exception StandardException Unexpected exception from the implementation
0224: */
0225: public void t_checkFetchFail(ContainerHandle c, RecordHandle rh)
0226: throws T_Fail, StandardException {
0227: Page page = t_getPage(c, rh.getPageNumber());
0228:
0229: try {
0230: if (page.recordExists(rh, true))
0231: throw T_Fail.testFailMsg("Record Exists");
0232: } finally {
0233: page.unlatch();
0234: }
0235: }
0236:
0237: /**
0238: Fetch a deleted record from a container using a record handle.
0239:
0240: @exception T_Fail Implementation failed expectation
0241: @exception StandardException Unexpected exception from the implementation
0242:
0243: @see Page#recordExists
0244: @see Page#fetch
0245: */
0246: public void t_checkFetchDeleted(ContainerHandle c, RecordHandle rh,
0247: String data) throws T_Fail, StandardException {
0248: Page p = t_getPage(c, rh.getPageNumber());
0249: if (p == null)
0250: throw T_Fail.testFailMsg("Page not found " + rh);
0251:
0252: T_RawStoreRow readRow = new T_RawStoreRow((String) null);
0253:
0254: try {
0255: int slot = p.getSlotNumber(rh);
0256: if (p.fetchFromSlot(rh, slot, readRow.getRow(),
0257: (FetchDescriptor) null, false) != null) {
0258: throw T_Fail.testFailMsg("Record at slot " + slot
0259: + " not deleted");
0260: }
0261: } finally {
0262: p.unlatch();
0263: }
0264: }
0265:
0266: /*
0267: Fetch a record that is expected to exist using a record handle.
0268: The record contains the values in the passed in row, which is a
0269: T_RawStoreRow. A T_RawStoreRow of the same number of columns will be made and fetched
0270: from the page and compared with the passed in row.
0271:
0272: */
0273: public static void t_checkFetch(Page page, RecordHandle rh,
0274: T_RawStoreRow row) throws T_Fail, StandardException {
0275: if (!page.recordExists(rh, false))
0276: throw T_Fail.testFailMsg("Record does not exist");
0277:
0278: // try to fetch the same number of columns as the passed in row
0279: int ncol = row.nColumns();
0280: T_RawStoreRow readRow = new T_RawStoreRow(ncol);
0281: for (int i = 0; i < ncol; i++)
0282: readRow.setColumn(i, (String) null);
0283:
0284: RecordHandle rhf = page.fetch(rh, readRow.getRow(),
0285: (FormatableBitSet) null, false);
0286: if (rhf == null)
0287: throw T_Fail.testFailMsg("Failed to read record");
0288: if (!readRow.toString().equals(row.toString()))
0289: throw T_Fail
0290: .testFailMsg("Record's value incorrect, expected :"
0291: + row.toString() + ": - got :"
0292: + readRow.toString());
0293: }
0294:
0295: /*
0296: Using sparse row representation:
0297: Fetch a column of a record that is expected to exist, using a record
0298: handle and a FormatableBitSet object.
0299: Check that column colNum has value data.
0300: */
0301: public static void t_checkFetchCol(Page page, RecordHandle rh,
0302: int colNum, int numCols, String data) throws T_Fail,
0303: StandardException {
0304: if (!page.recordExists(rh, false))
0305: throw T_Fail.testFailMsg("Record does not exist");
0306:
0307: T_RawStoreRow readRow = new T_RawStoreRow(numCols);
0308: for (int i = 0; i < numCols; i++)
0309: readRow.setColumn(i, (String) null);
0310: FormatableBitSet colList = new FormatableBitSet(numCols);
0311: colList.set(colNum);
0312:
0313: RecordHandle rhf = page.fetch(rh, readRow.getRow(), colList,
0314: false);
0315: if (rhf == null)
0316: throw T_Fail.testFailMsg("Failed to read record");
0317: String col = readRow.getStorableColumn(colNum).toString();
0318: if (!col.equals(data))
0319: throw T_Fail.testFailMsg("Record's value for column "
0320: + colNum + " incorrect, expected :" + data
0321: + ": - got :" + readRow.toString());
0322: }
0323:
0324: /*
0325: * the following is a sequence of fetches, fetching the first row, fetching
0326: * the next and previous rows, and fetching the last row in the page.
0327: *
0328: * The row is assumed to be a T_RawStoreRow with 1 column, which value is the
0329: * string specified in data.
0330: */
0331:
0332: /*
0333: * fetch and check the first row in the page.
0334: * Return the first row's recordHandle.
0335: */
0336: public static RecordHandle t_checkFetchFirst(Page page, String data)
0337: throws T_Fail, StandardException {
0338: T_RawStoreRow readRow = new T_RawStoreRow((String) null);
0339:
0340: int slot = 0;
0341: while (page.isDeletedAtSlot(slot)) {
0342: slot++;
0343: }
0344:
0345: RecordHandle rhf = page.fetchFromSlot((RecordHandle) null,
0346: slot, readRow.getRow(), (FetchDescriptor) null, false);
0347:
0348: if (rhf == null)
0349: throw T_Fail.testFailMsg("Failed to read record");
0350: if (!readRow.toString().equals(data))
0351: throw T_Fail
0352: .testFailMsg("Record's value incorrect, expected :"
0353: + data + ": - got :" + readRow.toString());
0354:
0355: return rhf;
0356: }
0357:
0358: /*
0359: * Fetch and check the next (next to rh) row in the page.
0360: * Return the next row's recordHandle
0361: */
0362: public static RecordHandle t_checkFetchNext(Page page,
0363: RecordHandle rh, String data) throws T_Fail,
0364: StandardException {
0365:
0366: if (!page.recordExists(rh, false))
0367: throw T_Fail.testFailMsg("Record does not exist");
0368:
0369: T_RawStoreRow readRow = new T_RawStoreRow((String) null);
0370:
0371: int slot = page.getSlotNumber(rh) + 1;
0372: while (page.isDeletedAtSlot(slot)) {
0373: slot++;
0374: }
0375:
0376: RecordHandle rhf = page.fetchFromSlot((RecordHandle) null,
0377: slot, readRow.getRow(), (FetchDescriptor) null, false);
0378:
0379: if (rhf == null)
0380: throw T_Fail.testFailMsg("Failed to read record");
0381: if (!readRow.toString().equals(data))
0382: throw T_Fail
0383: .testFailMsg("Record's value incorrect, expected :"
0384: + data + ": - got :" + readRow.toString());
0385:
0386: return rhf;
0387: }
0388:
0389: /*
0390: * Fetch and check the previous (previous to rh) row in the page.
0391: * Return the previous row's recordHandle
0392: */
0393: public static RecordHandle t_checkFetchPrevious(Page page,
0394: RecordHandle rh, String data) throws T_Fail,
0395: StandardException {
0396:
0397: if (!page.recordExists(rh, false))
0398: throw T_Fail.testFailMsg("Record does not exist");
0399:
0400: T_RawStoreRow readRow = new T_RawStoreRow((String) null);
0401:
0402: int slot = page.getSlotNumber(rh) - 1;
0403:
0404: while (page.isDeletedAtSlot(slot) && slot >= 0) {
0405: slot--;
0406: }
0407:
0408: if (slot == -1)
0409: return (null);
0410:
0411: RecordHandle rhf = page.fetchFromSlot((RecordHandle) null,
0412: slot, readRow.getRow(), (FetchDescriptor) null, false);
0413:
0414: if (rhf == null)
0415: throw T_Fail.testFailMsg("Failed to read record");
0416: if (!readRow.toString().equals(data))
0417: throw T_Fail
0418: .testFailMsg("Record's value incorrect, expected :"
0419: + data + ": - got :" + readRow.toString());
0420:
0421: return rhf;
0422: }
0423:
0424: /*
0425: * Fetch and check the last row in the page.
0426: * Return the last row's recordHandle
0427: */
0428: public static RecordHandle t_checkFetchLast(Page page, String data)
0429: throws T_Fail, StandardException {
0430: T_RawStoreRow readRow = new T_RawStoreRow((String) null);
0431:
0432: int slot = page.recordCount() - 1;
0433: while (page.isDeletedAtSlot(slot) && slot >= 0) {
0434: slot--;
0435: }
0436:
0437: if (slot == -1)
0438: return (null);
0439:
0440: RecordHandle rhf = page.fetchFromSlot((RecordHandle) null,
0441: slot, readRow.getRow(), (FetchDescriptor) null, false);
0442:
0443: if (rhf == null)
0444: throw T_Fail.testFailMsg("Failed to read record");
0445: if (!readRow.toString().equals(data))
0446: throw T_Fail
0447: .testFailMsg("Record's value incorrect, expected :"
0448: + data + ": - got :" + readRow.toString());
0449:
0450: return rhf;
0451: }
0452:
0453: /*
0454: * Fetch and check the slot on the page.
0455: *
0456: * The slot number is NOT a stable reference once the page is unlatched,
0457: * this check is only valid if you know the page has not been unlatched
0458: * since you put the row in, or you know nobody has touched the page since
0459: * you determined the slot number
0460: *
0461: * The slot refers to a row in the page which has a T_RawStoreRow of 1 column, the
0462: * column has the value of data input.
0463: *
0464: * @param page the page in question
0465: * @param slot the slot number (see above)
0466: * @param data the column value
0467: * @param deleted if the row is deleted, set to true
0468: * @param forUpdate If you want to lock the row for update, set forUpdate to true.
0469: *
0470: */
0471: public static void t_checkFetchBySlot(Page page, int slot,
0472: String data, boolean deleted, boolean forUpdate)
0473: throws T_Fail, StandardException {
0474: T_RawStoreRow readRow = new T_RawStoreRow((String) null);
0475: RecordHandle rh = page.fetchFromSlot((RecordHandle) null, slot,
0476: readRow.getRow(), (FetchDescriptor) null, true);
0477:
0478: if (rh == null)
0479: throw T_Fail.testFailMsg("Failed to read record");
0480: if (!readRow.toString().equals(data))
0481: throw T_Fail
0482: .testFailMsg("Record's value incorrect, expected :"
0483: + data + ": - got :" + readRow.toString());
0484:
0485: if (page.isDeletedAtSlot(slot) != deleted)
0486: throw T_Fail.testFailMsg("Record at slot " + slot
0487: + " deleted=" + page.isDeletedAtSlot(slot)
0488: + ", expect " + deleted);
0489:
0490: // RESOLVE: check locking
0491: }
0492:
0493: /*
0494: * check a column value from a slot on the page
0495: *
0496: * The slot number is NOT a stable reference once the page is unlatched,
0497: * this check is only valid if you know the page has not been unlatched
0498: * since you put the row in, or you know nobody has touched the page since
0499: * you determined the slot number
0500: *
0501: * The storable in the specified column put into the input column and it
0502: * is check for the same value as the input data
0503: *
0504: * @param page the page in question
0505: * @param slot the slot number (see above)
0506: * @param fieldId the field Id on the row
0507: * @param column the storable to put the column in
0508: * @param forUpdate true if you want to lock the row for update
0509: * @param data the expected value in the column
0510: */
0511: public static void t_checkFetchColFromSlot(Page page, int slot,
0512: int fieldId, DataValueDescriptor column, boolean forUpdate,
0513: String data, int stringLen) throws StandardException,
0514: T_Fail {
0515: t_checkFetchColFromSlot(page, slot, fieldId, column, forUpdate,
0516: T_Util.getStringFromData(data, stringLen));
0517: }
0518:
0519: public static void t_checkFetchColFromSlot(Page page, int slot,
0520: int fieldId, DataValueDescriptor column, boolean forUpdate,
0521: String data) throws StandardException, T_Fail {
0522: DataValueDescriptor[] fetch_row = new DataValueDescriptor[fieldId + 1];
0523: fetch_row[fieldId] = column;
0524: FormatableBitSet validCols = new FormatableBitSet(fieldId + 1);
0525: validCols.set(fieldId);
0526:
0527: RecordHandle rh = page.fetchFromSlot(null, slot, fetch_row,
0528: new FetchDescriptor(fetch_row.length, validCols,
0529: (Qualifier[][]) null), true);
0530:
0531: if (rh == null)
0532: throw T_Fail.testFailMsg("Failed to fetch record: slot "
0533: + slot + " field " + fieldId);
0534:
0535: // RESOLVE - how to check rh lock mode?
0536:
0537: if (data == null) {
0538: if (!column.isNull())
0539: throw T_Fail
0540: .testFailMsg("Failed to fetch null column: slot "
0541: + slot
0542: + " field "
0543: + fieldId
0544: + " column is " + column);
0545: } else {
0546: if (column.isNull())
0547: throw T_Fail
0548: .testFailMsg("expect non null column, got null: slot "
0549: + slot + " field " + fieldId);
0550: if (!column.toString().equals(data))
0551: throw T_Fail.testFailMsg("expect " + data + " got "
0552: + column.toString() + ": slot " + slot
0553: + " field " + fieldId);
0554: }
0555: }
0556:
0557: /**
0558: Take an empty page and check it does actually seem to be empty.
0559:
0560: @exception T_Fail Unexpected behaviour from the API
0561: @exception StandardException Unexpected exception from the implementation
0562: */
0563: public static void t_checkEmptyPage(Page page) throws T_Fail,
0564: StandardException {
0565:
0566: // check the counts
0567: t_checkRecordCount(page, 0, 0);
0568:
0569: try {
0570: page.fetchFromSlot((RecordHandle) null, 0, null,
0571: (FetchDescriptor) null, false);
0572:
0573: throw T_Fail
0574: .testFailMsg("fetchFromSlot() must throw exception on fetch from slot 0 on an empty page");
0575: } catch (StandardException se) {
0576: // expected exception.
0577: }
0578:
0579: // check we can't get a record handle. NB here we are guessing that 0
0580: // and RecordHandle.FIRST_RECORD_ID might be valid record identifiers,
0581: // nothing in the API states that they will be. Eother way we
0582: // shouldn't get a valid RecordHandle back.
0583: if (page.getRecordHandle(0) != null)
0584: throw T_Fail
0585: .testFailMsg("obtained a RecordHandle for an empty page");
0586:
0587: if (page.getRecordHandle(RecordHandle.FIRST_RECORD_ID) != null)
0588: throw T_Fail
0589: .testFailMsg("obtained a RecordHandle for an empty page");
0590:
0591: // should be no aux object
0592: if (page.getAuxObject() != null)
0593: throw T_Fail.testFailMsg("empty page has an aux object");
0594:
0595: t_readOnlySlotOutOfRange(page, Page.FIRST_SLOT_NUMBER);
0596:
0597: if (!page.spaceForInsert())
0598: throw T_Fail
0599: .testFailMsg("spaceForInsert() returned false on an empty page");
0600: }
0601:
0602: /*
0603: Check to see the correct behaviour for read only operations
0604: that take a slot when the slot is out of range.
0605: */
0606: public static void t_readOnlySlotOutOfRange(Page page, int slot)
0607: throws T_Fail, StandardException {
0608:
0609: try {
0610: page.fetchFromSlot((RecordHandle) null, slot,
0611: new DataValueDescriptor[0], (FetchDescriptor) null,
0612: true);
0613:
0614: throw T_Fail
0615: .testFailMsg("fetchFromSlot succeeded on out of range slot "
0616: + slot);
0617: } catch (StandardException se0) {
0618: // Statement exception expected, throw if not a statement exception.
0619: if (se0.getSeverity() > ExceptionSeverity.STATEMENT_SEVERITY)
0620: throw se0;
0621: }
0622: try {
0623: page.isDeletedAtSlot(slot);
0624: throw T_Fail
0625: .testFailMsg("isDeletedAtSlot succeeded on out of range slot "
0626: + slot);
0627: } catch (StandardException se2) {
0628: // Statement exception expected, throw if not a statement exception.
0629: if (se2.getSeverity() > ExceptionSeverity.STATEMENT_SEVERITY)
0630: throw se2;
0631: }
0632: }
0633:
0634: /*
0635: Check to see the correct behaviour for update operations
0636: that take a slot when the slot is out of range.
0637: */
0638: public static void t_updateSlotOutOfRange(Page page, int slot)
0639: throws T_Fail, StandardException {
0640:
0641: try {
0642: page.deleteAtSlot(slot, false, (LogicalUndo) null);
0643: throw T_Fail
0644: .testFailMsg("deleteAtSlot succeeded on out of range slot "
0645: + slot);
0646: } catch (StandardException se0) {
0647: // Statement exception expected, throw if not a statement exception.
0648: if (se0.getSeverity() > ExceptionSeverity.STATEMENT_SEVERITY)
0649: throw se0;
0650: }
0651: try {
0652: page.deleteAtSlot(slot, true, (LogicalUndo) null);
0653: throw T_Fail
0654: .testFailMsg("deleteAtSlot succeeded on out of range slot "
0655: + slot);
0656: } catch (StandardException se0) {
0657: // Statement exception expected, throw if not a statement exception.
0658: if (se0.getSeverity() > ExceptionSeverity.STATEMENT_SEVERITY)
0659: throw se0;
0660: }
0661:
0662: T_RawStoreRow row = new T_RawStoreRow((String) null);
0663:
0664: // insert at the last slot will succeed, so don't do it.
0665: if (page.recordCount() != slot) {
0666: try {
0667: page.insertAtSlot(slot, row.getRow(),
0668: (FormatableBitSet) null, (LogicalUndo) null,
0669: Page.INSERT_DEFAULT, 100);
0670: throw T_Fail
0671: .testFailMsg("insertAtSlot succeeded, on out of range slot "
0672: + slot);
0673: } catch (StandardException se0) {
0674: // Statement exception expected, throw if not a statement exception.
0675: if (se0.getSeverity() > ExceptionSeverity.STATEMENT_SEVERITY)
0676: throw se0;
0677: }
0678: }
0679:
0680: try {
0681: page.updateAtSlot(slot, row.getRow(),
0682: (FormatableBitSet) null);
0683: throw T_Fail
0684: .testFailMsg("updateAtSlot succeeded on out of range slot "
0685: + slot);
0686: } catch (StandardException se0) {
0687: // Statement exception expected, throw if not a statement exception.
0688: if (se0.getSeverity() > ExceptionSeverity.STATEMENT_SEVERITY)
0689: throw se0;
0690: }
0691: }
0692:
0693: /*
0694: * Save point checks
0695: */
0696:
0697: /**
0698: Negative test - check that an invalid savepoint is detected.
0699:
0700: @exception T_Fail Unexpected behaviour from the API
0701: @exception StandardException Unexpected exception from the implementation
0702: */
0703: public static void t_checkInvalidSavePoint(Transaction t,
0704: String name) throws T_Fail, StandardException {
0705:
0706: // check a non-existent save point is trapped
0707: try {
0708: t.rollbackToSavePoint(name, null);
0709:
0710: throw T_Fail
0711: .testFailMsg("non existent save point did not cause exception on rollbackToSavePoint");
0712: } catch (StandardException se) {
0713: // we expected this ...
0714: }
0715: try {
0716: t.releaseSavePoint(name, null);
0717: throw T_Fail
0718: .testFailMsg("non existent save point did not cause exception on releaseSavePoint");
0719:
0720: } catch (StandardException se) {
0721: // we expected this ...
0722: }
0723: }
0724:
0725: /*
0726: * same as above, check an invalid savepoint in the given transaction
0727: * context
0728: */
0729: public void t_checkInvalidSavePoint(T_TWC ctx, String name)
0730: throws T_Fail, StandardException {
0731: csFactory.setCurrentContextManager(ctx.cm);
0732: try {
0733: t_checkInvalidSavePoint(ctx.tran, name);
0734: } finally {
0735: csFactory.resetCurrentContextManager(ctx.cm);
0736: }
0737: }
0738:
0739: /*
0740: * function that actually do something, start, commit, abort a trasaction,
0741: * get a page, insert a row, etc.
0742: */
0743:
0744: /*
0745: Start a user transaction, ensures that the startTransaction method
0746: does not return null (which it shouldn't).
0747: */
0748: public Transaction t_startTransaction() throws StandardException,
0749: T_Fail {
0750:
0751: Transaction t1 = rsFactory.startTransaction(csFactory
0752: .getCurrentContextManager(),
0753: AccessFactoryGlobals.USER_TRANS_NAME);
0754:
0755: if (t1 == null)
0756: throw T_Fail.testFailMsg("Start a transaction");
0757: t_checkNullLockCount(t1);
0758: return t1;
0759: }
0760:
0761: /*
0762: Start a user transaction, ensures that the startTransaction method
0763: does not return null (which it shouldn't).
0764: */
0765: public Transaction t_startGlobalTransaction(int format_id,
0766: byte[] global_id, byte[] branch_id)
0767: throws StandardException, T_Fail {
0768:
0769: Transaction t1 = rsFactory.startGlobalTransaction(csFactory
0770: .getCurrentContextManager(), format_id, global_id,
0771: branch_id);
0772:
0773: if (t1 == null)
0774: throw T_Fail.testFailMsg("Start a transaction");
0775: t_checkNullLockCount(t1);
0776: return t1;
0777: }
0778:
0779: /*
0780: * start a user transaction with its own context (T_TWC)
0781: */
0782: public T_TWC t_startTransactionWithContext()
0783: throws StandardException, T_Fail {
0784: T_TWC ctx = new T_TWC(csFactory, lFactory, rsFactory);
0785: ctx.startUserTransaction();
0786: return ctx;
0787: }
0788:
0789: /*
0790: * start an internal transaction
0791: */
0792: public Transaction t_startInternalTransaction()
0793: throws StandardException, T_Fail {
0794:
0795: Transaction t1 = rsFactory.startInternalTransaction(csFactory
0796: .getCurrentContextManager());
0797:
0798: if (t1 == null)
0799: throw T_Fail
0800: .testFailMsg("Failed to start an internal transaction");
0801: t_checkNullLockCount(t1);
0802: return t1;
0803: }
0804:
0805: /*
0806: * commit a transaction
0807: */
0808: public void t_commit(Transaction t) throws StandardException,
0809: T_Fail {
0810: t.commit();
0811: t_checkNullLockCount(t);
0812: }
0813:
0814: /*
0815: * commit a transaction with context
0816: */
0817: public void t_commit(T_TWC ctx) throws StandardException, T_Fail {
0818: csFactory.setCurrentContextManager(ctx.cm);
0819: try {
0820: t_commit(ctx.tran);
0821: } finally {
0822: csFactory.resetCurrentContextManager(ctx.cm);
0823: }
0824: }
0825:
0826: /*
0827: * close a transaction with context
0828: */
0829: public void t_close(T_TWC ctx) throws StandardException, T_Fail {
0830: ctx.tran.close();
0831: ctx.tran = null;
0832: ctx.cm = null; // no need to close a context ???
0833: }
0834:
0835: /*
0836: * abort a transaction
0837: */
0838: public void t_abort(Transaction t) throws StandardException, T_Fail {
0839: t.abort();
0840: t_checkNullLockCount(t);
0841: }
0842:
0843: /*
0844: * abort a transaction with context
0845: */
0846: public void t_abort(T_TWC ctx) throws StandardException, T_Fail {
0847: csFactory.setCurrentContextManager(ctx.cm);
0848: try {
0849: t_abort(ctx.tran);
0850: } finally {
0851: csFactory.resetCurrentContextManager(ctx.cm);
0852: }
0853: }
0854:
0855: /**
0856: Add a new container in the transaction
0857:
0858: @exception T_Fail Unexpected behaviour from the API
0859: @exception StandardException Unexpected exception from the implementation
0860: */
0861: public long t_addContainer(Transaction t, long segmentId)
0862: throws StandardException, T_Fail {
0863:
0864: long cid = t.addContainer(segmentId,
0865: ContainerHandle.DEFAULT_ASSIGN_ID,
0866: ContainerHandle.MODE_DEFAULT, (Properties) null, 0);
0867:
0868: if (cid < 0)
0869: throw T_Fail.testFailMsg("add container");
0870:
0871: return cid;
0872: }
0873:
0874: public long t_addContainer(T_TWC ctx, long segmentId)
0875: throws StandardException, T_Fail {
0876: csFactory.setCurrentContextManager(ctx.cm);
0877: try {
0878: return t_addContainer(ctx.tran, segmentId);
0879: } finally {
0880: csFactory.resetCurrentContextManager(ctx.cm);
0881: }
0882: }
0883:
0884: /**
0885:
0886: Add a new container in the transaction with a specified page size
0887:
0888: @exception T_Fail Unexpected behaviour from the API
0889: @exception StandardException Unexpected exception from the implementation
0890: */
0891: public long t_addContainer(Transaction t, long segmentId,
0892: int pageSize) throws StandardException, T_Fail {
0893:
0894: Properties tableProperties = new Properties();
0895: tableProperties.put(Property.PAGE_SIZE_PARAMETER, Integer
0896: .toString(pageSize));
0897:
0898: long cid = t.addContainer(segmentId,
0899: ContainerHandle.DEFAULT_ASSIGN_ID,
0900: ContainerHandle.MODE_DEFAULT, tableProperties, 0);
0901:
0902: if (cid < 0)
0903: throw T_Fail.testFailMsg("add container");
0904:
0905: return cid;
0906: }
0907:
0908: public long t_addContainer(T_TWC ctx, long segmentId, int pageSize)
0909: throws StandardException, T_Fail {
0910:
0911: csFactory.setCurrentContextManager(ctx.cm);
0912: try {
0913: return t_addContainer(ctx.tran, segmentId, pageSize);
0914: } finally {
0915: csFactory.resetCurrentContextManager(ctx.cm);
0916: }
0917: }
0918:
0919: public long t_addContainer(Transaction t, long segmentId,
0920: Properties tableProperties) throws StandardException,
0921: T_Fail {
0922:
0923: long cid = t.addContainer(segmentId,
0924: ContainerHandle.DEFAULT_ASSIGN_ID,
0925: ContainerHandle.MODE_DEFAULT, tableProperties, 0);
0926:
0927: if (cid < 0)
0928: throw T_Fail.testFailMsg("add container");
0929:
0930: return cid;
0931: }
0932:
0933: /**
0934:
0935: Add a new container in the transaction with specified
0936: pageSize, spareSpace, minimumRecordSize, and reusableRecordId
0937:
0938: @exception T_Fail Unexpected behaviour from the API
0939: @exception StandardException Unexpected exception from the implementation
0940: */
0941: public long t_addContainer(Transaction t, long segmentId,
0942: int pageSize, int spareSpace, int minimumRecordSize,
0943: boolean reusableRecordId) throws StandardException, T_Fail {
0944:
0945: Properties tableProperties = new Properties();
0946: tableProperties.put(Property.PAGE_SIZE_PARAMETER, Integer
0947: .toString(pageSize));
0948: tableProperties.put(
0949: RawStoreFactory.PAGE_RESERVED_SPACE_PARAMETER, Integer
0950: .toString(spareSpace));
0951: tableProperties.put(
0952: RawStoreFactory.MINIMUM_RECORD_SIZE_PARAMETER, Integer
0953: .toString(minimumRecordSize));
0954:
0955: if (reusableRecordId) {
0956: tableProperties.put(
0957: RawStoreFactory.PAGE_REUSABLE_RECORD_ID, "true");
0958: }
0959:
0960: long cid = t.addContainer(segmentId,
0961: ContainerHandle.DEFAULT_ASSIGN_ID,
0962: ContainerHandle.MODE_DEFAULT, tableProperties, 0);
0963:
0964: if (cid < 0)
0965: throw T_Fail.testFailMsg("add container");
0966:
0967: return cid;
0968: }
0969:
0970: public long t_addContainer(T_TWC ctx, long segmentId, int pageSize,
0971: int spareSpace, int minimumRecordSize)
0972: throws StandardException, T_Fail {
0973: csFactory.setCurrentContextManager(ctx.cm);
0974: try {
0975: return t_addContainer(ctx.tran, segmentId, pageSize,
0976: spareSpace, minimumRecordSize, false);
0977: } finally {
0978: csFactory.resetCurrentContextManager(ctx.cm);
0979: }
0980: }
0981:
0982: /**
0983: Open a container.
0984:
0985: @exception T_Fail Unexpected behaviour from the API
0986: @exception StandardException Unexpected exception from the implementation
0987: */
0988:
0989: public ContainerHandle t_openContainer(Transaction t,
0990: long segmentId, long containerId, boolean forUpdate)
0991: throws StandardException, T_Fail {
0992: ContainerKey id = new ContainerKey(segmentId, containerId);
0993: ContainerHandle c = t
0994: .openContainer(
0995: id,
0996: forUpdate ? (ContainerHandle.MODE_FORUPDATE | openContainerMode)
0997: : ContainerHandle.MODE_READONLY);
0998: if (c == null)
0999: throw T_Fail
1000: .testFailMsg("ContainerHandle failed to open: ("
1001: + segmentId + "," + containerId + ")");
1002:
1003: return c;
1004: }
1005:
1006: public ContainerHandle t_openContainer(T_TWC ctx, long segmentId,
1007: long containerId, boolean forUpdate)
1008: throws StandardException, T_Fail {
1009: csFactory.setCurrentContextManager(ctx.cm);
1010: try {
1011: return t_openContainer(ctx.tran, segmentId, containerId,
1012: forUpdate);
1013: } finally {
1014: csFactory.resetCurrentContextManager(ctx.cm);
1015: }
1016: }
1017:
1018: /**
1019: Drop a container
1020:
1021: @exception T_Fail Unexpected behaviour from the API
1022: @exception StandardException Unexpected exception from the implementation
1023: */
1024: public void t_dropContainer(Transaction t, long segmentId,
1025: long containerId) throws StandardException, T_Fail {
1026: t.dropContainer(new ContainerKey(segmentId, containerId));
1027: }
1028:
1029: /**
1030: Get the last page in a container.
1031: Always returns a valid page or null if there is no page in the container.
1032:
1033: @exception T_Fail Unexpected behaviour from the API
1034: @exception StandardException Unexpected exception from the implementation
1035: */
1036: public Page t_getLastPage(ContainerHandle c) throws T_Fail,
1037: StandardException {
1038:
1039: Page page = c.getFirstPage();
1040: if (page != null) {
1041: Page nextPage;
1042: while ((nextPage = c.getNextPage(page.getPageNumber())) != null) {
1043: page.unlatch();
1044: page = nextPage;
1045: }
1046: }
1047:
1048: return page;
1049: }
1050:
1051: /**
1052: Get a specific page in a container.
1053: Always returns a valid page.
1054:
1055: @exception T_Fail Unexpected behaviour from the API
1056: @exception StandardException Unexpected exception from the implementation
1057: */
1058: public Page t_getPage(ContainerHandle c, long pageNumber)
1059: throws T_Fail, StandardException {
1060:
1061: Page page = c.getPage(pageNumber);
1062: if (page == null)
1063: throw T_Fail.testFailMsg("fail to get page " + pageNumber
1064: + " from container " + c);
1065:
1066: if (page.getPageNumber() != pageNumber)
1067: throw T_Fail
1068: .testFailMsg("page expected to have page number "
1069: + pageNumber + ", has "
1070: + page.getPageNumber() + " Container " + c);
1071:
1072: return page;
1073: }
1074:
1075: /**
1076: Add a page to a container.
1077:
1078: @exception T_Fail Unexpected behaviour from the API
1079: @exception StandardException Unexpected exception from the implementation
1080: */
1081: public Page t_addPage(ContainerHandle c) throws T_Fail,
1082: StandardException {
1083:
1084: Page page = c.addPage();
1085:
1086: if (page == null)
1087: throw T_Fail.testFailMsg("addPage() returned null");
1088:
1089: return page;
1090: }
1091:
1092: /**
1093: Remove a page from a container.
1094:
1095: @exception T_Fail Record handle returned is null.
1096: @exception StandardException Unexpected exception from the implementation
1097: */
1098: public void t_removePage(ContainerHandle c, Page p) throws T_Fail,
1099: StandardException {
1100: long pnum = p.getPageNumber();
1101: c.removePage(p);
1102:
1103: // we should not be able to get this page
1104: Page badp = c.getPage(pnum);
1105: if (badp != null)
1106: throw T_Fail.testFailMsg("got a deallcated page back");
1107: }
1108:
1109: /**
1110: Call page.insert() and ensure that the return record handle is not null.
1111: This assumes the caller has called spaceForInsert.
1112:
1113: @exception T_Fail Record handle returned is null.
1114: @exception StandardException Unexpected exception from the implementation
1115:
1116: @see Page#insert
1117: */
1118: public static RecordHandle t_insert(Page page, T_RawStoreRow row)
1119: throws T_Fail, StandardException {
1120:
1121: RecordHandle rh = page.insert(row.getRow(),
1122: (FormatableBitSet) null, Page.INSERT_DEFAULT, 100);
1123:
1124: return rh;
1125: }
1126:
1127: /**
1128: Call page.insert() and ensure that the return record handle is not null.
1129: This assumes the caller has called spaceForInsert.
1130:
1131: @exception T_Fail Record handle returned is null.
1132: @exception StandardException Unexpected exception from the implementation
1133:
1134: @see Page#insert
1135: */
1136: public static RecordHandle t_insertAtSlot(Page page, int slot,
1137: T_RawStoreRow row) throws T_Fail, StandardException {
1138:
1139: RecordHandle rh = page.insertAtSlot(slot, row.getRow(),
1140: (FormatableBitSet) null, (LogicalUndo) null,
1141: Page.INSERT_DEFAULT, 100);
1142:
1143: return rh;
1144: }
1145:
1146: /**
1147: Call page.insert() and ensure that the return record handle is not null.
1148: This assumes the caller has called spaceForInsert.
1149:
1150: @exception T_Fail Record handle returned is null.
1151: @exception StandardException Unexpected exception from the implementation
1152:
1153: @see Page#insert
1154: */
1155: public static RecordHandle t_insertAtSlot(Page page, int slot,
1156: T_RawStoreRow row, byte insertFlag) throws T_Fail,
1157: StandardException {
1158:
1159: RecordHandle rh = page.insertAtSlot(slot, row.getRow(),
1160: (FormatableBitSet) null, (LogicalUndo) null,
1161: insertFlag, 100);
1162:
1163: return rh;
1164: }
1165:
1166: /**
1167: Call page.insert() and ensure that the return record handle is not null.
1168: This assumes the caller has called spaceForInsert.
1169:
1170: @exception T_Fail Record handle returned is null.
1171: @exception StandardException Unexpected exception from the implementation
1172:
1173: @see Page#insert
1174: */
1175: public static RecordHandle t_insertAtSlot(Page page, int slot,
1176: T_RawStoreRow row, byte insertFlag, int overflowThreshold)
1177: throws T_Fail, StandardException {
1178:
1179: RecordHandle rh = page.insertAtSlot(slot, row.getRow(),
1180: (FormatableBitSet) null, (LogicalUndo) null,
1181: insertFlag, overflowThreshold);
1182:
1183: return rh;
1184: }
1185:
1186: /**
1187: Insert a record on the last page, if the row doesn't fit on the
1188: last page create a new page and insert there.
1189:
1190: @exception T_Fail Record handle returned is null.
1191: @exception StandardException Unexpected exception from the implementation
1192:
1193: @see Page#insert
1194: */
1195: public RecordHandle t_insert(ContainerHandle c, T_RawStoreRow row)
1196: throws T_Fail, StandardException {
1197:
1198: Page page = c.getPageForInsert(0);
1199: boolean addedPage = false;
1200:
1201: if (page == null) {
1202: page = t_addPage(c);
1203: addedPage = true;
1204: } else if (!page.spaceForInsert(row.getRow(),
1205: (FormatableBitSet) null, 100)) {
1206: page.unlatch();
1207: page = t_addPage(c);
1208: addedPage = true;
1209: }
1210:
1211: RecordHandle rh = t_insert(page, row);
1212: page.unlatch();
1213:
1214: if (rh == null) {
1215: if (addedPage)
1216: throw T_Fail
1217: .testFailMsg("insert returned null on an empty page");
1218:
1219: page = t_addPage(c);
1220: rh = t_insert(page, row);
1221: page.unlatch();
1222: }
1223: return rh;
1224: }
1225:
1226: /**
1227: Update a record.
1228:
1229: @exception T_Fail Record handle returned is null.
1230: @exception StandardException Unexpected exception from the implementation
1231:
1232: @see Page#update
1233: */
1234: public void t_update(ContainerHandle c, RecordHandle rh,
1235: T_RawStoreRow row) throws T_Fail, StandardException {
1236: Page page = t_getPage(c, rh.getPageNumber());
1237: try {
1238: if (!page.update(rh, row.getRow(), (FormatableBitSet) null))
1239: throw T_Fail.testFailMsg("update failed");
1240:
1241: t_checkFetch(page, rh, row);
1242: } finally {
1243: page.unlatch();
1244: }
1245: }
1246:
1247: /**
1248: Using sparse representation:
1249: Update a column of a record and check resulting value.
1250:
1251: @exception T_Fail Record handle returned is null.
1252: @exception StandardException Unexpected exception from the implementation
1253:
1254: @see Page#update
1255: */
1256: public void t_checkUpdateCol(Page page, RecordHandle rh,
1257: int colNum, int numCols, String data) throws T_Fail,
1258: StandardException {
1259: if (!page.recordExists(rh, false))
1260: throw T_Fail.testFailMsg("Record does not exist");
1261:
1262: T_RawStoreRow writeRow = new T_RawStoreRow(numCols);
1263: for (int i = 0; i < numCols; i++)
1264: writeRow.setColumn(i, (String) null);
1265: writeRow.setColumn(colNum, data);
1266: FormatableBitSet colList = new FormatableBitSet(numCols);
1267: colList.set(colNum);
1268:
1269: if (!page.update(rh, writeRow.getRow(), colList))
1270: throw T_Fail.testFailMsg("update failed");
1271:
1272: t_checkFetchCol(page, rh, colNum, numCols, data);
1273: }
1274:
1275: /**
1276: Delete a record.
1277:
1278: @exception T_Fail Record handle returned is null.
1279: @exception StandardException Unexpected exception from the implementation
1280:
1281: @see Page#delete
1282: */
1283: public void t_delete(ContainerHandle c, RecordHandle rh)
1284: throws T_Fail, StandardException {
1285:
1286: Page page = t_getPage(c, rh.getPageNumber());
1287:
1288: try {
1289: if (!page.recordExists(rh, false))
1290: throw T_Fail.testFailMsg("record does not exist");
1291:
1292: if (!page.delete(rh, (LogicalUndo) null))
1293: throw T_Fail.testFailMsg("delete failed");
1294:
1295: if (page.recordExists(rh, false))
1296: throw T_Fail
1297: .testFailMsg("recordExists() returns true after a delete");
1298: } finally {
1299: page.unlatch();
1300: }
1301: }
1302:
1303: /**
1304: Check to make sure a row (possibly with overflow) is of the correct length
1305:
1306: @exception T_Fail Record handle returned is null.
1307: @exception StandardException Unexpected exception from the implementation
1308:
1309: */
1310: public void t_checkStringLengthFetch(Page page, int slot,
1311: int expectedLength) throws T_Fail, StandardException {
1312:
1313: T_RawStoreRow rr = new T_RawStoreRow((String) null);
1314:
1315: page.fetchFromSlot((RecordHandle) null, slot, rr.getRow(),
1316: (FetchDescriptor) null, true);
1317:
1318: String s = ((SQLChar) (rr.getStorableColumn(0))).getString();
1319:
1320: if ((s == null) && (expectedLength < 0))
1321: return;
1322:
1323: if ((s != null) && (expectedLength < 0))
1324: throw T_Fail
1325: .testFailMsg("Expected null string, fetched one of length "
1326: + s.length());
1327:
1328: if (s == null)
1329: throw T_Fail.testFailMsg("Expected string length "
1330: + expectedLength + " got null string");
1331:
1332: if (s.length() != expectedLength)
1333: throw T_Fail
1334: .testFailMsg("fetch string length incorrect expected "
1335: + expectedLength + " got " + s.length());
1336: }
1337:
1338: /**
1339: Lazy people's random file generator:
1340: Generate a random file with specified name and file size
1341:
1342: @exception T_Fail Record handle returned is null.
1343: */
1344: public void t_genRandomFile(String fileName, String mode, int size)
1345: throws T_Fail {
1346:
1347: RandomAccessFile iFile = null;
1348: try {
1349: iFile = new RandomAccessFile(fileName, mode);
1350: for (int i = 0; i < size; i++) {
1351: byte b = (byte) (i & 0xff);
1352: b = (byte) (((b >= ' ') && (b <= '~')) ? b : ' ');
1353: iFile.write(b);
1354: }
1355: iFile.close();
1356: } catch (FileNotFoundException fnfe) {
1357: throw T_Fail.testFailMsg("cannot create new file");
1358: } catch (IOException ioe) {
1359: throw T_Fail.testFailMsg("io error, test failed");
1360: }
1361:
1362: }
1363:
1364: /**
1365: Return a string of stringLen characters that starts with data
1366: and is padded with nulls.
1367: */
1368: public static String getStringFromData(String data, int stringLen) {
1369: char[] ca = new char[stringLen];
1370:
1371: char[] sd = data.toCharArray();
1372:
1373: System.arraycopy(sd, 0, ca, 0, sd.length);
1374:
1375: return new String(ca);
1376: }
1377:
1378: /**
1379: Make this thread wait a bit, probably for post commit to finish
1380: */
1381: public static void t_wait(int milliSecond) {
1382: Thread.currentThread().yield();
1383: try {
1384: Thread.currentThread().sleep(milliSecond);
1385: } catch (InterruptedException ie) {
1386: }
1387: }
1388:
1389: /**
1390: Add in encryption parameters to the startParam if "testDataEncryption"
1391: is set to a non-null string.
1392: */
1393: public static Properties setEncryptionParam(Properties startParams) {
1394: // see if we are testing encryption
1395: String encryptionPassword = PropertyUtil
1396: .getSystemProperty("testDataEncryption");
1397: //look for alternate encryption provider
1398: String encryptionProvider = PropertyUtil
1399: .getSystemProperty("testEncryptionProvider");
1400: if (encryptionPassword != null) {
1401: if (startParams == null)
1402: startParams = new Properties();
1403:
1404: startParams.put(Attribute.DATA_ENCRYPTION, "true");
1405: startParams
1406: .put(Attribute.BOOT_PASSWORD, encryptionPassword);
1407: if (encryptionProvider != null) {
1408: startParams.put(Attribute.CRYPTO_PROVIDER,
1409: encryptionProvider);
1410: }
1411:
1412: // System.out.println("Setting encryption password to " + encryptionPassword);
1413:
1414: }
1415:
1416: return startParams;
1417: }
1418:
1419: }
|