@Override
    public void deserializeKAM(final String kamName, final String filePath,
            final boolean noPreserve) throws PKAMSerializationFailure {

        // load destination KAM
        final SystemConfiguration cfg =
                SystemConfiguration.getSystemConfiguration();

        // parse and insert KAM data from portable KAM file
        PKAMReader pkr = null;
        CSVReader tabbedReader = null;
        KAMImportDAO kamImportDAO = null;
        try {
            try {
                pkr = new PKAMReader(filePath);
            } catch (Exception e) {
                throw new PKAMSerializationFailure(filePath,
                        "Unable to process KAM.");
            }
            tabbedReader = new CSVReader(pkr, FIELD_SEPARATOR,
                    CSVParser.DEFAULT_QUOTE_CHARACTER,
                    CSVParser.DEFAULT_ESCAPE_CHARACTER);

            KAMStoreTables1_0 table;
            String[] data;
            while ((data = tabbedReader.readNext()) != null) {
                Matcher matcher = TABLE_HEADER_PATTERN.matcher(data[0]);
                if (data.length == 1 && matcher.matches()) {
                    table = KAMStoreTables1_0.getTableByName(matcher.group(1));

                    if (table == KAMStoreTables1_0.KAM_CATALOG_KAM) {
                        String[] kcRowData = tabbedReader.readNext();

                        final String newKAMSchema = createKAMSchema(cfg,
                                kamName, kcRowData, filePath, noPreserve);

                        final DBConnection kcc =
                                createKAMConnection(filePath, cfg);
                        kamImportDAO = new KAMImportDAO(kcc, newKAMSchema);
                        continue;
                    }

                    if (kamImportDAO == null) {
                        throw new IllegalStateException(
                                "KAMImportDAO has not been constructed");
                    }

                    // commit previous table batch, if any
                    kamImportDAO.commitTableBatch();
                    kamImportDAO.startTableBatch(table);
                } else {
                    if (kamImportDAO == null) {
                        throw new IllegalStateException(
                                "KAMImportDAO has not been constructed");
                    }

                    kamImportDAO.importDataRow(data);
                }
            }

            if (kamImportDAO == null) {
                throw new IllegalStateException(
                        "KAMImportDAO has not been constructed");
            }

            // commit final table batch
            kamImportDAO.commitTableBatch();
        } catch (IOException e) {
            throw new PKAMSerializationFailure(filePath, e.getMessage());
        } catch (SQLException e) {
            throw new PKAMSerializationFailure(filePath, e.getMessage());
        } finally {
            // close tabbed-data reader
            if (tabbedReader != null) {
                try {
                    tabbedReader.close();
                } catch (IOException e) {}
            }

            if (kamImportDAO != null) {
                kamImportDAO.terminate();
            }
        }
    }
@ Override public void deserializeKAM ( final String kamName , final String filePath , final boolean noPreserve ) throws PKAMSerializationFailure { final SystemConfiguration cfg = SystemConfiguration . getSystemConfiguration ( ) ; PKAMReader pkr = null ; CSVReader tabbedReader = null ; KAMImportDAO kamImportDAO = null ; try { try { pkr = new PKAMReader ( filePath ) ; } catch ( Exception e ) { throw new PKAMSerializationFailure ( filePath , "Unable to process KAM." ) ; } tabbedReader = new CSVReader ( pkr , FIELD_SEPARATOR , CSVParser . DEFAULT_QUOTE_CHARACTER , CSVParser . DEFAULT_ESCAPE_CHARACTER ) ; KAMStoreTables1_0 table ; String [ ] data ; while ( ( data = tabbedReader . readNext ( ) ) != null ) { Matcher matcher = TABLE_HEADER_PATTERN . matcher ( data [ 0 ] ) ; if ( data . length == 1 && matcher . matches ( ) ) { table = KAMStoreTables1_0 . getTableByName ( matcher . group ( 1 ) ) ; if ( table == KAMStoreTables1_0 . KAM_CATALOG_KAM ) { String [ ] kcRowData = tabbedReader . readNext ( ) ; final String newKAMSchema = createKAMSchema ( cfg , kamName , kcRowData , filePath , noPreserve ) ; final DBConnection kcc = createKAMConnection ( filePath , cfg ) ; kamImportDAO = new KAMImportDAO ( kcc , newKAMSchema ) ; continue ; } if ( kamImportDAO == null ) { throw new IllegalStateException ( "KAMImportDAO has not been constructed" ) ; } kamImportDAO . commitTableBatch ( ) ; kamImportDAO . startTableBatch ( table ) ; } else { if ( kamImportDAO == null ) { throw new IllegalStateException ( "KAMImportDAO has not been constructed" ) ; } kamImportDAO . importDataRow ( data ) ; } } if ( kamImportDAO == null ) { throw new IllegalStateException ( "KAMImportDAO has not been constructed" ) ; } kamImportDAO . commitTableBatch ( ) ; } catch ( IOException e ) { throw new PKAMSerializationFailure ( filePath , e . getMessage ( ) ) ; } catch ( SQLException e ) { throw new PKAMSerializationFailure ( filePath , e . getMessage ( ) ) ; } finally { if ( tabbedReader != null ) { try { tabbedReader . close ( ) ; } catch ( IOException e ) { } } if ( kamImportDAO != null ) { kamImportDAO . terminate ( ) ; } } }
{@inheritDoc}