Package overit.geocall.sql
Class DBView
java.lang.Object
overit.geocall.sql.DBView
- All Implemented Interfaces:
Serializable,JsonSerializable,DBFieldMapper,DBObjectMapper
- Direct Known Subclasses:
DBViewWithLikeFilterOnString,IndexedDBView
public class DBView
extends Object
implements DBObjectMapper, DBFieldMapper, Serializable, JsonSerializable
The class implements the DBView, the logical view of a portion of a database table usually obtained as a result of a query and maintained
in memory, and all the methods to manage its content. A DBView object can be also created starting from a
The DBView is the logical element whose values can be displayed using the two graphic interface components TableView and ServerTableView
DBFields object or a list of
strings used as columns name. The DBView is the logical element whose values can be displayed using the two graphic interface components TableView and ServerTableView
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DBFieldMapGeneric map object between the fields of a table in memory and a server database table, and vice versaprotected DBObjectMapGeneral map between Java objects in memory and SQL objects and vice versaprotected intstatic final StringControl field that defines that the record of the DBView is a deleted onestatic final intDefines the numbers of the control fieldsstatic final StringControl field that defines that the record of the DBView is an inserted onestatic final intDefines the operation mode of theDBRowComparator.static final intDefines the operation mode of theDBRowComparator.static final intDefines the operation mode of theDBRowComparator.protected booleanstatic final intDefines the position of theDELETEDcontrol fieldstatic final intDefines the position of theINSERTEDcontrol fieldstatic final intDefines the position of theUPDATEDcontrol fieldprotected booleanprotected booleanstatic final StringControl field that defines that the record of the DBView is an updated one -
Constructor Summary
ConstructorsConstructorDescriptionDBView()Creates an editable DBViewDBView(boolean noUndo) Deprecated.Creates a DBView, starting from a string array that contains the columns namesDBView(Collection<String> cols) Creates a DBView, starting from a string set that contains the columns namesDeprecated.Legacy mode.Creates a DBView, starting from theDBFieldsobject, which the readonly state that depends on the value passed as parameter -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a column to the DBViewvoidAdds new elements to the filter on the DBViewvoidAppend the ResultSet to the DBViewvoidAppend a row as the last row of the DBViewvoidAppend a DBView to the current onevoidAppend a row as the first row of the DBViewvoidMakes the changes (insertions, updates and deletions) effectiveprotected voidprotected voidprotected voidcalcRows()intcols()Returns the number of the columns of the DBViewvoidResets the user imposed filtersvoiddelete(int row) Removes a row from the DBViewprotected voidfinal voidempty()Empties the DBView, resetting the rows, setting to 0 the shift (seesetShift(int)) and applying thedefaultFilter()intSearch a specific value for a field of the DBViewReturns the object that corresponds to a field in a specific rowgetAttribute(String key) Returns the attribute of the DBView defined by the key passed as parameterReturns theDBFieldMapReturns a copy of theDBFieldsof the DBViewgetDBFields(boolean dropMetadata) Returns a copy of theDBFieldsof the DBView in which the control fields can be removed or notReturns theDBObjectMapcontained in the instanceDeprecated.UsegetDBFields()intgetFieldPos(String field) Returns the position of the field referring to theDBFieldsof the DBViewReturns the map used as filter for the current DBViewgetLongSet(String column) Creates aLongSetpopulating it with the values of a column of the DBViewgetOrder()Returns theDBRowComparatorused to compare the rows of the DBViewgetOriginalMap(int row) Returns TheHashGetterthat contains the original map of values of the desired rowgetOriginalRowList(int row) Returns The ArrayList that contains the original values of the desired rowgetRowList(int row) Returns The ArrayList that contains the values of the desired rowgetRowMap(int row) Returns theHashGetterthat defines the desired rowprotected HashGetterprotected static HashGetterintgetShift()Returns the shift value set to the DBViewbooleanhasMore()Return a boolean value indicating if there's more records to load from the DB.booleanChecks the presence of a correctDBFieldMapbooleanChecks the presence of a validDBObjectMapcontained in the instance.voidInsert a row into a specific position of the DBViewvoidInsert a row as the last row of the DBViewbooleanisNoUndo()queries the no-undo statebooleanisRoData()queries the read-only statebooleanisRoView()queries the read-only stateprotected booleanmatchesFilter(ArrayList row) static booleanmatchesFilter(DBFields fields, Map filter, ArrayList row) Returnstrueif matches the filter,falseotherwisestatic DBFieldsvoidOrders randomly the rows of the DBViewPuts an object to a field in a specific rowvoidputAttribute(String key, Object o) Puts an attribute in the attribute's map of the DBViewvoidremoveAttribute(String key) Removes from the map of the attributes of the DBView the one defined by the key passed as parametervoidremoveColumn(String name) Removes a column from the DBViewvoidRemoves the map used as for the DBViewprotected voidremoveMapTags(Map m) voidRemoves theDBRowComparatorobject used to compare the rows of the DBViewvoidrenameColumn(String from, String to) static StringresultingOperation(HashGetter hCurrRow) Returns the string that defines the status of the operations for the specificHashGetterthat defines a row of the DBViewintrows()Returns the number of the rows of the DBViewintSearch a specific object for a field of the DBViewvoidSets an object to a field in a specific rowvoidsetDBFieldMap(DBFieldMap fieldMap) Sets theDBFieldMapvoidsetDBObjectMap(DBObjectMap objectMap) Sets theDBObjectMapcontained in the instancevoidSets a filter on the DBViewSets this DBView to not track the changes (updates), so that the undoChanges will throw anIllegalStateException.voidsetOrder(DBRowComparator comparator, int keepMode) Sets theDBRowComparatorobject, and use it to order the rows of the DBViewSets this DBView to not be modified in content data.Sets this DBView to not be modified in view features like sorting or filtering.voidsetShift(int missingHeadRows) Sets the shift for the DBView, i.e. the number of rows starting from head that must be not consideredtoString()Returns the string representation of the DBViewvoidUndoes the changes (insertions, updates and deletions).voidUpdates a row of the DBView
-
Field Details
-
INSERTED
Control field that defines that the record of the DBView is an inserted one- See Also:
-
UPDATED
Control field that defines that the record of the DBView is an updated one- See Also:
-
DELETED
Control field that defines that the record of the DBView is a deleted one- See Also:
-
POS_INSERTED
public static final int POS_INSERTEDDefines the position of theINSERTEDcontrol field- See Also:
-
POS_UPDATED
public static final int POS_UPDATEDDefines the position of theUPDATEDcontrol field- See Also:
-
POS_DELETED
public static final int POS_DELETEDDefines the position of theDELETEDcontrol field- See Also:
-
FIRST_POS
public static final int FIRST_POSDefines the numbers of the control fields- See Also:
-
KEEP_ALL
public static final int KEEP_ALLDefines the operation mode of theDBRowComparator. Used to keep all the equal rows.- See Also:
-
KEEP_FIRST
public static final int KEEP_FIRSTDefines the operation mode of theDBRowComparator. Used to keep the first of two equal rows.- See Also:
-
KEEP_LAST
public static final int KEEP_LASTDefines the operation mode of theDBRowComparator. Used to keep the last of two equal rows.- See Also:
-
_shift
protected int _shift -
noUndo
protected boolean noUndo -
roData
protected boolean roData -
roView
protected boolean roView -
_fieldmap
Generic map object between the fields of a table in memory and a server database table, and vice versa -
_objectmap
General map between Java objects in memory and SQL objects and vice versa
-
-
Constructor Details
-
DBView
public DBView()Creates an editable DBView -
DBView
Deprecated.UseDBView- Parameters:
noUndo- Boolean value indicating if the DBView should track the changes (updates), so that the undoChanges will throw anIllegalStateException.
-
DBView
Deprecated.Legacy mode. Please useDBView(DBFields). For example if you want to clone aDBViewdbvjust writenew DBView(dbv.getDBFields());Build a new DBView with the columns as the keys of the passed Map.- Parameters:
m- The Map
-
DBView
Creates a DBView, starting from theDBFieldsobject, which the readonly state that depends on the value passed as parameter- Parameters:
dbf- The DBFields (ordered collection of fields) object used to create the DBView
-
DBView
Creates a DBView, starting from a string array that contains the columns names- Parameters:
cols- A variable number of strings to be used as columns names
-
DBView
Creates a DBView, starting from a string set that contains the columns names- Parameters:
cols- A variable number of strings to be used as columns names
-
-
Method Details
-
newBaseFields
- Returns:
- A static instance of DBFields
-
setNoUndo
Sets this DBView to not track the changes (updates), so that the undoChanges will throw anIllegalStateException. The state is not reversible- Returns:
- this DBView
-
isNoUndo
public boolean isNoUndo()queries the no-undo state- Returns:
- the no-undo state
-
isRoData
public boolean isRoData()queries the read-only state- Returns:
- the read-only state
-
setRoData
Sets this DBView to not be modified in content data. Operations like sorting or filtering are still possible. Every attempt to change the content of a DBView will throw anIllegalStateExceptionThe state is not reversible- Returns:
- this DBView
-
isRoView
public boolean isRoView()queries the read-only state- Returns:
- the read-only state
-
setRoView
Sets this DBView to not be modified in view features like sorting or filtering. Data content will still be modifiable. Every attempt to change the DBView view (filtering or sorting) will throw anIllegalStateExceptionThe state is not reversible- Returns:
- this DBView
-
setShift
public void setShift(int missingHeadRows) Sets the shift for the DBView, i.e. the number of rows starting from head that must be not considered- Parameters:
missingHeadRows- The shift value
-
getShift
public int getShift()Returns the shift value set to the DBView- Returns:
- The shift value
-
hasMore
public boolean hasMore()Return a boolean value indicating if there's more records to load from the DB.- Returns:
trueif there's more record to load,falseif all records has been loaded
-
addColumn
Adds a column to the DBView- Parameters:
name- The name of the column to be added to the DBView. If there is already a column with the same name in the DBView, anRuntimeExceptionwill be raised
-
removeColumn
Removes a column from the DBView- Parameters:
name- The name of the column to be removed from the DBView. If there isn't a column with this name in the DBView, anRuntimeExceptionwill be raised
-
renameColumn
-
putAttribute
Puts an attribute in the attribute's map of the DBView- Parameters:
key- The key of the attribute, that will be used to retrieve the entry from the mapo- The value of the attribute
-
removeAttribute
Removes from the map of the attributes of the DBView the one defined by the key passed as parameter- Parameters:
key- The key of the attribute to remove
-
getAttribute
Returns the attribute of the DBView defined by the key passed as parameter- Parameters:
key- The key of the desired attribute- Returns:
- The value of the attribute that corresponds to the key, or null if in the attribute's map there isn't an entry with the desired key
-
getAttributeNames
-
matchesFilter
-
matchesFilter
Returnstrueif matches the filter,falseotherwise- Parameters:
fields- The fields of the DBFieldsfilter- The map containing the filtersrow- The number that identifies the position of the row- Returns:
trueif matches the filter,falseotherwise
-
calcRows
protected void calcRows() -
applyFilterNotOrding
protected void applyFilterNotOrding() -
applyFilterOrding
protected void applyFilterOrding() -
orderRandom
public void orderRandom()Orders randomly the rows of the DBView -
setOrder
Sets theDBRowComparatorobject, and use it to order the rows of the DBView- Parameters:
comparator- TheDBRowComparatorobject used to compare the rowskeepMode- One ofKEEP_ALL,KEEP_FIRST,KEEP_LAST
-
getOrder
Returns theDBRowComparatorused to compare the rows of the DBView- Returns:
- The
DBRowComparatorused to compare the rows
-
setFilter
Sets a filter on the DBView- Parameters:
m- The map used as filter
-
getFilter
Returns the map used as filter for the current DBView- Returns:
- The map used as filter
-
addFilter
Adds new elements to the filter on the DBView- Parameters:
m- The map that must be added to the existent filter (if no filter exists, the map itself is used as new filter)
-
defaultFilter
public void defaultFilter()Resets the user imposed filters -
removeFilter
public void removeFilter()Removes the map used as for the DBView -
removeOrder
public void removeOrder()Removes theDBRowComparatorobject used to compare the rows of the DBView -
append
Append the ResultSet to the DBView- Parameters:
rs- The ResultSet to append- Throws:
SQLException- If a database access error occurs, or this method is called on a closed result set, anSQLExceptionis raised
-
cols
public int cols()Returns the number of the columns of the DBView- Returns:
- The number of the columns
-
rows
public int rows()Returns the number of the rows of the DBView- Returns:
- The number of the rows, calculated considering also the shift (see
setShift(int))
-
empty
public final void empty()Empties the DBView, resetting the rows, setting to 0 the shift (seesetShift(int)) and applying thedefaultFilter() -
getRowList
Returns The ArrayList that contains the values of the desired row- Parameters:
row- The number that identifies the position of the row- Returns:
- The ArrayList of values of the row
-
getOriginalRowList
Returns The ArrayList that contains the original values of the desired row- Parameters:
row- The number that identifies the position of the row- Returns:
- The ArrayList original values of the row
-
getRowMap
Returns theHashGetterthat defines the desired row- Parameters:
row- The number that identifies the position of the row- Returns:
- The map with the association "name of the column" -> "value" that defines the desired row
-
getFieldMap
Deprecated.UsegetDBFields()- Returns:
- Returns the
HashGetterwith the associations key -> position
-
getDBFields
Returns a copy of theDBFieldsof the DBView- Returns:
- A copy of the DBFields structure of the DBView
-
getDBFields
Returns a copy of theDBFieldsof the DBView in which the control fields can be removed or not- Parameters:
dropMetadata- true to remove the control fields (__i,__u,__d) and update the positions, false otherwise- Returns:
- A copy of the DBFields structure of the DBView
-
get
Returns the object that corresponds to a field in a specific row- Parameters:
row- The number that identifies the position of the row in the DBViewfield- The name of the field- Returns:
- The object that corresponds to the field in the row
-
set
Sets an object to a field in a specific row- Parameters:
row- The number that identifies the position of the row in the DBViewfield- The name of the fieldo- The object to set
-
put
Puts an object to a field in a specific row- Parameters:
row- The number that identifies the position of the row in the DBViewfield- The name of the fieldvalue- The object to set- Returns:
- The object previously at the specified position
-
getFieldPos
Returns the position of the field referring to theDBFieldsof the DBView- Parameters:
field- The name of the field- Returns:
- The position of the field, or -1 if the field does not exist
-
getOriginalMap
Returns TheHashGetterthat contains the original map of values of the desired row- Parameters:
row- The number that identifies the position of the row- Returns:
- The map that contains the original values of the row
-
getRowMap
-
getRowMap
-
delete
public void delete(int row) Removes a row from the DBView- Parameters:
row- The number that identifies the position of the row to be removed from the DBView
-
insert
Insert a row as the last row of the DBView- Parameters:
m- The map that defines the row that must be inserted
-
insert
Insert a row into a specific position of the DBView- Parameters:
pos- The position in which we want to insert the row (null to insert as the last row)m- The map that defines the row that must be inserted
-
append
Append a row as the last row of the DBView- Parameters:
l- The ArrayList that defines the row to append
-
append0
Append a row as the first row of the DBView- Parameters:
l- The ArrayList that defines the row to append
-
append
Append a DBView to the current one- Parameters:
dbv- The DBView to append
-
removeMapTags
-
doInsert
-
update
Updates a row of the DBView- Parameters:
pos- The position of the row to updatem- The map that contains the new values for the row
-
applyChanges
public void applyChanges()Makes the changes (insertions, updates and deletions) effective -
undoChanges
public void undoChanges()Undoes the changes (insertions, updates and deletions). If the DBView is in readonly state, the changes cannot be canceled, and anRuntimeExceptionis raised -
getDBFieldMap
Returns theDBFieldMap- Specified by:
getDBFieldMapin interfaceDBFieldMapper- Returns:
- The map of objects used in this instance
-
setDBFieldMap
Sets theDBFieldMap- Specified by:
setDBFieldMapin interfaceDBFieldMapper- Parameters:
fieldMap- The map of objects used in this instance
-
haveDBFieldMap
public boolean haveDBFieldMap()Checks the presence of a correctDBFieldMap- Specified by:
haveDBFieldMapin interfaceDBFieldMapper- Returns:
- true if the instance contains a correct map of object (that is not null), false otherwise
-
getDBObjectMap
Returns theDBObjectMapcontained in the instance- Specified by:
getDBObjectMapin interfaceDBObjectMapper- Returns:
- The map of objects used in this instance
-
setDBObjectMap
Sets theDBObjectMapcontained in the instance- Specified by:
setDBObjectMapin interfaceDBObjectMapper- Parameters:
objectMap- The map of objects used in this instance
-
haveDBObjectMap
public boolean haveDBObjectMap()Checks the presence of a validDBObjectMapcontained in the instance. Implements theDBObjectMapperinterface.- Specified by:
haveDBObjectMapin interfaceDBObjectMapper- Returns:
- true if the instance contains a map of object that is not null, false otherwise
-
find
Search a specific value for a field of the DBView- Parameters:
field- The name of the column of the DBView in which perform the searchvalue- The value searched- Returns:
- The number of the first rows in which there is the value for the specific column, or -1 if the search is not successful
-
seek
Search a specific object for a field of the DBView- Parameters:
field- The name of the column of the DBView in which perform the searchvalue- The value searchedexactFind- true if the object found must be equals to the searched one (seeComparable), false otherwise- Returns:
- The number of the first rows in which there is the value for the specific column, or -1 if the search is not successful
-
toString
Returns the string representation of the DBView -
resultingOperation
Returns the string that defines the status of the operations for the specificHashGetterthat defines a row of the DBView -
getLongSet
Creates aLongSetpopulating it with the values of a column of the DBView- Parameters:
column- Name of the column from which extract the values- Returns:
- LongSet The LongSet that contains the extracted values
-