1 package com.imcode.db.commands; 2 3 import com.imcode.db.DatabaseCommand; 4 import com.imcode.db.DatabaseConnection; 5 import com.imcode.db.DatabaseException; 6 7 import java.util.*; 8 9 public class CompositeDatabaseCommand extends TransactionDatabaseCommand { 10 11 private final List databaseCommands = new ArrayList(); 12 13 public CompositeDatabaseCommand() {} 14 15 public CompositeDatabaseCommand( DatabaseCommand[] databaseCommands ) { 16 this.databaseCommands.addAll( Arrays.asList( databaseCommands ) ); 17 } 18 19 public CompositeDatabaseCommand(DatabaseCommand databaseCommand) { 20 add(databaseCommand); 21 } 22 23 public void add(DatabaseCommand databaseCommand) { 24 databaseCommands.add(databaseCommand); 25 } 26 27 public Object executeInTransaction( DatabaseConnection connection ) throws DatabaseException { 28 for ( Iterator iterator = databaseCommands.iterator(); iterator.hasNext(); ) { 29 DatabaseCommand databaseCommand = (DatabaseCommand)iterator.next(); 30 databaseCommand.executeOn( connection ); 31 } 32 return null; 33 } 34 35 36 37 }