@Test public void testDoExportSite() throws Exception { try { final JobStatusListener listener = mockery.mock(JobStatusListener.class, "listener"); mockery.checking(new Expectations() {{ allowing(listener).notifyPing(); allowing(listener).notifyPing(with(any(String.class)), with(any(Object[].class))); allowing(listener).notifyMessage(with(any(String.class)), with(any(Object[].class))); allowing(listener).count(with(any(String.class))); }}); long dt = System.currentTimeMillis(); String fileToExport = "target/site-export-" + UUID.randomUUID().toString() + ".zip"; bulkExportService.doExport(createContext("src/test/resources/export/xml/site.xml", listener, fileToExport)); final long shop = System.currentTimeMillis() - dt; System.out.println(String.format("%5d", 1) + " shop in " + shop + "millis (~" + (shop) + " per item)"); mockery.assertIsSatisfied(); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } }
protected void doExport(final JobStatusListener statusListener, final String xmlExportDescriptorName, final XmlExportDescriptor xmlExportDescriptor, final String fileToExport) throws Exception { statusListener.notifyMessage("export file : {}", fileToExport); final XmlEntityExportHandler<Object> handler = this.handlerMap.get(xmlExportDescriptor.getXmlHandler()); if (handler == null) { statusListener.notifyError("no handler : {}", xmlExportDescriptor.getXmlHandler()); return; } final OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(new File(fileToExport)), StandardCharsets.UTF_8); ResultsIterator<Object> results = null; try { handler.startXml(writer); results = getExistingEntities(xmlExportDescriptor, xmlExportDescriptor.getSelectCmd(), null, null); while (results.hasNext()) { final Object entity = results.next(); final XmlExportTuple tuple = new XmlExportTupleImpl(entity); handler.handle(statusListener, xmlExportDescriptor, tuple, valueDataAdapter, fileToExport, writer); releaseEntity(entity); } handler.endXml(writer); } catch (UnsupportedEncodingException e) { statusListener.notifyError("wrong file encoding in xml descriptor : {} {}", e, xmlExportDescriptor.getExportFileDescriptor().getFileEncoding(), e.getMessage()); } catch (IOException e) { statusListener.notifyError("cannot write the xml file : {} {}", e, fileToExport, e.getMessage()); } finally { try { if (results != null) { results.close(); } } catch (Exception exp) { statusListener.notifyError("cannot close the xml resultset : {} {}", exp, fileToExport, exp.getMessage()); } try { writer.close(); } catch (IOException ioe) { statusListener.notifyError("cannot close the xml file : {} {}", ioe, fileToExport, ioe.getMessage()); } } }
XmlFastBulkExportServiceImpl extends AbstractExportService<XmlExportDescriptor> implements ExportService { protected void doExport(final JobStatusListener statusListener, final String xmlExportDescriptorName, final XmlExportDescriptor xmlExportDescriptor, final String fileToExport) throws Exception { statusListener.notifyMessage("export file : {}", fileToExport); final XmlEntityExportHandler<Object> handler = this.handlerMap.get(xmlExportDescriptor.getXmlHandler()); if (handler == null) { statusListener.notifyError("no handler : {}", xmlExportDescriptor.getXmlHandler()); return; } final OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(new File(fileToExport)), StandardCharsets.UTF_8); ResultsIterator<Object> results = null; try { handler.startXml(writer); results = getExistingEntities(xmlExportDescriptor, xmlExportDescriptor.getSelectCmd(), null, null); while (results.hasNext()) { final Object entity = results.next(); final XmlExportTuple tuple = new XmlExportTupleImpl(entity); handler.handle(statusListener, xmlExportDescriptor, tuple, valueDataAdapter, fileToExport, writer); releaseEntity(entity); } handler.endXml(writer); } catch (UnsupportedEncodingException e) { statusListener.notifyError("wrong file encoding in xml descriptor : {} {}", e, xmlExportDescriptor.getExportFileDescriptor().getFileEncoding(), e.getMessage()); } catch (IOException e) { statusListener.notifyError("cannot write the xml file : {} {}", e, fileToExport, e.getMessage()); } finally { try { if (results != null) { results.close(); } } catch (Exception exp) { statusListener.notifyError("cannot close the xml resultset : {} {}", exp, fileToExport, exp.getMessage()); } try { writer.close(); } catch (IOException ioe) { statusListener.notifyError("cannot close the xml file : {} {}", ioe, fileToExport, ioe.getMessage()); } } } }
XmlFastBulkExportServiceImpl extends AbstractExportService<XmlExportDescriptor> implements ExportService { protected void doExport(final JobStatusListener statusListener, final String xmlExportDescriptorName, final XmlExportDescriptor xmlExportDescriptor, final String fileToExport) throws Exception { statusListener.notifyMessage("export file : {}", fileToExport); final XmlEntityExportHandler<Object> handler = this.handlerMap.get(xmlExportDescriptor.getXmlHandler()); if (handler == null) { statusListener.notifyError("no handler : {}", xmlExportDescriptor.getXmlHandler()); return; } final OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(new File(fileToExport)), StandardCharsets.UTF_8); ResultsIterator<Object> results = null; try { handler.startXml(writer); results = getExistingEntities(xmlExportDescriptor, xmlExportDescriptor.getSelectCmd(), null, null); while (results.hasNext()) { final Object entity = results.next(); final XmlExportTuple tuple = new XmlExportTupleImpl(entity); handler.handle(statusListener, xmlExportDescriptor, tuple, valueDataAdapter, fileToExport, writer); releaseEntity(entity); } handler.endXml(writer); } catch (UnsupportedEncodingException e) { statusListener.notifyError("wrong file encoding in xml descriptor : {} {}", e, xmlExportDescriptor.getExportFileDescriptor().getFileEncoding(), e.getMessage()); } catch (IOException e) { statusListener.notifyError("cannot write the xml file : {} {}", e, fileToExport, e.getMessage()); } finally { try { if (results != null) { results.close(); } } catch (Exception exp) { statusListener.notifyError("cannot close the xml resultset : {} {}", exp, fileToExport, exp.getMessage()); } try { writer.close(); } catch (IOException ioe) { statusListener.notifyError("cannot close the xml file : {} {}", ioe, fileToExport, ioe.getMessage()); } } } XmlFastBulkExportServiceImpl(); }
XmlFastBulkExportServiceImpl extends AbstractExportService<XmlExportDescriptor> implements ExportService { protected void doExport(final JobStatusListener statusListener, final String xmlExportDescriptorName, final XmlExportDescriptor xmlExportDescriptor, final String fileToExport) throws Exception { statusListener.notifyMessage("export file : {}", fileToExport); final XmlEntityExportHandler<Object> handler = this.handlerMap.get(xmlExportDescriptor.getXmlHandler()); if (handler == null) { statusListener.notifyError("no handler : {}", xmlExportDescriptor.getXmlHandler()); return; } final OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(new File(fileToExport)), StandardCharsets.UTF_8); ResultsIterator<Object> results = null; try { handler.startXml(writer); results = getExistingEntities(xmlExportDescriptor, xmlExportDescriptor.getSelectCmd(), null, null); while (results.hasNext()) { final Object entity = results.next(); final XmlExportTuple tuple = new XmlExportTupleImpl(entity); handler.handle(statusListener, xmlExportDescriptor, tuple, valueDataAdapter, fileToExport, writer); releaseEntity(entity); } handler.endXml(writer); } catch (UnsupportedEncodingException e) { statusListener.notifyError("wrong file encoding in xml descriptor : {} {}", e, xmlExportDescriptor.getExportFileDescriptor().getFileEncoding(), e.getMessage()); } catch (IOException e) { statusListener.notifyError("cannot write the xml file : {} {}", e, fileToExport, e.getMessage()); } finally { try { if (results != null) { results.close(); } } catch (Exception exp) { statusListener.notifyError("cannot close the xml resultset : {} {}", exp, fileToExport, exp.getMessage()); } try { writer.close(); } catch (IOException ioe) { statusListener.notifyError("cannot close the xml file : {} {}", ioe, fileToExport, ioe.getMessage()); } } } XmlFastBulkExportServiceImpl(); void setGenericDAO(GenericDAO<Object, Long> genericDAO); void setValueDataAdapter(final XmlValueAdapter valueDataAdapter); void setColumnLookUpQueryParameterStrategy(final LookUpQueryParameterStrategy<XmlImpExDescriptor, XmlImpExTuple, XmlValueAdapter> columnLookUpQueryParameterStrategy); void setHandlerMap(final Map<String, XmlEntityExportHandler> handlerMap); }
XmlFastBulkExportServiceImpl extends AbstractExportService<XmlExportDescriptor> implements ExportService { protected void doExport(final JobStatusListener statusListener, final String xmlExportDescriptorName, final XmlExportDescriptor xmlExportDescriptor, final String fileToExport) throws Exception { statusListener.notifyMessage("export file : {}", fileToExport); final XmlEntityExportHandler<Object> handler = this.handlerMap.get(xmlExportDescriptor.getXmlHandler()); if (handler == null) { statusListener.notifyError("no handler : {}", xmlExportDescriptor.getXmlHandler()); return; } final OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(new File(fileToExport)), StandardCharsets.UTF_8); ResultsIterator<Object> results = null; try { handler.startXml(writer); results = getExistingEntities(xmlExportDescriptor, xmlExportDescriptor.getSelectCmd(), null, null); while (results.hasNext()) { final Object entity = results.next(); final XmlExportTuple tuple = new XmlExportTupleImpl(entity); handler.handle(statusListener, xmlExportDescriptor, tuple, valueDataAdapter, fileToExport, writer); releaseEntity(entity); } handler.endXml(writer); } catch (UnsupportedEncodingException e) { statusListener.notifyError("wrong file encoding in xml descriptor : {} {}", e, xmlExportDescriptor.getExportFileDescriptor().getFileEncoding(), e.getMessage()); } catch (IOException e) { statusListener.notifyError("cannot write the xml file : {} {}", e, fileToExport, e.getMessage()); } finally { try { if (results != null) { results.close(); } } catch (Exception exp) { statusListener.notifyError("cannot close the xml resultset : {} {}", exp, fileToExport, exp.getMessage()); } try { writer.close(); } catch (IOException ioe) { statusListener.notifyError("cannot close the xml file : {} {}", ioe, fileToExport, ioe.getMessage()); } } } XmlFastBulkExportServiceImpl(); void setGenericDAO(GenericDAO<Object, Long> genericDAO); void setValueDataAdapter(final XmlValueAdapter valueDataAdapter); void setColumnLookUpQueryParameterStrategy(final LookUpQueryParameterStrategy<XmlImpExDescriptor, XmlImpExTuple, XmlValueAdapter> columnLookUpQueryParameterStrategy); void setHandlerMap(final Map<String, XmlEntityExportHandler> handlerMap);  }