Package ch.epfl.lbd.etl.loaders

Source Code of ch.epfl.lbd.etl.loaders.RAWGPSLoader

package ch.epfl.lbd.etl.loaders;

import java.text.DecimalFormat;

import ch.epfl.lbd.database.objects.RelationalTable;
import ch.epfl.lbd.database.providers.oracle.connection.OracleConnection;
import ch.epfl.lbd.database.providers.postgresql.connection.PostgreSqlConnection;
import ch.epfl.lbd.etl.ETLProcedure;

public class RAWGPSLoader extends ETLProcedure{
 
  //Constructor
  public RAWGPSLoader(){
    super();
  }
 
  @Override
  public void run() throws Exception{
   
    String[] columns = {"ID",
              "USERID",
              "DATETIME",
              "LATITUDE",
              "LONGITUDE",
              "NORTHING",
              "EASTING",
              "DIRECTION",
              "SPEED",
              "DISTANCE",
              "DURATION",
              "TAG"};
   
    String tableName = "MILAN_GMD3";
   
    //SOURCE TABLE
    RelationalTable source = new RelationalTable(tableName,columns);
   
    //SOURCE DATABASE
    OracleConnection sourceConnection = new OracleConnection("connections.properties","connection1");
    sourceConnection.openConnection();
   
    //DESTINATION TABLE
    RelationalTable destination = new RelationalTable(tableName,columns);
    destination.setForced(true);
   
    //DESTINATION DATABASE
    PostgreSqlConnection destinationConnection = new PostgreSqlConnection("connections.properties","connection4");
    destinationConnection.openConnection();
   
    //LOAD TABLES
    source.loadObject(sourceConnection);
    destination.setTypes(source.getTypes());
    destination.loadObject(destinationConnection);
   
    double size = source.size();
    logger.info("source table size is "+size);
   
    logger.info("populating destination table");
    DecimalFormat twoPlaces = new DecimalFormat("0.00");

    double i = 0;
    while(true){
      i++;
      boolean success = destination.insertRow(source.getNextRow());
      if(!success) break;
      logger.info(twoPlaces.format((i/size)*100)+"% done...");
    }
   
    logger.info("destination table size is "+destination.size());
   
    //RELEASE OBJECT LOCKS AND MEMORY
    source.releaseObject();
    destination.releaseObject();
   
    //CLOSE DATABASE CONNECTIONS
    sourceConnection.closeConnection();
    destinationConnection.closeConnection();
  }
}
TOP

Related Classes of ch.epfl.lbd.etl.loaders.RAWGPSLoader

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.