trafodion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hzel...@apache.org
Subject [23/37] incubator-trafodion git commit: support add/alter/drop libraries
Date Tue, 01 Mar 2016 22:36:09 GMT
support add/alter/drop libraries


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

Branch: refs/heads/master
Commit: 1b74ea6c23f75903c51628ea68a56dface71b8ac
Parents: 980ebc7
Author: Kevin Xu <kaihua.xu@esgyn.cn>
Authored: Wed Jan 13 10:09:40 2016 +0800
Committer: Kevin Xu <kaihua.xu@esgyn.cn>
Committed: Wed Jan 13 10:09:40 2016 +0800

----------------------------------------------------------------------
 .../java/org/trafodion/libmgmt/FileMgmt.java    | 97 ++++++++++++++++++++
 .../lib_mgmt/src/main/resources/init_libmgmt.sh | 50 +++++++++-
 2 files changed, 142 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/1b74ea6c/core/sql/lib_mgmt/src/main/java/org/trafodion/libmgmt/FileMgmt.java
----------------------------------------------------------------------
diff --git a/core/sql/lib_mgmt/src/main/java/org/trafodion/libmgmt/FileMgmt.java b/core/sql/lib_mgmt/src/main/java/org/trafodion/libmgmt/FileMgmt.java
index 64575d1..918a894 100644
--- a/core/sql/lib_mgmt/src/main/java/org/trafodion/libmgmt/FileMgmt.java
+++ b/core/sql/lib_mgmt/src/main/java/org/trafodion/libmgmt/FileMgmt.java
@@ -103,6 +103,103 @@ public class FileMgmt {
 
 	}
 
+	/** create a library
+	 * @param libName library name
+	 * @param fileName related file name
+	 * @param hostName host name
+	 * @param localFile local file
+	 * @throws SQLException
+	 */
+	public static void addLib(String libName, String fileName, String hostName,
+			String localFile) throws SQLException {
+		checkFileName(fileName);
+		Connection conn = getConn();
+		Statement st = null;
+		try {
+			st = conn.createStatement();
+			String userPath = getCodeFilePath(conn);
+			String sql = "create library " + libName + " file '" + userPath
+					+ fileName + "'";
+			if (hostName != null) {
+				sql += " HOST NAME '" + hostName + "'";
+			}
+			if (localFile != null) {
+				sql += " LOCAL FILE '" + localFile + "'";
+			}
+			st.execute(sql);
+		} finally {
+			if (st != null) {
+				try {
+					st.close();
+				} catch (Exception e) {
+				}
+			}
+		}
+	}
+
+	/**
+	 * change the library related attribute
+	 *
+	 * @param libName
+	 *            library name
+	 * @param fileName
+	 *            uploaded file's name
+	 * @param hostName
+	 * @param localFile
+	 * @throws SQLException
+	 */
+	public static void alterLib(String libName, String fileName,
+			String hostName, String localFile) throws SQLException {
+		checkFileName(fileName);
+		Connection conn = getConn();
+		Statement st = null;
+		String userPath = getCodeFilePath(conn);
+		String sql = "alter library " + libName + " FILE '" + userPath
+				+ fileName + "'";
+
+		if (hostName != null) {
+			sql += " HOST NAME '" + hostName + "'";
+		}
+		if (localFile != null) {
+			sql += " LOCAL FILE '" + localFile + "'";
+		}
+		try {
+			st = conn.createStatement();
+			st.execute(sql);
+		} finally {
+			if (st != null)
+				st.close();
+		}
+	}
+
+	/**
+	 * drop the library
+	 *
+	 * @param libName
+	 * @param isdefault
+	 *            true is RESTRICT false is CASCADE
+	 * @throws SQLException
+	 */
+	public static void dropLib(String libName, String mode) throws SQLException {
+		String sql = null;
+		Connection con = getConn();
+		Statement st = null;
+		try {
+			st = con.createStatement();
+			sql = "drop library " + libName;
+			if (mode != null)
+				if (mode.trim().equalsIgnoreCase("RESTRICT"))
+					sql += " RESTRICT";
+				else if (mode.trim().equalsIgnoreCase("CASCADE"))
+					sql += " CASCADE";
+
+			st.execute(sql);
+		} finally {
+			if (st != null)
+				st.close();
+		}
+	}
+
 	public static void syncJar(String userPath, String fileName) throws SQLException, IOException
{
 		checkFileName(fileName);
 		LOG.info("syncJars " + fileName);

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/1b74ea6c/core/sql/lib_mgmt/src/main/resources/init_libmgmt.sh
----------------------------------------------------------------------
diff --git a/core/sql/lib_mgmt/src/main/resources/init_libmgmt.sh b/core/sql/lib_mgmt/src/main/resources/init_libmgmt.sh
index 003c785..6f111e3 100644
--- a/core/sql/lib_mgmt/src/main/resources/init_libmgmt.sh
+++ b/core/sql/lib_mgmt/src/main/resources/init_libmgmt.sh
@@ -69,10 +69,50 @@ function createProcedures {
       READS SQL DATA
       ;
       GRANT EXECUTE ON PROCEDURE HELP TO ${DB__LIBMGRROLE};
-      
+
+      CREATE PROCEDURE ADDLIB (
+      IN LIBNAME VARCHAR(1024) CHARACTER SET UTF8,
+      IN FILENAME VARCHAR(1024) CHARACTER SET UTF8,
+      IN HOSTNAME VARCHAR(1024) CHARACTER SET UTF8,
+      IN LOCALFILE VARCHAR(1024) CHARACTER SET UTF8)
+      EXTERNAL NAME 'org.trafodion.libmgmt.FileMgmt.addLib (java.lang.String,java.lang.String,java.lang.String,java.lang.String)'
+      LIBRARY SPJMGMT
+      EXTERNAL SECURITY DEFINER
+      LANGUAGE JAVA
+      PARAMETER STYLE JAVA
+      READS SQL DATA
+      ;
+      GRANT EXECUTE ON PROCEDURE ADDLIB TO ${DB__LIBMGRROLE};
+
+      CREATE PROCEDURE DROPLIB (
+      IN LIBNAME VARCHAR(1024) CHARACTER SET UTF8,
+      IN MODETYPE VARCHAR(1024) CHARACTER SET ISO88591)
+      EXTERNAL NAME 'org.trafodion.libmgmt.FileMgmt.dropLib (java.lang.String,java.lang.String)'
+      EXTERNAL SECURITY DEFINER
+      LIBRARY SPJMGMT
+      LANGUAGE JAVA
+      PARAMETER STYLE JAVA
+      READS SQL DATA
+      ;
+      GRANT EXECUTE ON PROCEDURE DROPLIB TO ${DB__LIBMGRROLE};
+
+      CREATE PROCEDURE ALTERLIB (
+      IN LIBNAME VARCHAR(1024) CHARACTER SET UTF8,
+      IN FILENAME VARCHAR(1024) CHARACTER SET UTF8,
+      IN HOSTNAME VARCHAR(1024) CHARACTER SET UTF8,
+      IN LOCALFILE VARCHAR(1024) CHARACTER SET UTF8)
+      EXTERNAL NAME 'org.trafodion.libmgmt.FileMgmt.alterLib (java.lang.String,java.lang.String,java.lang.String,java.lang.String)'
+      EXTERNAL SECURITY DEFINER
+      LIBRARY SPJMGMT
+      LANGUAGE JAVA
+      PARAMETER STYLE JAVA
+      READS SQL DATA
+      ;
+      GRANT EXECUTE ON PROCEDURE ALTERLIB TO ${DB__LIBMGRROLE};
+
       CREATE PROCEDURE PUT (
       IN FILEDATA VARCHAR(102400) CHARACTER SET ISO88591,
-      IN FILENAME VARCHAR(256) CHARACTER SET ISO88591,
+      IN FILENAME VARCHAR(256) CHARACTER SET UTF8,
       IN CREATEFLAG INTEGER)
       EXTERNAL NAME 'org.trafodion.libmgmt.FileMgmt.put(java.lang.String,java.lang.String,int)'
       EXTERNAL SECURITY DEFINER
@@ -84,7 +124,7 @@ function createProcedures {
       GRANT EXECUTE ON PROCEDURE PUT TO ${DB__LIBMGRROLE};
       
       CREATE PROCEDURE LS (
-      IN FILENAME VARCHAR(256) CHARACTER SET ISO88591,
+      IN FILENAME VARCHAR(256) CHARACTER SET UTF8,
       OUT FILENAMES VARCHAR(10240) CHARACTER SET ISO88591)
       EXTERNAL NAME 'org.trafodion.libmgmt.FileMgmt.ls(java.lang.String,java.lang.String[])'
       EXTERNAL SECURITY DEFINER
@@ -107,7 +147,7 @@ function createProcedures {
       GRANT EXECUTE ON PROCEDURE LSALL TO ${DB__LIBMGRROLE};
       
       CREATE PROCEDURE RM (
-      IN FILENAME VARCHAR(256) CHARACTER SET ISO88591)
+      IN FILENAME VARCHAR(256) CHARACTER SET UTF8)
       EXTERNAL NAME 'org.trafodion.libmgmt.FileMgmt.rm(java.lang.String)'
       EXTERNAL SECURITY DEFINER
       LIBRARY ${LIB_NAME}
@@ -118,7 +158,7 @@ function createProcedures {
       GRANT EXECUTE ON PROCEDURE RM TO ${DB__LIBMGRROLE};
       
       CREATE PROCEDURE RMREX (
-      IN FILENAME VARCHAR(256) CHARACTER SET ISO88591,
+      IN FILENAME VARCHAR(256) CHARACTER SET UTF8,
       OUT FILENAMES VARCHAR(10240) CHARACTER SET ISO88591)
       EXTERNAL NAME 'org.trafodion.libmgmt.FileMgmt.rmRex(java.lang.String, java.lang.String[])'
       EXTERNAL SECURITY DEFINER


Mime
View raw message