Class DBViewUtils
java.lang.Object
overit.geocallapp.utilities.dataaccess.DBViewUtils
Utility class providing helper methods for working with
This class offers a collection of static utility methods that simplify common operations on
It provides standardized approaches for handling these operations with consistent behavior.
DBView objects. This class offers a collection of static utility methods that simplify common operations on
DBView objects, such as cloning, transformation, and manipulation. It provides standardized approaches for handling these operations with consistent behavior.
- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddColumns(DBView dbv, String[] columns) Adds an array of columns to the givenDBView.static voidaddColumns(DBView dbv, Collection<String> columns) Adds a collection of columns to the givenDBView.static DBViewcloneDBView(DBView dbv) Creates a deep copy of the givenDBView.static <T> List<T> extractObjects(DBView dbv, String itemObjectColumn) Extracts values from a specific column of aDBViewinto a typed list.static voidfillDBView(DBView toFill, Iterable<? extends DynO> items) getChangedKeys(HashGetter hgBefore, HashGetter hg, String[] excludedFields) Identifies which keys have different values between twoHashGetterobjects.static booleanhgCompare(HashGetter hgBefore, HashGetter hg, String[] excludedFields) Compares twoHashGetterobjects to check if they have different values, excluding specified fields.static booleanCompares two maps to check if they have different values for common keys.static booleanCompares two maps to check if they have different values, excluding specified fields.static DBViewremoveRowsInValues(DBView dbv, String fieldName, Collection<?> values) Creates a newDBViewwith only the rows where the value of the specified field is among the given values.static DBViewremoveRowsNotInValues(DBView dbv, String fieldName, Collection<?> values) Creates a newDBViewwith only the rows where the value of the specified field is NOT among the given values.static voidsetDefaultValue(DBView dbv, String column, Object value) Sets a default value for a specific column on each record of aDBViewif the column is empty or null.static DBViewstatic DBViewstatic DBViewstatic DBViewtoDBView(Collection<? extends Map<String, Object>> items) Converts a collection of maps into a newDBView.toDBView(DynOExtractor<T> extractor, String itemObjectColumn, Iterable<T> items) static List<HashGetter> Converts aDBViewinto a list ofHashGetterobjects.toList(DBView dbv, DynOCreator<T> creator) static <T extends DynO>
PageResponse<T> toPageResponse(DBView in, DynOCreator<T> creator, int pageNumber) Converts aDBViewinto aPageResponsewith pagination information.
-
Method Details
-
cloneDBView
-
addColumns
Adds a collection of columns to the givenDBView. This method adds each column from the provided collection to theDBViewif it doesn't already exist.- Parameters:
dbv- theDBViewto add columns tocolumns- the collection of column names to add
-
addColumns
Adds an array of columns to the givenDBView. It checks if each column is already present in the DBView before adding it, to avoid duplicate columns.- Parameters:
dbv- theDBViewto add columns tocolumns- the array of column names to add
-
setDefaultValue
Sets a default value for a specific column on each record of aDBViewif the column is empty or null.- Parameters:
dbv- theDBViewcontaining the records to processcolumn- the name of the column to check and potentially setvalue- the default value to set if the column is empty or null
-
fillDBView
Populates aDBViewwith data from a collection ofDynOobjects. Note that this method assumes the DBView already has the necessary columns defined. If theDBViewneeds to have columns added dynamically based on theDynOobjects, usetoDBView(Iterable)instead.- Parameters:
toFill- theDBViewto populate with dataitems- the collection of DynO objects to add as rows
-
toDBView
-
toDBView
-
toDBView
public static <T extends DynO> DBView toDBView(DynOExtractor<T> extractor, String itemObjectColumn, Iterable<T> items) Converts a collection ofDynOobjects into a newDBViewwith an optional reference column. If itemObjectColumn is not null, each row in theDBViewwill also include a column with that name containing a reference to the originalDynOobject.- Parameters:
extractor- theDynOExtractorused to convert theDynOobjects intoMapitemObjectColumn- the name of the column to store references to the originalDynOobjects, or null if not neededitems- the collection ofDynOobjects to convert to a DBView- Returns:
- a new
DBViewcontaining the data from the DynO objects
-
toDBView
-
toDBView
-
toList
Converts aDBViewinto a list ofHashGetterobjects. The resulting list preserves the order of rows from the originalDBView.- Parameters:
dbv- theDBViewto convert- Returns:
- a list of
HashGetterobjects, each representing a row from theDBView
-
toList
-
toList
- Type Parameters:
T- the type ofDynOobjects to create- Parameters:
dbv- theDBViewto convertcreator- theDynOCreatorto use for instantiating objects- Returns:
- a list of
DynOobjects created by the specified creator, each representing a row from theDBView
-
extractObjects
Extracts values from a specific column of aDBViewinto a typed list.- Type Parameters:
T- the target type of the extracted values- Parameters:
dbv- theDBViewcontaining the dataitemObjectColumn- the name of the column to extract values from- Returns:
- a list of values extracted from the specified column, cast to type T
-
toMap
-
toPageResponse
public static <T extends DynO> PageResponse<T> toPageResponse(DBView in, DynOCreator<T> creator, int pageNumber) Converts aDBViewinto aPageResponsewith pagination information.- Type Parameters:
T- the type of DynO objects to create- Parameters:
in- the DBView to convertcreator- the DynOCreator to use for instantiating objectspageNumber- the current page number (1-based)- Returns:
- a PageResponse containing DynO objects and pagination information
-
mapCompare
public static boolean mapCompare(Map<String, Object> firstMap, Map<String, Object> secondMap, String[] excludedFields) Compares two maps to check if they have different values, excluding specified fields. This method returns true if any value in the second map (except for excluded fields) is different from the corresponding value in the first map. In addition to the specified excluded fields, this method always excludes system fields (LOGIN, ACTION, and DATASTAMP) from the comparison.- Parameters:
firstMap- the first map to comparesecondMap- the second map to compare against the firstexcludedFields- an array of field names to exclude from the comparison- Returns:
- true if the maps have different values for any common key (except excluded fields), false if all common keys have the same values
-
mapCompare
Compares two maps to check if they have different values for common keys. This method returns true if any value in the second map is different from the corresponding value in the first map.- Parameters:
firstMap- the first map to comparesecondMap- the second map to compare against the first- Returns:
- true if the maps have different values for any common key, false if all common keys have the same values
-
hgCompare
Compares twoHashGetterobjects to check if they have different values, excluding specified fields. It returns true if any value in the secondHashGetter(except for excluded fields) is different from the corresponding value in the firstHashGetter.- Parameters:
hgBefore- the firstHashGetterto comparehg- the secondHashGetterto compare against the firstexcludedFields- an array of field names to exclude from the comparison- Returns:
- true if the
HashGetters have different values for any common key (except excluded fields), false if all common keys have the same values
-
getChangedKeys
public static List<String> getChangedKeys(HashGetter hgBefore, HashGetter hg, String[] excludedFields) Identifies which keys have different values between twoHashGetterobjects. It returns a list of keys where the values differ between the two objects.- Parameters:
hgBefore- the firstHashGetterto compare, can be nullhg- the secondHashGetterto compare against the firstexcludedFields- an array of field names to exclude from the comparison- Returns:
- a list of keys where the values differ between the two HashGetter objects
-
removeRowsInValues
Creates a newDBViewwith only the rows where the value of the specified field is among the given values. -
removeRowsNotInValues
Creates a newDBViewwith only the rows where the value of the specified field is NOT among the given values.- Parameters:
dbv- the startingDBViewfieldName- the name of the field to use for comparisonsvalues- the values to exclude- Returns:
- a new filtered DBView
-