Package wbs.utils.util.database
Class WbsTable
java.lang.Object
wbs.utils.util.database.WbsTable
-
Constructor Summary
ConstructorsConstructorDescriptionWbsTable(WbsDatabase database, String tableName, @NotNull WbsField... primaryKey) -
Method Summary
Modifier and TypeMethodDescriptionvoidbooleanaddFieldIfNotExists(WbsField field) Adds a field if it doesn't already exist.booleanaddNewField(WbsField field) Add a new field, updating the underlying database.@Nullable WbsFieldgetInsertStatement(int amount) getName()getSelectQuery(String whereClause) getSelectQuery(String fields, String whereClause) getUpdateStatement(@NotNull String whereClaus) booleanbooleanInserts the given map of objects.booleaninsert(List<WbsRecord> records, Connection connection) booleanremoveField(WbsField field) selectOnField(@NotNull WbsField field, @Nullable Object match) selectOnField(@NotNull WbsField field, @Nullable Object match, @Nullable CollateFunction collate) selectOnFields(Collection<WbsField> fields, Collection<?> matches) voidsetDebugMode(boolean debugMode) booleanbooleanUpdates the given list of records using the provided whereClause.booleanupdate(List<WbsRecord> records, Connection connection, String whereClause) Updates the given list of records using the provided whereClause.booleanupdate(WbsRecord record, Connection connection, String whereClause) Performs an update using a single record for the fields, using the given where clause.booleanupdateField(WbsField field) Update the definition of a field.
Note that this change is potentially destructive, as it requirebooleanInserts the given map of objects.
-
Constructor Details
-
WbsTable
-
-
Method Details
-
addField
-
removeField
-
addNewField
Add a new field, updating the underlying database.- Parameters:
field- The field to add- Returns:
- True if the field was added successfully, or false if the field failed to add for any reason.
-
addFieldIfNotExists
Adds a field if it doesn't already exist.- Parameters:
field- The field to try adding.- Returns:
- True if the field now exists, regardless of if it existed previously. False if there was an error.
-
updateField
Update the definition of a field.
Note that this change is potentially destructive, as it require- Parameters:
field- The field to update- Returns:
- True if the field was updated (or already existed as-is), false if an error occurred or if the field didn't exist to be updated
-
getCreationQuery
-
getInsertStatement
-
getInsertStatement
-
getUpdateStatement
-
selectOnField
-
selectOnField
@NotNull public @NotNull List<WbsRecord> selectOnField(@NotNull @NotNull WbsField field, @Nullable @Nullable Object match, @Nullable @Nullable CollateFunction collate) -
selectOnFields
@NotNull public @NotNull List<WbsRecord> selectOnFields(Collection<WbsField> fields, Collection<?> matches) -
upsert
Inserts the given map of objects.- Parameters:
records- The record to insert, with all fields populated.- Returns:
- True if the upsert was successful, false if any key was missing or no records were provided
-
insert
Inserts the given map of objects.- Parameters:
records- The record to insert, with all fields populated.- Returns:
- True if the insert was successful, false if any key was missing or no records were provided
-
insert
- Throws:
WbsDatabaseException
-
update
-
update
Updates the given list of records using the provided whereClause.- Parameters:
records- The records to update, with all fields populated.whereClause- The where condition to update on, with fields populated for each record individually, in the same order as the fields are declared on the table. To use complex conditions that use fields in another order, or more than once, perform a direct query.- Returns:
- True if the update was successful, false if any key was missing or no records were provided.
-
update
public boolean update(List<WbsRecord> records, Connection connection, String whereClause) throws WbsDatabaseException Updates the given list of records using the provided whereClause. The given connection is not closed, allowing for batching.- Parameters:
records- The records to update, with all fields populated.connection- The connection to use for all queries performed.whereClause- The where condition to update on, with fields populated for each record individually, in the same order as the fields are declared on the table. To use complex conditions that use fields in another order, or more than once, perform a direct query.- Returns:
- True if the update was successful, false if any key was missing or no records were provided.
- Throws:
WbsDatabaseException
-
update
public boolean update(WbsRecord record, Connection connection, String whereClause) throws WbsDatabaseException Performs an update using a single record for the fields, using the given where clause. The given connection is not closed, allowing for batching.- Parameters:
record- The records to update, with all fields populated.connection- The connection to use for all queries performed.whereClause- The where condition to update on, with fields populated for each record individually, in the same order as the fields are declared on the table. To use complex conditions that use fields in another order, or more than once, perform a direct query.- Returns:
- True if the update was successful, false if any key was missing or no records were provided.
- Throws:
WbsDatabaseException
-
getName
-
getSelectQuery
-
getSelectQuery
-
getField
-
getPrimaryKeyQuery
-
getPrimaryKeys
-
getFields
-
inDebugMode
public boolean inDebugMode() -
setDebugMode
public void setDebugMode(boolean debugMode)
-