001package io.ebean.text.csv; 002 003import io.ebean.EbeanServer; 004 005/** 006 * Provides callback methods for customisation of CSV processing. 007 * <p> 008 * You can provide your own CsvCallback implementation to customise the CSV 009 * processing. It is expected that the DefaultCsvCallback provides a good base 010 * class that you can extend. 011 * </p> 012 * 013 * @param <T> 014 */ 015public interface CsvCallback<T> { 016 017 /** 018 * The processing is about to begin. 019 * <p> 020 * Typically the callback will create a transaction, set batch mode, batch 021 * size etc. 022 * </p> 023 */ 024 void begin(EbeanServer server); 025 026 /** 027 * Read the header row. 028 * <p> 029 * This is only called if {@link CsvReader#setHasHeader(boolean, boolean)} has 030 * been set to true. 031 * </p> 032 * 033 * @param line the header line content. 034 */ 035 void readHeader(String[] line); 036 037 /** 038 * Check that the row should be processed - return true to process the row or 039 * false to ignore the row. Gives ability to handle bad data... empty rows etc 040 * and ignore it rather than fail. 041 */ 042 boolean processLine(int row, String[] line); 043 044 /** 045 * Called for each bean after it has been loaded from the CSV content. 046 * <p> 047 * This allows you to process the bean however you like. 048 * </p> 049 * <p> 050 * When you use a CsvCallback the CsvReader *WILL NOT* create a transaction 051 * and will not save the bean for you. You have complete control and must do 052 * these things yourself (if that is want you want). 053 * </p> 054 * 055 * @param row the index of the content being processed 056 * @param line the content that has been used to load the bean 057 * @param bean the entity bean after it has been loaded from the csv content 058 */ 059 void processBean(int row, String[] line, T bean); 060 061 /** 062 * The processing has ended successfully. 063 * <p> 064 * Typically the callback will commit the transaction. 065 * </p> 066 */ 067 void end(int row); 068 069 /** 070 * The processing has ended due to an error. 071 * <p> 072 * This gives the callback the opportunity to rollback the transaction if one 073 * was created. 074 * </p> 075 * 076 * @param row the row that the error has occured on 077 * @param e the error that occured 078 */ 079 void endWithError(int row, Exception e); 080 081}