com.legacyj.isam
Class ISAMRecord

java.lang.Object
  |
  +--com.legacyj.isam.ISAMRecord

public class ISAMRecord
extends java.lang.Object

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

ISAMRecord

public ISAMRecord(byte[] data,
                  int offset,
                  int length)
Construct an ISAMRecord using a given byte[] array, offset and length.
Parameters:
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.

ISAMRecord

public ISAMRecord(byte[] data,
                  int offset)
Construct an ISAMRecord using a given byte[] array and offset.
Parameters:
data - The byte array of initial data.
offset - The offset into the byte array of initial data, the length if data's length-offset

ISAMRecord

public ISAMRecord(byte[] data)
Construct an ISAMRecord using a given byte[] array.
Parameters:
data - The byte array of initial data.

ISAMRecord

public ISAMRecord(int recordLength)
Construct an empty ISAMRecord of the given length.
Parameters:
recordLength - The maximum record length.
Method Detail

getByteArray

public byte[] getByteArray()
Return the entire byte array representing the record.
Returns:
the ISAMRecord's byte array.

getOffset

public int getOffset()
Gets offset into byte array data of record.
Returns:
the offset into the ISAMRecord's byte array.

getLength

public int getLength()
Return the length of the ISAMRecord.
Returns:
the length of the ISAMRecord

getData

public byte[] getData()
Return a copy of the record's byte array form.
Returns:
a copy of the ISAMRecord's byte array data (used by native code)

setData

public void setData(byte[] record)
Sets the ISAMRecord's byte array data to another byte array's contents (used by native code)
Parameters:
record - the byte[] array containing data to which to set this record

setData

public void setData(byte[] record,
                    int offset,
                    int length)
Sets a segment of the ISAMRecord's byte array data to another byte array's contents
Parameters:
record - the byte[] array containing data to which to set this record
offset - into the array containing the record data
length - of data starting at offset

trim

protected java.lang.String trim(java.lang.String value)
Trim spaces from the given String (null is OK)
Parameters:
value - The String value from which to trim spaces
Returns:
the trimmed String, no spaces at left or right

rightTrim

protected java.lang.String rightTrim(java.lang.String value)
Trim spaces from the right of given String (null is OK)
Parameters:
value - The String value from which to trim right spaces
Returns:
the trimmed String, no spaces on right

leftTrim

protected java.lang.String leftTrim(java.lang.String value)
Trim spaces from the left of given String (null is OK)
Parameters:
value - The String value from which to trim left spaces
Returns:
the trimmed String, no spaces on left

setFieldData

public void setFieldData(int fieldOffset,
                         byte[] fieldData,
                         int offset,
                         int length)
Sets field within record at fieldOffset to fieldData segment at offset for length.
Parameters:
fieldOffset - offset in bytes into ISAMRecord
fieldData - data with which to set the field
offset - offset within fieldData
length - length of fieldData

setFieldData

public void setFieldData(int fieldOffset,
                         byte[] fieldData,
                         int offset)
Sets field within record at fieldOffset to fieldData segment at offset for length.
Parameters:
fieldOffset - offset in bytes into ISAMRecord
fieldData - data with which to set the field
offset - offset within fieldData, length is fieldData.length-offset

setFieldData

public void setFieldData(int fieldOffset,
                         byte[] fieldData)
Sets field within record at fieldOffset to fieldData segment at offset for length.
Parameters:
fieldOffset - offset in bytes into ISAMRecord
fieldData - data with which to set the field

getFieldData

public byte[] getFieldData(int fieldOffset,
                           int length)
Gets field within a record at fieldOffset for the given length.
Parameters:
fieldOffset - byte offset into ISAMRecord
length - the length of the field in bytes
Returns:
field of data

getFieldData

public byte[] getFieldData(int fieldOffset,
                           int length,
                           byte[] field)
Gets field within a record at fieldOffset for the given length into pre-existing byte array.
Parameters:
fieldOffset - byte offset into ISAMRecord
length - the length of the field in bytes
field - the destination byte array for the field's contents
Returns:
field for convenience

getFieldData

public 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.
Parameters:
fieldOffset - byte offset into ISAMRecord
length - the length of the field in bytes
field - the destination byte array for the field's contents
offset - offset into the destination field to begin the field.
Returns:
field for convenience


©Copyright LegacyJ Corporation 2001