|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnl.knaw.dans.common.dbflib.Record
public class Record
Represents a record in a table. A record basically maps a String key to a value object
for a specified row in a table. The type of the value object depends on the field type. To find
out which DBF types map to which Java types, see Type.
Values that are too large to fit in their designated fields will cause a
ValueTooLargeException.
| Constructor Summary | |
|---|---|
Record(Map<String,Value> valueMap)
Creates a new Record object. |
|
| Method Summary | |
|---|---|
Boolean |
getBooleanValue(String fieldName)
Returns the specified value as a Boolean object. |
Date |
getDateValue(String fieldName)
Returns the specified value as a Date object. |
Number |
getNumberValue(String fieldName)
Returns the value of the specified field as a Number. |
byte[] |
getRawValue(Field field)
Returns the raw field value. |
String |
getStringValue(String fieldName)
Returns the specified value as a java.lang.String object. |
Object |
getTypedValue(String fieldName)
Returns the value as a Java object. |
boolean |
isMarkedDeleted()
Returns whether the record is marked deleted in the database. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public Record(Map<String,Value> valueMap)
aValueMap must specify the values for the fields in
the record. The concrete Value subclasses must be compatible with the
corresponding DBF field types, otherwise DataMismatchException is thrown when trying
to add the record.
The following is a table of the Value subclasses, the DBF field types and the
result of passing the one as a value for the other:
| CHARACTER | LOGICAL | NUMBER | FLOAT | DATE | MEMO | BINARY | GENERAL | |
| StringValue | Accepted if within maximum length | Accepted if one of "Y", "N", "T", "F" or a space, no leading/trailing spaces allowed | Accepted if a valid number, that fits in the field and has exactly the number of decimals as the field's decimal count | See NUMBER | Accepted if in the format YYYYMMDD. No leading or trailing spaces. No check is done whether the date is itself valid. | Accepted | Accepted | Accepted |
| BooleanValue | Accepted, Y or N written as first character of the field | Accepted, Y or N written | DME)* | DME | DME | Accepted | Accepted | Accepted |
| NumberValue | Accepted, if the number fits in the field | DME | Accepted, if the digits before the decimal point and the minus sign (if any) together do not occupy more space than reserved for them by the field. If there are too many digits after the decimal point they are rounded | See NUMBER | DME | Accepted | Accepted | Accepted |
| DateValue | Accepted, if the CHARACTER field is at least 10 long (the size of a DATE field in DBF). | DME | DME | DME | Accepted | Accepted, Date written as YYYYMMDD | Accepted, Date written as YYYYMMDD | Accepted, Date written as YYYYMMDD |
| ByteArrayValue | DME | DME | DME | DME | DME | Accepted, Date written as YYYYMMDD | Accepted, Date written as YYYYMMDD | Accepted, Date written as YYYYMMDD |
valueMap - the mapping from field name to field value| Method Detail |
|---|
public byte[] getRawValue(Field field)
throws DbfLibException
null or a series of ASCII spaces may be returned.
field - the field for which to get the raw value
DbfLibException - if the value was too large to be readpublic Object getTypedValue(String fieldName)
Type for the mapping between the two.
fieldName - the field for which to get the value
public Number getNumberValue(String fieldName)
Number. The exact subclass of
Number used depends on the size of the corresponding Field and its
decimalCount property. If decimalCount is zero an integral type is
returned, otherwise a fractional type. Depending on the size java.lang.Integer,
java.lang.Long or java.math.BigInteger is used as an integral type.
For non-integral types the classes used are either java.lang.Double or
java.math.BigDecimal.
It is not necessary to know the exact type used. You can use the conversion methods on the
java.lang.Number class to convert the value before using it. (E.g.,
Number.intValue().) Of course you do need to know whether the value will fit in
the chosen type. Note that comparisons may fail if you do not first convert the values. For
instance if you compare the a java.math.BigInteger with a long
using the equals method, false will be returned even if the values
represent the same logical value.
Example:
public Record searchSomeNum(final double val)
{
//
//... SOME CODE HERE THAT RETRIEVES table1 ...
//
// Get a record iterator to loop over all the records.
Iterator ri = table1.recordIterator();
// Search for the record with SOMENUM = val
while(ri.hasNext())
{
Record r = ri.next();
Number n = r.getNumberValue("SOMENUM");
// Convert n to a double before comparing it.
if(n.doubleValue() == val)
{
return r;
}
}
return null;
}
fieldName - the name of the field with numerical data
Number objectpublic String getStringValue(String fieldName)
java.lang.String object.
fieldName - the name of the field with character data
String objectpublic Boolean getBooleanValue(String fieldName)
Boolean object.
fieldName - the name of the field with logical data
Boolean objectpublic Date getDateValue(String fieldName)
Date object.
fieldName - the name of the field with date data
Date objectpublic boolean isMarkedDeleted()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||