dont fire multiple sql statments in batch because selects throwed an
exception
This commit is contained in:
parent
4829a67fba
commit
2582919493
@ -15,50 +15,48 @@ public class JDBCProcessor extends AbstractProcessor {
|
|||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
private String driver;
|
final private String driver;
|
||||||
private String url;
|
final private String url;
|
||||||
private String user;
|
final private String user;
|
||||||
private String password;
|
final private String password;
|
||||||
private List<String> sql;
|
final private List<String> sql;
|
||||||
|
|
||||||
private String errorMsg;
|
private String errorMsg;
|
||||||
|
|
||||||
public JDBCProcessor(String driver, String url, String user, String password) {
|
public JDBCProcessor(final String driver, final String url, final String user, final String password) {
|
||||||
this.driver = driver;
|
this.driver = driver;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.user = user;
|
this.user = user;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
this.errorMsg = "";
|
this.errorMsg = "";
|
||||||
|
this.sql = new ArrayList<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public JDBCProcessor(String driver, String url) {
|
public JDBCProcessor(final String driver, final String url) throws ProcessorException {
|
||||||
this.driver = driver;
|
this.driver = driver;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
|
final Config config = Config.getInstance();
|
||||||
|
if ("com.mysql.jdbc.Driver".equals(driver)) {
|
||||||
|
user = config.getProperty("mysqladmin.user", "root");
|
||||||
|
password = config.getProperty("mysqladmin.password");
|
||||||
|
} else {
|
||||||
|
if ("org.postgresql.Driver".equals(driver)) {
|
||||||
|
user = config.getProperty("pgsqladmin.user", "postgres");
|
||||||
|
password = config.getProperty("pgsqladmin.password");
|
||||||
|
} else {
|
||||||
|
throw new ProcessorException("database admin-user configuration failed");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.errorMsg = "";
|
||||||
|
this.sql = new ArrayList<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSQL(String sqlStatement) {
|
public void addSQL(String sqlStatement) {
|
||||||
if (sql == null)
|
|
||||||
sql = new ArrayList<String>();
|
|
||||||
sql.add(sqlStatement);
|
sql.add(sqlStatement);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object process() throws ProcessorException {
|
public Object process() throws ProcessorException {
|
||||||
Connection c = null;
|
Connection c = null;
|
||||||
Config config = Config.getInstance();
|
|
||||||
if ("com.mysql.jdbc.Driver".equals(driver)) {
|
|
||||||
if (user == null)
|
|
||||||
user = config.getProperty("mysqladmin.user", "root");
|
|
||||||
if (password == null)
|
|
||||||
password = config.getProperty("mysqladmin.password");
|
|
||||||
}
|
|
||||||
if ("org.postgresql.Driver".equals(driver)) {
|
|
||||||
if (user == null)
|
|
||||||
user = config.getProperty("pgsqladmin.user", "postgres");
|
|
||||||
if (password == null)
|
|
||||||
password = config.getProperty("pgsqladmin.password");
|
|
||||||
}
|
|
||||||
if (user == null || password == null) {
|
|
||||||
throw new ProcessorException("database admin-user configuration failed");
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
Class.forName(driver);
|
Class.forName(driver);
|
||||||
c = DriverManager.getConnection(url, user, password);
|
c = DriverManager.getConnection(url, user, password);
|
||||||
@ -66,10 +64,10 @@ public class JDBCProcessor extends AbstractProcessor {
|
|||||||
throw new ProcessorException("cannot connect to '" + url + "'");
|
throw new ProcessorException("cannot connect to '" + url + "'");
|
||||||
Statement s = c.createStatement();
|
Statement s = c.createStatement();
|
||||||
for (String sqlStatement : sql) {
|
for (String sqlStatement : sql) {
|
||||||
s.addBatch(sqlStatement);
|
|
||||||
System.out.println("SQL: " + sqlStatement);
|
System.out.println("SQL: " + sqlStatement);
|
||||||
|
s.execute(sqlStatement);
|
||||||
}
|
}
|
||||||
return s.executeBatch();
|
return s.getUpdateCount();
|
||||||
} catch (SQLException aSqlExc) {
|
} catch (SQLException aSqlExc) {
|
||||||
Exception exc = aSqlExc.getNextException();
|
Exception exc = aSqlExc.getNextException();
|
||||||
if (exc == null) {
|
if (exc == null) {
|
||||||
@ -82,10 +80,7 @@ public class JDBCProcessor extends AbstractProcessor {
|
|||||||
throw new ProcessorException(aExc.getMessage());
|
throw new ProcessorException(aExc.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
if (c != null) {
|
if (c != null) {
|
||||||
try {
|
try { c.close(); } catch (Exception exc) { }
|
||||||
c.close();
|
|
||||||
} catch (Exception exc) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import de.hsadmin.core.model.AbstractEntity;
|
|||||||
import de.hsadmin.core.qserv.EntityProcessorFactory;
|
import de.hsadmin.core.qserv.EntityProcessorFactory;
|
||||||
import de.hsadmin.core.qserv.JDBCProcessor;
|
import de.hsadmin.core.qserv.JDBCProcessor;
|
||||||
import de.hsadmin.core.qserv.Processor;
|
import de.hsadmin.core.qserv.Processor;
|
||||||
|
import de.hsadmin.core.qserv.ProcessorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory class which creates Processor instances for dealing with UNIX user
|
* Factory class which creates Processor instances for dealing with UNIX user
|
||||||
@ -20,12 +21,12 @@ public class MySqlDatabaseProcessorFactory implements EntityProcessorFactory {
|
|||||||
"jdbc:mysql://localhost/" + database, user, password);
|
"jdbc:mysql://localhost/" + database, user, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JDBCProcessor createMySqlAdminProcessor() {
|
public static JDBCProcessor createMySqlAdminProcessor() throws ProcessorException {
|
||||||
return new JDBCProcessor("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/");
|
return new JDBCProcessor("com.mysql.jdbc.Driver", "jdbc:mysql://localhost/");
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends AbstractEntity> Processor createCreateProcessor(
|
public <T extends AbstractEntity> Processor createCreateProcessor(
|
||||||
EntityManager em, T entity) {
|
EntityManager em, T entity) throws ProcessorException {
|
||||||
Database db = (Database) entity;
|
Database db = (Database) entity;
|
||||||
assert db.getInstance().equals("mysql");
|
assert db.getInstance().equals("mysql");
|
||||||
JDBCProcessor aJDBCP = null;
|
JDBCProcessor aJDBCP = null;
|
||||||
@ -38,7 +39,7 @@ public class MySqlDatabaseProcessorFactory implements EntityProcessorFactory {
|
|||||||
return aJDBCP;
|
return aJDBCP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em, T entity) {
|
public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em, T entity) throws ProcessorException {
|
||||||
Database db = (Database) entity;
|
Database db = (Database) entity;
|
||||||
assert db.getInstance().equals("mysql");
|
assert db.getInstance().equals("mysql");
|
||||||
String aName = AbstractEntity.escapeString(db.getName());
|
String aName = AbstractEntity.escapeString(db.getName());
|
||||||
@ -49,7 +50,7 @@ public class MySqlDatabaseProcessorFactory implements EntityProcessorFactory {
|
|||||||
return aJDBCP;
|
return aJDBCP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends AbstractEntity> Processor createDeleteProcessor(EntityManager em, T entity) {
|
public <T extends AbstractEntity> Processor createDeleteProcessor(EntityManager em, T entity) throws ProcessorException {
|
||||||
Database db = (Database) entity;
|
Database db = (Database) entity;
|
||||||
assert db.getInstance().equals("mysql");
|
assert db.getInstance().equals("mysql");
|
||||||
JDBCProcessor aJDBCP = createMySqlAdminProcessor();
|
JDBCProcessor aJDBCP = createMySqlAdminProcessor();
|
||||||
|
@ -6,6 +6,7 @@ import de.hsadmin.core.model.AbstractEntity;
|
|||||||
import de.hsadmin.core.qserv.EntityProcessorFactory;
|
import de.hsadmin.core.qserv.EntityProcessorFactory;
|
||||||
import de.hsadmin.core.qserv.JDBCProcessor;
|
import de.hsadmin.core.qserv.JDBCProcessor;
|
||||||
import de.hsadmin.core.qserv.Processor;
|
import de.hsadmin.core.qserv.Processor;
|
||||||
|
import de.hsadmin.core.qserv.ProcessorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory class which creates Processor instances for dealing with UNIX user
|
* Factory class which creates Processor instances for dealing with UNIX user
|
||||||
@ -15,7 +16,7 @@ import de.hsadmin.core.qserv.Processor;
|
|||||||
*/
|
*/
|
||||||
public class MySqlUserProcessorFactory implements EntityProcessorFactory {
|
public class MySqlUserProcessorFactory implements EntityProcessorFactory {
|
||||||
|
|
||||||
public <T extends AbstractEntity> Processor createCreateProcessor(EntityManager em, T entity) {
|
public <T extends AbstractEntity> Processor createCreateProcessor(EntityManager em, T entity) throws ProcessorException {
|
||||||
DatabaseUser dbu = (DatabaseUser) entity;
|
DatabaseUser dbu = (DatabaseUser) entity;
|
||||||
assert dbu.getInstance().equals("mysql");
|
assert dbu.getInstance().equals("mysql");
|
||||||
JDBCProcessor aJDBCP = MySqlDatabaseProcessorFactory.createMySqlAdminProcessor();
|
JDBCProcessor aJDBCP = MySqlDatabaseProcessorFactory.createMySqlAdminProcessor();
|
||||||
@ -25,7 +26,7 @@ public class MySqlUserProcessorFactory implements EntityProcessorFactory {
|
|||||||
return aJDBCP;
|
return aJDBCP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em, T entity) {
|
public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em, T entity) throws ProcessorException {
|
||||||
DatabaseUser dbu = (DatabaseUser) entity;
|
DatabaseUser dbu = (DatabaseUser) entity;
|
||||||
assert dbu.getInstance().equals("mysql");
|
assert dbu.getInstance().equals("mysql");
|
||||||
JDBCProcessor aJDBCP = MySqlDatabaseProcessorFactory.createMySqlAdminProcessor();
|
JDBCProcessor aJDBCP = MySqlDatabaseProcessorFactory.createMySqlAdminProcessor();
|
||||||
@ -35,7 +36,7 @@ public class MySqlUserProcessorFactory implements EntityProcessorFactory {
|
|||||||
return aJDBCP;
|
return aJDBCP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends AbstractEntity> Processor createDeleteProcessor(EntityManager em, T entity) {
|
public <T extends AbstractEntity> Processor createDeleteProcessor(EntityManager em, T entity) throws ProcessorException {
|
||||||
DatabaseUser dbu = (DatabaseUser) entity;
|
DatabaseUser dbu = (DatabaseUser) entity;
|
||||||
assert dbu.getInstance().equals("mysql");
|
assert dbu.getInstance().equals("mysql");
|
||||||
JDBCProcessor aJDBCP = MySqlDatabaseProcessorFactory.createMySqlAdminProcessor();
|
JDBCProcessor aJDBCP = MySqlDatabaseProcessorFactory.createMySqlAdminProcessor();
|
||||||
|
@ -6,6 +6,7 @@ import de.hsadmin.core.model.AbstractEntity;
|
|||||||
import de.hsadmin.core.qserv.EntityProcessorFactory;
|
import de.hsadmin.core.qserv.EntityProcessorFactory;
|
||||||
import de.hsadmin.core.qserv.JDBCProcessor;
|
import de.hsadmin.core.qserv.JDBCProcessor;
|
||||||
import de.hsadmin.core.qserv.Processor;
|
import de.hsadmin.core.qserv.Processor;
|
||||||
|
import de.hsadmin.core.qserv.ProcessorException;
|
||||||
|
|
||||||
public class PgSqlDatabaseProcessorFactory implements EntityProcessorFactory {
|
public class PgSqlDatabaseProcessorFactory implements EntityProcessorFactory {
|
||||||
|
|
||||||
@ -13,11 +14,11 @@ public class PgSqlDatabaseProcessorFactory implements EntityProcessorFactory {
|
|||||||
return new JDBCProcessor("org.postgresql.Driver", "jdbc:postgresql://localhost/template1", user, password);
|
return new JDBCProcessor("org.postgresql.Driver", "jdbc:postgresql://localhost/template1", user, password);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JDBCProcessor createPostgreSqlAdminProcessor() {
|
public static JDBCProcessor createPostgreSqlAdminProcessor() throws ProcessorException {
|
||||||
return new JDBCProcessor("org.postgresql.Driver", "jdbc:postgresql://localhost/template1");
|
return new JDBCProcessor("org.postgresql.Driver", "jdbc:postgresql://localhost/template1");
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends AbstractEntity> Processor createCreateProcessor(EntityManager em, T entity) {
|
public <T extends AbstractEntity> Processor createCreateProcessor(EntityManager em, T entity) throws ProcessorException {
|
||||||
Database db = (Database) entity;
|
Database db = (Database) entity;
|
||||||
assert db.getInstance().equals("pgsql");
|
assert db.getInstance().equals("pgsql");
|
||||||
JDBCProcessor aJDBCP = null;
|
JDBCProcessor aJDBCP = null;
|
||||||
@ -29,7 +30,7 @@ public class PgSqlDatabaseProcessorFactory implements EntityProcessorFactory {
|
|||||||
return aJDBCP;
|
return aJDBCP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em, T entity) {
|
public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em, T entity) throws ProcessorException {
|
||||||
Database db = (Database) entity;
|
Database db = (Database) entity;
|
||||||
assert db.getInstance().equals("pgsql");
|
assert db.getInstance().equals("pgsql");
|
||||||
String aName = AbstractEntity.escapeString(db.getName());
|
String aName = AbstractEntity.escapeString(db.getName());
|
||||||
@ -40,7 +41,7 @@ public class PgSqlDatabaseProcessorFactory implements EntityProcessorFactory {
|
|||||||
return aJDBCP;
|
return aJDBCP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends AbstractEntity> Processor createDeleteProcessor(EntityManager em, T entity) {
|
public <T extends AbstractEntity> Processor createDeleteProcessor(EntityManager em, T entity) throws ProcessorException {
|
||||||
Database db = (Database) entity;
|
Database db = (Database) entity;
|
||||||
assert db.getInstance().equals("pgsql");
|
assert db.getInstance().equals("pgsql");
|
||||||
JDBCProcessor aJDBCP = createPostgreSqlAdminProcessor();
|
JDBCProcessor aJDBCP = createPostgreSqlAdminProcessor();
|
||||||
|
@ -6,6 +6,7 @@ import de.hsadmin.core.model.AbstractEntity;
|
|||||||
import de.hsadmin.core.qserv.EntityProcessorFactory;
|
import de.hsadmin.core.qserv.EntityProcessorFactory;
|
||||||
import de.hsadmin.core.qserv.JDBCProcessor;
|
import de.hsadmin.core.qserv.JDBCProcessor;
|
||||||
import de.hsadmin.core.qserv.Processor;
|
import de.hsadmin.core.qserv.Processor;
|
||||||
|
import de.hsadmin.core.qserv.ProcessorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory class which creates Processor instances for dealing with UNIX user
|
* Factory class which creates Processor instances for dealing with UNIX user
|
||||||
@ -15,7 +16,7 @@ import de.hsadmin.core.qserv.Processor;
|
|||||||
*/
|
*/
|
||||||
public class PgSqlUserProcessorFactory implements EntityProcessorFactory {
|
public class PgSqlUserProcessorFactory implements EntityProcessorFactory {
|
||||||
|
|
||||||
public <T extends AbstractEntity> Processor createCreateProcessor(EntityManager em, T entity) {
|
public <T extends AbstractEntity> Processor createCreateProcessor(EntityManager em, T entity) throws ProcessorException {
|
||||||
DatabaseUser dbu = (DatabaseUser) entity;
|
DatabaseUser dbu = (DatabaseUser) entity;
|
||||||
assert dbu.getInstance().equals("pgsql");
|
assert dbu.getInstance().equals("pgsql");
|
||||||
JDBCProcessor aJDBCP = PgSqlDatabaseProcessorFactory.createPostgreSqlAdminProcessor();
|
JDBCProcessor aJDBCP = PgSqlDatabaseProcessorFactory.createPostgreSqlAdminProcessor();
|
||||||
@ -25,7 +26,7 @@ public class PgSqlUserProcessorFactory implements EntityProcessorFactory {
|
|||||||
return aJDBCP;
|
return aJDBCP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em, T entity) {
|
public <T extends AbstractEntity> Processor createUpdateProcessor(EntityManager em, T entity) throws ProcessorException {
|
||||||
DatabaseUser dbu = (DatabaseUser) entity;
|
DatabaseUser dbu = (DatabaseUser) entity;
|
||||||
assert dbu.getInstance().equals("pgsql");
|
assert dbu.getInstance().equals("pgsql");
|
||||||
JDBCProcessor aJDBCP = PgSqlDatabaseProcessorFactory.createPostgreSqlAdminProcessor();
|
JDBCProcessor aJDBCP = PgSqlDatabaseProcessorFactory.createPostgreSqlAdminProcessor();
|
||||||
@ -35,7 +36,7 @@ public class PgSqlUserProcessorFactory implements EntityProcessorFactory {
|
|||||||
return aJDBCP;
|
return aJDBCP;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends AbstractEntity> Processor createDeleteProcessor(EntityManager em, T entity) {
|
public <T extends AbstractEntity> Processor createDeleteProcessor(EntityManager em, T entity) throws ProcessorException {
|
||||||
DatabaseUser dbu = (DatabaseUser) entity;
|
DatabaseUser dbu = (DatabaseUser) entity;
|
||||||
assert dbu.getInstance().equals("pgsql");
|
assert dbu.getInstance().equals("pgsql");
|
||||||
JDBCProcessor aJDBCP = PgSqlDatabaseProcessorFactory.createPostgreSqlAdminProcessor();
|
JDBCProcessor aJDBCP = PgSqlDatabaseProcessorFactory.createPostgreSqlAdminProcessor();
|
||||||
|
Loading…
Reference in New Issue
Block a user