11 changed files with 288 additions and 8 deletions
@ -1,10 +1,20 @@ |
|||||||
<?xml version="1.0" encoding="UTF-8"?> |
<?xml version="1.0" encoding="UTF-8"?> |
||||||
<classpath> |
<classpath> |
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11"> |
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> |
||||||
<attributes> |
<attributes> |
||||||
<attribute name="module" value="true"/> |
<attribute name="maven.pomderived" value="true"/> |
||||||
</attributes> |
</attributes> |
||||||
</classpathentry> |
</classpathentry> |
||||||
<classpathentry kind="src" path="src"/> |
<classpathentry kind="src" output="target/classes" path="src"> |
||||||
<classpathentry kind="output" path="bin"/> |
<attributes> |
||||||
|
<attribute name="optional" value="true"/> |
||||||
|
<attribute name="maven.pomderived" value="true"/> |
||||||
|
</attributes> |
||||||
|
</classpathentry> |
||||||
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> |
||||||
|
<attributes> |
||||||
|
<attribute name="maven.pomderived" value="true"/> |
||||||
|
</attributes> |
||||||
|
</classpathentry> |
||||||
|
<classpathentry kind="output" path="target/classes"/> |
||||||
</classpath> |
</classpath> |
||||||
|
|||||||
@ -1,2 +1,3 @@ |
|||||||
/bin/ |
/bin/ |
||||||
/settings.properties |
/settings.properties |
||||||
|
/target/ |
||||||
|
|||||||
@ -1,12 +1,13 @@ |
|||||||
eclipse.preferences.version=1 |
eclipse.preferences.version=1 |
||||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled |
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11 |
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 |
||||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve |
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve |
||||||
org.eclipse.jdt.core.compiler.compliance=11 |
org.eclipse.jdt.core.compiler.compliance=1.7 |
||||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate |
org.eclipse.jdt.core.compiler.debug.lineNumber=generate |
||||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate |
org.eclipse.jdt.core.compiler.debug.localVariable=generate |
||||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate |
org.eclipse.jdt.core.compiler.debug.sourceFile=generate |
||||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error |
||||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error |
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error |
||||||
org.eclipse.jdt.core.compiler.release=enabled |
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning |
||||||
org.eclipse.jdt.core.compiler.source=11 |
org.eclipse.jdt.core.compiler.release=disabled |
||||||
|
org.eclipse.jdt.core.compiler.source=1.7 |
||||||
|
|||||||
@ -0,0 +1,4 @@ |
|||||||
|
activeProfiles= |
||||||
|
eclipse.preferences.version=1 |
||||||
|
resolveWorkspaceProjects=true |
||||||
|
version=1 |
||||||
@ -0,0 +1,41 @@ |
|||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<groupId>org.leolo.internal.transport</groupId> |
||||||
|
<artifactId>nrdata-2</artifactId> |
||||||
|
<version>0.0.1-SNAPSHOT</version> |
||||||
|
<build> |
||||||
|
<sourceDirectory>src</sourceDirectory> |
||||||
|
<plugins> |
||||||
|
<plugin> |
||||||
|
<artifactId>maven-compiler-plugin</artifactId> |
||||||
|
<version>3.8.0</version> |
||||||
|
<configuration> |
||||||
|
<source>1.7</source> |
||||||
|
<target>1.7</target> |
||||||
|
</configuration> |
||||||
|
</plugin> |
||||||
|
</plugins> |
||||||
|
</build> |
||||||
|
<dependencies> |
||||||
|
<dependency> |
||||||
|
<groupId>org.mariadb.jdbc</groupId> |
||||||
|
<artifactId>mariadb-java-client</artifactId> |
||||||
|
<version>2.7.2</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.json</groupId> |
||||||
|
<artifactId>json</artifactId> |
||||||
|
<version>20210307</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.logging.log4j</groupId> |
||||||
|
<artifactId>log4j-core</artifactId> |
||||||
|
<version>2.13.3</version> |
||||||
|
</dependency> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.logging.log4j</groupId> |
||||||
|
<artifactId>log4j-api</artifactId> |
||||||
|
<version>2.13.3</version> |
||||||
|
</dependency> |
||||||
|
</dependencies> |
||||||
|
</project> |
||||||
@ -0,0 +1,14 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<Configuration status="warn"> |
||||||
|
<Appenders> |
||||||
|
<Console name="Console" target="SYSTEM_OUT"> |
||||||
|
<PatternLayout |
||||||
|
pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" /> |
||||||
|
</Console> |
||||||
|
</Appenders> |
||||||
|
<Loggers> |
||||||
|
<Root level="debug"> |
||||||
|
<AppenderRef ref="Console" /> |
||||||
|
</Root> |
||||||
|
</Loggers> |
||||||
|
</Configuration> |
||||||
@ -0,0 +1,103 @@ |
|||||||
|
package org.leolo.transport.nr2; |
||||||
|
|
||||||
|
import java.io.FileReader; |
||||||
|
import java.io.IOException; |
||||||
|
import java.io.PrintStream; |
||||||
|
import java.io.PrintWriter; |
||||||
|
import java.util.Collection; |
||||||
|
import java.util.Enumeration; |
||||||
|
import java.util.Properties; |
||||||
|
import java.util.Set; |
||||||
|
import java.util.function.BiConsumer; |
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager; |
||||||
|
import org.apache.logging.log4j.Logger; |
||||||
|
|
||||||
|
public class ConfigurationManager { |
||||||
|
|
||||||
|
private static ConfigurationManager instance; |
||||||
|
private Logger log = LogManager.getLogger(); |
||||||
|
|
||||||
|
private Properties properties; |
||||||
|
|
||||||
|
public static synchronized final ConfigurationManager getInstance() { |
||||||
|
if(instance==null) { |
||||||
|
instance = new ConfigurationManager(); |
||||||
|
} |
||||||
|
return instance; |
||||||
|
} |
||||||
|
|
||||||
|
private ConfigurationManager() { |
||||||
|
properties = new Properties(); |
||||||
|
try { |
||||||
|
properties.load(new FileReader("settings.properties")); |
||||||
|
} catch (IOException e) { |
||||||
|
log.atError().log(e.getMessage(), e); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public String getProperty(String key) { |
||||||
|
return properties.getProperty(key); |
||||||
|
} |
||||||
|
|
||||||
|
public String getProperty(String key, String defaultValue) { |
||||||
|
return properties.getProperty(key, defaultValue); |
||||||
|
} |
||||||
|
|
||||||
|
public Enumeration<?> propertyNames() { |
||||||
|
return properties.propertyNames(); |
||||||
|
} |
||||||
|
|
||||||
|
public void list(PrintStream out) { |
||||||
|
properties.list(out); |
||||||
|
} |
||||||
|
|
||||||
|
public void list(PrintWriter out) { |
||||||
|
properties.list(out); |
||||||
|
} |
||||||
|
|
||||||
|
public int size() { |
||||||
|
return properties.size(); |
||||||
|
} |
||||||
|
|
||||||
|
public boolean isEmpty() { |
||||||
|
return properties.isEmpty(); |
||||||
|
} |
||||||
|
|
||||||
|
public Enumeration<Object> keys() { |
||||||
|
return properties.keys(); |
||||||
|
} |
||||||
|
|
||||||
|
public boolean contains(Object value) { |
||||||
|
return properties.contains(value); |
||||||
|
} |
||||||
|
|
||||||
|
public boolean containsValue(Object value) { |
||||||
|
return properties.containsValue(value); |
||||||
|
} |
||||||
|
|
||||||
|
public boolean containsKey(Object key) { |
||||||
|
return properties.containsKey(key); |
||||||
|
} |
||||||
|
|
||||||
|
public Object get(Object key) { |
||||||
|
return properties.get(key); |
||||||
|
} |
||||||
|
|
||||||
|
public Set<Object> keySet() { |
||||||
|
return properties.keySet(); |
||||||
|
} |
||||||
|
|
||||||
|
public Collection<Object> values() { |
||||||
|
return properties.values(); |
||||||
|
} |
||||||
|
|
||||||
|
public Object getOrDefault(Object key, Object defaultValue) { |
||||||
|
return properties.getOrDefault(key, defaultValue); |
||||||
|
} |
||||||
|
|
||||||
|
public void forEach(BiConsumer<? super Object, ? super Object> action) { |
||||||
|
properties.forEach(action); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,14 @@ |
|||||||
|
package org.leolo.transport.nr2; |
||||||
|
|
||||||
|
public class Constants { |
||||||
|
|
||||||
|
public static final int RV_NORMAL = 0x00000000; |
||||||
|
public static final int RV_FATAL_ERROR = 0xfeedbeef; |
||||||
|
public static final int RV_DB_CONN_ERROR = 0xfeedbeee; |
||||||
|
|
||||||
|
public static final int DB_MIN_CONN = 5; |
||||||
|
public static final int DB_MAX_CONN = 100; |
||||||
|
|
||||||
|
public static final int MAX_THREAD = 20; |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,22 @@ |
|||||||
|
package org.leolo.transport.nr2; |
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager; |
||||||
|
import org.apache.logging.log4j.Logger; |
||||||
|
|
||||||
|
public class DataLoader { |
||||||
|
|
||||||
|
private Logger log = LogManager.getLogger(); |
||||||
|
|
||||||
|
public static final void main(String [] args) { |
||||||
|
new DataLoader().start(); |
||||||
|
} |
||||||
|
|
||||||
|
private DataLoader() { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
private void start() { |
||||||
|
log.always().log("Started"); |
||||||
|
DatabaseManager.getInstance(); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,64 @@ |
|||||||
|
package org.leolo.transport.nr2; |
||||||
|
|
||||||
|
import java.sql.Connection; |
||||||
|
import java.sql.SQLException; |
||||||
|
|
||||||
|
import javax.sql.XAConnection; |
||||||
|
|
||||||
|
import org.apache.logging.log4j.LogManager; |
||||||
|
import org.apache.logging.log4j.Logger; |
||||||
|
import org.mariadb.jdbc.MariaDbPoolDataSource; |
||||||
|
|
||||||
|
public class DatabaseManager { |
||||||
|
|
||||||
|
private static DatabaseManager instance; |
||||||
|
private static Logger log = LogManager.getLogger(DatabaseManager.class); |
||||||
|
private MariaDbPoolDataSource ds; |
||||||
|
|
||||||
|
|
||||||
|
public synchronized final static DatabaseManager getInstance() { |
||||||
|
if(instance==null) { |
||||||
|
instance = new DatabaseManager(); |
||||||
|
} |
||||||
|
return instance; |
||||||
|
} |
||||||
|
|
||||||
|
private DatabaseManager() { |
||||||
|
ConfigurationManager cm = ConfigurationManager.getInstance(); |
||||||
|
log.atInfo().log("Creating Database Manager"); |
||||||
|
if( |
||||||
|
!cm.containsKey("host") || |
||||||
|
!cm.containsKey("user") || |
||||||
|
!cm.containsKey("pass") || |
||||||
|
!cm.containsKey("name") |
||||||
|
) { |
||||||
|
log.atFatal().log("Missing required parameter!"); |
||||||
|
System.exit(Constants.RV_FATAL_ERROR); |
||||||
|
} |
||||||
|
String url = "jdbc:mariadb://"+cm.getProperty("host")+ |
||||||
|
":3306"+ |
||||||
|
"/"+cm.getProperty("name"); |
||||||
|
log.info("Connecting to DB {} as {}", url, cm.get("user")); |
||||||
|
try { |
||||||
|
ds = new MariaDbPoolDataSource(url); |
||||||
|
ds.setMaxPoolSize(Constants.DB_MAX_CONN); |
||||||
|
ds.setMinPoolSize(Constants.DB_MIN_CONN); |
||||||
|
ds.setUser(cm.getProperty("user").toString()); |
||||||
|
ds.setPassword(cm.getProperty("pwd").toString()); |
||||||
|
} catch (SQLException e) { |
||||||
|
log.fatal("Cannot connect to DB",e); |
||||||
|
System.exit(Constants.RV_DB_CONN_ERROR); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public Connection getConnection() throws SQLException { |
||||||
|
Connection conn = ds.getConnection(); |
||||||
|
conn.setAutoCommit(false); |
||||||
|
return conn; |
||||||
|
} |
||||||
|
|
||||||
|
public XAConnection getXAConnection() throws SQLException { |
||||||
|
XAConnection conn = ds.getXAConnection(); |
||||||
|
return conn; |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue