Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/utils/MapUtils.java @ 8202:e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Fri, 05 Sep 2014 12:58:17 +0200 |
parents | af13ceeba52a |
children | 5e38e2924c07 |
comparison
equal
deleted
inserted
replaced
8201:4b8c5a08de04 | 8202:e4606eae8ea5 |
---|---|
17 import org.dive4elements.river.backend.SessionFactoryProvider; | 17 import org.dive4elements.river.backend.SessionFactoryProvider; |
18 | 18 |
19 | 19 |
20 public class MapUtils | 20 public class MapUtils |
21 { | 21 { |
22 private static final Logger logger = Logger.getLogger(MapUtils.class); | 22 private static final Logger log = Logger.getLogger(MapUtils.class); |
23 | 23 |
24 public static final Pattern DB_URL_PATTERN = | 24 public static final Pattern DB_URL_PATTERN = |
25 Pattern.compile("(.*)\\/\\/(.*):([0-9]+)\\/([\\.a-zA-Z0-9_-]+)"); | 25 Pattern.compile("(.*)\\/\\/(.*):([0-9]+)\\/([\\.a-zA-Z0-9_-]+)"); |
26 | 26 |
27 public static final Pattern DB_PSQL_URL_PATTERN = | 27 public static final Pattern DB_PSQL_URL_PATTERN = |
39 | 39 |
40 String user = SessionFactoryProvider.getUser(sf); | 40 String user = SessionFactoryProvider.getUser(sf); |
41 String pass = SessionFactoryProvider.getPass(sf); | 41 String pass = SessionFactoryProvider.getPass(sf); |
42 String url = SessionFactoryProvider.getURL(sf); | 42 String url = SessionFactoryProvider.getURL(sf); |
43 | 43 |
44 logger.debug("Parse connection url: " + url); | 44 log.debug("Parse connection url: " + url); |
45 | 45 |
46 Matcher m = DB_URL_PATTERN.matcher(url); | 46 Matcher m = DB_URL_PATTERN.matcher(url); |
47 if (!m.matches()) { | 47 if (!m.matches()) { |
48 logger.warn("Could not parse Connection string." + | 48 log.warn("Could not parse Connection string." + |
49 "Try to parse PostgreSQL string."); | 49 "Try to parse PostgreSQL string."); |
50 // maybe this is a PostgreSQL connection... | 50 // maybe this is a PostgreSQL connection... |
51 return getPostgreSQLConnection(); | 51 return getPostgreSQLConnection(); |
52 } | 52 } |
53 | 53 |
54 logger.debug("Groups for connection string: " + m.groupCount()); | 54 log.debug("Groups for connection string: " + m.groupCount()); |
55 int groups = m.groupCount(); | 55 int groups = m.groupCount(); |
56 | 56 |
57 | 57 |
58 if (logger.isDebugEnabled()) { | 58 if (log.isDebugEnabled()) { |
59 for (int i = 0; i <= groups; i++) { | 59 for (int i = 0; i <= groups; i++) { |
60 logger.debug("Group " + i + ": " + m.group(i)); | 60 log.debug("Group " + i + ": " + m.group(i)); |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 String connection = null; | 64 String connection = null; |
65 | 65 |
66 if (RiverUtils.isUsingOracle()) { | 66 if (RiverUtils.isUsingOracle()) { |
67 if (groups < 4) { | 67 if (groups < 4) { |
68 logger.warn("Could only partially parse connection string."); | 68 log.warn("Could only partially parse connection string."); |
69 return null; | 69 return null; |
70 } | 70 } |
71 | 71 |
72 String host = m.group(2); | 72 String host = m.group(2); |
73 String port = m.group(3); | 73 String port = m.group(3); |
74 String backend = m.group(4); | 74 String backend = m.group(4); |
75 connection = user + "/" + pass + "@" + host + ":" + port + "/" + backend; | 75 connection = user + "/" + pass + "@" + host + ":" + port + "/" + backend; |
76 } | 76 } |
77 else { | 77 else { |
78 if (groups < 4) { | 78 if (groups < 4) { |
79 logger.warn("Could only partially parse connection string."); | 79 log.warn("Could only partially parse connection string."); |
80 return null; | 80 return null; |
81 } | 81 } |
82 | 82 |
83 String host = m.group(2); | 83 String host = m.group(2); |
84 String port = m.group(3); | 84 String port = m.group(3); |
116 String pass = SessionFactoryProvider.getPass(sf); | 116 String pass = SessionFactoryProvider.getPass(sf); |
117 String url = SessionFactoryProvider.getURL(sf); | 117 String url = SessionFactoryProvider.getURL(sf); |
118 | 118 |
119 Matcher m = DB_PSQL_URL_PATTERN.matcher(url); | 119 Matcher m = DB_PSQL_URL_PATTERN.matcher(url); |
120 if (!m.matches()) { | 120 if (!m.matches()) { |
121 logger.warn("Could not parse PostgreSQL Connection string."); | 121 log.warn("Could not parse PostgreSQL Connection string."); |
122 return null; | 122 return null; |
123 } | 123 } |
124 | 124 |
125 int groups = m.groupCount(); | 125 int groups = m.groupCount(); |
126 logger.debug("Groups for PostgreSQL connection string: " + groups); | 126 log.debug("Groups for PostgreSQL connection string: " + groups); |
127 | 127 |
128 if (logger.isDebugEnabled()) { | 128 if (log.isDebugEnabled()) { |
129 for (int i = 0; i <= groups; i++) { | 129 for (int i = 0; i <= groups; i++) { |
130 logger.debug("Group " + i + ": " + m.group(i)); | 130 log.debug("Group " + i + ": " + m.group(i)); |
131 } | 131 } |
132 } | 132 } |
133 | 133 |
134 String connection = null; | 134 String connection = null; |
135 | 135 |
136 if (groups < 4) { | 136 if (groups < 4) { |
137 logger.warn("Could only partially parse connection string."); | 137 log.warn("Could only partially parse connection string."); |
138 return null; | 138 return null; |
139 } | 139 } |
140 | 140 |
141 String host = m.group(2); | 141 String host = m.group(2); |
142 String port = m.group(3); | 142 String port = m.group(3); |
143 String db = m.group(4); | 143 String db = m.group(4); |
144 | 144 |
145 connection = createConnectionString(user, pass, host, db, port); | 145 connection = createConnectionString(user, pass, host, db, port); |
146 | 146 |
147 logger.debug("Created connection: '" + connection + "'"); | 147 log.debug("Created connection: '" + connection + "'"); |
148 | 148 |
149 return connection; | 149 return connection; |
150 } | 150 } |
151 | 151 |
152 public static String getConnectionType() { | 152 public static String getConnectionType() { |