/*
 * ARX: Efficient, Stable and Optimal Data Anonymization
 * Copyright (C) 2014 Karol Babioch <karol@babioch.de>
 * Copyright (C) 2014 Fabian Prasser
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

package org.deidentifier.arx.examples;

import java.io.IOException;
import java.sql.SQLException;

import org.deidentifier.arx.Data;
import org.deidentifier.arx.DataSource;
import org.deidentifier.arx.DataType;

/**
 * This class demonstrates the use of data import functionality provided by ARX
 * 
 * @author Karol Babioch
 * @author Fabian Prasser
 */
public class Example21 extends Example {

    /**
     * Main entry point
     * @throws SQLException 
     * @throws ClassNotFoundException 
     */
    public static void main(final String[] args) throws IOException, SQLException, ClassNotFoundException {

        exampleCSV();
        exampleExcel();
        exampleJDBC();
    }

    /**
     * This class implements an example on how to use the API to import data from
     * a CSV file. It uses more advanced features than {@link #Example2}. Columns
     * are renamed and could be ignored altogether.
     */
    private static void exampleCSV() throws IOException {
        
        // Define configuration for CSV file
        DataSource source = DataSource.createCSVSource("data/test.csv", ';', true);

        // Add columns (index, name and datatype) to configuration
        // The name is optional and can be detected/assigned automatically
        source.addColumn(0, "renamed", DataType.INTEGER);
        source.addColumn(1, DataType.STRING);
        source.addColumn(2, DataType.STRING);

        // Create data object
        final Data data = Data.create(source);

        // Print to console
        print(data.getHandle());
    }

    /**
     * This class demonstrates how to use the API to import data from an Excel
     * source It is loosely based upon previous examples
     * as the API is quite similar.
     */
    private static void exampleExcel() throws IOException {
        

        // Define configuration for Excel file
        DataSource source = DataSource.createExcelSource("data/test.xls", 0, true);

        // Add columns (index, name and datatype) to configuration
        // The name is optional and can be detected/assigned automatically
        source.addColumn("age", "renamed", DataType.INTEGER);
        source.addColumn(1, DataType.STRING);
        source.addColumn(2, DataType.STRING);

        // Create data object
        final Data data = Data.create(source);

        // Print to console
        print(data.getHandle());
    }
    
    /**
     * This class demonstrates how to use the API to import data from a JDBC
     * source (SQLite in this case). It is loosely based upon previous examples
     * as the API is quite similar.
     * @throws ClassNotFoundException 
     */
    private static void exampleJDBC() throws IOException, SQLException, ClassNotFoundException {

        // Configuration for JDBC source
        Class.forName("org.sqlite.JDBC");
        DataSource source = DataSource.createJDBCSource("jdbc:sqlite:data/test.db", "test");

        // Add columns (index, name and datatype) to configuration
        // The name is optional and can be detected/assigned automatically
        source.addColumn("age", "renamed", DataType.INTEGER);
        source.addColumn(1, DataType.STRING);
        source.addColumn(2, DataType.STRING);

        // Create data object
        final Data data = Data.create(source);

        // Print to console
        print(data.getHandle());
    }
}

@@ -1914,33 +1914,32 @@
 ';', true);%0A
-%0A
         
 // Add colum
@@ -1930,291 +1930,573 @@
     
-// Add columns (index, name and datatype) to configuration%0A        // The name is optional and can be detected/assigned automatically%0A        source.addColumn(0, %22renamed%22, DataType.INTEGER);%0A        source.addColumn(1, DataType.STRING);%0A        source.addColumn(2, DataType.STRING);
+source.addColumn(%22age%22, %22renamed%22, DataType.INTEGER);%0A        source.addColumn(1, DataType.STRING);%0A        source.addColumn(2, DataType.STRING);%0A        %0A        // In the output dataset, the columns will appear in the same order as%0A        // specified by the order of calls to addColumn(). Columns in the source%0A        // can be addressed by either zero-based indexes or names. If columns%0A        // are addressed by name, the data source must contain a header. Optionally,%0A        // columns can be renamed by providing an alias or a data type can be specified
 %0A%0A  
@@ -3031,151 +3031,8 @@
 ue);
-%0A%0A        // Add columns (index, name and datatype) to configuration%0A        // The name is optional and can be detected/assigned automatically
 %0A   
@@ -3173,32 +3173,452 @@
 ataType.STRING);
+%0A        %0A        // In the output dataset, the columns will appear in the same order as%0A        // specified by the order of calls to addColumn(). Columns in the source%0A        // can be addressed by either zero-based indexes or names. If columns%0A        // are addressed by name, the data source must contain a header. Optionally,%0A        // columns can be renamed by providing an alias or a data type can be specified
 %0A%0A        // Cre
@@ -4278,151 +4278,8 @@
 t%22);
-%0A%0A        // Add columns (index, name and datatype) to configuration%0A        // The name is optional and can be detected/assigned automatically
 %0A   
@@ -4428,16 +4428,436 @@
 STRING);
+%0A        %0A        // In the output dataset, the columns will appear in the same order as%0A        // specified by the order of calls to addColumn(). Columns in the source%0A        // can be addressed by either zero-based indexes or names. If columns%0A        // are addressed by name, the data source must contain a header. Optionally,%0A        // columns can be renamed by providing an alias or a data type can be specified
 %0A%0A      

Add comments