Merge branch 'master' of ssh://dev.hostsharing.net:29418/hsadmin/hs.hsadmin
This commit is contained in:
commit
f9be1a497c
@ -6,33 +6,37 @@ import java.sql.SQLException;
|
|||||||
import java.sql.Statement;
|
import java.sql.Statement;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
import de.hsadmin.core.util.Config;
|
import de.hsadmin.core.util.Config;
|
||||||
|
import de.hsadmin.core.util.TextUtil;
|
||||||
|
|
||||||
public class JDBCProcessor extends AbstractProcessor {
|
public class JDBCProcessor extends AbstractProcessor {
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private static final Logger LOG = Logger.getLogger(JDBCProcessor.class.getName());
|
||||||
|
|
||||||
final private String driver;
|
final private String driver;
|
||||||
final private String url;
|
final private String url;
|
||||||
final private String user;
|
|
||||||
final private String password;
|
|
||||||
final private List<String> sql;
|
final private List<String> sql;
|
||||||
|
|
||||||
private String errorMsg;
|
private String errorMsg;
|
||||||
|
|
||||||
public JDBCProcessor(final String driver, final String url, final String user, final String password) {
|
public JDBCProcessor(final String driver, final String url) throws ProcessorException {
|
||||||
this.driver = driver;
|
this.driver = driver;
|
||||||
this.url = url;
|
this.url = url;
|
||||||
this.user = user;
|
|
||||||
this.password = password;
|
|
||||||
this.errorMsg = "";
|
this.errorMsg = "";
|
||||||
this.sql = new ArrayList<String>();
|
this.sql = new ArrayList<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public JDBCProcessor(final String driver, final String url) throws ProcessorException {
|
public void addSQL(String sqlStatement) {
|
||||||
this.driver = driver;
|
sql.add(sqlStatement);
|
||||||
this.url = url;
|
}
|
||||||
|
|
||||||
|
public Object process() throws ProcessorException {
|
||||||
|
Connection c = null;
|
||||||
|
String user, password;
|
||||||
final Config config = Config.getInstance();
|
final Config config = Config.getInstance();
|
||||||
if ("com.mysql.jdbc.Driver".equals(driver)) {
|
if ("com.mysql.jdbc.Driver".equals(driver)) {
|
||||||
user = config.getProperty("mysqladmin.user", "root");
|
user = config.getProperty("mysqladmin.user", "root");
|
||||||
@ -45,16 +49,7 @@ public class JDBCProcessor extends AbstractProcessor {
|
|||||||
throw new ProcessorException("database admin-user configuration failed");
|
throw new ProcessorException("database admin-user configuration failed");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.errorMsg = "";
|
LOG.info("process() - DB-User: " + user + " Password: " + TextUtil.hidePassword(password));
|
||||||
this.sql = new ArrayList<String>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addSQL(String sqlStatement) {
|
|
||||||
sql.add(sqlStatement);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object process() throws ProcessorException {
|
|
||||||
Connection c = null;
|
|
||||||
try {
|
try {
|
||||||
Class.forName(driver);
|
Class.forName(driver);
|
||||||
c = DriverManager.getConnection(url, user, password);
|
c = DriverManager.getConnection(url, user, password);
|
||||||
|
@ -3,10 +3,13 @@ package de.hsadmin.core.util;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
public class Config {
|
public class Config {
|
||||||
|
|
||||||
private static Config instance;
|
private static Config instance;
|
||||||
|
|
||||||
|
private static Logger LOG = Logger.getLogger(Config.class.getName());
|
||||||
|
|
||||||
private Properties props;
|
private Properties props;
|
||||||
|
|
||||||
@ -27,6 +30,7 @@ public class Config {
|
|||||||
}
|
}
|
||||||
if (file.canRead()) {
|
if (file.canRead()) {
|
||||||
try {
|
try {
|
||||||
|
LOG.info("Constructor - Properties-File: " + file.getAbsolutePath());
|
||||||
props.load(new FileReader(file));
|
props.load(new FileReader(file));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// should not happen
|
// should not happen
|
||||||
|
@ -76,4 +76,12 @@ public class TextUtil {
|
|||||||
return parsedValue;
|
return parsedValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static synchronized String hidePassword(String passwd) {
|
||||||
|
StringBuffer val = new StringBuffer(passwd.substring(0, 2));
|
||||||
|
for (int i = 2; i < passwd.length(); i++) {
|
||||||
|
val.append('*');
|
||||||
|
}
|
||||||
|
return val.toString();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -15,11 +15,12 @@ import de.hsadmin.core.qserv.ProcessorException;
|
|||||||
* @author mi
|
* @author mi
|
||||||
*/
|
*/
|
||||||
public class MySqlDatabaseProcessorFactory implements EntityProcessorFactory {
|
public class MySqlDatabaseProcessorFactory implements EntityProcessorFactory {
|
||||||
public static JDBCProcessor createMySqlProcessor(String database,
|
|
||||||
String user, String password) {
|
// public static JDBCProcessor createMySqlProcessor(String database,
|
||||||
return new JDBCProcessor("com.mysql.jdbc.Driver",
|
// String user, String password) {
|
||||||
"jdbc:mysql://localhost/" + database, user, password);
|
// return new JDBCProcessor("com.mysql.jdbc.Driver",
|
||||||
}
|
// "jdbc:mysql://localhost/" + database, user, password);
|
||||||
|
// }
|
||||||
|
|
||||||
public static JDBCProcessor createMySqlAdminProcessor() throws ProcessorException {
|
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/");
|
||||||
|
@ -10,9 +10,9 @@ import de.hsadmin.core.qserv.ProcessorException;
|
|||||||
|
|
||||||
public class PgSqlDatabaseProcessorFactory implements EntityProcessorFactory {
|
public class PgSqlDatabaseProcessorFactory implements EntityProcessorFactory {
|
||||||
|
|
||||||
public static JDBCProcessor createPostgreSqlProcessor(String user, String password) {
|
// public static JDBCProcessor createPostgreSqlProcessor(String user, String password) {
|
||||||
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() throws ProcessorException {
|
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");
|
||||||
|
Loading…
Reference in New Issue
Block a user