1 23 package org.hammurapi; 24 25 import java.io.IOException ; 26 import java.io.InputStream ; 27 import java.io.InputStreamReader ; 28 import java.sql.SQLException ; 29 import java.util.Properties ; 30 31 import com.pavelvlasov.sql.SQLExceptionEx; 32 import com.pavelvlasov.sql.SQLProcessor; 33 34 39 public class PersistingInspectorBase extends ParameterizableInspectorBase { 40 41 44 public void initDb(SQLProcessor processor, Properties dbProperties) throws SQLException { 45 try { 46 ClassLoader classLoader = getClass().getClassLoader(); 47 String prefix = getClass().getName().replace('.','/'); 48 String resourceName=prefix+"."+dbProperties.getProperty("type")+".sql"; 50 InputStream resourceAsStream = classLoader.getResourceAsStream(resourceName); 51 52 if (resourceAsStream==null) { 54 resourceName=prefix+".sql"; 55 resourceAsStream = classLoader.getResourceAsStream(resourceName); 56 } 57 58 if (resourceAsStream==null) { 59 throw new SQLException ("Initialization script resource not found: "+resourceName); 60 } else { 61 processor.executeScript(new InputStreamReader (resourceAsStream)); 62 } 63 } catch (IOException e) { 64 throw new SQLExceptionEx(e); 65 } 66 } 67 68 } 69 | Popular Tags |