JdbcStorage extends DataStorageBase { @Override public <E extends TaggedLogAPIEntity> ModifyResult<String> create(List<E> entities, EntityDefinition entityDefinition) throws IOException { ModifyResult<String> result = new ModifyResult<>(); try { JdbcEntityDefinition jdbcEntityDefinition = JdbcEntityDefinitionManager.getJdbcEntityDefinition(entityDefinition); JdbcEntityWriter writer = new JdbcEntityWriterImpl(jdbcEntityDefinition); List<String> keys = writer.write(entities); result.setIdentifiers(keys); result.setSize(keys.size()); result.setSuccess(true); } catch (Exception e) { LOG.error(e.getMessage(), e.getCause()); 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 testWrite() throws IOException { List<TestTimeSeriesAPIEntity> entityList = new ArrayList<TestTimeSeriesAPIEntity>(); int i= 0; while( i++ < 5){ TestTimeSeriesAPIEntity entity = newInstance(); entityList.add(entity); } ModifyResult<String> result = storage.create(entityList, entityDefinition); Assert.assertTrue(result.getSize() > 0); }
@Test @Ignore("Ignore performance auto testing") public void testWriterPerformance() throws IOException { StopWatch stopWatch = new StopWatch(); stopWatch.start(); List<TestTimeSeriesAPIEntity> entityList = new ArrayList<TestTimeSeriesAPIEntity>(); int i= 0; while( i++ < 100000){ entityList.add(newInstance()); if(entityList.size()>=1000) { ModifyResult<String> result = storage.create(entityList, entityDefinition); Assert.assertNotNull(result); entityList.clear(); } } stopWatch.stop(); LOG.info("Wrote 100000 records in "+stopWatch.getTime()+" ms"); }