public class AnResultset
extends io.odysz.anson.Anson
ResultSet
.Modifier and Type | Class and Description |
---|---|
static interface |
AnResultset.ObjCreator<T>
Object creator for converting an entity record to a user type instance.
|
Constructor and Description |
---|
AnResultset()
for deserializing
|
AnResultset(AnResultset icrs) |
AnResultset(ArrayList<String> colNames) |
AnResultset(HashMap<String,Integer> colnames,
ArrayList<ArrayList<Object>>... rows)
Construct an empty set, used for appending rows.
|
AnResultset(HashMap<String,Object[]> columns) |
AnResultset(HashMap<String,Object[]> colnames,
boolean toUpperCase)
Construct an empty set, used for appending rows.
|
AnResultset(int rows,
int cols) |
AnResultset(int rows,
int cols,
String colPrefix)
For debug, generate a fake rs.
|
AnResultset(int rows,
String[] colNames,
boolean generateData) |
AnResultset(ResultSet rs) |
AnResultset(ResultSet rs,
Connection connection,
Statement statement) |
AnResultset(String[] colNames) |
Modifier and Type | Method and Description |
---|---|
int |
append(AnResultset more) |
AnResultset |
append(ArrayList<Object> includingRow) |
AnResultset |
appendDeeply(ArrayList<Object> row)
Append a new row - deep copy, set current row as the appended row.
|
AnResultset |
before(int idx)
idx start from 1.
|
AnResultset |
beforeFirst() |
void |
close() |
static String |
collectFields(AnResultset rs,
String... fields)
Collect fields value that can be used in "IN" condition, e.g.
|
HashMap<String,Object[]> |
colnames() |
int |
currentRow()
current row index, start from 1.
|
int |
findFirst(String col,
String regex)
Find the first row that contain a matched value in field col.
|
void |
first() |
<T extends io.odysz.transact.sql.parts.AnDbField> |
getAnson(int colIndex) |
<T extends io.odysz.transact.sql.parts.AnDbField> |
getAnson(String col) |
Blob |
getBlob(int colIndex) |
Blob |
getBlob(String colName) |
boolean |
getBoolean(int colIndex)
if value is equals case insensitive to 1,true, yes, y, t, decimal > 0.001 return true, else return false;
|
boolean |
getBoolean(String colName) |
int |
getColCount() |
HashMap<String,Object[]> |
getColnames() |
int |
getColumex(String colName)
Get col index
|
int |
getColumnCount() |
String |
getColumnName(int i)
Get col name in raw case.
|
Date |
getDate(int index) |
Date |
getDate(String colName) |
Date |
getDateTime(int index) |
Date |
getDateTime(String colName) |
double |
getDouble(int colIndex) |
double |
getDouble(String colName) |
String[] |
getFlatColumns0()
Get the cached flat column names in the same sequence with rows.
|
int |
getInt(int colIndex) |
int |
getInt(String colName) |
int |
getInt(String col,
int deflt) |
long |
getLong(int colIndex) |
long |
getLong(String colName) |
long |
getLong(String size,
long empty) |
long |
getLongAt(String colName,
int row) |
long |
getLongAtRow(int col,
int row0) |
Object |
getObject(int colIndex) |
Object |
getObject(String colName) |
int |
getRow()
Get current row index.
Row index start from 1. The last row indix == getRowCount() |
ArrayList<Object> |
getRowAt()
Get current row
|
ArrayList<Object> |
getRowAt(int idx0) |
ArrayList<Object> |
getRowById(String id) |
ArrayList<Object> |
getRowCells() |
int |
getRowCount() |
ArrayList<ArrayList<Object>> |
getRows() |
ArrayList<?> |
getRowsInt()
Try in-place convert all values to integer elements
- expensive, especially with many non-integers.
|
String[] |
getStrArray(String udpcols) |
String |
getString(int colIndex) |
String |
getString(int colIndex,
SimpleDateFormat sdf)
If field is a date value, return string formatted by sdf.
|
String |
getString(int rowix,
String field) |
String |
getString(String colName) |
String |
getString(String colName,
SimpleDateFormat sdf)
If field is a date value, return string formatted by sdf.
|
String |
getString(String colName,
String deflt)
Get string.
|
String |
getStringAtRow(int col,
int row) |
String |
getStringAtRow(String colName,
int row)
Get row's field value
|
String |
getStringByIndex(String colName,
String entityId) |
String |
getStringNonull(String colName)
if null, change to ""
|
boolean |
hasCol(String c) |
boolean |
hasnext()
Are there rows following current row index?
|
boolean |
hasprev()
Are there rows before current row index?
|
void |
ICRconstructor(ResultSet rs) |
AnResultset |
index0(String pk)
Generate row indices, start at 0.
|
HashMap<String,Integer> |
indices0() |
<T> HashMap<String,T> |
map(String[] keyFields,
AnResultset.ObjCreator<T> objCreator) |
<T> HashMap<String,T> |
map(String keyField,
AnResultset.ObjCreator<T> objCreator)
Iterating through the results and convert to hash map, like this:
|
boolean |
next() |
String |
nextString(String col)
Get next row's string value.
|
boolean |
nextUntill(int last)
last start at 1, included in nexting range.
If current index = 4, nextUntill(5) return true; If current index = 5, nextUntill(5) return false; |
AnResultset |
nxt()
A mutation of
next() . |
boolean |
previous() |
String |
prevString(String col)
Get previous row's string value.
|
AnResultset |
print(PrintStream out) |
AnResultset |
print(String... cols)
Print all data with in cols.
|
int |
printSomeData(boolean err,
int max,
String... includeCols)
Print ResutSet in System.out or System.err.
|
int |
printSomeData(PrintStream out,
int max,
String... includeCols) |
AnResultset |
results(ArrayList<ArrayList<Object>> rows) |
int |
rowIndex0(String k)
Get row index, starting at 0.
|
AnResultset |
set(int colIndex,
String v)
Set value to current row
|
HashSet<String> |
set(String f)
Construct a hash set using all value of field f.
|
AnResultset |
set(String colName,
String v)
Set value to current row
|
void |
setColumnName(int i,
String n)
Set column raw name.
|
int |
size() |
AnResultset |
stringFormat(Class<?> clz,
String format)
Add a formatter to type of clz when converting to String.
|
List<String> |
toArr(String col)
Convert results to an 1D array with elements from col
|
int |
total() |
AnResultset |
total(int total) |
boolean |
validx()
Is current row index valid?
|
appendArr, appendObjStr, appendPair, escape, fromBlock, fromJson, fromJson, toBlock, toEnvelope, toJson, toJson, toMapBlock, toString, unescape
public AnResultset()
public AnResultset(ResultSet rs) throws SQLException
SQLException
public AnResultset(ResultSet rs, Connection connection, Statement statement) throws SQLException
SQLException
public AnResultset(AnResultset icrs) throws SQLException
SQLException
@SafeVarargs public AnResultset(HashMap<String,Integer> colnames, ArrayList<ArrayList<Object>>... rows)
colnames
- rows
- public AnResultset(HashMap<String,Object[]> colnames, boolean toUpperCase)
colnames
- public AnResultset(int rows, int cols, String colPrefix)
rows
- cols
- public AnResultset(int rows, String[] colNames, boolean generateData)
public AnResultset(String[] colNames)
public int currentRow()
getRowAt(int)
, must - 1.public int rowIndex0(String k)
k
- public void ICRconstructor(ResultSet rs) throws SQLException
SQLException
public AnResultset appendDeeply(ArrayList<Object> row)
row
- public AnResultset append(ArrayList<Object> includingRow)
public AnResultset results(ArrayList<ArrayList<Object>> rows)
public boolean hasCol(String c)
public boolean next() throws SQLException
SQLException
public boolean nextUntill(int last) throws SQLException
last
- SQLException
public int append(AnResultset more) throws SQLException
SQLException
public AnResultset stringFormat(Class<?> clz, String format)
clz
- format
- public String getString(int colIndex) throws SQLException
SQLException
public String getString(String colName) throws SQLException
SQLException
public String getString(String colName, SimpleDateFormat sdf) throws SQLException
colName
- sdf
- SQLException
public String getString(int colIndex, SimpleDateFormat sdf) throws SQLException
colIndex
- sdf
- SQLException
public String getStringNonull(String colName) throws SQLException
colName
- SQLException
public String getString(String colName, String deflt) throws SQLException
deflt
.colName
- deflt
- deflt
SQLException
public String getStringAtRow(String colName, int row) throws NumberFormatException, SQLException
colName
- field namerow
- row index, start at 1. (If get from rowIndex0(String)
, add 1.)NumberFormatException
SQLException
public String getStringAtRow(int col, int row) throws NumberFormatException, SQLException
NumberFormatException
SQLException
public String getStringByIndex(String colName, String entityId) throws SQLException
SQLException
public boolean getBoolean(int colIndex) throws SQLException
colIndex
- SQLException
public boolean getBoolean(String colName) throws SQLException
SQLException
public double getDouble(int colIndex) throws SQLException
SQLException
public double getDouble(String colName) throws SQLException
SQLException
public Date getDate(int index) throws SQLException
SQLException
public Date getDate(String colName) throws SQLException
SQLException
public Date getDateTime(int index) throws SQLException
index
- SQLException
public Date getDateTime(String colName) throws SQLException
SQLException
public int getInt(int colIndex) throws SQLException
SQLException
public int getInt(String col, int deflt)
public long getLong(int colIndex) throws SQLException
SQLException
public long getLong(String size, long empty)
public long getLong(String colName) throws SQLException
SQLException
public long getLongAt(String colName, int row) throws NumberFormatException, SQLException
colName
- row0
- index start at 0NumberFormatException
SQLException
public long getLongAtRow(int col, int row0) throws NumberFormatException, SQLException
col
- column index start at 0row0
- index start at 0NumberFormatException
SQLException
public int getInt(String colName) throws SQLException
SQLException
public Blob getBlob(int colIndex) throws SQLException
SQLException
public Blob getBlob(String colName) throws SQLException
SQLException
public Object getObject(String colName) throws SQLException
SQLException
public Object getObject(int colIndex) throws SQLException
SQLException
public <T extends io.odysz.transact.sql.parts.AnDbField> T getAnson(int colIndex) throws io.odysz.anson.x.AnsonException, SQLException
T
- colIndex
- io.odysz.anson.x.AnsonException
SQLException
public <T extends io.odysz.transact.sql.parts.AnDbField> T getAnson(String col) throws io.odysz.anson.x.AnsonException, SQLException
col
- io.odysz.anson.x.AnsonException
SQLException
public int getRow()
public int getColumnCount()
public void first() throws SQLException
SQLException
public AnResultset beforeFirst() throws SQLException
SQLException
public AnResultset before(int idx) throws SQLException
idx
- SQLException
public void close() throws SQLException
SQLException
public boolean previous() throws SQLException
SQLException
public String getColumnName(int i)
i
- start at 1public int getColumex(String colName)
colName
- public void setColumnName(int i, String n)
i
- indexn
- namepublic int getRowCount()
public int size()
public int getColCount()
public ArrayList<Object> getRowAt(int idx0) throws SQLException
idx0
- start at 0SQLException
public AnResultset set(int colIndex, String v) throws SQLException
colIndex
- v
- SQLException
public AnResultset set(String colName, String v) throws SQLException
colName
- v
- SQLException
public int findFirst(String col, String regex) throws SQLException
regex
.col
- regex
- SQLException
public int printSomeData(boolean err, int max, String... includeCols)
err
- weather output in "out" or "err"max
- max rows to printincludeCols
- include column of names.public int printSomeData(PrintStream out, int max, String... includeCols)
public AnResultset print(String... cols)
cols
- public AnResultset print(PrintStream out)
public static String collectFields(AnResultset rs, String... fields) throws SQLException
rs
- fields
- SQLException
public String getString(int rowix, String field) throws SQLException
SQLException
public int total()
public AnResultset total(int total)
public ArrayList<?> getRowsInt()
public String[] getStrArray(String udpcols) throws SQLException
SQLException
public List<String> toArr(String col) throws SQLException
col
- column nameSQLException
public <T> HashMap<String,T> map(String keyField, AnResultset.ObjCreator<T> objCreator) throws SQLException
HashMap <String, SynState> res = st .select(met.tbl, "l") .rs(st.instancontxt(conn, usr)) .rs(0) .<UserType>map((currow) -> { // create instance according current row return new UserType(currow.getString("id")); });TODO: This is a temporary way. Which will be moved to
select()
.keyField
- value of the field name used for map's keyobjCreator
- object creator (mapper)SQLException
public <T> HashMap<String,T> map(String[] keyFields, AnResultset.ObjCreator<T> objCreator) throws SQLException
SQLException
public HashSet<String> set(String f) throws SQLException
f
- SQLException
public AnResultset nxt() throws SQLException
next()
. If has a next row, move index and
return this, otherwise null.
For convenience if only needs to check the first row.
E.g. to check the updating records' existence:return ((AnResultset) transbuilder .select(targetable) .col(Funcall.count(pk), "c") .where(updt.where()) .rs(syb.instancontxt(stx.connId(), usr)) .rs(0)) .nxt() .getInt("c") > 0;
SQLException
public boolean hasnext()
public boolean hasprev()
public AnResultset index0(String pk)
pk
- public String nextString(String col) throws SQLException
hasnext()
before calling this.col
- SQLException
public String prevString(String col) throws SQLException
hasprev()
before calling this.col
- SQLException
public boolean validx()
public ArrayList<Object> getRowAt() throws SQLException
SQLException
public String[] getFlatColumns0()
public ArrayList<Object> getRowById(String id) throws SQLException
SQLException
Copyright © 2024. All rights reserved.