Class UpdateBuilder


  • public class UpdateBuilder
    extends SQLBuilder
    A builder class for creating an UPDATE sql statement to update a row in a table.
    Since:
    1.4.0
    • Constructor Summary

      Constructors 
      Constructor Description
      UpdateBuilder()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      TypedStatement build​(Database db)
      Runs buildPreparedStatement and passes this object to a new instance of TypedStatement.
      long buildAndLargeUpdate​(Database db)
      Runs buildPreparedStatement, executes the statement and returns the the number of rows updated.
      int buildAndUpdate​(Database db)
      Runs buildPreparedStatement, executes the statement and returns the number of rows updated.
      UpdateBuilder SET​(java.lang.String columnName, java.lang.String value)
      Sets the values to replace in the table.
      UpdateBuilder UPDATE​(java.lang.String tableName)
      Generates sql code to update a row in a table.
      UpdateBuilder WHERE​(java.lang.String columnName, java.lang.String value)
      Specifies a condition to constrain the SELECT statement and if this is not the first WHERE added it is separated by AND.
      UpdateBuilder WHERE_BETWEEN​(java.lang.String columnName, java.lang.String start, java.lang.String stop)
      Specifies a condition to constrain the SELECT statement that checks if the specified column value equals the start or stop values or falls between those values and if this is not the first WHERE added it is separated by AND.
      UpdateBuilder WHERE_BETWEEN_OR​(java.lang.String columnName, java.lang.String start, java.lang.String stop)
      Specifies a condition to constrain the SELECT statement that checks if the specified column value equals the start or stop values or falls between those values and if this is not the first WHERE added it is separated by OR.
      UpdateBuilder WHERE_EXISTS​(QueryBuilder builder)
      Specifies a condition to constrain the SELECT statement that checks if any record exists in the sub query and if this is not the first WHERE added it is separated by AND.
      UpdateBuilder WHERE_EXISTS_OR​(QueryBuilder builder)
      Specifies a condition to constrain the SELECT statement that checks if any record exists in the sub query and if this is not the first WHERE added it is separated by OR.
      UpdateBuilder WHERE_IN​(java.lang.String columnName, java.lang.String... values)
      Specifies a condition to constrain the SELECT statement that checks if the column matches one of the specified values.
      UpdateBuilder WHERE_IN_OR​(java.lang.String columnName, java.lang.String... values)
      Specifies a condition to constrain the SELECT statement that checks if the column matches one of the specified values.
      UpdateBuilder WHERE_IS_NOT_NULL​(java.lang.String columnName)
      Specifies a condition to constrain the SELECT statement that checks if the specified column is NOT NULL and if this is not the first WHERE added it is separated by AND.
      UpdateBuilder WHERE_IS_NOT_NULL_OR​(java.lang.String columnName)
      Specifies a condition to constrain the SELECT statement that checks if the specified column is NOT NULL and if this is not the first WHERE added it is separated by OR.
      UpdateBuilder WHERE_IS_NULL​(java.lang.String columnName)
      Specifies a condition to constrain the SELECT statement that checks if the specified column is NULL and if this is not the first WHERE added it is separated by AND.
      UpdateBuilder WHERE_IS_NULL_OR​(java.lang.String columnName)
      Specifies a condition to constrain the SELECT statement that checks if the specified column is NULL and if this is not the first WHERE added it is separated by OR.
      UpdateBuilder WHERE_NOT​(java.lang.String columnName, java.lang.String value)
      Specifies an inverse condition using NOT to constrain the SELECT statement and if this is not the first WHERE added it is separated by AND.
      UpdateBuilder WHERE_NOT_BETWEEN​(java.lang.String columnName, java.lang.String start, java.lang.String stop)
      Specifies a condition to constrain the SELECT statement that checks if the specified column value does not equal the start or stop values and does not fall between those values and if this is not the first WHERE added it is separated by AND.
      UpdateBuilder WHERE_NOT_BETWEEN_OR​(java.lang.String columnName, java.lang.String start, java.lang.String stop)
      Specifies a condition to constrain the SELECT statement that checks if the specified column value does not equal the start or stop values and does not fall between those values and if this is not the first WHERE added it is separated by OR.
      UpdateBuilder WHERE_NOT_EXISTS​(QueryBuilder builder)
      Specifies a condition to constrain the SELECT statement that checks if no records exist in the sub query and if this is not the first WHERE added it is separated by AND.
      UpdateBuilder WHERE_NOT_EXISTS_OR​(QueryBuilder builder)
      Specifies a condition to constrain the SELECT statement that checks if no records exist in the sub query and if this is not the first WHERE added it is separated by OR.
      UpdateBuilder WHERE_NOT_IN​(java.lang.String columnName, java.lang.String... values)
      Specifies a condition to constrain the SELECT statement that checks if the column does not match one of the specified values.
      UpdateBuilder WHERE_NOT_IN_OR​(java.lang.String columnName, java.lang.String... values)
      Specifies a condition to constrain the SELECT statement that checks if the column does not match one of the specified values.
      UpdateBuilder WHERE_NOT_OR​(java.lang.String columnName, java.lang.String value)
      Specifies an inverse condition using NOT to constrain the SELECT statement and if this is not the first WHERE added it is separated by OR.
      UpdateBuilder WHERE_OR​(java.lang.String columnName, java.lang.String value)
      Specifies a condition to constrain the SELECT statement and if this is not the first WHERE added it is separated by OR.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • UpdateBuilder

        public UpdateBuilder()
    • Method Detail

      • UPDATE

        public UpdateBuilder UPDATE​(java.lang.String tableName)
        Generates sql code to update a row in a table.
        Parameters:
        tableName - the name of the table
        Returns:
        the instance of the builder to continue building
        Throws:
        java.lang.IllegalStateException - if this is not the first method called
      • SET

        public UpdateBuilder SET​(java.lang.String columnName,
                                 java.lang.String value)
        Sets the values to replace in the table.
        Parameters:
        columnName - the name of the column
        value - the value to set
        Returns:
        the instance of the builder to continue building
        Throws:
        java.lang.IllegalStateException - if the UPDATE statement is not called first
      • WHERE

        public UpdateBuilder WHERE​(java.lang.String columnName,
                                   java.lang.String value)
        Specifies a condition to constrain the SELECT statement and if this is not the first WHERE added it is separated by AND.
        Parameters:
        columnName - the column name to check against
        value - the expected value
        Returns:
        the instance of the builder to continue building
      • WHERE_OR

        public UpdateBuilder WHERE_OR​(java.lang.String columnName,
                                      java.lang.String value)
        Specifies a condition to constrain the SELECT statement and if this is not the first WHERE added it is separated by OR.
        Parameters:
        columnName - the column name to check against
        value - the expected value
        Returns:
        the instance of the builder to continue building
      • WHERE_NOT

        public UpdateBuilder WHERE_NOT​(java.lang.String columnName,
                                       java.lang.String value)
        Specifies an inverse condition using NOT to constrain the SELECT statement and if this is not the first WHERE added it is separated by AND.
        Parameters:
        columnName - the column name to check against
        value - the expected value
        Returns:
        the instance of the builder to continue building
      • WHERE_NOT_OR

        public UpdateBuilder WHERE_NOT_OR​(java.lang.String columnName,
                                          java.lang.String value)
        Specifies an inverse condition using NOT to constrain the SELECT statement and if this is not the first WHERE added it is separated by OR.
        Parameters:
        columnName - the column name to check against
        value - the expected value
        Returns:
        the instance of the builder to continue building
      • WHERE_IS_NULL

        public UpdateBuilder WHERE_IS_NULL​(java.lang.String columnName)
        Specifies a condition to constrain the SELECT statement that checks if the specified column is NULL and if this is not the first WHERE added it is separated by AND.
        Parameters:
        columnName - the column name to check against
        Returns:
        the instance of the builder to continue building
      • WHERE_IS_NOT_NULL

        public UpdateBuilder WHERE_IS_NOT_NULL​(java.lang.String columnName)
        Specifies a condition to constrain the SELECT statement that checks if the specified column is NOT NULL and if this is not the first WHERE added it is separated by AND.
        Parameters:
        columnName - the column name to check against
        Returns:
        the instance of the builder to continue building
      • WHERE_IS_NULL_OR

        public UpdateBuilder WHERE_IS_NULL_OR​(java.lang.String columnName)
        Specifies a condition to constrain the SELECT statement that checks if the specified column is NULL and if this is not the first WHERE added it is separated by OR.
        Parameters:
        columnName - the column name to check against
        Returns:
        the instance of the builder to continue building
      • WHERE_IS_NOT_NULL_OR

        public UpdateBuilder WHERE_IS_NOT_NULL_OR​(java.lang.String columnName)
        Specifies a condition to constrain the SELECT statement that checks if the specified column is NOT NULL and if this is not the first WHERE added it is separated by OR.
        Parameters:
        columnName - the column name to check against
        Returns:
        the instance of the builder to continue building
      • WHERE_IN

        public UpdateBuilder WHERE_IN​(java.lang.String columnName,
                                      java.lang.String... values)
        Specifies a condition to constrain the SELECT statement that checks if the column matches one of the specified values. and if this is not the first WHERE added it is separated by AND.
        Parameters:
        columnName - the column name to check against
        values - a list of expected values
        Returns:
        the instance of the builder to continue building
      • WHERE_NOT_IN

        public UpdateBuilder WHERE_NOT_IN​(java.lang.String columnName,
                                          java.lang.String... values)
        Specifies a condition to constrain the SELECT statement that checks if the column does not match one of the specified values. and if this is not the first WHERE added it is separated by AND.
        Parameters:
        columnName - the column name to check against
        values - a list of expected values
        Returns:
        the instance of the builder to continue building
      • WHERE_IN_OR

        public UpdateBuilder WHERE_IN_OR​(java.lang.String columnName,
                                         java.lang.String... values)
        Specifies a condition to constrain the SELECT statement that checks if the column matches one of the specified values. and if this is not the first WHERE added it is separated by OR.
        Parameters:
        columnName - the column name to check against
        values - a list of expected values
        Returns:
        the instance of the builder to continue building
      • WHERE_NOT_IN_OR

        public UpdateBuilder WHERE_NOT_IN_OR​(java.lang.String columnName,
                                             java.lang.String... values)
        Specifies a condition to constrain the SELECT statement that checks if the column does not match one of the specified values. and if this is not the first WHERE added it is separated by AND.
        Parameters:
        columnName - the column name to check against
        values - a list of expected values
        Returns:
        the instance of the builder to continue building
      • WHERE_BETWEEN

        public UpdateBuilder WHERE_BETWEEN​(java.lang.String columnName,
                                           java.lang.String start,
                                           java.lang.String stop)
        Specifies a condition to constrain the SELECT statement that checks if the specified column value equals the start or stop values or falls between those values and if this is not the first WHERE added it is separated by AND.
        Parameters:
        columnName - the column name to check against
        start - the inclusive beginning value
        stop - the inclusive ending value
        Returns:
        the instance of the builder to continue building
      • WHERE_NOT_BETWEEN

        public UpdateBuilder WHERE_NOT_BETWEEN​(java.lang.String columnName,
                                               java.lang.String start,
                                               java.lang.String stop)
        Specifies a condition to constrain the SELECT statement that checks if the specified column value does not equal the start or stop values and does not fall between those values and if this is not the first WHERE added it is separated by AND.
        Parameters:
        columnName - the column name to check against
        start - the inclusive beginning value
        stop - the inclusive ending value
        Returns:
        the instance of the builder to continue building
      • WHERE_BETWEEN_OR

        public UpdateBuilder WHERE_BETWEEN_OR​(java.lang.String columnName,
                                              java.lang.String start,
                                              java.lang.String stop)
        Specifies a condition to constrain the SELECT statement that checks if the specified column value equals the start or stop values or falls between those values and if this is not the first WHERE added it is separated by OR.
        Parameters:
        columnName - the column name to check against
        start - the inclusive beginning value
        stop - the inclusive ending value
        Returns:
        the instance of the builder to continue building
      • WHERE_NOT_BETWEEN_OR

        public UpdateBuilder WHERE_NOT_BETWEEN_OR​(java.lang.String columnName,
                                                  java.lang.String start,
                                                  java.lang.String stop)
        Specifies a condition to constrain the SELECT statement that checks if the specified column value does not equal the start or stop values and does not fall between those values and if this is not the first WHERE added it is separated by OR.
        Parameters:
        columnName - the column name to check against
        start - the inclusive beginning value
        stop - the inclusive ending value
        Returns:
        the instance of the builder to continue building
      • WHERE_EXISTS

        public UpdateBuilder WHERE_EXISTS​(QueryBuilder builder)
        Specifies a condition to constrain the SELECT statement that checks if any record exists in the sub query and if this is not the first WHERE added it is separated by AND.
        Parameters:
        builder - the UpdateBuilder containing the sql statement to retrieve results from
        Returns:
        the instance of the builder to continue building
      • WHERE_EXISTS_OR

        public UpdateBuilder WHERE_EXISTS_OR​(QueryBuilder builder)
        Specifies a condition to constrain the SELECT statement that checks if any record exists in the sub query and if this is not the first WHERE added it is separated by OR.
        Parameters:
        builder - the UpdateBuilder containing the sql statement to retrieve results from
        Returns:
        the instance of the builder to continue building
      • WHERE_NOT_EXISTS

        public UpdateBuilder WHERE_NOT_EXISTS​(QueryBuilder builder)
        Specifies a condition to constrain the SELECT statement that checks if no records exist in the sub query and if this is not the first WHERE added it is separated by AND.
        Parameters:
        builder - the UpdateBuilder containing the sql statement to retrieve results from
        Returns:
        the instance of the builder to continue building
      • WHERE_NOT_EXISTS_OR

        public UpdateBuilder WHERE_NOT_EXISTS_OR​(QueryBuilder builder)
        Specifies a condition to constrain the SELECT statement that checks if no records exist in the sub query and if this is not the first WHERE added it is separated by OR.
        Parameters:
        builder - the UpdateBuilder containing the sql statement to retrieve results from
        Returns:
        the instance of the builder to continue building
      • build

        public TypedStatement build​(Database db)
                             throws java.sql.SQLException
        Runs buildPreparedStatement and passes this object to a new instance of TypedStatement.
        Specified by:
        build in class SQLBuilder
        Parameters:
        db - the database to request the PreparedStatement object from
        Returns:
        a new instance of TypedStatement
        Throws:
        java.sql.SQLException - if a database access error occurs
      • buildAndUpdate

        public int buildAndUpdate​(Database db)
                           throws java.sql.SQLException
        Runs buildPreparedStatement, executes the statement and returns the number of rows updated.
        Parameters:
        db - the database to request the PreparedStatement object from
        Returns:
        the result of the statement as a ResultSet
        Throws:
        java.sql.SQLException - if a database access error occurs
      • buildAndLargeUpdate

        public long buildAndLargeUpdate​(Database db)
                                 throws java.sql.SQLException
        Runs buildPreparedStatement, executes the statement and returns the the number of rows updated. This method should be used when the returned row count may exceed Integer.MAX_VALUE.
        Parameters:
        db - the database to request the PreparedStatement object from
        Returns:
        the result of the statement as a ResultSet
        Throws:
        java.sql.SQLException - if a database access error occurs