public long getCount(Query query) throws IOException { return getFeatureSource().getCount(query); }
public void testCount() throws Exception { assertEquals(3, featureSource.getCount(Query.ALL)); }
public void testCountWithOffsetLimit() throws Exception { Query query = new Query(); query.setStartIndex(1); query.setMaxFeatures(1); assertEquals(1, featureSource.getCount(query)); }
public void testFiltersByDate() throws Exception { setup.setUpData(); FilterFactory ff = dataStore.getFilterFactory(); DateFormat df = new SimpleDateFormat("yyyy-dd-MM"); ContentFeatureSource fs = dataStore.getFeatureSource(tname("dates")); Filter f = ff.lessOrEqual(ff.property(aname("d")), ff.literal(df.parse("2009-28-06"))); assertEquals( "wrong number of records for " + TimeZone.getDefault().getDisplayName(), 2, fs.getCount(new Query(tname("dates"), f))); TimeZone.setDefault(originalTimeZone); setup.setUpData(); } }
public void testPaginationWithPlaceHolder() throws Exception { Query query = new Query("riverFullPlaceHolder"); query.setStartIndex(1); query.setMaxFeatures(2); int count = dataStore.getFeatureSource("riverFullPlaceHolder").getCount(query); assertTrue(count == 1); } }
public void testLikeFilter() throws Exception { FilterFactory2 ff = (FilterFactory2) dataStore.getFilterFactory(); PropertyIsLike caseSensitiveLike = ff.like(ff.property(aname("stringProperty")), "Z*", "*", "?", "\\", true); PropertyIsLike caseInsensitiveLike = ff.like(ff.property(aname("stringProperty")), "Z*", "*", "?", "\\", false); PropertyIsLike caseInsensitiveLike2 = ff.like(ff.property(aname("stringProperty")), "z*", "*", "?", "\\", false); assertEquals(0, featureSource.getCount(new Query(null, caseSensitiveLike))); assertEquals(1, featureSource.getCount(new Query(null, caseInsensitiveLike))); assertEquals(1, featureSource.getCount(new Query(null, caseInsensitiveLike2))); }
public void testCaseInsensitiveFilter() throws Exception { FilterFactory ff = dataStore.getFilterFactory(); PropertyIsEqualTo sensitive = ff.equal(ff.property(aname("stringProperty")), ff.literal("OnE"), true); PropertyIsEqualTo insensitive = ff.equal(ff.property(aname("stringProperty")), ff.literal("OnE"), false); assertEquals(0, featureSource.getCount(new Query(null, sensitive))); assertEquals(1, featureSource.getCount(new Query(null, insensitive))); }
public void testJoinViews() throws Exception { Query joinQuery = new Query("riverFull"); FilterFactory ff = dataStore.getFilterFactory(); Join join = new Join( "riverReduced", ff.equal( ff.property("a." + aname("river")), ff.property(aname("river")), false)); join.setAlias("a"); joinQuery.getJoins().add(join); // get the two feature sources ContentFeatureSource fsFull = dataStore.getFeatureSource("riverFull"); ContentFeatureSource fsReduced = dataStore.getFeatureSource("riverReduced"); // check count int expectedCount = fsReduced.getCount(Query.ALL); int count = fsFull.getCount(joinQuery); assertEquals(expectedCount, count); }
public void testJoinViewsWithPlaceHolder() { Query joinQuery = new Query("riverFullPlaceHolder"); FilterFactory ff = dataStore.getFilterFactory(); Join join = new Join( "riverFullPlaceHolder", ff.equal( ff.property("a." + aname("river")), ff.property(aname("river")), false)); join.setAlias("a"); joinQuery.getJoins().add(join); try { dataStore.getFeatureSource("riverFullPlaceHolder").getCount(joinQuery); } catch (Exception exception) { assertTrue( exception .getMessage() .contains( "Joins between virtual tables that provide a " + ":where_placeholder: are not supported")); return; } fail("count query should have fail with an exception"); }
public void testCountWithFilter() throws Exception { FilterFactory ff = dataStore.getFilterFactory(); PropertyIsEqualTo filter = ff.equals(ff.property(aname("stringProperty")), ff.literal("one")); Query query = new Query(); query.setFilter(filter); assertEquals(1, featureSource.getCount(query)); }
public void testWrite() throws Exception { int count = dataStore.getFeatureSource(tname("udt")).getCount(Query.ALL); try (FeatureWriter w = dataStore.getFeatureWriterAppend(tname("udt"), Transaction.AUTO_COMMIT)) { w.hasNext(); SimpleFeature f = (SimpleFeature) w.next(); f.setAttribute(aname("ut"), "abcd"); try { w.write(); fail("Write should have failed with UDT constraint failure"); } catch (Exception e) { } f.setAttribute(aname("ut"), "34cd"); w.write(); } assertEquals(count + 1, dataStore.getFeatureSource(tname("udt")).getCount(Query.ALL)); }
public void testGetFeaturesWithArithmeticOpFilter() throws Exception { FilterFactory ff = dataStore.getFilterFactory(); Subtract sub = ff.subtract(ff.property(aname("doubleProperty")), ff.literal(0.1)); PropertyIsEqualTo filter = ff.equals(ff.property(aname("intProperty")), sub); // this test is very dependent on the specific database, some db's will round, some won't // so just assert that something is returned assertTrue(featureSource.getCount(new Query(null, filter)) > 0); }
public void testSimpleNegation() throws Exception { Not filter = ff.not(ff.equal(ff.property(aname(A)), ff.literal(10), false)); ContentFeatureSource fs = dataStore.getFeatureSource(tname(ABC)); int count = fs.getCount(new Query(tname(ABC), filter)); assertEquals(2, count); }
public void testConversionFilter() throws Exception { FilterFactory ff = dataStore.getFilterFactory(); PropertyIsEqualTo f = ff.equals( ff.property(aname("doubleProperty")), ff.add(ff.property(aname("intProperty")), ff.literal("0.1"))); assertEquals(1, featureSource.getCount(new Query(null, f))); }
public void testNegateOr() throws Exception { // not(a > 3 or b = 5 or c < 0) Filter fa = ff.greater(ff.property(aname(A)), ff.literal(3)); Filter fb = ff.equal(ff.property(aname(B)), ff.literal(5), false); Filter fc = ff.less(ff.property(aname(C)), ff.literal(0)); Not filter = ff.not(ff.and(Arrays.asList(fa, fb, fc))); ContentFeatureSource fs = dataStore.getFeatureSource(tname(ABC)); Query q = new Query(tname(ABC), filter); int count = fs.getCount(q); assertEquals(2, count); }
public void testSerialTransactions() throws IOException { SimpleFeatureStore st = (SimpleFeatureStore) dataStore.getFeatureSource(tname("ft1")); SimpleFeatureBuilder b = new SimpleFeatureBuilder(st.getSchema()); b.set(aname("intProperty"), Integer.valueOf(100)); SimpleFeature f1 = b.buildFeature(null); DefaultFeatureCollection features = new DefaultFeatureCollection(null, null); features.add(f1); try (Transaction tx1 = new DefaultTransaction()) { st.setTransaction(tx1); st.addFeatures(features); tx1.commit(); } assertEquals(4, dataStore.getFeatureSource(tname("ft1")).getCount(Query.ALL)); try (Transaction tx2 = new DefaultTransaction()) { st.setTransaction(tx2); st.addFeatures(features); tx2.commit(); } assertEquals(5, dataStore.getFeatureSource(tname("ft1")).getCount(Query.ALL)); } }
void doTestSimpleJoinWithFilterCount(boolean exposePrimaryKeys) throws Exception { dataStore.setExposePrimaryKeyColumns(exposePrimaryKeys); FilterFactory ff = dataStore.getFilterFactory(); Query q = new Query(tname("ft1")); Join j = new Join( tname("ftjoin"), ff.equal( ff.property(aname("stringProperty")), ff.property(aname("name")), true)); j.filter(ff.greater(ff.property(aname("join1intProperty")), ff.literal(1))); q.getJoins().add(j); q.setFilter(ff.less(ff.property(aname("intProperty")), ff.literal(3))); assertEquals(1, dataStore.getFeatureSource(tname("ft1")).getCount(q)); }
public void testBetweenNegation() throws Exception { Not filter = ff.not( ff.between( ff.property(aname(B)), ff.property(aname(A)), ff.property(aname(C)))); ContentFeatureSource fs = dataStore.getFeatureSource(tname(ABC)); Query q = new Query(tname(ABC), filter); int count = fs.getCount(q); assertEquals(1, count); SimpleFeature f = DataUtilities.first(fs.getFeatures(q)); assertEquals("n_n_n", f.getAttribute(aname(NAME))); }
public void test() throws Exception { Not filter = ff.not( ff.between( ff.property(aname(B)), ff.property(aname(A)), ff.property(aname(C)))); ContentFeatureSource fs = dataStore.getFeatureSource(tname(ABC)); Query q = new Query(tname(ABC), filter); int count = fs.getCount(q); assertEquals(1, count); SimpleFeature f = DataUtilities.first(fs.getFeatures(q)); assertEquals("n_n_n", f.getAttribute(aname(NAME))); } }