package mosaik;

import java.io.File;
import java.io.IOException;

import dataBase.DataBase;

import util.Timer;
import util.simpleIO.Out;

public class _MakeDataBase_KRISI {

	//public static File dir = new File("D:/_testData_/12GB");
	//public static File dir = new File("D:/_testData_/alt1k");
	public static File dir = new File("D:/_testData_/11k");
	//public static File dir = new File("D:/_testData_/neu10k");
//	public static File dir = new File("./testdaten/alt");
	public static File dbFile = new File(dir.getAbsolutePath()+"/DataBase0.db");
	
	/**
	 * @param args
	 * @throws IOException 
	 * @throws ClassNotFoundException 
	 */
	public static void main(String[] args) throws IOException, ClassNotFoundException {

		Out.pl("Making DB:");
		Timer t = new Timer();
		DataBase db = MosaikFunctions.makeDatabase(dir);
		Out.pl("DB generated in "+(t.getTime()/1000.0)+" sec.");
		
		MosaikFunctions.storeDatabase(db, dbFile);
		Out.pl("DB stored.");
		
		//DataBase dbCopy = MosaikFunctions.loadDatabase(dbFile);
		//Out.pl("DB loaded again: "+dbCopy);
		
		
//		//--------------------------------------------------------
//		File[] dbFiles = {
//				new File("D:/_testData_/12GB/DataBase0.db"),
//				new File("D:/_testData_/neu10k/DataBase0.db"),
//		};
//		
//		DataBase db = combineDatabase(dbFiles);
//		MosaikFunctions.storeDatabase(db, new File("D:/_testData_/DataBase1.db"));
//		Out.pl("finished");
	}

	
	static DataBase combineDatabase(File[] dbFiles) throws IOException, ClassNotFoundException{
		
		DataBase db=null;
		//DataBase[] dbs = new DataBase[dbFiles.length];
		
		Out.pl("Combine DBs:");
		for(int i=0; i<dbFiles.length; i++){
			
			if(db==null)
				db = MosaikFunctions.loadDatabase(dbFiles[i]);
			else
				db.add( MosaikFunctions.loadDatabase(dbFiles[i]) );
		}
		
		return db;
	}
	
	
}
