1 4 package org.ashkelon.db; 5 6 import java.util.*; 7 import java.io.*; 8 9 import org.apache.tools.ant.*; 10 import org.apache.tools.ant.types.EnumeratedAttribute; 11 12 15 public class StatementsBuilder extends Task 16 { 17 44 45 private static final String [] DBTYPES = {"postgres", "mysql", "mckoidb"}; 46 private String _dbtype = null; 47 private File _tofile = null; 48 49 public void setDbtype(DbType dbtype) { _dbtype = dbtype.getValue(); } 50 public void setTofile(File tofile) { _tofile = tofile; } 51 52 public void execute() 53 { 54 try 55 { 56 File general = new File("etc/db/statements.properties"); 57 Properties statements = new Properties(); 58 statements.load(new FileInputStream(general)); 59 60 File specific = new File("etc/db/statements-"+_dbtype+".properties"); 61 if (!specific.exists()) 62 { 63 statements.store(new FileOutputStream(_tofile), 64 "statements file for "+_dbtype); 65 return; 66 } 67 68 statements.load(new FileInputStream(specific)); 69 statements.store(new FileOutputStream(_tofile), 70 "merged statements file for "+_dbtype); 71 } 72 catch (IOException ex) 73 { 74 throw new BuildException(ex); 75 } 76 } 77 78 public static class DbType extends EnumeratedAttribute 79 { 80 public String [] getValues() { return DBTYPES; } 81 } 82 83 } 84 | Popular Tags |