com.ninja_squad.dbsetup.operation
Class Insert

java.lang.Object
  extended by com.ninja_squad.dbsetup.operation.Insert
All Implemented Interfaces:
Operation

@Immutable
public final class Insert
extends java.lang.Object
implements Operation

Operation which inserts one or several rows into a table. Example usage:

   Insert insert =
       Insert.into("CLIENT")
             .columns("CLIENT_ID", "FIRST_NAME", "LAST_NAME", "DATE_OF_BIRTH", "CLIENT_TYPE")
             .values(1L, "John", "Doe", "1975-07-19", ClientType.NORMAL)
             .values(2L, "Jack", "Smith", "1969-08-22", ClientType.HIGH_PRIORITY)
             .withDefaultValue("DELETED", false)
             .withDefaultValue("VERSION", 1)
             .withBinder(new ClientTypeBinder(), "CLIENT_TYPE")
             .build();
 
The above operation will insert two rows inside the CLIENT table. For each row, the column DELETED will be set to false and the column VERSION will be set to 1. For the column CLIENT_TYPE, instead of using the Binder associated to the type of the column found in the metadata of the table, a custom binder will be used.


Nested Class Summary
static class Insert.Builder
          A builder used to create an Insert operation.
 
Method Summary
 boolean equals(java.lang.Object obj)
           
 void execute(java.sql.Connection connection, BinderConfiguration configuration)
          Inserts the values and default values in the table.
 int hashCode()
           
static Insert.Builder into(java.lang.String table)
          Creates a new Builder instance, in order to build an Insert operation into the given table
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

execute

public void execute(java.sql.Connection connection,
                    BinderConfiguration configuration)
             throws java.sql.SQLException
Inserts the values and default values in the table. Unless useMetadata has been set to false, the given configuration is used to get the appropriate binder. Nevertheless, if a binder has explicitely been associated to a given column, this binder will always be used for this column.

Specified by:
execute in interface Operation
Parameters:
connection - the connection used to execute the operation
configuration - the binder configuration, used to get appropriate binders based on the metadata of the prepared statements
Throws:
java.sql.SQLException - if the execution throws a SQLException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

into

public static Insert.Builder into(@Nonnull
                                  java.lang.String table)
Creates a new Builder instance, in order to build an Insert operation into the given table

Parameters:
table - the name of the table to insert into
Returns:
the created Builder