protected Optional<String> getConfig(String key, ConfigDatabase config) { Optional<String> val = config.get(key); if (!val.isPresent()) { val = config.getGlobal(key); } return val; } }
protected Optional<String> getConfig(String key, ConfigDatabase config) { Optional<String> val = config.get(key); if (!val.isPresent()) { val = config.getGlobal(key); } return val; } }
@Override public void configure() throws RepositoryConnectionException { RepositoryConnectionException.StorageType.OBJECT.configure(config, "mongodb", "0.1"); String uri = config.get("mongodb.uri").or(config.getGlobal("mongodb.uri")) .or("mongodb://localhost:27017/"); String database = config.get("mongodb.database").or(config.getGlobal("mongodb.database")) .or("geogig"); config.put("mongodb.uri", uri); config.put("mongodb.database", database); }
Optional<Integer> tpoolSize = configdb.getGlobal(KEY_THREADPOOL_SIZE, Integer.class); if (getAllFetchSize.isPresent()) { Integer fetchSize = getAllFetchSize.get();
Optional<Integer> tpoolSize = configdb.getGlobal(KEY_THREADPOOL_SIZE, Integer.class); if (getAllFetchSize.isPresent()) { Integer fetchSize = getAllFetchSize.get();
@Nullable private Transaction newTransaction() { final boolean transactional = objectDb.getConfig().getTransactional(); if (transactional) { TransactionConfig txConfig = new TransactionConfig(); txConfig.setReadUncommitted(true); Optional<String> durability = configDB.get(OBJECT_DURABILITY_CONFIG_KEY); if (!durability.isPresent()) { durability = configDB.getGlobal(OBJECT_DURABILITY_CONFIG_KEY); } if ("safe".equals(durability.orNull())) { txConfig.setDurability(Durability.COMMIT_SYNC); } else { txConfig.setDurability(Durability.COMMIT_WRITE_NO_SYNC); } Transaction transaction = env.beginTransaction(null, txConfig); return transaction; } return null; }
@Test public void testGlobal() { // Test integer and string config.putGlobal("section.int", 1); config.putGlobal("section.string", "2"); final int one = config.getGlobal("section.int", Integer.class).or(-1); assertEquals(one, 1); final String two = config.getGlobal("section.string").or("-1"); assertEquals(two, "2"); // Test overwriting a value that already exists config.putGlobal("section.string", "3"); final String three = config.getGlobal("section.string").or("-1"); assertEquals(three, "3"); }
@Test public void testGlobal() { // Test integer and string config.putGlobal("section.int", 1); config.putGlobal("section.string", "2"); final int one = config.getGlobal("section.int", Integer.class).or(-1); assertEquals(one, 1); final String two = config.getGlobal("section.string").or("-1"); assertEquals(two, "2"); // Test overwriting a value that already exists config.putGlobal("section.string", "3"); final String three = config.getGlobal("section.string").or("-1"); assertEquals(three, "3"); }
@Test public void testRemoveSectionGlobal() { // Test integer and string config.putGlobal("section1.int", 1); config.putGlobal("section1.subsection.string", "2"); config.putGlobal("section1.subsection.subsub.int", 1); config.putGlobal("section1.subsection.subsub.string", "4"); config.putGlobal("section2.int", 3); assertTrue(config.getGlobal("section1.subsection.subsub.string").isPresent()); assertTrue(config.getGlobal("section1.subsection.subsub.int").isPresent()); config.removeSectionGlobal("section1.subsection.subsub"); assertFalse(config.getGlobal("section1.subsection.subsub.string").isPresent()); assertFalse(config.getGlobal("section1.subsection.subsub.int").isPresent()); assertTrue(config.getGlobal("section1.int").isPresent()); config.removeSectionGlobal("section1"); assertFalse(config.getGlobal("section1.int").isPresent()); } }
try (ConfigDatabase config = FileRepositoryResolver .resolveConfigDatabase(platform.pwd().toURI(), context, resolveAsRootURI)) { Optional<String> ansiEnabled = config.getGlobal("ansi.enabled"); if (ansiEnabled.isPresent()) { boolean enable = Boolean.getBoolean(ansiEnabled.get());
@Test public void testRemoveSectionGlobal() { // Test integer and string config.putGlobal("section1.int", 1); config.putGlobal("section1.subsection.string", "2"); config.putGlobal("section1.subsection.subsub.int", 1); config.putGlobal("section1.subsection.subsub.string", "4"); config.putGlobal("section2.int", 3); assertTrue(config.getGlobal("section1.subsection.subsub.string").isPresent()); assertTrue(config.getGlobal("section1.subsection.subsub.int").isPresent()); config.removeSectionGlobal("section1.subsection.subsub"); assertFalse(config.getGlobal("section1.subsection.subsub.string").isPresent()); assertFalse(config.getGlobal("section1.subsection.subsub.int").isPresent()); assertTrue(config.getGlobal("section1.int").isPresent()); config.removeSectionGlobal("section1"); assertFalse(config.getGlobal("section1.int").isPresent()); } }
@Test public void testGetDefaultWithNoLocalRepository() { ConfigDatabase database = mock(ConfigDatabase.class); when(database.get(anyString())).thenThrow(new ConfigException(StatusCode.INVALID_LOCATION)); when(database.getGlobal(anyString())).thenReturn(Optional.of("value")); ConfigOp config = new ConfigOp(database); config.setScope(ConfigScope.DEFAULT).setAction(ConfigAction.CONFIG_GET) .setName("section.key").setValue(null).call(); }
@Test public void testGetDefaultWithNoLocalRepository() { ConfigDatabase database = mock(ConfigDatabase.class); when(database.get(anyString())).thenThrow(new ConfigException(StatusCode.INVALID_LOCATION)); when(database.getGlobal(anyString())).thenReturn(Optional.of("value")); ConfigOp config = new ConfigOp(database); config.setScope(ConfigScope.DEFAULT).setAction(ConfigAction.CONFIG_GET) .setName("section.key").setValue(null).call(); }
@Test public void testRemoveGlobal() { // Test integer and string config.putGlobal("section1.int", 1); config.putGlobal("section1.subsection.string", "2"); config.putGlobal("section1.subsection.subsub.int", 1); config.putGlobal("section1.subsection.subsub.string", "4"); config.putGlobal("section2.int", 3); assertTrue(config.getGlobal("section1.int").isPresent()); config.removeGlobal("section1.int"); assertFalse(config.getGlobal("section1.int").isPresent()); assertTrue(config.getGlobal("section1.subsection.subsub.string").isPresent()); config.removeGlobal("section1.subsection.subsub.string"); assertFalse(config.getGlobal("section1.subsection.subsub.string").isPresent()); }
@Test public void testRemoveGlobal() { // Test integer and string config.putGlobal("section1.int", 1); config.putGlobal("section1.subsection.string", "2"); config.putGlobal("section1.subsection.subsub.int", 1); config.putGlobal("section1.subsection.subsub.string", "4"); config.putGlobal("section2.int", 3); assertTrue(config.getGlobal("section1.int").isPresent()); config.removeGlobal("section1.int"); assertFalse(config.getGlobal("section1.int").isPresent()); assertTrue(config.getGlobal("section1.subsection.subsub.string").isPresent()); config.removeGlobal("section1.subsection.subsub.string"); assertFalse(config.getGlobal("section1.subsection.subsub.string").isPresent()); }