/*******************************************************************************
 * Copyright 2013 DIMA Research Group, TU Berlin (http://www.dima.tu-berlin.de)
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/
package de.tu_berlin.dima.oligos.db.oracle;

import java.sql.SQLException;
import java.util.Set;

import org.javatuples.Quartet;

import de.tu_berlin.dima.oligos.db.JdbcConnector;
import de.tu_berlin.dima.oligos.db.SchemaConnector;


import org.apache.log4j.Logger;

public class OracleSchemaConnector implements SchemaConnector {

	private final static String RAW2NUM_FUNC = 
			"CREATE OR REPLACE FUNCTION raw2num(i_raw RAW) RETURN NUMBER " +
			"as " +
	    	"n NUMBER; " +
	    "begin " +
	    	"dbms_stats.convert_raw_value(i_raw, n); " +
	    	"return n; " +
	    "end;"; 
	
	private final static String RAW2DATE_FUNC = 
			"CREATE OR REPLACE FUNCTION raw2date(i_raw RAW) RETURN DATE " +
			"as " +
	    	"n DATE; " +
	    "begin " +
	    	"dbms_stats.convert_raw_value(i_raw, n); " +
	    	"return n; " +
	    "end;"; 
	
	private final static String RAW2CHAR_FUNC = 
			"CREATE OR REPLACE FUNCTION raw2char(i_raw RAW) RETURN VARCHAR2 " +
			"as " +
	    	"n VARCHAR2(1); " +
	    "begin " +
	    	"dbms_stats.convert_raw_value(i_raw, n); " +
	    	"return n; " +
	    "end;"; 

	
	private final JdbcConnector connector;
	
	private static final Logger LOGGER = Logger.getLogger(OracleSchemaConnector.class);
	
	 public OracleSchemaConnector(final JdbcConnector jdbcConnector) {
		 	this.connector = jdbcConnector;
		  LOGGER.info("entering OracleSchemaConnector() ...");  
		  try {	// register set of conversion functions 
		  	LOGGER.debug("register raw2* functions ...");
			  this.connector.execPreparedStmt(RAW2NUM_FUNC);
			  this.connector.execPreparedStmt(RAW2DATE_FUNC);
			  this.connector.execPreparedStmt(RAW2CHAR_FUNC);
			} catch (SQLException e) {
				e.printStackTrace();
			}
		  LOGGER.info("leaving OracleSchemaConnector");  
	 }
	
	@Override
	public Set<Quartet<String, String, String, String>> getReferences(String schema) throws SQLException {
		return this.connector.getReferences(schema);
	}
	
	
}

@@ -156,17 +156,16 @@
 n.de)%0A *
- 
 %0A * Lice
@@ -337,17 +337,16 @@
 se at%0A *
- 
 %0A *   ht
@@ -388,17 +388,16 @@
 E-2.0%0A *
- 
 %0A * Unle
@@ -840,93 +840,8 @@
 e;%0A%0A
-import java.sql.SQLException;%0Aimport java.util.Set;%0A%0Aimport org.javatuples.Quartet;%0A%0A
 impo
@@ -938,18 +938,16 @@
 nector;%0A
-%0A%0A
 import o
@@ -974,830 +974,160 @@
 er;%0A
-%0Apublic class OracleSchemaConnector implements SchemaConnector %7B%0A%0A%09private final static String RAW2NUM_FUNC = %0A%09%09%09%22CREATE OR REPLACE FUNCTION raw2num(i_raw RAW) RETURN NUMBER %22 +%0A%09%09%09%22as %22 +%0A%09    %09%22n NUMBER; %22 +%0A%09    %22begin %22 +%0A%09    %09%22dbms_stats.convert_raw_value(i_raw, n); %22 +%0A%09    %09%22return n; %22 +%0A%09    %22end;%22; %0A%09%0A%09private final static String RAW2DATE_FUNC = %0A%09%09%09%22CREATE OR REPLACE FUNCTION raw2date(i_raw RAW) RETURN DATE %22 +%0A%09%09%09%22as %22 +%0A%09    %09%22n DATE; %22 +%0A%09    %22begin %22 +%0A%09    %09%22dbms_stats.convert_raw_value(i_raw, n); %22 +%0A%09    %09%22return n; %22 +%0A%09    %22end;%22; %0A%09%0A%09private final static String RAW2CHAR_FUNC = %0A%09%09%09%22CREATE OR REPLACE FUNCTION raw2char(i_raw RAW) RETURN VARCHAR2 %22 +%0A%09%09%09%22as %22 +%0A%09    %09%22n VARCHAR2(1); %22 +%0A%09    %22begin %22 +%0A%09    %09%22dbms_stats.convert_raw_value(i_raw, n); %22 +%0A%09    %09%22return n; %22 +%0A%09    %22end;%22; %0A%0A%09%0A%09
+import org.javatuples.Quartet;%0A%0Aimport java.sql.SQLException;%0Aimport java.util.Set;%0A%0Apublic class OracleSchemaConnector implements SchemaConnector %7B%0A%0A  
 priv
@@ -1161,19 +1161,19 @@
 nector;%0A
-%09%0A%09
+%0A  
 private 
@@ -1248,19 +1248,18 @@
 class);%0A
-%09%0A%09
+%0A 
  public 
@@ -1321,12 +1321,12 @@
 ) %7B%0A
-%09%09 %09
+    
 this
@@ -1357,446 +1357,15 @@
 or;%0A
-%09%09  LOGGER.info(%22entering OracleSchemaConnector() ...%22);  %0A%09%09  try %7B%09// register set of conversion functions %0A%09%09  %09LOGGER.debug(%22register raw2* functions ...%22);%0A%09%09%09  this.connector.execPreparedStmt(RAW2NUM_FUNC);%0A%09%09%09  this.connector.execPreparedStmt(RAW2DATE_FUNC);%0A%09%09%09  this.connector.execPreparedStmt(RAW2CHAR_FUNC);%0A%09%09%09%7D catch (SQLException e) %7B%0A%09%09%09%09e.printStackTrace();%0A%09%09%09%7D%0A%09%09  LOGGER.info(%22leaving OracleSchemaConnector%22);  %0A%09 %7D%0A%09%0A%09
+  %7D%0A%0A  
 @Ove
@@ -1370,17 +1370,18 @@
 verride%0A
-%09
+  
 public S
@@ -1479,10 +1479,12 @@
 n %7B%0A
-%09%09
+    
 retu
@@ -1528,13 +1528,12 @@
 a);%0A
-%09%7D%0A%09%0A%09
+  %7D%0A%0A
 %0A%7D%0A

Remove redundant stored procedures from SchemaConnector.