com.ninja_squad.dbsetup.operation
Class Insert.Builder

java.lang.Object
  extended by com.ninja_squad.dbsetup.operation.Insert.Builder
Enclosing class:
Insert

public static final class Insert.Builder
extends java.lang.Object

A builder used to create an Insert operation. Such a builder may only be used once. Once it has built its Insert operation, all its methods throw an IllegalStateException.

See Also:
Insert.into(String)

Method Summary
 Insert build()
          Builds the Insert operation.
 Insert.Builder columns(java.lang.String... columns)
          Specifies the list of columns into which values wil be inserted.
 Insert.Builder useMetadata(boolean useMetadata)
          Determines if the metadata must be used to get the appropriate binder for each inserted column (except the ones which have been associated explicitely with a Binder).
 Insert.Builder values(java.lang.Object... values)
          Adds a row of values to insert.
 Insert.Builder withBinder(Binder binder, java.lang.String... columns)
          Associates a Binder to one or several columns.
 Insert.Builder withDefaultValue(java.lang.String column, java.lang.Object value)
          Specifies a default value to be inserted in a column for all the rows inserted by the Insert operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

columns

public Insert.Builder columns(@Nonnull
                              java.lang.String... columns)
Specifies the list of columns into which values wil be inserted. The values must the be specifed, after, using the values(Object...) method.

Parameters:
columns - the names of the columns to insert into.
Returns:
this Builder instance, for chaining.
Throws:
java.lang.IllegalStateException - if the Insert has already been built, or if this method has already been called, or if one of the given columns is also specified as one of the "default value" columns.

values

public Insert.Builder values(@Nonnull
                             java.lang.Object... values)
Adds a row of values to insert.

Parameters:
values - the values to insert.
Returns:
this Builder instance, for chaining.
Throws:
java.lang.IllegalStateException - if the Insert has already been built, or if the number of values doesn't match the number of columns.

withBinder

public Insert.Builder withBinder(@Nonnull
                                 Binder binder,
                                 @Nonnull
                                 java.lang.String... columns)
Associates a Binder to one or several columns.

Parameters:
binder - the binder to use, regardless of the metadata, for the given columns
columns - the name of the columns to associate with the given Binder
Returns:
this Builder instance, for chaining.
Throws:
java.lang.IllegalStateException - if the Insert has already been built, or if any of the given columns is not part of the columns or "default value" columns.

withDefaultValue

public Insert.Builder withDefaultValue(@Nonnull
                                       java.lang.String column,
                                       java.lang.Object value)
Specifies a default value to be inserted in a column for all the rows inserted by the Insert operation.

Parameters:
column - the name of the column
value - the default value to insert into the column
Returns:
this Builder instance, for chaining.
Throws:
java.lang.IllegalStateException - if the Insert has already been built, or if the given column is part of the columns to insert.

useMetadata

public Insert.Builder useMetadata(boolean useMetadata)
Determines if the metadata must be used to get the appropriate binder for each inserted column (except the ones which have been associated explicitely with a Binder). The default is true. The insert can be faster if set to false, but in this case, the default binder will be used for all the columns (except the ones which have been associated explicitely with a Binder).

Returns:
this Builder instance, for chaining.
Throws:
java.lang.IllegalStateException - if the Insert has already been built.

build

public Insert build()
Builds the Insert operation.

Returns:
the created Insert operation.
Throws:
java.lang.IllegalStateException - if the Insert has already been built, or if no column and no default value column has been specified.