com.ninja_squad.dbsetup
Class DbSetup

java.lang.Object
  extended by com.ninja_squad.dbsetup.DbSetup

public final class DbSetup
extends java.lang.Object

Allows executing a sequence of database operations. This object is reusable, and can thus be used several times to launch the same sequence of database operations. Here's a typical usage scenario in a unit test:

 @Before
 public void setUp() throws Exception {
     Operation operation =
         Operations.sequenceOf(
             CommonOperations.DELETE_ALL,
             CommonOperations.INSERT_REFERENCE_DATA,
             Operations.insertInto("CLIENT")
                       .columns("CLIENT_ID", "FIRST_NAME", "LAST_NAME", "DATE_OF_BIRTH", "COUNTRY_ID")
                       .values(1L, "John", "Doe", "1975-07-19", 1L)
                       .values(2L, "Jack", "Smith", "1969-08-22", 2L)
                       .build());
     DbSetup dbSetup = new DbSetup(new DataSourceDestination(dataSource), operation);
     dbSetup.launch();
 }
 
In the above code, CommonOperations.DELETE_ALL and CommonOperations.INSERT_REFERENCE_DATA are operations shared by multiple test classes.

Note that, to speed up test executions, a DbSetupTracker can be used, at the price of a slightly bigger complexity.


Constructor Summary
DbSetup(Destination destination, Operation operation)
          Constructor which uses the default binder configuration.
DbSetup(Destination destination, Operation operation, BinderConfiguration binderConfiguration)
          Constructor allowing to use a custom BinderConfiguration.
 
Method Summary
 boolean equals(java.lang.Object obj)
           
 int hashCode()
           
 void launch()
          Executes the sequence of operations.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DbSetup

public DbSetup(@Nonnull
               Destination destination,
               @Nonnull
               Operation operation)
Constructor which uses the default binder configuration.

Parameters:
destination - the destination of the sequence of database operations
operation - the operation to execute (most of the time, an instance of CompositeOperation

DbSetup

public DbSetup(@Nonnull
               Destination destination,
               @Nonnull
               Operation operation,
               @Nonnull
               BinderConfiguration binderConfiguration)
Constructor allowing to use a custom BinderConfiguration.

Parameters:
destination - the destination of the sequence of database operations
operation - the operation to execute (most of the time, an instance of CompositeOperation
binderConfiguration - the binder configuration to use.
Method Detail

launch

public void launch()
Executes the sequence of operations. All the operations use the same connection, and are grouped in a single transaction. The transaction is rolled back if any exception occurs.


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