package urSQL.RuntimeDatabaseProcessor;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;

import urSQL.StoredDataManager.Pair;
import urSQL.StoredDataManager.StoreDataManager;
import urSQL.System.ResultSet;
import urSQL.System.TableAttribute;
import urSQL.System.TableMetadata;
import urSQL.System.TableRegister;
import urSQL.SystemCatalog.SystemCatalog;

public class DataIntegrityManager 
{
	
	public DataIntegrityManager()
	{
		
	}
	
	public boolean examineRS(ResultSet rs){
		boolean result = false;
	
		//manejo de archivos
		SystemCatalog sc = SystemCatalog.getInstance();
		StoreDataManager sdm = new StoreDataManager();
		//metadata
		TableMetadata  metadata = rs.getTableMetadata();
		//nombre de la tabla
		String table_name = metadata.getTableName();
		//se guardan las columnas con referencias
		Queue<String> queue_columns = new LinkedList<String>();
		//verifica si tienen referencias las 
		LinkedList<TableAttribute> list = metadata.getTableColumns();
		for(int i =0; i < list.size(); i++){
			String tmp = list.get(i).getName();
			if(sc.isHaveReferences(table_name, tmp)){
				queue_columns.add(tmp);
			}
		}
		
		
		LinkedList<Pair<Pair<String,String>,String>> list_2 = new LinkedList<Pair<Pair<String,String>,String>>();
		
		while(!queue_columns.isEmpty()){
			String column = queue_columns.poll();
			Pair<Pair<String,String>,String> tmp = sc.getReference(table_name, column);
			list_2.add(tmp);
		}
		
		LinkedList<TableRegister> rows = rs.getTableData().getData();
		
		for (int i = 0; i < rows.size(); i++) {
			for (int j = 0; j < list_2.size(); j++) {
				
			}
		}
		
		
		return result;
	}
	
	private int indexOf(LinkedList<String> list, String column){
		for (int i = 0; i < list.size(); i++) {
			if(list.get(i).compareTo(column) == 0){
				return i;
			}
		}
		return -1;
	}
}

@@ -38,35 +38,8 @@
 r;%0A%0A
-import java.util.Iterator;%0A
 impo
@@ -499,12 +499,11 @@
 t = 
-fals
+tru
 e;%0A%09
@@ -1582,16 +1582,311 @@
 ) %7B%0A%09%09%09%09
+LinkedList%3CString%3E reg = rows.get(i).getRegister();%0A%09%09%09%09%0A%09%09%09%09int index = indexOf(reg, list_2.get(j).getSecond());%0A%09%09%09%09%0A%09%09%09%09String value1 = reg.get(index);%0A%09%09%09%09%0A%09%09%09%09boolean flag = sdm.isColumn(list_2.get(j).getFirst().getFirst(), value1);%0A%09%09%09%09%0A%09%09%09%09if(!flag)%7B%0A%09%09%09%09%09result =false;%0A%09%09%09%09%09break;%0A%09%09%09%09%7D
 %0A%09%09%09%7D%0A%09%09

Valida Integración