1 package org.apache.ojb.broker.ant; 2 3 17 18 import java.io.IOException ; 19 import java.io.Writer ; 20 import java.sql.SQLException ; 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 24 import org.apache.commons.beanutils.DynaBean; 25 import org.apache.ddlutils.Platform; 26 import org.apache.ddlutils.model.Database; 27 28 33 public class DataSet 34 { 35 36 private ArrayList _beans = new ArrayList (); 37 38 43 public void add(DynaBean bean) 44 { 45 _beans.add(bean); 46 } 47 48 55 public void createInsertionSql(Database model, Platform platform, Writer writer) throws IOException 56 { 57 for (Iterator it = _beans.iterator(); it.hasNext();) 58 { 59 writer.write(platform.getInsertSql(model, (DynaBean)it.next())); 60 if (it.hasNext()) 61 { 62 writer.write("\n"); 63 } 64 } 65 } 66 67 74 public void insert(Platform platform, Database model, int batchSize) throws SQLException 75 { 76 if (batchSize <= 1) 77 { 78 for (Iterator it = _beans.iterator(); it.hasNext();) 79 { 80 platform.insert(model, (DynaBean)it.next()); 81 } 82 } 83 else 84 { 85 for (int startIdx = 0; startIdx < _beans.size(); startIdx += batchSize) 86 { 87 platform.insert(model, _beans.subList(startIdx, startIdx + batchSize)); 88 } 89 } 90 } 91 } 92 | Popular Tags |