8 |
import java.util.HashMap; |
import java.util.HashMap; |
9 |
import java.util.regex.Pattern; |
import java.util.regex.Pattern; |
10 |
|
|
|
import javax.management.RuntimeErrorException; |
|
|
|
|
11 |
import org.apache.commons.lang.ArrayUtils; |
import org.apache.commons.lang.ArrayUtils; |
12 |
import org.apache.commons.lang.StringUtils; |
import org.apache.commons.lang.StringUtils; |
13 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
32 |
* The first group of keys, are all keys provided by Geotools to create a WFS |
* The first group of keys, are all keys provided by Geotools to create a WFS |
33 |
* datastore, like: {@link JDBCDataStore#SCHEMA} .<br/> |
* datastore, like: {@link JDBCDataStore#SCHEMA} .<br/> |
34 |
* The second group are additional keys defined in the enum |
* The second group are additional keys defined in the enum |
35 |
* {@link DbServerSettings.Key}.<br/> |
* {@link GtDbServerSettings.Key}.<br/> |
36 |
* This class can serialize all important parameters needed to define the |
* This class can serialize all important parameters needed to define the |
37 |
* connection into a {@link String} with {@link #toPropertiesString()} and |
* connection into a {@link String} with {@link #toPropertiesString()} and |
38 |
* re-import the String with {@link #parsePropertiesString(String)}. |
* re-import the String with {@link #parsePropertiesString(String)}. |
39 |
*/ |
*/ |
40 |
public class DbServerSettings extends ServerSettings<Object, Object> { |
public class GtDbServerSettings extends AbstractGTServerSettings<Object, Object> { |
41 |
|
|
42 |
Logger log = Logger.getLogger(DbServerSettings.class); |
Logger log = Logger.getLogger(GtDbServerSettings.class); |
43 |
|
|
44 |
public enum DbType { |
public enum DbType { |
45 |
postgis("postgresql"); |
postgis("postgresql"); |
82 |
* <code>null</code> to create a new instance, or an instance to |
* <code>null</code> to create a new instance, or an instance to |
83 |
* edit. |
* edit. |
84 |
* @return <code>null</code> if the user cancelled the creation of a new |
* @return <code>null</code> if the user cancelled the creation of a new |
85 |
* {@link DbServerSettings}, otherwise the edited instance. |
* {@link GtDbServerSettings}, otherwise the edited instance. |
86 |
*/ |
*/ |
87 |
public static DbServerSettings createOrEdit(Component owner, |
public static GtDbServerSettings createOrEdit(Component owner, |
88 |
DbServerSettings dbServer) { |
GtDbServerSettings dbServer) { |
89 |
boolean newCreated = false; |
boolean newCreated = false; |
90 |
|
|
91 |
if (dbServer == null) { |
if (dbServer == null) { |
92 |
newCreated = true; |
newCreated = true; |
93 |
dbServer = new DbServerSettings(DbType.postgis); |
dbServer = new GtDbServerSettings(DbType.postgis); |
94 |
} |
} |
95 |
|
|
96 |
Combo<DbType> dpTypeInput = new SelectionInputOption.Combo<DbType>( |
Combo<DbType> dpTypeInput = new SelectionInputOption.Combo<DbType>( |
149 |
* @throws MalformedURLException |
* @throws MalformedURLException |
150 |
*/ |
*/ |
151 |
@Override |
@Override |
152 |
public DbServerSettings parsePropertiesString(String propString) |
public boolean parsePropertiesString(String propString) { |
|
throws MalformedURLException { |
|
153 |
|
|
154 |
if (propString == null || propString.isEmpty()) |
if (propString == null || propString.isEmpty()) |
155 |
throw new IllegalArgumentException("parameter to parse was empty"); |
return false; |
156 |
try { |
try { |
157 |
|
|
158 |
String[] split = propString.split(Pattern.quote(DELIMITER)); |
String[] split = propString.split(Pattern.quote(DELIMITER)); |
159 |
|
|
160 |
int i = 0; |
int i = 0; |
161 |
DbServerSettings dbServer = new DbServerSettings( |
setDbType(DbType.valueOf(split[i++])); |
162 |
DbType.valueOf(split[i++])); |
// DbServerSettings dbServer = new DbServerSettings( |
163 |
|
// DbType.valueOf(split[i++]) |
164 |
dbServer.setTitle(split[i++]); |
// ); |
165 |
dbServer.setHost(split[i++]); |
|
166 |
dbServer.setPort(java.lang.Integer.valueOf(split[i++])); |
setTitle(split[i++]); |
167 |
dbServer.setUsername(StringUtils.stripToNull(split[i++])); |
setHost(split[i++]); |
168 |
dbServer.setPassword(split[i++]); |
setPort(java.lang.Integer.valueOf(split[i++])); |
169 |
dbServer.setDatabase(split[i++]); |
setUsername(StringUtils.stripToNull(split[i++])); |
170 |
dbServer.setExposePrimaryKey(Boolean.valueOf(split[i++])); |
setPassword(split[i++]); |
171 |
dbServer.setSchema(stringOrNull(split[i++])); |
setDatabase(split[i++]); |
172 |
|
setExposePrimaryKey(Boolean.valueOf(split[i++])); |
173 |
|
setSchema(stringOrNull(split[i++])); |
174 |
|
|
175 |
return dbServer; |
return true; |
176 |
} catch (Exception e) { |
} catch (Exception e) { |
177 |
Log.warn("couldn't parse " + propString, e); |
Log.warn("couldn't parse " + propString, e); |
178 |
return null; |
return false; |
179 |
} |
} |
180 |
} |
} |
181 |
|
|
182 |
private String[] cachedTypeNames = null; |
private String[] cachedTypeNames = null; |
183 |
private String[] cachedGeometryTableNames; |
private String[] cachedGeometryTableNames; |
184 |
|
|
185 |
public DbServerSettings() { |
public GtDbServerSettings() { |
186 |
this(DbType.postgis); |
this(DbType.postgis); |
187 |
|
|
188 |
} |
} |
189 |
|
|
190 |
public DbServerSettings(DbType dbType) { |
public GtDbServerSettings(DbType dbType) { |
191 |
setDbType(dbType); |
setDbType(dbType); |
192 |
setHost("localhost"); |
setHost("localhost"); |
193 |
setSchema("public"); |
setSchema("public"); |
194 |
put(JDBCDataStoreFactory.PK_METADATA_TABLE.key, null); |
put(JDBCDataStoreFactory.PK_METADATA_TABLE.key, null); |
195 |
} |
} |
196 |
|
|
197 |
public DbServerSettings(String propertiesString) { |
public GtDbServerSettings(String propertiesString) { |
198 |
try { |
parsePropertiesString(propertiesString); |
|
parsePropertiesString(propertiesString); |
|
|
} catch (MalformedURLException e) { |
|
|
throw new RuntimeException(e); |
|
|
} |
|
199 |
} |
} |
200 |
|
|
201 |
public String[] getCachedTypeNames() { |
public String[] getCachedTypeNames() { |