/[schmitzm]/branches/2.4.x/src/skrueger/geotools/io/GtDbServerSettings.java
ViewVC logotype

Diff of /branches/2.4.x/src/skrueger/geotools/io/GtDbServerSettings.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/src/skrueger/geotools/io/DbServerSettings.java revision 1291 by alfonx, Mon Nov 22 01:18:13 2010 UTC trunk/src/skrueger/geotools/io/GtDbServerSettings.java revision 1327 by alfonx, Sun Dec 5 17:23:22 2010 UTC
# Line 8  import java.sql.SQLException; Line 8  import java.sql.SQLException;
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.NotImplementedException;
13  import org.apache.commons.lang.StringUtils;  import org.apache.commons.lang.StringUtils;
14  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
15  import org.geotools.data.postgis.PostgisNGDataStoreFactory;  import org.geotools.data.postgis.PostgisNGDataStoreFactory;
# Line 34  import skrueger.db.PGUtil; Line 33  import skrueger.db.PGUtil;
33   * 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
34   * datastore, like: {@link JDBCDataStore#SCHEMA} .<br/>   * datastore, like: {@link JDBCDataStore#SCHEMA} .<br/>
35   * The second group are additional keys defined in the enum   * The second group are additional keys defined in the enum
36   * {@link DbServerSettings.Key}.<br/>   * {@link GtDbServerSettings.Key}.<br/>
37   * This class can serialize all important parameters needed to define the   * This class can serialize all important parameters needed to define the
38   * connection into a {@link String} with {@link #toPropertiesString()} and   * connection into a {@link String} with {@link #toPropertiesString()} and
39   * re-import the String with {@link #parsePropertiesString(String)}.   * re-import the String with {@link #parsePropertiesString(String)}.
40   */   */
41  public class DbServerSettings extends ServerSettings<Object, Object> {  public class GtDbServerSettings extends
42                    AbstractGTServerSettings<Object, Object> {
43    
44          Logger log = Logger.getLogger(DbServerSettings.class);          Logger log = Logger.getLogger(GtDbServerSettings.class);
45    
46          public enum DbType {          public enum DbType {
47                  postgis("postgresql");                  postgis("postgresql");
# Line 84  public class DbServerSettings extends Se Line 84  public class DbServerSettings extends Se
84           *            <code>null</code> to create a new instance, or an instance to           *            <code>null</code> to create a new instance, or an instance to
85           *            edit.           *            edit.
86           * @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
87           *         {@link DbServerSettings}, otherwise the edited instance.           *         {@link GtDbServerSettings}, otherwise the edited instance.
88           */           */
89          public static DbServerSettings createOrEdit(Component owner,          public static GtDbServerSettings createOrEdit(Component owner,
90                          DbServerSettings dbServer) {                          GtDbServerSettings dbServer) {
91                  boolean newCreated = false;                  boolean newCreated = false;
92    
93                  if (dbServer == null) {                  if (dbServer == null) {
94                          newCreated = true;                          newCreated = true;
95                          dbServer = new DbServerSettings(DbType.postgis);                          dbServer = new GtDbServerSettings(DbType.postgis);
96                  }                  }
97    
98                  Combo<DbType> dpTypeInput = new SelectionInputOption.Combo<DbType>(                  Combo<DbType> dpTypeInput = new SelectionInputOption.Combo<DbType>(
# Line 151  public class DbServerSettings extends Se Line 151  public class DbServerSettings extends Se
151           * @throws MalformedURLException           * @throws MalformedURLException
152           */           */
153          @Override          @Override
154          public DbServerSettings parsePropertiesString(String propString)          public boolean parsePropertiesString(String propString) {
                         throws MalformedURLException {  
155    
156                  if (propString == null || propString.isEmpty())                  if (propString == null || propString.isEmpty())
157                          throw new IllegalArgumentException("parameter to parse was empty");                          return false;
158                  try {                  try {
159    
160                          String[] split = propString.split(Pattern.quote(DELIMITER));                          String[] split = propString.split(Pattern.quote(DELIMITER));
161    
162                          int i = 0;                          int i = 0;
163                          DbServerSettings dbServer = new DbServerSettings(                          setDbType(DbType.valueOf(split[i++]));
164                                          DbType.valueOf(split[i++]));                          // DbServerSettings dbServer = new DbServerSettings(
165                            // DbType.valueOf(split[i++])
166                          dbServer.setTitle(split[i++]);                          // );
167                          dbServer.setHost(split[i++]);  
168                          dbServer.setPort(java.lang.Integer.valueOf(split[i++]));                          setTitle(split[i++]);
169                          dbServer.setUsername(StringUtils.stripToNull(split[i++]));                          setHost(split[i++]);
170                          dbServer.setPassword(split[i++]);                          setPort(java.lang.Integer.valueOf(split[i++]));
171                          dbServer.setDatabase(split[i++]);                          setUsername(StringUtils.stripToNull(split[i++]));
172                          dbServer.setExposePrimaryKey(Boolean.valueOf(split[i++]));                          setPassword(split[i++]);
173                          dbServer.setSchema(stringOrNull(split[i++]));                          setDatabase(split[i++]);
174                            setExposePrimaryKey(Boolean.valueOf(split[i++]));
175                            setSchema(stringOrNull(split[i++]));
176    
177                          return dbServer;                          return true;
178                  } catch (Exception e) {                  } catch (Exception e) {
179                          Log.warn("couldn't parse " + propString, e);                          Log.warn("couldn't parse " + propString, e);
180                          return null;                          return false;
181                  }                  }
182          }          }
183    
184          private String[] cachedTypeNames = null;          private String[] cachedTypeNames = null;
185          private String[] cachedGeometryTableNames;          private String[] cachedGeometryTableNames;
186    
187          public DbServerSettings() {          public GtDbServerSettings() {
188                  this(DbType.postgis);                  this(DbType.postgis);
189                    
190          }          }
191    
192          public DbServerSettings(DbType dbType) {          public GtDbServerSettings(DbType dbType) {
193                  setDbType(dbType);                  setDbType(dbType);
194                  setHost("localhost");                  setHost("localhost");
195                  setSchema("public");                  setSchema("public");
196                  put(JDBCDataStoreFactory.PK_METADATA_TABLE.key, null);                  put(JDBCDataStoreFactory.PK_METADATA_TABLE.key, null);
197          }          }
198    
199          public DbServerSettings(String propertiesString) {          public GtDbServerSettings(String propertiesString) {
200                  try {                  parsePropertiesString(propertiesString);
                         parsePropertiesString(propertiesString);  
                 } catch (MalformedURLException e) {  
                         throw new RuntimeException(e);  
                 }  
201          }          }
202    
203          public String[] getCachedTypeNames() {          public String[] getCachedTypeNames() {
# Line 470  public class DbServerSettings extends Se Line 467  public class DbServerSettings extends Se
467                                          + toString(), e);                                          + toString(), e);
468                  }                  }
469          }          }
470    
471            @Override
472            public boolean isAvailable() {
473                    // TODO
474                    throw new NotImplementedException("");
475            }
476  }  }

Legend:
Removed from v.1291  
changed lines
  Added in v.1327

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26