Browse Source

HUE-2745 [dbms] Add initial DBProxy app

Based on py4j
Erick Tryzelaar 10 years ago
parent
commit
f620d0f

+ 19 - 0
desktop/libs/librdbms/java/README.md

@@ -0,0 +1,19 @@
+Build with:
+
+```
+% mvn package
+% virtualenv build
+% ./build/bin/pip install py4j
+```
+
+Start JVM:
+
+```
+% java -jar target/dbproxy-1.0-SNAPSHOT.jar
+```
+
+Run a query:
+
+```
+% ./build/bin/python query.py
+```

+ 77 - 0
desktop/libs/librdbms/java/pom.xml

@@ -0,0 +1,77 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>com.cloudera.hue</groupId>
+    <artifactId>dbproxy</artifactId>
+    <version>1.0-SNAPSHOT</version>
+
+    <dependencies>
+        <dependency>
+            <groupId>net.sf.py4j</groupId>
+            <artifactId>py4j</artifactId>
+            <version>0.8.2.1</version>
+        </dependency>
+
+        <dependency>
+            <groupId>mysql</groupId>
+            <artifactId>mysql-connector-java</artifactId>
+            <version>5.1.34</version>
+        </dependency>
+    </dependencies>
+
+    <build>
+    <plugins>
+        <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-jar-plugin</artifactId>
+            <configuration>
+                <archive>
+                    <manifest>
+                        <addClasspath>true</addClasspath>
+                        <classpathPrefix>lib/</classpathPrefix>
+                        <mainClass>com.cloudera.hue.dbproxy.DBProxy</mainClass>
+                    </manifest>
+                </archive>
+            </configuration>
+        </plugin>
+
+        <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-shade-plugin</artifactId>
+
+            <configuration>
+                <shadedArtifactAttached>false</shadedArtifactAttached>
+                <outputFile>${livy.jar}</outputFile>
+                <artifactSet>
+                    <includes>
+                        <include>*:*</include>
+                    </includes>
+                </artifactSet>
+                <filters>
+                    <filter>
+                        <artifact>*:*</artifact>
+                        <excludes>
+                            <exclude>META-INF/*.SF</exclude>
+                            <exclude>META-INF/*.DSA</exclude>
+                            <exclude>META-INF/*.RSA</exclude>
+                        </excludes>
+                    </filter>
+                </filters>
+            </configuration>
+
+            <executions>
+                <execution>
+                    <phase>package</phase>
+                    <goals>
+                        <goal>shade</goal>
+                    </goals>
+                </execution>
+            </executions>
+        </plugin>
+    </plugins>
+    </build>
+
+</project>

+ 33 - 0
desktop/libs/librdbms/java/query.py

@@ -0,0 +1,33 @@
+from py4j.java_gateway import JavaGateway
+
+gateway = JavaGateway()
+
+jdbc_driver = 'com.mysql.jdb.Driver'
+db_url = 'jdbc:mysql://localhost/hue'
+username = 'root'
+password = 'root'
+
+conn = gateway.jvm.java.sql.DriverManager.getConnection(db_url, username, password)
+
+try:
+  stmt = conn.createStatement()
+  try:
+    rs = stmt.executeQuery('select username,email from auth_user')
+
+    try:
+
+      md = rs.getMetaData()
+
+      for i in xrange(md.getColumnCount()):
+         print md.getColumnTypeName(i + 1)
+
+      while rs.next():
+        username = rs.getString("username")
+        email = rs.getString("email")
+        print username, email
+    finally:
+      rs.close()
+  finally:
+    stmt.close()
+finally:
+  conn.close()

+ 12 - 0
desktop/libs/librdbms/java/src/main/java/com/cloudera/hue/dbproxy/DBProxy.java

@@ -0,0 +1,12 @@
+package com.cloudera.hue.dbproxy;
+
+import py4j.GatewayServer;
+
+public class DBProxy {
+  public static void main(String[] args) {
+    DBProxy proxy = new DBProxy();
+    GatewayServer server = new GatewayServer(proxy);
+    System.out.println("port: " + server.getPort());
+    server.start();
+  }
+}