|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.ninja_squad.dbsetup.operation.Insert.Builder
public static final class Insert.Builder
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
.
Insert
,
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 will be inserted. |
Insert.RowBuilder |
row()
Starts building a new row with named columns to insert. |
java.lang.String |
toString()
|
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.util.Map<java.lang.String,?> row)
Adds a row to this builder. |
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. |
Insert.Builder |
withGeneratedValue(java.lang.String column,
ValueGenerator<?> valueGenerator)
Allows the given column to be populated by a value generator, which will be called for every row of the Insert operation being built. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Method Detail |
---|
public Insert.Builder columns(@Nonnull java.lang.String... columns)
values(Object...)
method, or with the values(java.util.Map)
method, or by adding
a row with named columns fluently using row()
.
columns
- the names of the columns to insert into.
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 generated value columns, or if the
set of columns has already been defined by adding a first row to the builder.public Insert.Builder values(@Nonnull java.lang.Object... values)
values
- the values to insert.
java.lang.IllegalStateException
- if the Insert has already been built, or if the number of values doesn't match
the number of columns.public Insert.RowBuilder row()
columns()
, then the columns of this row constitute the
column names (excluding the generated ones) of the Insert being built
Insert.RowBuilder
instance, which, when built, will add a row to this insert builder.
java.lang.IllegalStateException
- if the Insert has already been built.Insert.RowBuilder
public Insert.Builder values(@Nonnull java.util.Map<java.lang.String,?> row)
columns()
, then the keys of this map constitute the column names (excluding the generated ones)
of the Insert being built, in the order of the keys in the map (which is arbitrary unless an ordered or
sorted map is used).
row
- the row to add. The keys of the map are the column names, which must match with
the column names specified in the call to columns(String...)
, or with the column names of the first
added row. If a column name is not present in the map, null is inserted for this column.
java.lang.IllegalStateException
- if the Insert has already been built.
java.lang.IllegalArgumentException
- if a column name of the map doesn't match with any of the column names
specified with columns(String...)
public Insert.Builder withBinder(@Nonnull Binder binder, @Nonnull java.lang.String... columns)
binder
- the binder to use, regardless of the metadata, for the given columnscolumns
- the name of the columns to associate with the given Binder
java.lang.IllegalStateException
- if the Insert has already been built,
java.lang.IllegalArgumentException
- if any of the given columns is not
part of the columns or "generated value" columns.public Insert.Builder withDefaultValue(@Nonnull java.lang.String column, java.lang.Object value)
withGeneratedValue(column, ValueGenerators.constant(value))
column
- the name of the columnvalue
- the default value to insert into the column
java.lang.IllegalStateException
- if the Insert has already been built, or if the given column is part
of the columns to insert.public Insert.Builder withGeneratedValue(@Nonnull java.lang.String column, @Nonnull ValueGenerator<?> valueGenerator)
column
- the name of the columnvalueGenerator
- the generator generating values for the given column of every row
java.lang.IllegalStateException
- if the Insert has already been built, or if the given column is part
of the columns to insert.public Insert.Builder useMetadata(boolean useMetadata)
true
. The insert
can be faster if set to false
, but in this case, the binder used will be the one returned
by the BinderConfiguration
for a null metadata (which is, by default, the
default binder
), except the ones which have been associated explicitely with
a Binder.useMetadata(false)
wasn't called. Since version 1.3.0, if useMetadata
is true
(the default) but the database doesn't support metadata, then the default binder configuration returns the
default binder. Using this method is thus normally unnecessary as of 1.3.0.
java.lang.IllegalStateException
- if the Insert has already been built.public Insert build()
java.lang.IllegalStateException
- if the Insert has already been built, or if no column and no generated value
column has been specified.public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |