JdbcStorage extends DataStorageBase { @Override @SuppressWarnings("unchecked") public <E extends Object> QueryResult<E> query(CompiledQuery query, EntityDefinition entityDefinition) throws IOException { QueryResult<E> result = new QueryResult<E>(); try { JdbcEntityDefinition jdbcEntityDefinition = JdbcEntityDefinitionManager.getJdbcEntityDefinition(entityDefinition); JdbcEntityReader reader = new JdbcEntityReaderImpl(jdbcEntityDefinition); List<E> entities = reader.query(query); result.setData(entities); if(entities!=null) { result.setSize(entities.size()); }else{ result.setSize(0); } if(query.isHasAgg()){ result.setEntityType((Class<E>) Map.class); }else { result.setEntityType((Class<E>) entityDefinition.getEntityClass()); } result.setFirstTimestamp(reader.getResultFirstTimestamp()); result.setLastTimestamp(reader.getResultLastTimestamp()); result.setSuccess(true); } catch (Exception e) { LOG.error(e.getMessage(), e); result.setSuccess(false); throw new IOException(e.getCause()); } return result; }  @Override void init(); @Override ModifyResult<String> update(List<E> entities, EntityDefinition entityDefinition); @Override ModifyResult<String> create(List<E> entities, EntityDefinition entityDefinition); @Override ModifyResult<String> delete(List<E> entities, EntityDefinition entityDefinition); @Override @SuppressWarnings("unchecked") ModifyResult<String> deleteByID(List<String> ids, EntityDefinition entityDefinition); @Override ModifyResult<String> delete(CompiledQuery query, EntityDefinition entityDefinition); @Override @SuppressWarnings("unchecked") QueryResult<E> query(CompiledQuery query, EntityDefinition entityDefinition); @Override QueryResult<E> queryById(List<String> ids, EntityDefinition entityDefinition); @Override void close();  }
@Test public void testReadBySimpleQuery() throws QueryCompileException, IOException { RawQuery rawQuery = new RawQuery(); rawQuery.setQuery("TestTimeSeriesAPIEntity[@cluster=\"c4ut\"]{*}"); System.out.println(DateTimeUtil.millisecondsToHumanDateWithSeconds(baseTimestamp)); rawQuery.setStartTime(DateTimeUtil.millisecondsToHumanDateWithSeconds(baseTimestamp)); rawQuery.setEndTime(DateTimeUtil.millisecondsToHumanDateWithMilliseconds(baseTimestamp+2000)); rawQuery.setPageSize(1000); CompiledQuery query = new CompiledQuery(rawQuery); QueryResult<TestTimeSeriesAPIEntity> result = storage.query(query, entityDefinition); Assert.assertNotNull(result); }
@Test public void testReadByNotEqualCondition() throws QueryCompileException, IOException { RawQuery rawQuery = new RawQuery(); rawQuery.setQuery("TestTimeSeriesAPIEntity[@cluster!=\"c4ut_not_found\" AND @field1 != 0]{*}"); System.out.println(DateTimeUtil.millisecondsToHumanDateWithSeconds(baseTimestamp)); rawQuery.setStartTime(DateTimeUtil.millisecondsToHumanDateWithSeconds(baseTimestamp)); rawQuery.setEndTime(DateTimeUtil.millisecondsToHumanDateWithMilliseconds(baseTimestamp+2000)); rawQuery.setPageSize(1000); CompiledQuery query = new CompiledQuery(rawQuery); QueryResult<TestTimeSeriesAPIEntity> result = storage.query(query, entityDefinition); Assert.assertNotNull(result); }
@Test public void testReadByComplexQuery() throws QueryCompileException, IOException { RawQuery rawQuery = new RawQuery(); rawQuery.setQuery("TestTimeSeriesAPIEntity[@cluster=\"c4ut\" AND @field4 > 1000 OR @datacenter =\"d4ut\" ]{@field1,@field2}"); rawQuery.setStartTime(DateTimeUtil.millisecondsToHumanDateWithSeconds(baseTimestamp)); rawQuery.setEndTime(DateTimeUtil.millisecondsToHumanDateWithSeconds(baseTimestamp + 2000)); rawQuery.setPageSize(1000); CompiledQuery query = new CompiledQuery(rawQuery); storage.query(query,entityDefinition); }
@Test public void testReadByComplexQueryWithLike() throws QueryCompileException, IOException { RawQuery rawQuery = new RawQuery(); rawQuery.setQuery("TestTimeSeriesAPIEntity[@cluster=\"c4ut\" AND @field4 > 1000 AND @field7 CONTAINS \"99404f47e309\" OR @datacenter =\"d4ut\" ]{@field1,@field2}"); rawQuery.setStartTime(DateTimeUtil.millisecondsToHumanDateWithSeconds(baseTimestamp)); rawQuery.setEndTime(DateTimeUtil.millisecondsToHumanDateWithSeconds(baseTimestamp + 2000)); rawQuery.setPageSize(1000); CompiledQuery query = new CompiledQuery(rawQuery); storage.query(query,entityDefinition); }