trafodion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmar...@apache.org
Subject [1/2] incubator-trafodion git commit: Add java files needed for TEST125
Date Tue, 27 Jun 2017 18:48:08 GMT
Repository: incubator-trafodion
Updated Branches:
  refs/heads/master 665ea9330 -> c401633eb


Add java files needed for TEST125


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/commit/e67e90f8
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/tree/e67e90f8
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafodion/diff/e67e90f8

Branch: refs/heads/master
Commit: e67e90f8bd94f8022d98904d7105f2c782f57080
Parents: 012d654
Author: Roberta Marton <rmarton@edev07.esgyn.local>
Authored: Tue Jun 27 15:32:39 2017 +0000
Committer: Roberta Marton <rmarton@edev07.esgyn.local>
Committed: Tue Jun 27 15:32:39 2017 +0000

----------------------------------------------------------------------
 core/sql/regress/privs1/TEST125       |   4 +-
 core/sql/regress/privs1/TestHive.java |  91 ++++++++++
 core/sql/regress/privs1/Utils.java    | 279 +++++++++++++++++++++++++++++
 3 files changed, 371 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e67e90f8/core/sql/regress/privs1/TEST125
----------------------------------------------------------------------
diff --git a/core/sql/regress/privs1/TEST125 b/core/sql/regress/privs1/TEST125
index 09e0d2d..0025c53 100644
--- a/core/sql/regress/privs1/TEST125
+++ b/core/sql/regress/privs1/TEST125
@@ -160,9 +160,6 @@ create view games_by_player as
   order by player_name, team_number;
 
 -- create function to display bitmaps as a bitmap rather than longs
--- set envvar REGRRUNDIR '/mnt/rmarton/gitws/incubator-trafodion/core/sql/regress/rundir/privs1';
--- set envvar REGRTSTDIR '/mnt/rmarton/gitws/incubator-trafodion/core/sql/regress/privs1';
--- set envvar scriptsdir '/mnt/rmarton/gitws/incubator-trafodion/core/sql/regress';
 sh rm -f ./etest141.dll;
 sh sh $$scriptsdir$$/tools/dll-compile.ksh etest141.cpp
   2>&1 | tee LOG125-SECONDARY;
@@ -175,6 +172,7 @@ language c parameter style sql external name 'translateBitmap'
 library t125_l1
 deterministic no sql final call allow any parallelism state area size 1024 ;
 
+-- create procedure that accesses hive tables
 sh sh $$scriptsdir$$/tools/java-compile.ksh Utils.java TestHive.java 2> LOG125-SECONDARY
| tee -a LOG125;
 sh sh $$scriptsdir$$/tools/java-archive.ksh TEST125_procs.jar TestHive.class Utils.class
2>> LOG125-SECONDARY | tee -a LOG125;
 set pattern $$JARF$$ TEST125_procs.jar;

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e67e90f8/core/sql/regress/privs1/TestHive.java
----------------------------------------------------------------------
diff --git a/core/sql/regress/privs1/TestHive.java b/core/sql/regress/privs1/TestHive.java
new file mode 100644
index 0000000..352f226
--- /dev/null
+++ b/core/sql/regress/privs1/TestHive.java
@@ -0,0 +1,91 @@
+import java.io.*;
+import java.sql.*;
+import java.util.*;
+
+// ===================================================================
+// Class: testHive
+//
+// ===================================================================
+public class TestHive
+{
+  // --------------------------------------------------------------------------
+  // Main code for credentials procedure
+  // --------------------------------------------------------------------------
+  public static void accessHive (
+    String operationIn,
+    String[] results)
+
+  throws SQLException
+  {
+    // Initialize the Utils structure
+    // Utils provides connection, user, current time, and logging information
+    Utils util = null;
+
+    try
+    {
+       util = new Utils();
+    }
+    catch(Exception e)
+    {
+      String theError = "ERROR: unable to create the Util object";
+      throw e;
+    }
+
+    util.log ("");
+    util.log ("***** Starting credentials request *****");
+
+    // Set up the connection
+    Connection conn = null;
+    String sessionUser = null;
+    String currentUser = null;
+    String currentTime = null;
+    try
+    {
+       conn = util.myConnection();
+    }
+    catch(Exception e)
+    {
+      String theError = "ERROR: unable to get a connection";
+      throw e;
+    }
+
+    sessionUser = util.getSessionUser(conn);
+    currentUser = util.getCurrentUser(conn);
+    currentTime = util.getCurrentTime(conn);
+
+    results[0] = "External user: " + sessionUser + '\n';
+    results[0] += "Current user: " + currentUser + '\n';
+    results[0] += "Current time: " + currentTime + '\n';
+
+    util.log("Session user: " + sessionUser);
+    util.log("Current user: " + currentUser);
+    util.log("Current time: " + currentTime);
+
+    try
+    {
+      int numRows;
+      String selectQuery = "select count(*) from hive.hive.";
+      selectQuery += operationIn;
+      Statement stmt = conn.createStatement();
+      util.log("Executing select query");
+      ResultSet rset = stmt.executeQuery(selectQuery);
+      if (rset.next())
+      {
+        numRows = rset.getInt(1);
+        results[0] += "Number rows:" + numRows + '\n';
+      }
+      else
+        results[0] += "none found" + '\n';
+
+      rset.close(); stmt.close();
+    } 
+    catch (SQLException e) {
+      util.log("Error encountered in getCurrentUser " + e.getMessage());
+      throw new SQLException(e.getMessage());
+    }
+
+    results[0] += "Operation successful";
+    util.log ("***** Completed credentials request *****");
+  }
+}
+

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e67e90f8/core/sql/regress/privs1/Utils.java
----------------------------------------------------------------------
diff --git a/core/sql/regress/privs1/Utils.java b/core/sql/regress/privs1/Utils.java
new file mode 100644
index 0000000..c48846a
--- /dev/null
+++ b/core/sql/regress/privs1/Utils.java
@@ -0,0 +1,279 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you 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.
+//
+// @@@ END COPYRIGHT @@@
+
+import java.io.*;
+import java.sql.*;
+import java.util.*;
+
+// ===================================================================
+// Class:  Utils
+//
+//  This is a helper class for the other SPJs that: 
+//     - gets connection (myConnection)
+//     - gets current user executing the SPJ (getCurrentUser)
+//     - gets session user if definer rights are used (getSessionUser)
+//     - gets current timestamp ( getCurrentTime )
+//     - transaction management ops
+//        - BEGIN
+//        - COMMIT
+//        - ROLLBACK
+//     - log debug statements (log)
+//     - log execeptions (printExceptionStack)
+//
+// ===================================================================
+public class Utils 
+{
+   static boolean log = false;
+   static String logFileName = "udr_tools.log";
+   static String logLocation = null;
+   static String sqRoot = null;
+   static String userName = null;
+
+   Utils () 
+   {
+     if (!log)
+       log = Boolean.getBoolean("debugOn");
+     
+     if (log) { 
+       sqRoot = System.getenv("TRAF_HOME");
+       logLocation = sqRoot + "/logs/";
+     }
+   }
+
+   // Returns a JDBC Connection for use within the SPJ 
+   // returns Connection and throws Exception
+
+    public static Connection myConnection() throws SQLException
+    {
+        Connection conn = null;
+        try
+        {
+           String url = "jdbc:default:connection";
+           java.util.Properties props = new java.util.Properties();
+           props.setProperty("maxStatements", "0"); // disable JDBC statement caching
+           conn = DriverManager.getConnection(url, props);
+           log("Returning connection from myConnection " + (conn != null));
+        }
+        catch (Throwable t)
+        {
+           log("Error encountered while getting connection " + t.getMessage());
+           printExceptionStack(t);
+           throw new SQLException(t.getMessage());
+        }
+        return conn;
+    }
+
+    private static String getLogFile(String path) 
+    {
+       String file=null;
+
+       if (path != null)
+        file = path + logFileName;
+       else 
+        file = logFileName;
+       return file;
+    }
+
+    // Log a message to a log file.    
+    protected static void log(String message)
+    {
+      if (log)
+      {
+       try
+       {
+          String file = getLogFile(logLocation);
+          FileWriter fw = new FileWriter(file, true);
+          PrintWriter pw = new PrintWriter(fw);
+          pw.println("@" + Calendar.getInstance().getTime() + ": " + message);
+          pw.close();
+          fw.flush();
+          fw.close();
+       } catch (Exception ex) {}
+      }
+    }
+    
+     // Print exception stack.
+    protected static void printExceptionStack(Throwable t)
+    {
+      if (log)
+      {
+       try
+       {
+          String file = getLogFile(logLocation);
+          FileWriter fw = new FileWriter(file, true);
+          PrintWriter pw = new PrintWriter(fw);
+          t.printStackTrace(pw);
+          pw.close();
+          fw.flush();
+          fw.close();
+        } catch (Exception ex) { }
+      }
+    }
+
+    public static String getCurrentUser(Connection conn) throws SQLException
+    {
+        log("In method getCurrentUser");
+        try {
+          Statement stmt = conn.createStatement();
+          log("In method getCurrentUser:gotStatement");
+          ResultSet rset = stmt.executeQuery("VALUES(USER)");
+          while (rset != null && rset.next())
+          {
+            userName = rset.getString(1);
+          }
+          log("In method getCurrentUser:doneExecuteQuery::" + userName);
+          rset.close(); stmt.close();
+        } catch (SQLException e) {
+          log("Error encountered in getCurrentUser " + e.getMessage());
+          printExceptionStack(e);
+          throw new SQLException(e.getMessage());
+        }
+        return userName;
+    }
+    
+    public static String getSessionUser(Connection conn) throws SQLException
+    {
+        log("In method getSessionUser");
+        try {
+          Statement stmt = conn.createStatement();
+          log("In method getSessionUser:gotStatement");
+          ResultSet rset = stmt.executeQuery("VALUES(SESSION_USER)");
+          while (rset != null && rset.next())
+          {
+            userName = rset.getString(1);
+          }
+          log("In method getSessionUser:doneExecuteQuery::" + userName);
+          rset.close(); stmt.close();
+        } catch (SQLException e) {
+          log("Error encountered in getSessionUser " + e.getMessage());
+          printExceptionStack(e);
+          throw new SQLException(e.getMessage());
+        }
+        return userName;
+    }
+
+    public static String getCurrentTime(Connection conn) throws SQLException
+    {
+        log("In method getCurrentTime");
+        try {
+          Statement stmt = conn.createStatement();
+          log("In method getCurrentTime:gotStatement");
+          ResultSet rset = stmt.executeQuery("VALUES(CURRENT_TIMESTAMP(2))");
+          while (rset != null && rset.next())
+          {
+            userName = rset.getString(1);
+          }
+          log("In method getCurrentTime:doneExecuteQuery::" + userName);
+          rset.close(); stmt.close();
+        } catch (SQLException e) {
+          log("Error encountered in getCurrentTime " + e.getMessage());
+          printExceptionStack(e);
+          throw new SQLException(e.getMessage());
+        }
+        return userName;
+    }
+
+    public static void beginTxn(Connection conn) throws SQLException
+    {
+        log("In method beginTxn");
+        try {
+          log("In method beginTxn:gotStatement");
+          PreparedStatement stmt = conn.prepareStatement("begin work;");
+          stmt.executeUpdate();
+
+          log("In method beginTxn:doneExecuteUpdate");
+          stmt.close();
+        } catch (SQLException e) {
+          if (e.getErrorCode() != -8603) {
+            log("Error encountered in beginTxn " + e.getMessage());
+            printExceptionStack(e);
+            throw new SQLException(e.getMessage());
+          }
+        }
+    }
+
+    public static void commitTxn(Connection conn) throws SQLException
+    {
+        log("In method commitTxn");
+        try {
+          log("In method commitTxn:gotStatement");
+          PreparedStatement stmt = conn.prepareStatement("commit work;");
+          stmt.executeUpdate();
+
+          log("In method commitTxn:doneExecuteUpdate");
+          stmt.close();
+        } catch (SQLException e) {
+          if (e.getErrorCode() != -8605) {
+            log("Error encountered in commitTxn " + e.getMessage());
+            printExceptionStack(e);
+            throw new SQLException(e.getMessage());
+          }
+        }
+    }
+
+    public static void rollbackTxn(Connection conn) throws SQLException
+    {
+        log("In method rollbackTxn");
+        try {
+          log("In method rollbackTxn:gotStatement");
+          PreparedStatement stmt = conn.prepareStatement("rollback work;");
+          stmt.executeUpdate();
+
+          log("In method rollbackTxn:doneExecuteUpdate");
+          stmt.close();
+        } catch (SQLException e) {
+          if (e.getErrorCode() != -8609) {
+            log("Error encountered in rollbackTxn " + e.getMessage());
+            printExceptionStack(e);
+            throw new SQLException(e.getMessage());
+          }
+        }
+    }
+
+    InputStream origIn_;
+    PrintStream origOut_;
+    PrintStream origErr_;
+    
+    public static void RedirectStdOut(String filename) throws Exception
+    {
+       InputStream origIn_  = System.in;
+       PrintStream origOut_ = System.out;
+       PrintStream origErr_ = System.err;
+        
+       String sqRoot      = System.getenv("TRAF_HOME");
+       String stdoutFile  = sqRoot + "/sql/scripts/" + filename;
+       PrintStream stdout = null;
+
+       try
+       {
+          stdout = new PrintStream(new FileOutputStream(stdoutFile));
+       }
+       catch (Exception e)
+       {
+          System.out.println("RedirectStdOut: unable to open " + stdoutFile);
+          throw new Exception(e.getMessage());
+       }
+       
+       System.setOut(stdout);
+    } // RedirectStdOut  
+
+} // class utils
+


Mime
View raw message