private List<LayerInfo> filterLayers(final Filter filter) { CloseableIterator<LayerInfo> iterator; iterator = list(LayerInfo.class, filter); try { return ImmutableList.copyOf(iterator); } finally { iterator.close(); } }
private <T> Set<T> asSet(CloseableIterator<T> list) { ImmutableSet<T> set; try { set = ImmutableSet.copyOf(list); } finally { list.close(); } return set; }
@Override public <T extends CatalogInfo> T get(Class<T> type, Filter filter) throws IllegalArgumentException { final Integer limit = Integer.valueOf(2); CloseableIterator<T> it = list(type, filter, null, limit, null); T result = null; try { if (it.hasNext()) { result = it.next(); if (it.hasNext()) { throw new IllegalArgumentException( "Specified query predicate resulted in more than one object"); } } } finally { it.close(); } return result; }
private <T extends CatalogInfo> void testOrderBy( Class<T> clazz, Filter filter, Integer offset, Integer limit, SortBy sortOrder, List<T> expected) { CatalogPropertyAccessor pe = new CatalogPropertyAccessor(); List<Object> props = new ArrayList<Object>(); List<Object> actual = new ArrayList<Object>(); String sortProperty = sortOrder.getPropertyName().getPropertyName(); for (T info : expected) { Object pval = pe.getProperty(info, sortProperty); props.add(pval); } CloseableIterator<T> it = catalog.list(clazz, filter, offset, limit, sortOrder); try { while (it.hasNext()) { Object property = pe.getProperty(it.next(), sortProperty); actual.add(property); } } finally { it.close(); } assertEquals(props, actual); }
@Override public boolean hasMoreElements() { if (it.hasNext()) { return true; } else { it.close(); return false; } }
@Override public boolean hasNext() { if (next != null) { return true; } boolean hasNext = featureTypes.hasNext(); if (!hasNext) { featureTypes.close(); return false; } else { try { FeatureTypeInfo featureType = featureTypes.next(); CollectionDocument collection = new CollectionDocument(geoServer, request, featureType); next = collection; return true; } catch (Exception e) { featureTypes.close(); throw new ServiceException( "Failed to iterate over the feature types in the catalog", e); } } }
private void updateLayers(CloseableIterator<LayerInfo> affectedLayers) { try { while (affectedLayers.hasNext()) { LayerInfo geogigLayer = affectedLayers.next(); setIdentifier(geogigLayer); } } finally { affectedLayers.close(); } }
@Override protected List<Tuple> load() { Catalog catalog = GeoServerApplication.get().getCatalog(); Filter filter = Predicates.acceptAll(); CloseableIterator<WorkspaceInfo> list = catalog.list(WorkspaceInfo.class, filter, null, 4000, null); List<Tuple> workspaces; try { workspaces = Lists.newArrayList( Iterators.transform( list, new Function<WorkspaceInfo, Tuple>() { @Override public Tuple apply(WorkspaceInfo input) { return new Tuple( input.getId(), input.getName()); } })); } finally { list.close(); } Collections.sort(workspaces); return workspaces; } };
static <T> List<T> collectAndClose(CloseableIterator<T> it) throws IOException { if (it == null) return null; try { LinkedList<T> list = new LinkedList<T>(); while (it.hasNext()) { list.add(it.next()); } return list; } finally { it.close(); } }
static <T> List<T> collectAndClose(CloseableIterator<T> it) throws IOException { if (it == null) return null; try { LinkedList<T> list = new LinkedList<T>(); while (it.hasNext()) { list.add(it.next()); } return list; } finally { it.close(); } }
private void handleWorkspaceChange(WorkspaceInfo ws) { final CatalogModifyEvent preModifyEvent = PRE_MODIFY_EVENT.get(); PRE_MODIFY_EVENT.remove(); final List<String> changedProperties = preModifyEvent.getPropertyNames(); // was the workspace name modified? this implies a name change in workspace local styles int nameIdx = changedProperties.indexOf("name"); if (nameIdx == -1) { return; } String oldWorkspaceName = (String) preModifyEvent.getOldValues().get(nameIdx); String newWorkspaceName = (String) preModifyEvent.getNewValues().get(nameIdx); // grab the styles CloseableIterator<StyleInfo> styles = catalog.list(StyleInfo.class, Predicates.equal("workspace.name", newWorkspaceName)); try { while (styles.hasNext()) { StyleInfo style = styles.next(); String oldStyleName = oldWorkspaceName + ":" + style.getName(); String newStyleName = newWorkspaceName + ":" + style.getName(); handleStyleRenamed(oldStyleName, newStyleName); } } finally { styles.close(); } }
private synchronized int getConnectionCount() { int count = 0; CloseableIterator<DataStoreInfo> i = getDataStores(); try { for (; i.hasNext(); ) { DataStoreInfo meta = i.next(); if (!meta.isEnabled()) { // Don't count connections from disabled datastores. continue; } try { meta.getDataStore(null); } catch (Throwable notAvailable) { // TODO: Logging. continue; } count += 1; } } finally { i.close(); } return count; }
geogigLayers.close();
private synchronized int getLockCount() { int count = 0; CloseableIterator<DataStoreInfo> i = getDataStores(); try { for (; i.hasNext(); ) { DataStoreInfo meta = (DataStoreInfo) i.next(); if (!meta.isEnabled()) { // Don't count locks from disabled datastores. continue; } try { DataAccess store = meta.getDataStore(null); if (store instanceof DataStore) { LockingManager lockingManager = ((DataStore) store).getLockingManager(); if (lockingManager != null) { // we can't actually *count* locks right now? // count += lockingManager.getLockSet().size(); } } } catch (IllegalStateException notAvailable) { continue; } catch (Throwable huh) { continue; } } } finally { i.close(); } return count; }
@Test public void testGetDomain() throws IOException { Name name = new NameImpl(DC.NAMESPACE, "type"); CloseableIterator<String> domain = store.getDomain(new NameImpl(CSW.NAMESPACE, "Record"), name); assertTrue(domain.hasNext()); assertEquals("http://purl.org/dc/dcmitype/Dataset", domain.next()); assertEquals("http://purl.org/dc/dcmitype/Image", domain.next()); assertEquals("http://purl.org/dc/dcmitype/Service", domain.next()); assertEquals("http://purl.org/dc/dcmitype/Text", domain.next()); assertFalse(domain.hasNext()); domain.close(); }