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

- Adds factory for a database driver;

- A scan is now specific to a database, an operator has access to the
targeted database.
parent 33853fec
Branches
No related tags found
No related merge requests found
package qir.ast;
import com.oracle.truffle.api.source.SourceSection;
import qir.util.IQIRVisitor;
import com.oracle.truffle.api.source.*;
/**
* A generic QIR node. Every QIR node must inherit from {@link QIRNode}.
*/
......
......@@ -3,6 +3,7 @@ package qir.ast.operator;
import com.oracle.truffle.api.source.SourceSection;
import qir.ast.QIRNode;
import qir.driver.*;
import qir.util.IQIRVisitor;
/**
......@@ -33,6 +34,11 @@ public class QIRGroup extends QIROperator {
return child;
}
@Override
public DBDriver getDriver() {
return child.getDriver();
}
@Override
public <T> T accept(IQIRVisitor<T> visitor) {
return visitor.visit(this);
......
......@@ -3,6 +3,7 @@ package qir.ast.operator;
import com.oracle.truffle.api.source.SourceSection;
import qir.ast.QIRNode;
import qir.driver.*;
import qir.util.IQIRVisitor;
/**
......@@ -13,6 +14,8 @@ public abstract class QIROperator extends QIRNode {
super(source);
}
public abstract DBDriver getDriver();
@Override
public <T> T accept(IQIRVisitor<T> visitor) {
return visitor.visit(this);
......
......@@ -3,6 +3,7 @@ package qir.ast.operator;
import com.oracle.truffle.api.source.SourceSection;
import qir.ast.QIRNode;
import qir.driver.*;
import qir.util.IQIRVisitor;
/**
......@@ -33,6 +34,11 @@ public class QIROrder extends QIROperator {
return child;
}
@Override
public DBDriver getDriver() {
return child.getDriver();
}
@Override
public <T> T accept(IQIRVisitor<T> visitor) {
return visitor.visit(this);
......
......@@ -3,6 +3,7 @@ package qir.ast.operator;
import com.oracle.truffle.api.source.SourceSection;
import qir.ast.QIRNode;
import qir.driver.*;
import qir.util.IQIRVisitor;
/**
......@@ -33,6 +34,11 @@ public class QIRProject extends QIROperator {
return formatter;
}
@Override
public DBDriver getDriver() {
return child.getDriver();
}
@Override
public <T> T accept(IQIRVisitor<T> visitor) {
return visitor.visit(this);
......
......@@ -3,6 +3,7 @@ package qir.ast.operator;
import com.oracle.truffle.api.source.SourceSection;
import qir.ast.QIRNode;
import qir.driver.*;
import qir.util.IQIRVisitor;
/**
......@@ -13,16 +14,23 @@ public class QIRScan extends QIROperator {
* An expression that identifies the table to access.
*/
private final QIRNode table;
private final DBDriver driver;
public QIRScan(SourceSection source, QIRNode table) {
public QIRScan(SourceSection source, QIRNode table, DBDriver driver) {
super(source);
this.table = table;
this.driver = driver;
}
public QIRNode getTable() {
return table;
}
@Override
public DBDriver getDriver() {
return driver;
}
@Override
public <T> T accept(IQIRVisitor<T> visitor) {
return visitor.visit(this);
......
......@@ -3,6 +3,7 @@ package qir.ast.operator;
import com.oracle.truffle.api.source.SourceSection;
import qir.ast.QIRNode;
import qir.driver.*;
import qir.util.IQIRVisitor;
/**
......@@ -33,6 +34,11 @@ public class QIRSelect extends QIROperator {
return child;
}
@Override
public DBDriver getDriver() {
return child.getDriver();
}
@Override
public <T> T accept(IQIRVisitor<T> visitor) {
return visitor.visit(this);
......
......@@ -31,6 +31,7 @@ public class OracleDriver extends DBDriver {
public QIRList run(QIRNode root) {
QIROracleVisitor visitor = new QIROracleVisitor();
String query = root.accept(visitor);
System.out.println("Query: " + query);
Map<String, String> funs = visitor.popProlog();
try {
enableWalnut();
......
......@@ -2,12 +2,24 @@ package qir.driver;
import qir.ast.*;
import qir.ast.data.*;
import qir.util.*;
/**
* TODO: Add interface to stream results; add interface to get database info (table exists?, table
* schema, ...).
*/
public class QIRDriver {
public DBDriver defaultDriver;
private final DBDriver defaultDriver;
public QIRDriver(DBDriver defaultDriver) {
this.defaultDriver = defaultDriver;
}
public QIRList run(QIRNode root) {
DummyDBDriver dummydbdriver = new DummyDBDriver();
QIRPrintVisitor debugVisitor = new QIRPrintVisitor();
System.out.println(root.accept(debugVisitor));
try {
return defaultDriver.run(root);
} catch (Exception e) {
......
package qir.factory;
import java.sql.*;
import qir.driver.*;
import qir.driver.OracleDriver.ConnectionData;
public class DBDriverFactory {
public static DBDriver createDBDriver(String dbName, String sessionId, String serverName, int port, String userName, String passwd) {
if (dbName.equalsIgnoreCase("Oracle"))
try {
return new OracleDriver(new ConnectionData(sessionId, serverName, port, userName, passwd));
} catch (SQLException e) {
e.printStackTrace();
}
throw new IllegalArgumentException("Error: \"" + dbName + "\" is not a valid database name.");
}
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ import qir.ast.expression.logic.*;
import qir.ast.expression.relational.*;
import qir.ast.value.*;
import qir.ast.operator.*;
import qir.driver.*;
import com.oracle.truffle.api.frame.*;
import com.oracle.truffle.api.source.NullSourceSection;
......@@ -48,10 +49,11 @@ public class QIRFactory {
* @param value An identifier for the node used to recreate its {@link SourceSection} (and the
* table name).
* @param charPos The position of the node in the source.
* @param driver The driver to the targeted database.
* @return A new {@link QIRScan} node.
*/
public QIRScan createScan(String value, int charPos) {
return new QIRScan(srcFromToken(value, charPos), new QIRTable(srcFromToken(value, charPos), value));
public QIRScan createScan(String value, int charPos, DBDriver driver) {
return new QIRScan(srcFromToken(value, charPos), new QIRTable(srcFromToken(value, charPos), value), driver);
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment