Mercurial Hosting > luan
comparison src/luan/modules/lucene/PostgresBackup.java @ 1393:cc0dbca576dc
better logging
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 06 Sep 2019 05:09:56 -0600 |
parents | 002152af497a |
children | 67c0e47b5be3 |
comparison
equal
deleted
inserted
replaced
1392:002152af497a | 1393:cc0dbca576dc |
---|---|
15 import luan.LuanTable; | 15 import luan.LuanTable; |
16 import luan.LuanFunction; | 16 import luan.LuanFunction; |
17 import luan.LuanException; | 17 import luan.LuanException; |
18 import luan.modules.Utils; | 18 import luan.modules.Utils; |
19 import luan.modules.parsers.LuanToString; | 19 import luan.modules.parsers.LuanToString; |
20 import luan.modules.logging.LuanLogger; | |
21 import luan.lib.logging.Logger; | 20 import luan.lib.logging.Logger; |
22 import luan.lib.logging.LoggerFactory; | 21 import luan.lib.logging.LoggerFactory; |
23 | 22 |
24 | 23 |
25 final class PostgresBackup { | 24 final class PostgresBackup { |
26 private static final Logger logger = LoggerFactory.getLogger(PostgresBackup.class); | 25 private static final Logger sysLogger = LoggerFactory.getLogger(PostgresBackup.class); |
26 | |
27 private final Logger luanLogger; | |
27 | 28 |
28 final boolean wasCreated; | 29 final boolean wasCreated; |
29 private final String url; | 30 private final String url; |
30 private final Properties props = new Properties(); | 31 private final Properties props = new Properties(); |
31 private final Connection con; | 32 private final Connection con; |
33 private final PreparedStatement updateStmt; | 34 private final PreparedStatement updateStmt; |
34 private final PreparedStatement deleteStmt; | 35 private final PreparedStatement deleteStmt; |
35 private int trans = 0; | 36 private int trans = 0; |
36 private final LuanToString luanToString = new LuanToString(); | 37 private final LuanToString luanToString = new LuanToString(); |
37 | 38 |
38 PostgresBackup(Map spec) | 39 PostgresBackup(Luan luan,Map spec) |
39 throws ClassNotFoundException, SQLException, LuanException | 40 throws ClassNotFoundException, SQLException, LuanException |
40 { | 41 { |
42 this.luanLogger = luan.getLogger(PostgresBackup.class); | |
41 /* | 43 /* |
42 Class.forName("org.postgresql.Driver"); | 44 Class.forName("org.postgresql.Driver"); |
43 url = "jdbc:postgresql://localhost:5432/luan"; | 45 url = "jdbc:postgresql://localhost:5432/luan"; |
44 props.setProperty("user","postgres"); | 46 props.setProperty("user","postgres"); |
45 props.setProperty("password",""); | 47 props.setProperty("password",""); |
96 } | 98 } |
97 | 99 |
98 protected void finalize() throws Throwable { | 100 protected void finalize() throws Throwable { |
99 super.finalize(); | 101 super.finalize(); |
100 if( !con.isClosed() ) { | 102 if( !con.isClosed() ) { |
101 logger.error("con not closed"); | 103 sysLogger.error("con not closed"); |
102 con.close(); | 104 con.close(); |
103 } | 105 } |
104 } | 106 } |
105 | 107 |
106 void add(LuanTable doc) throws LuanException, SQLException { | 108 void add(LuanTable doc) throws LuanException, SQLException { |
116 String data = luanToString.toString(doc); | 118 String data = luanToString.toString(doc); |
117 updateStmt.setString(1,data); | 119 updateStmt.setString(1,data); |
118 updateStmt.setLong(2,id); | 120 updateStmt.setLong(2,id); |
119 int n = updateStmt.executeUpdate(); | 121 int n = updateStmt.executeUpdate(); |
120 if( n==0 ) { | 122 if( n==0 ) { |
121 Logger logger = LuanLogger.getLogger(doc.luan(),PostgresBackup.class); | 123 luanLogger.error("update not found for id="+id+", trying add"); |
122 logger.error("update not found for id="+id+", trying add"); | |
123 add(doc); | 124 add(doc); |
124 } else if( n!=1 ) | 125 } else if( n!=1 ) |
125 throw new RuntimeException(); | 126 throw new RuntimeException(); |
126 } | 127 } |
127 | 128 |