Browse Source

not upper case columns for in mem db

Ademar Crotti 5 years ago
parent
commit
6db193da7a
1 changed files with 28 additions and 26 deletions
  1. 28 26
      src/r2rml/engine/R2RMLProcessor.java

+ 28 - 26
src/r2rml/engine/R2RMLProcessor.java

@@ -30,18 +30,18 @@ public class R2RMLProcessor {
 	private Configuration configuration = null;
 	private Connection connection = null;
 	private Dataset dataset = DatasetFactory.create();
-	
+
 	public R2RMLProcessor(Configuration configuration) {
 		this.configuration = configuration;
 	}
 
 	public void execute() {
 		createDatabaseConnection();
-		
+
 		String file = configuration.getMappingFile();
 		String R2RMLmapping = configuration.getMapping();
 		String baseIRI = configuration.getBaseIRI();
-		
+
 		R2RMLMapping mapping = null;
 		if (file != null) {
 			mapping = R2RMLMappingFactory.createR2RMLMappingFromFile(file, baseIRI);
@@ -53,37 +53,38 @@ public class R2RMLProcessor {
 		}
 
 		DB database = new DB(connection, configuration);
-		
+
 		boolean abort = false;
-		
+
 		if (mapping != null) {
 			if (!mapping.generateTriples(database, dataset))
 				abort = true;
 		} else {
 			abort = true;
 		}
-		
+
 		closeDatabaseConnection();
 
-		if(abort) {
+		if (abort) {
 			logger.error("We had to abort generation of triples. See log for details.");
 		}
 	}
 
 	private void createDatabaseConnection() {
 		// Determine situation
-		if(configuration.hasConnectionURL() && configuration.hasCSVFiles()) {
+		if (configuration.hasConnectionURL() && configuration.hasCSVFiles()) {
 			logger.error("You cannot provide a connection URL and a list of CSV files at the same time.");
 			System.exit(-1);
 		}
-		
+
 		try {
 			Properties props = new Properties();
-			
+
 			// If files, create in-memory database
-			if(configuration.hasCSVFiles()) {
+			if (configuration.hasCSVFiles()) {
 				try {
-					// This method will create a new connection URL that will be added to the configuration
+					// This method will create a new connection URL that will be
+					// added to the configuration
 					connection = createTablesFromCSVFiles();
 				} catch (Exception ex) {
 					logger.error("Exception during database startup.", ex);
@@ -93,13 +94,13 @@ public class R2RMLProcessor {
 				// Connecting to a database
 				String user = configuration.getUser();
 				String pass = configuration.getPassword();
-				if(user != null && !"".equals(user))
+				if (user != null && !"".equals(user))
 					props.setProperty("user", user);
-				if(pass != null && !"".equals(pass))
-					props.setProperty("password", pass);			
+				if (pass != null && !"".equals(pass))
+					props.setProperty("password", pass);
 				connection = DriverManager.getConnection(configuration.getConnectionURL(), props);
 			}
-			
+
 		} catch (SQLException e) {
 			logger.error("Error connecting to database.", e);
 			System.exit(-1);
@@ -110,24 +111,25 @@ public class R2RMLProcessor {
 	private Connection createTablesFromCSVFiles() throws Exception {
 		String connectionURL = "jdbc:h2:mem:" + System.currentTimeMillis();
 		configuration.setConnectionURL(connectionURL);
-		
+
 		logger.info("Starting in-memory database");
-		DriverManager.getConnection(connectionURL + ";create=true").close();
-		
+		DriverManager.getConnection(connectionURL + ";create=true;DATABASE_TO_UPPER=false").close();
+
 		Connection connection = DriverManager.getConnection(connectionURL);
 		Statement statement = connection.createStatement();
-		
+
 		// for each file, load file as table...
-		for(String f : configuration.getCSVFiles()) {
+		for (String f : configuration.getCSVFiles()) {
 			File file = new File(f);
 			String name = createTableNameForFile(file);
 			logger.info("Loading " + file + " as table " + name);
-			String sql = "CREATE TABLE " + name + " AS SELECT * FROM CSVREAD('"  + file.getAbsolutePath() + "', NULL, NULL);";
+			String sql = "CREATE TABLE " + name + " AS SELECT * FROM CSVREAD('" + file.getAbsolutePath()
+					+ "', NULL, NULL);";
 			statement.execute(sql);
-			logger.info("Loaded " + file + " as table " + name);	
+			logger.info("Loaded " + file + " as table " + name);
 		}
-		
-		// only close the statement. Don't close connection! It will be returned 
+
+		// only close the statement. Don't close connection! It will be returned
 		statement.close();
 		return connection;
 	}
@@ -139,7 +141,7 @@ public class R2RMLProcessor {
 
 	private void closeDatabaseConnection() {
 		try {
-			if(!connection.isClosed())
+			if (!connection.isClosed())
 				connection.close();
 		} catch (SQLException e) {
 			logger.error("Error closing connection with database.", e);