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