}
}
public void executeSql(String resource, Connection conn)
{
UserTransaction tx =null;
try
{
tx = (UserTransaction)new InitialContext().lookup("UserTransaction");
tx.begin();
log.debug("Execute SQL from resource: "+resource);
URL url = Thread.currentThread().getContextClassLoader().getResource(resource);
log.debug("Execute SQL from resource URL: "+url);
String sql = getStringFromStream(url.openStream());
sql = sql.replaceAll("(?m)^--([^\n]+)?$", ""); // Remove all commented lines
final String[] statements ;
if (useEOL) {
statements = sql.split("[\n;]");
} else {
statements = sql.split(";");
}
for (String statement : statements)
{
if ((statement == null) || ("".equals(statement.trim()))) {
}
else {
Statement sqlStatement = conn.createStatement();
try
{
sqlStatement.executeUpdate(statement);
}
finally
{
sqlStatement.close();
}
}
}
tx.commit();
}
catch (Throwable t)
{
if(tx!=null)
try {
tx.rollback();
} catch (SystemException e) {
//
}
throw new RuntimeException("Failed to create database", t);
}