Skip to content
Snippets Groups Projects
Commit aa60010f authored by Julien Lopez's avatar Julien Lopez
Browse files

Update to new QIR version

parent 079b8b7e
No related branches found
No related tags found
No related merge requests found
ora.host = myoracle.com host = myoracle.com
ora.sid = myview sid = myview
ora.port = 7658 port = 7658
ora.user = julilope user = julilope
ora.passwd = AVONEJ$sartec3 passwd = Pa$$w0rd
pgsql.host = localhost host = localhost
pgsql.sid = postgres sid = postgres
pgsql.port = 5432 port = 5432
pgsql.user = julien user = julien
pgsql.passwd = Pa$$w0rd passwd = Pa$$w0rd
pgsql.host = localhost host = localhost
pgsql.sid = other sid = other
pgsql.port = 5432 port = 5432
pgsql.user = julien user = julien
pgsql.passwd = Pa$$w0rd passwd = Pa$$w0rd
...@@ -22,16 +22,11 @@ ...@@ -22,16 +22,11 @@
*/ */
package com.oracle.truffle.r.nodes.qirinterface; package com.oracle.truffle.r.nodes.qirinterface;
import java.io.FileReader;
import java.io.IOException;
import java.io.Reader;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import com.oracle.truffle.api.frame.Frame; import com.oracle.truffle.api.frame.Frame;
import com.oracle.truffle.api.frame.FrameDescriptor; import com.oracle.truffle.api.frame.FrameDescriptor;
import com.oracle.truffle.api.frame.FrameSlot; import com.oracle.truffle.api.frame.FrameSlot;
...@@ -48,16 +43,10 @@ import com.oracle.truffle.r.runtime.env.REnvironment; ...@@ -48,16 +43,10 @@ import com.oracle.truffle.r.runtime.env.REnvironment;
import qir.ast.*; import qir.ast.*;
import qir.ast.data.*; import qir.ast.data.*;
import qir.ast.expression.*; import qir.ast.expression.*;
import qir.driver.sql.OracleDriver;
import qir.driver.sql.PostgreSQLDriver;
import qir.driver.ConnectionData;
import qir.driver.DBDriver; import qir.driver.DBDriver;
import qir.driver.QIRDriver; import qir.driver.QIRDriver;
import qir.driver.hbase.HBaseDriver;
public final class QIRInterface { public final class QIRInterface {
private static final Map<String, DBDriver<?, ?>> driverCache = new HashMap<>();
/** /**
* Runs a query in the database pointed by the given driver and returns the results. * Runs a query in the database pointed by the given driver and returns the results.
* *
...@@ -124,65 +113,10 @@ public final class QIRInterface { ...@@ -124,65 +113,10 @@ public final class QIRInterface {
} }
/** /**
* Returns a {@link DBDriver} of a database using a configuration file. This function uses a * This function closes the connection of database drivers.
* cache for the drivers.
*
* @param dbName The name of the targeted database
* @param fileName The name of the configuration file
* @return A {@link DBDriver} to the given database with the given configuration
*/
public static final DBDriver<?, ?> createDriver(final String dbName, final String fileName) throws UnsupportedOperationException {
final String cacheKey = dbName + '@' + fileName;
DBDriver<?, ?> result = driverCache.get(cacheKey);
if (result != null)
return result;
switch (dbName) {
case "Oracle":
result = new OracleDriver(createConnectionData("ora", fileName));
break;
case "PostgreSQL":
result = new PostgreSQLDriver(createConnectionData("pgsql", fileName));
break;
case "HBase":
result = new HBaseDriver(fileName);
break;
default:
throw new RuntimeException("Unknown database: " + dbName);
}
driverCache.put(cacheKey, result);
return result;
}
/**
* This function closes the connection of drivers created with the function
* {@link #createDriver(String, String)}.
*/ */
public static final void closeDrivers() { public static final void closeDrivers() {
driverCache.values().stream().forEach(driver -> driver.closeConnection()); DBDriver.closeDrivers();
}
/**
* Creates a {@link ConnectionData} object based on the given configuration file.
*
* @param prefix A prefix for properties in the configuration file
* @param fileName The name of the configuration file
* @return A {@link ConnectionData} created from the given configuration file
*/
private static final ConnectionData createConnectionData(final String prefix, final String fileName) {
try {
final Reader dbConfigReader = new FileReader(fileName);
final Properties p = new Properties();
p.load(dbConfigReader);
final String sessionId = p.getProperty(prefix + ".sid");
final String serverName = p.getProperty(prefix + ".host");
final int port = Integer.parseInt(p.getProperty(prefix + ".port"));
final String userName = p.getProperty(prefix + ".user");
final String passwd = p.getProperty(prefix + ".passwd");
return new ConnectionData(sessionId, serverName, port, userName, passwd);
} catch (IOException e) {
throw new RuntimeException("Invalid configuration file for connection to a database: " + fileName);
}
} }
/** /**
......
ora.host = myoracle.com host = myoracle.com
ora.sid = myview sid = myview
ora.port = 7658 port = 7658
ora.user = julilope user = julilope
ora.passwd = AVONEJ$sartec3 passwd = Pa$$w0rd
pgsql.host = localhost host = localhost
pgsql.sid = postgres sid = postgres
pgsql.port = 5432 port = 5432
pgsql.user = julien user = julien
pgsql.passwd = Pa$$w0rd passwd = Pa$$w0rd
pgsql.host = localhost host = localhost
pgsql.sid = other sid = other
pgsql.port = 5432 port = 5432
pgsql.user = julien user = julien
pgsql.passwd = Pa$$w0rd passwd = Pa$$w0rd
ora.host = myoracle.com host = myoracle.com
ora.sid = myview sid = myview
ora.port = 7658 port = 7658
ora.user = julilope user = julilope
ora.passwd = AVONEJ$sartec3 passwd = Pa$$w0rd
pgsql.host = localhost host = localhost
pgsql.sid = postgres sid = postgres
pgsql.port = 5432 port = 5432
pgsql.user = julien user = julien
pgsql.passwd = Pa$$w0rd passwd = Pa$$w0rd
pgsql.host = localhost host = localhost
pgsql.sid = other sid = other
pgsql.port = 5432 port = 5432
pgsql.user = julien user = julien
pgsql.passwd = Pa$$w0rd passwd = Pa$$w0rd
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment