Author: tchemit Date: 2012-09-10 14:29:27 +0200 (Mon, 10 Sep 2012) New Revision: 2659 Url: http://nuiton.org/repositories/revision/topia/2659 Log: fixes #2309: Add a new method to import a talbe and return imported entities Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/ImportStrategy.java branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/TopiaCsvImports.java Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/ImportStrategy.java =================================================================== --- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/ImportStrategy.java 2012-09-07 16:21:52 UTC (rev 2658) +++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/ImportStrategy.java 2012-09-10 12:29:27 UTC (rev 2659) @@ -49,7 +49,7 @@ ImportModelFactory<T> getModelFactory(); /** - * Import a table given a {@code importer}. with an optional csv result. + * Import a table given a {@code importer} with an optional csv result. * * @param meta type of table to import * @param importer the csv importer @@ -60,8 +60,22 @@ CsvImportResult<T> csvResult) throws TopiaException; /** - * Import a association given a {@code importer}. with an optional csv result. + * Import a table given a {@code importer} with an optional csv result, + * and return them. * + * @param meta type of table to import + * @param importer the csv importer + * @param csvResult optional object where to put csv import result + * @return imported entities + * @throws TopiaException if any db problem + * @since 2.6.14 + */ + <E extends TopiaEntity> Iterable<E> importTableAndReturnThem(TableMeta<T> meta, Import<E> importer, + CsvImportResult<T> csvResult) throws TopiaException; + + /** + * Import a association given a {@code importer} with an optional csv result. + * * @param meta type of association to import * @param importer the csv importer * @param csvResult optional object where to put csv import result Modified: branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/TopiaCsvImports.java =================================================================== --- branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/TopiaCsvImports.java 2012-09-07 16:21:52 UTC (rev 2658) +++ branches/topia-2.6.x/topia-persistence/src/main/java/org/nuiton/topia/persistence/csv/in/TopiaCsvImports.java 2012-09-10 12:29:27 UTC (rev 2659) @@ -164,14 +164,47 @@ ImportModel<E> model = importStrategy.getModelFactory().buildForImport(meta); Import<E> importer = Import.newImport(model, reader); try { - importStrategy.importTable(meta, importer, - csvResult); + importStrategy.importTable(meta, importer, csvResult); } finally { importer.close(); } } /** + * To import a table (given by his {@code meta}) from a reader and a strategy. + * <p/> + * Result of import can be stored in an optional csv result. + * + * @param reader where to read csv data + * @param importStrategy import strategy used to store csv data + * @param meta meta of the data + * @param csvResult optional csv result + * @param <T> type of entity enum + * @param <E> type of data + * @throws TopiaException if any db problem while storing datas + * @throws IOException if any pb while reading csv data + * @see ImportStrategy#importTable(TableMeta, Import, CsvImportResult) + */ + public static <T extends TopiaEntityEnum, E extends TopiaEntity> Iterable<E> importTableAndReturn(Reader reader, + ImportStrategy<T> importStrategy, + TableMeta<T> meta, + CsvImportResult<T> csvResult) throws TopiaException, IOException { + + + if (log.isInfoEnabled()) { + log.info("Will import " + meta); + } + + ImportModel<E> model = importStrategy.getModelFactory().buildForImport(meta); + Import<E> importer = Import.newImport(model, reader); + try { + return importStrategy.importTableAndReturnThem(meta, importer, csvResult); + } finally { + importer.close(); + } + } + + /** * To import a association (given by his {@code meta}) from a reader and a strategy. * <p/> * Result of import can be stored in an optional csv result.