Package io.odysz.module.xtable
Class XMLTable
java.lang.Object
io.odysz.module.xtable.XMLTable
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
static interface
XMLTable.IParser<T extends XMLTable.IMapValue>
-
Field Summary
-
Constructor Summary
ConstructorDescriptionConstruct an empty table according to cols and pk. Table construction not finished without calling endTablePush().Constructing an empty table, table structure value copied from parameters.XMLTable
(String newTableID, HashMap<String, Integer> fromColumns, HashMap<String, Integer> fromPkCols, ArrayList<String[]> fromList) value copy and construct a new table, according to parameters.XMLTable
(HashMap<String, Integer> fromColumns, HashMap<String, Integer> fromPkCols, ArrayList<ArrayList<Object>> fromList) This can be used to clone from FLResultset.
Becareful, the cols and rows indexes in result set start at 1, but in XMLTable that start at 0!
All columns and rows idxes are -1. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
appendFieldValue
(int colIdx, String fieldValue) protected void
appendFieldValue
(String colName, String fieldValue) void
void
Clone a column index for id reference.
Sometimes the E2Engine will refere to a fixed name field to retrieve data, e.g.void
end()
protected void
endRecordPush
(boolean checkPK) Push the temp record into table rows.findRecords
(HashMap<String, String> kv) findRecordsTable
(HashMap<String, String> pkVals) getAttribute
(String attr, String defaultVal) boolean
float
float[]
int
getInt
(int col, int defaultVal) int
int
int
getIntAt
(int row, int col, int defaultVal) int
int[]
getPKs()
String[]
getRecordByPK
(String[] pkVals) Find record according to pk values.String[]
getRow()
String[]
getRowAt
(int position) int
int
getRows()
String[]
getString
(int col) getStringAt
(int row, String colName) String[]
getStrings
(String colName) boolean
goAt
(int position) void
insertRowAt
(int rowIdx, HashMap<String, String> row) void
last()
go last record - getXXX(c) got last row's field.<T extends XMLTable.IMapValue>
HashMap<String,T> map
(XMLTable.IParser<T> parser) void
Merge withTable to this object.
Table name and colomns order can be different, but both table must have exactly the same columns and pk fields.
Note:
This method is not suitable for large record's number.boolean
next()
boolean
previous()
void
void
void
setXmlAttrs
(Attributes attributes) protected void
void
-
Field Details
-
_tableID
-
columns
-
pkCols
-
rows
-
currentRec
-
duplicateIgnor
public static final int duplicateIgnorIf pk is duplicating, merging record is ignored.- See Also:
-
duplicateReplace
public static final int duplicateReplaceIf pk is duplicating, this obj's record is replaced with merging.- See Also:
-
-
Constructor Details
-
XMLTable
Construct an empty table according to cols and pk. Table construction not finished without calling endTablePush().- Parameters:
tableID
-cols
-pk
-- Throws:
Exception
SAXException
-
XMLTable
public XMLTable(String tableID, HashMap<String, Integer> fromColumns, HashMap<String, Integer> fromPkCols) Constructing an empty table, table structure value copied from parameters. Table construction not finished without calling endTablePush(). This is useful for reduced rows and cols table copying.- Parameters:
tableID
-fromColumns
-fromPkCols
-
-
XMLTable
public XMLTable(String newTableID, HashMap<String, Integer> fromColumns, HashMap<String, Integer> fromPkCols, ArrayList<String[]> fromList) value copy and construct a new table, according to parameters.- Parameters:
newTableID
-fromColumns
-fromPkCols
-fromList
-
-
XMLTable
public XMLTable(HashMap<String, Integer> fromColumns, HashMap<String, Integer> fromPkCols, ArrayList<ArrayList<Object>> fromList) This can be used to clone from FLResultset.
Becareful, the cols and rows indexes in result set start at 1, but in XMLTable that start at 0!
All columns and rows idxes are -1.- Parameters:
fromColumns
-fromPkCols
-fromList
-
-
-
Method Details
-
appendFieldValue
- Throws:
SAXParseException
-
appendFieldValue
- Throws:
SAXParseException
-
startRecordPush
- Throws:
SAXParseException
-
endRecordPush
Push the temp record into table rows. For data validation, checkPK shall be true. But it's a serious performance defect. Set checkPK to false when deploying a release version.- Parameters:
checkPK
-- Throws:
SAXParseException
-
getRecordByPK
Find record according to pk values. pkVals is exactly the same order specified in xmlfile/table pk attribute.
IMPORTANT: There are no index or any other performance facilities, be careful!- Parameters:
pkVals
-- Returns:
- target record
- Throws:
SAXParseException
-
startTablePush
public void startTablePush() -
endTablePush
-
beforeFirst
- Throws:
SAXException
-
last
go last record - getXXX(c) got last row's field.- Throws:
SAXException
-
next
- Throws:
SAXException
-
goAt
- Throws:
SAXException
-
end
- Throws:
SAXException
-
previous
- Throws:
SAXException
-
getRow
- Throws:
SAXException
-
getString
- Parameters:
col
- start from 0.- Returns:
- target field value
- Throws:
SAXException
-
getString
- Throws:
SAXException
-
getStringAt
- Throws:
SAXException
-
getTableID
-
getRowCount
public int getRowCount() -
getRowIdx
public int getRowIdx() -
findRecords
- Parameters:
kv
- - [key = colname, val = fieldVal]- Returns:
- record list
- Throws:
SAXException
-
findRecordsTable
- Parameters:
pkVals
- - [key = colname, val = fieldVal]- Returns:
- target table
- Throws:
SAXException
-
getRowAt
- Throws:
SAXException
-
getColumns
-
getPKs
-
cloneCol
Clone a column index for id reference.
Sometimes the E2Engine will refere to a fixed name field to retrieve data, e.g. "itemId".- Parameters:
newName
-oldName
-- Throws:
SAXException
-
getRows
-
getRows
- Throws:
SAXException
-
getInt
-
getInt
- Throws:
SAXException
-
getInt
public int getInt(int col, int defaultVal) -
getIntAt
-
getIntAt
public int getIntAt(int row, int col, int defaultVal) -
getBool
-
getStrings
- Throws:
SAXException
-
getFloat
-
getFloats
- Throws:
SAXException
-
getInts
- Throws:
SAXException
-
setXmlAttrs
-
getAttribute
-
setField
- Throws:
SAXException
-
mergeWith
Merge withTable to this object.
Table name and colomns order can be different, but both table must have exactly the same columns and pk fields.
Note:
This method is not suitable for large record's number. There is a performance problem, especially when both table has many duplicated records. xTable is not designed for DB functioning, it's designed for retrieve data such as App configurations.- Parameters:
withTable
-duplicateMode
- one ofduplicateIgnor
andduplicateReplace
- Throws:
SAXException
-
appendRow
- Throws:
SAXException
-
insertRowAt
- Throws:
SAXException
-
remove
- Throws:
SAXException
-
map
public <T extends XMLTable.IMapValue> HashMap<String,T> map(XMLTable.IParser<T> parser) throws Exception - Throws:
Exception
-