|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
java.lang.Object | +--com.legacyj.isam.ISAMRecord
ISAMRecord
ISAMRecord represents a single ISAMRecord worth of data. It is used as the parameter for all ISAM methods requiring a record.
ISAMRecord has convenience methods to access fields within the record.
Field data from pre-existing sources may be in a variety of formats, so a variety of field get and set methods are provided; always check pre-existing data using get before ever writing data to the file.
ISAMRecord may be extended by custom user classes to encapsulate the fields by name.
For example:
import com.legacyj.isam.*;
public class EmployeeRecord extends ISAMRecord
{
private static final int NAME_OFFSET=0, NAME_LEN=20;
private static final int SSN_OFFSET=20, SSN_LEN=4;
private static final int PERCENT_OFFSET=24, PERCENT_LEN=8;
private static final int HIRE_DATA_OFFSET=32, HIRE_DATE_LEN=4;
public EmployeeRecord()
{
super();
}
public EmployeeRecord(String name)
{
super();
setName(name);
}
public void setName(String name) { setFieldString(NAME_OFFSET,NAME_LEN,name); }
public String getName() { return getFieldString(NAME_OFFSET,NAME_LEN); }
public void setSSN(int socialSecurityNumber) { setFieldBinary(SSN_OFFSET,SSN_LEN,socialSecurityNumber); }
public int getSSN() { return getFieldBinary(SSN_OFFSET,SSN_LEN); }
public void setPercent(double percent) { setFieldDouble(PERCENT_OFFSET,percent); }
public double getPercent() { return getFieldDouble(PERCENT_OFFSET); }
public void setHireDate(int hireData) { setFieldPD(HIRE_DATE_OFFSET,HIRE_DATE_LEN,hireData); }
public int getHireDate() { return getFieldPD(HIRE_DATE_OFFSET,HIRE_DATE_LEN); }
}
Sample Usage of Extended Class:
EmployeeRecord bob=new EmployeeRecord("Bob");
bob.setSSN(123456789); bob.setPercent(32.47): bob.setHireDate(12312000);
ISAM.iswrite(bob);
ISAMJ Copyright 2000-2001 LegacyJ Corp. All Rights Reserved.
| Constructor Summary |
ISAMRecord(byte[] data)
Construct an ISAMRecord using a given byte[] array. |
ISAMRecord(byte[] data,
int offset) Construct an ISAMRecord using a given byte[] array and offset. |
ISAMRecord(byte[] data,
int offset, int length) Construct an ISAMRecord using a given byte[] array, offset and length. |
ISAMRecord(int recordLength)
Construct an empty ISAMRecord of the given length. |
| Method Summary | |
byte[] |
getByteArray() Return the entire byte array representing the record. |
byte[] |
getData() Return a copy of the record's byte array form. |
byte[] |
getFieldData(int fieldOffset,
int length) Gets field within a record at fieldOffset for the given length. |
byte[] |
getFieldData(int fieldOffset,
int length, byte[] field) Gets field within a record at fieldOffset for the given length into pre-existing byte array. |
byte[] |
getFieldData(int fieldOffset,
int length, byte[] field, int offset) Gets field within a record at fieldOffset for the given length into pre-existing byte array. |
int |
getLength() Return the length of the ISAMRecord. |
int |
getOffset() Gets offset into byte array data of record. |
protected
java.lang.String |
leftTrim(java.lang.String value)
Trim spaces from the left of given String (null is OK) |
protected
java.lang.String |
rightTrim(java.lang.String value)
Trim spaces from the right of given String (null is OK) |
void |
setData(byte[] record)
Sets the ISAMRecord's byte array data to another byte array's contents (used by native code) |
void |
setData(byte[] record,
int offset, int length) Sets a segment of the ISAMRecord's byte array data to another byte array's contents |
void |
setFieldData(int fieldOffset,
byte[] fieldData) Sets field within record at fieldOffset to fieldData segment at offset for length. |
void |
setFieldData(int fieldOffset,
byte[] fieldData, int offset) Sets field within record at fieldOffset to fieldData segment at offset for length. |
void |
setFieldData(int fieldOffset,
byte[] fieldData, int offset, int length) Sets field within record at fieldOffset to fieldData segment at offset for length. |
protected
java.lang.String |
trim(java.lang.String value)
Trim spaces from the given String (null is OK) |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait,
wait, wait |
| Constructor Detail |
public ISAMRecord(byte[] data,
int offset,
int length)
data - The byte array of initial data.offset - The offset into the byte array of initial data.length - The length of the ISAMRecord within data.
public ISAMRecord(byte[] data,
int offset)
data - The byte array of initial data.offset - The offset into the byte array of initial data, the length if
data's length-offsetpublic ISAMRecord(byte[] data)
data - The byte array of initial data.public ISAMRecord(int recordLength)
recordLength - The maximum record length.| Method Detail |
public byte[] getByteArray()
public int getOffset()
public int getLength()
public byte[] getData()
public void setData(byte[] record)
record - the byte[] array containing data to which to set this record
public void setData(byte[] record,
int offset,
int length)
record - the byte[] array containing data to which to set this recordoffset - into the array containing the record datalength - of data starting at offsetprotected java.lang.String trim(java.lang.String value)
value - The String value from which to trim spacesprotected java.lang.String rightTrim(java.lang.String value)
value - The String value from which to trim right spacesprotected java.lang.String leftTrim(java.lang.String value)
value - The String value from which to trim left spaces
public void setFieldData(int fieldOffset,
byte[] fieldData,
int offset,
int length)
fieldOffset - offset in bytes into ISAMRecordfieldData - data with which to set the fieldoffset - offset within fieldDatalength - length of fieldData
public void setFieldData(int fieldOffset,
byte[] fieldData,
int offset)
fieldOffset - offset in bytes into ISAMRecordfieldData - data with which to set the fieldoffset - offset within fieldData, length is fieldData.length-offset
public void setFieldData(int fieldOffset,
byte[] fieldData)
fieldOffset - offset in bytes into ISAMRecordfieldData - data with which to set the field
public byte[] getFieldData(int fieldOffset,
int length)
fieldOffset - byte offset into ISAMRecordlength - the length of the field in bytes
public byte[] getFieldData(int fieldOffset,
int length,
byte[] field)
fieldOffset - byte offset into ISAMRecordlength - the length of the field in bytesfield - the destination byte array for the field's contents
public byte[] getFieldData(int fieldOffset,
int length,
byte[] field,
int offset)
fieldOffset - byte offset into ISAMRecordlength - the length of the field in bytesfield - the destination byte array for the field's contentsoffset - offset into the destination field to begin the field.
|
|||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||
©Copyright LegacyJ Corporation 2001