org.geotools.data.DataAccessFactory.Param Java Examples

The following examples show how to use org.geotools.data.DataAccessFactory.Param. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DatabaseConnectionFactory.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/** Populate name map. */
private static void populateNameMap() {
    Iterator<DataStoreFactorySpi> datastore = DataStoreFinder.getAvailableDataStores();

    while (datastore.hasNext()) {
        DataStoreFactorySpi dSPI = datastore.next();

        Param dbType = null;
        for (Param param : dSPI.getParametersInfo()) {
            if (param.key.equals(JDBCDataStoreFactory.DBTYPE.key)) {
                dbType = param;
                break;
            }
        }
        if (dbType != null) {
            nameMap.put(dSPI.getDisplayName(), (String) dbType.sample);
        }
    }
}
 
Example #2
Source File: DatabaseConnection.java    From sldeditor with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Constructor.
 *
 * @param databaseType the database type
 * @param databaseTypeLabel the database type label
 * @param supportsDuplication the supports duplication
 * @param detailList the detail list
 * @param databaseConnectionName the database connection name
 */
public DatabaseConnection(
        Param databaseType,
        String databaseTypeLabel,
        boolean supportsDuplication,
        List<DatabaseConnectionField> detailList,
        DatabaseConnectionNameInterface databaseConnectionName) {
    this.databaseType = (databaseType == null) ? "" : (String) databaseType.sample;
    this.databaseTypeLabel = databaseTypeLabel;
    this.detailList = detailList;
    this.databaseConnectionName = databaseConnectionName;
    this.supportsDuplication = supportsDuplication;

    createInitialValues();

    this.connectionDataMap = this.initialValues;

    if (detailList != null) {
        for (DatabaseConnectionField param : detailList) {
            if (!param.isOptional() && !(param.isPassword() || param.isUsername())) {
                expectedKeys.add(param.getKey());
            }
        }
    }
}
 
Example #3
Source File: GeoWavePluginConfig.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Override
public Param apply(final ConfigOption input) {
  if (input.isPassword()) {
    return new Param(
        input.getName(),
        String.class,
        input.getDescription(),
        !input.isOptional(),
        "mypassword",
        Collections.singletonMap(Parameter.IS_PASSWORD, Boolean.TRUE));
  }
  if (input.getType().isPrimitive() && (input.getType() == boolean.class)) {
    return new Param(
        input.getName(),
        input.getType(),
        input.getDescription(),
        true,
        "true",
        Collections.singletonMap(Parameter.OPTIONS, BooleanOptions));
  }
  return new Param(
      input.getName(),
      input.getType(),
      input.getDescription(),
      !input.isOptional());
}
 
Example #4
Source File: GeoWavePluginConfigTest.java    From geowave with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws GeoWavePluginException, URISyntaxException {
  final List<Param> params = GeoWavePluginConfig.getPluginParams(new MemoryStoreFactoryFamily());
  final HashMap<String, Serializable> paramValues = new HashMap<>();
  for (final Param param : params) {
    if (param.getName().equals(GeoWavePluginConfig.LOCK_MGT_KEY)) {
      final List<String> options = (List<String>) param.metadata.get(Parameter.OPTIONS);
      assertNotNull(options);
      assertTrue(options.size() > 0);
      paramValues.put(param.getName(), options.get(0));
    } else if (param.getName().equals(GeoWavePluginConfig.FEATURE_NAMESPACE_KEY)) {
      paramValues.put(param.getName(), new URI("http://test/test"));
    } else if (param.getName().equals(GeoWavePluginConfig.TRANSACTION_BUFFER_SIZE)) {
      paramValues.put(param.getName(), 1000);
    } else if (!param.getName().equals(GeoWavePluginConfig.AUTH_URL_KEY)) {
      paramValues.put(
          param.getName(),
          (Serializable) (param.getDefaultValue() == null ? "" : param.getDefaultValue()));
    }
  }
  final GeoWavePluginConfig config =
      new GeoWavePluginConfig(new MemoryStoreFactoryFamily(), paramValues);
  Assert.assertEquals(1000, (int) config.getTransactionBufferSize());
  assertNotNull(config.getLockingManagementFactory());
  assertNotNull(config.getLockingManagementFactory().createLockingManager(config));
}
 
Example #5
Source File: DatabaseConnectionField.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Instantiates a new database connection field.
 *
 * @param param the param
 */
public DatabaseConnectionField(Param param) {
    super();
    this.param = param;
    if (param.key.equals(JDBCDataStoreFactory.USER.key)) {
        username = true;
    }

    password = param.isPassword();
}
 
Example #6
Source File: DatabaseConnectionField.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Instantiates a new database connection field.
 *
 * @param param the param
 * @param fileExtensionFilter the file extension filter
 */
public DatabaseConnectionField(Param param, FileNameExtensionFilter fileExtensionFilter) {
    super();
    this.param = param;
    this.isFilename = true;
    this.fileExtensionFilter = fileExtensionFilter;
}
 
Example #7
Source File: GeoWavePluginConfig.java    From geowave with Apache License 2.0 5 votes vote down vote up
public static synchronized List<Param> getPluginParams(
    final StoreFactoryFamilySpi storeFactoryFamily) {
  List<Param> params = paramMap.get(storeFactoryFamily.getType());
  if (params == null) {
    final ConfigOption[] configOptions =
        GeoWaveStoreFinder.getAllOptions(storeFactoryFamily, false);
    params =
        Arrays.stream(configOptions).map(new GeoWaveConfigOptionToGeoToolsConfigOption()).collect(
            Collectors.toList());
    params.addAll(BASE_GEOWAVE_PLUGIN_PARAMS);
    paramMap.put(storeFactoryFamily.getType(), params);
  }
  return params;
}
 
Example #8
Source File: DataStoreFactoryTest.java    From geomajas-project-server with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void main(String[] args) throws IOException {
    /**
     * Optional - enable/disable the use of memory-mapped io
     */
    Param test = new Param("test",
            Boolean.class, "enable/disable the use of memory-mapped io", false);
    Map<String,Object> map = new HashMap<String,Object>();
    map.put("test", test);
    Boolean b = (Boolean)test.lookUp(map);
    System.out.println(b);

}
 
Example #9
Source File: DatabaseConnectionFactory.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Creates a new DatabaseConnection object for DB2.
 *
 * @return the database connection
 */
public static DatabaseConnection createDB2() {
    List<DatabaseConnectionField> list = new ArrayList<>();

    list.add(new DatabaseConnectionField(DB2NGDataStoreFactory.HOST));
    list.add(new DatabaseConnectionField(DB2NGDataStoreFactory.PORT));
    Param tabSchema = new Param("tabschema", String.class, "Schema", false);
    list.add(new DatabaseConnectionField(tabSchema));
    list.add(new DatabaseConnectionField(DB2NGDataStoreFactory.DATABASE));
    list.add(new DatabaseConnectionField(DB2NGDataStoreFactory.USER));
    list.add(new DatabaseConnectionField(DB2NGDataStoreFactory.PASSWD));

    DB2NGDataStoreFactory factory = new DB2NGDataStoreFactory();

    return new DatabaseConnection(
            DB2NGDataStoreFactory.DBTYPE,
            factory.getDisplayName(),
            true,
            list,
            new DatabaseConnectionNameInterface() {
                /** The Constant serialVersionUID. */
                private static final long serialVersionUID = 1L;

                @Override
                public String getConnectionName(
                        String duplicatePrefix,
                        int noOfTimesDuplicated,
                        Map<String, String> properties) {
                    String connectionName =
                            String.format(
                                    CONNECTION_STRING_4,
                                    properties.get("tabschema"),
                                    properties.get(JDBCDataStoreFactory.DATABASE.key),
                                    properties.get(JDBCDataStoreFactory.HOST.key),
                                    properties.get(JDBCDataStoreFactory.PORT.key));

                    return createConnectionName(
                            connectionName, noOfTimesDuplicated, duplicatePrefix);
                }
            });
}
 
Example #10
Source File: DatabaseConnectionTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Test method for {@link
 * com.sldeditor.common.data.DatabaseConnection#DatabaseConnection(com.sldeditor.common.data.DatabaseConnection)}.
 */
@Test
public void testDatabaseConnection() {
    Param param = GeoPkgDataStoreFactory.DBTYPE;
    List<DatabaseConnectionField> expectedDetailList = new ArrayList<DatabaseConnectionField>();

    expectedDetailList.add(new DatabaseConnectionField(GeoPkgDataStoreFactory.DATABASE));
    expectedDetailList.add(new DatabaseConnectionField(GeoPkgDataStoreFactory.USER));
    String expectedDatabaseTypeLabel = "GeoPackage";
    boolean expectedSupportsDuplication = false;

    DatabaseConnection test =
            new DatabaseConnection(
                    param,
                    expectedDatabaseTypeLabel,
                    expectedSupportsDuplication,
                    expectedDetailList,
                    new DatabaseConnectionNameInterface() {
                        /** The Constant serialVersionUID. */
                        private static final long serialVersionUID = 1L;

                        @Override
                        public String getConnectionName(
                                String duplicatePrefix,
                                int noOfDuplicates,
                                Map<String, String> properties) {
                            String connectionName =
                                    Localisation.getString(
                                            DatabaseConnectionTest.class,
                                            Localisation.COMMON_NOT_SET);
                            String databaseName =
                                    properties.get(GeoPkgDataStoreFactory.DATABASE.key);
                            if (databaseName != null) {
                                File f = new File(databaseName);
                                if (f.isFile()) {
                                    connectionName = f.getName();
                                }
                            }

                            for (int i = 0; i < noOfDuplicates; i++) {
                                connectionName = duplicatePrefix + connectionName;
                            }
                            return connectionName;
                        }
                    });

    Map<String, String> connectionDataMap = new HashMap<String, String>();
    connectionDataMap.put(GeoPkgDataStoreFactory.DATABASE.key, "test datatbase");
    test.setConnectionDataMap(connectionDataMap);
    assertEquals(test.isSupportsDuplication(), expectedSupportsDuplication);
    assertNotNull(test.getConnectionName());
    assertNotNull(test.getDatabaseConnectionName());
    assertEquals(test.getDetailList(), expectedDetailList);
    assertEquals(test.getDatabaseTypeLabel(), expectedDatabaseTypeLabel);
    assertTrue(test.hashCode() != 0);
    assertEquals(1, test.getExpectedKeys().size());
    assertEquals(GeoPkgDataStoreFactory.DATABASE.key, test.getExpectedKeys().get(0));
    assertEquals(test.getDatabaseType(), param.sample);
    assertEquals(
            test.getConnectionDataMap().get(GeoPkgDataStoreFactory.DATABASE.key),
            connectionDataMap.get(GeoPkgDataStoreFactory.DATABASE.key));
    assertEquals(
            test.getConnectionDataMap().get(GeoPkgDataStoreFactory.DBTYPE.key),
            GeoPkgDataStoreFactory.DBTYPE.sample);

    String expectedUserName = "test user";
    test.setUserName(expectedUserName);
    assertEquals(test.getUserName(), expectedUserName);
    assertNotNull(test.getDBConnectionParams());

    String expectedPassword = "password123";
    test.setPassword(expectedPassword);
    assertEquals(test.getPassword(), expectedPassword);

    // Duplicate
    DatabaseConnection testCopy = test.duplicate();

    assertTrue(testCopy.compareTo(test) < 0);

    testCopy.update(test);
    assertEquals(testCopy, test);
    assertEquals(testCopy, testCopy);

    testCopy.setUserName("new username");
    assertFalse(testCopy.equals(test));

    testCopy.update(test);
    assertTrue(testCopy.equals(test));

    String actualString = test.encodeAsString();
    DatabaseConnection newTest = DatabaseConnection.decodeString(actualString);
    assertTrue(newTest.equals(test));
}
 
Example #11
Source File: DatabaseConnectionTest.java    From sldeditor with GNU General Public License v3.0 4 votes vote down vote up
@SuppressWarnings("unlikely-arg-type")
@Test
void testEquals() {
    Param param = GeoPkgDataStoreFactory.DBTYPE;
    List<DatabaseConnectionField> expectedDetailList = new ArrayList<DatabaseConnectionField>();

    expectedDetailList.add(new DatabaseConnectionField(GeoPkgDataStoreFactory.DATABASE));
    expectedDetailList.add(new DatabaseConnectionField(GeoPkgDataStoreFactory.USER));
    String expectedDatabaseTypeLabel = "GeoPackage";
    boolean expectedSupportsDuplication = false;

    DatabaseConnection test =
            new DatabaseConnection(
                    param,
                    expectedDatabaseTypeLabel,
                    expectedSupportsDuplication,
                    expectedDetailList,
                    null);

    assertTrue(test.equals(test));
    assertFalse(test.equals(""));
    assertFalse(test.equals(null));
    assertFalse(
            new DatabaseConnection(
                            null,
                            expectedDatabaseTypeLabel,
                            expectedSupportsDuplication,
                            expectedDetailList,
                            null)
                    .equals(test));
    assertFalse(
            new DatabaseConnection(
                            param, null, expectedSupportsDuplication, expectedDetailList, null)
                    .equals(test));
    assertFalse(
            new DatabaseConnection(
                            param,
                            expectedDatabaseTypeLabel,
                            expectedSupportsDuplication,
                            null,
                            null)
                    .equals(test));

    assertFalse(
            new DatabaseConnection(
                            new Param(
                                    "differetdbtype",
                                    String.class,
                                    "Type",
                                    true,
                                    "testgeopkg",
                                    Collections.singletonMap(Parameter.LEVEL, "program")),
                            expectedDatabaseTypeLabel,
                            expectedSupportsDuplication,
                            expectedDetailList,
                            null)
                    .equals(test));
    assertFalse(
            new DatabaseConnection(
                            param, "", expectedSupportsDuplication, expectedDetailList, null)
                    .equals(test));
    assertFalse(
            new DatabaseConnection(
                            param,
                            expectedDatabaseTypeLabel,
                            !expectedSupportsDuplication,
                            expectedDetailList,
                            null)
                    .equals(test));

    assertFalse(
            new DatabaseConnection(
                            param,
                            expectedDatabaseTypeLabel,
                            expectedSupportsDuplication,
                            new ArrayList<DatabaseConnectionField>(),
                            null)
                    .equals(test));
}
 
Example #12
Source File: DatabaseConnectionFactory.java    From sldeditor with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Adds the file database.
 *
 * @param databaseFileHandler the database file handler
 * @param param the param
 */
private static void addFileDatabase(DatabaseFileHandler databaseFileHandler, Param param) {
    fileHandlerList.add(databaseFileHandler);
    fileHandlerMap.put(databaseFileHandler, (String) param.sample);
}