|
|
@@ -0,0 +1,70 @@
|
|
|
+package ss.db;
|
|
|
+
|
|
|
+import java.sql.Connection;
|
|
|
+import javax.naming.Context;
|
|
|
+import javax.naming.InitialContext;
|
|
|
+import javax.sql.DataSource;
|
|
|
+import org.apache.logging.log4j.LogManager;
|
|
|
+import org.apache.logging.log4j.Logger;
|
|
|
+import ss.WebC;
|
|
|
+
|
|
|
+public class FaceCollectDb {
|
|
|
+ public static final String JNDI_NAME = "jdbc/face_collect";
|
|
|
+
|
|
|
+ private static volatile DataSource dataSource;
|
|
|
+
|
|
|
+ private static final Logger log4j = LogManager.getLogger(FaceCollectDb.class);
|
|
|
+
|
|
|
+ private FaceCollectDb() {
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Db makeConn() {
|
|
|
+ Connection conn = null;
|
|
|
+ try {
|
|
|
+ conn = fetchDataSource().getConnection();
|
|
|
+ conn.setAutoCommit(false);
|
|
|
+ Db gdba = Db.makeConn(conn);
|
|
|
+ if (gdba != null) {
|
|
|
+ DbListener.addThreadDba(gdba);
|
|
|
+ }
|
|
|
+ return gdba;
|
|
|
+ } catch (Exception e) {
|
|
|
+ if (conn != null) {
|
|
|
+ try {
|
|
|
+ conn.close();
|
|
|
+ } catch (Exception closeE) {
|
|
|
+ log4j.error("FaceCollectDb.makeConn() 关闭连接异常", closeE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log4j.error("FaceCollectDb.makeConn() 异常", e);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static Connection makeSqlConn() throws Exception {
|
|
|
+ Connection conn = fetchDataSource().getConnection();
|
|
|
+ conn.setAutoCommit(false);
|
|
|
+ return conn;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static DataSource fetchDataSource() {
|
|
|
+ DataSource localDs = dataSource;
|
|
|
+ if (localDs != null) {
|
|
|
+ return localDs;
|
|
|
+ }
|
|
|
+ synchronized (FaceCollectDb.class) {
|
|
|
+ if (dataSource == null) {
|
|
|
+ try {
|
|
|
+ Context ctx = new InitialContext();
|
|
|
+ if (WebC.AS_tomcatType == base.SsC.AS_type) {
|
|
|
+ ctx = (Context) ctx.lookup("java:comp/env");
|
|
|
+ }
|
|
|
+ dataSource = (DataSource) ctx.lookup(JNDI_NAME);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("获取人脸采集数据源失败: " + JNDI_NAME, e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return dataSource;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|