Move project into ${MY_SQROOT}/sql/

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

Branch: refs/heads/master
Commit: e4ea1ca34361709f7c997290f79243822e3b4b81
Parents: 794662e
Author: Kevin Xu <[email protected]>
Authored: Wed Dec 23 12:45:58 2015 +0800
Committer: Kevin Xu <[email protected]>
Committed: Wed Dec 23 12:45:58 2015 +0800

----------------------------------------------------------------------
 core/Makefile                                   |   6 +-
 core/conn/spj_mgmt/.gitignore                   |   4 -
 core/conn/spj_mgmt/Makefile                     |  34 --
 core/conn/spj_mgmt/README.md                    |  24 -
 core/conn/spj_mgmt/pom.xml                      |  63 ---
 .../java/org/trafodion/libmgmt/FileMgmt.java    | 434 -------------------
 .../spj_mgmt/src/main/resources/init_libmgmt.sh | 155 -------
 .../com/trafodion/libmgmt/JarFileMgmtTest.java  |  27 --
 core/sql/lib_mgmt/.gitignore                    |   4 +
 core/sql/lib_mgmt/Makefile                      |  34 ++
 core/sql/lib_mgmt/README.md                     |  24 +
 core/sql/lib_mgmt/pom.xml                       |  63 +++
 .../java/org/trafodion/libmgmt/FileMgmt.java    | 434 +++++++++++++++++++
 .../lib_mgmt/src/main/resources/init_libmgmt.sh | 155 +++++++
 .../com/trafodion/libmgmt/JarFileMgmtTest.java  |  27 ++
 15 files changed, 744 insertions(+), 744 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e4ea1ca3/core/Makefile
----------------------------------------------------------------------
diff --git a/core/Makefile b/core/Makefile
index c7d2640..a765974 100644
--- a/core/Makefile
+++ b/core/Makefile
@@ -35,7 +35,7 @@ include macros.gmk
 # Server-side only
 
 # Default target (all components)
-all: $(MPI_TARGET) dbsecurity foundation jdbc_jar $(SEAMONSTER_TARGET) ndcs ci 
jdbc_type2_jar dcs rest odb spj_mgmt
+all: $(MPI_TARGET) dbsecurity foundation jdbc_jar $(SEAMONSTER_TARGET) ndcs ci 
jdbc_type2_jar dcs rest odb lib_mgmt
 
 package: pkg-product pkg-client
 
@@ -205,5 +205,5 @@ eclipseclean:
 trafinstall:
        cd $(MY_SQROOT)/sql/scripts && install_traf_components
 
-spj_mgmt: 
-       cd conn/spj_mgmt && $(MAKE) all
+lib_mgmt:
+       cd sql/lib_mgmt && $(MAKE) all

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e4ea1ca3/core/conn/spj_mgmt/.gitignore
----------------------------------------------------------------------
diff --git a/core/conn/spj_mgmt/.gitignore b/core/conn/spj_mgmt/.gitignore
deleted file mode 100644
index c541155..0000000
--- a/core/conn/spj_mgmt/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-/target/
-/bin/
-/.classpath
-/.project

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e4ea1ca3/core/conn/spj_mgmt/Makefile
----------------------------------------------------------------------
diff --git a/core/conn/spj_mgmt/Makefile b/core/conn/spj_mgmt/Makefile
deleted file mode 100644
index a32c511..0000000
--- a/core/conn/spj_mgmt/Makefile
+++ /dev/null
@@ -1,34 +0,0 @@
-# @@@ 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 @@@
-
-INSTALL_LIBDIR := ${MY_SQROOT}/export/lib
-INSTALL_SCRIPTSDIR := ${MY_SQROOT}/sql/scripts
-CP :=/bin/cp -f
-all:
-       @$(MAVEN) package
-       ${CP} target/spj_mgmt-*.jar ${INSTALL_LIBDIR}/lib_mgmt.jar
-       ${CP} src/main/resources/init_libmgmt.sh ${INSTALL_SCRIPTSDIR}/
-       @chmod +x ${INSTALL_SCRIPTSDIR}/init_libmgmt.sh
-clean:
-       @rm ${INSTALL_LIBDIR}/lib_mgmt.jar
-       @rm -f ${INSTALL_SCRIPTSDIR}/init_libmgmt.sh
-       @$(MAVEN) clean
-cleanall: clean

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e4ea1ca3/core/conn/spj_mgmt/README.md
----------------------------------------------------------------------
diff --git a/core/conn/spj_mgmt/README.md b/core/conn/spj_mgmt/README.md
deleted file mode 100644
index 7228a65..0000000
--- a/core/conn/spj_mgmt/README.md
+++ /dev/null
@@ -1,24 +0,0 @@
-##How to build and initialize default SPJs
-###Build
-```  
-cd $MY_SQROOT/../conn/spj_init    
-make clean && make all  
-```
-###Initialization
-```  
-cds  
-./init_spj.sql  
-```  
-###SPJ Example
-```
-DEFAULT_SPJ.HELP(INOUT COMMANDNAME VARCHAR)  
-E.g.   
-trafci>set param ?p1 help;  
-trafci>call DEFAULT_SPJ.HELP(?p1)  
-PUT - Upload a JAR. SHOWDDL PRODURE DEFAULT_SPJ.PUT for more info.  
-LS - List JARs. SHOWDDL PRODURE DEFAULT_SPJ.LS for more info.  
-LSALL - List all JARs. SHOWDDL PRODURE DEFAULT_SPJ.LSALL for more info.  
-RM - Remove a JAR. SHOWDDL PRODURE DEFAULT_SPJ.RM for more info.  
-RMREX - Remove JARs by a perticular pattern. SHOWDDL PRODURE DEFAULT_SPJ.RMREX 
for more info.  
-GETFILE - Upload a JAR. SHOWDDL PRODURE DEFAULT_SPJ.GETFILE for more info.  
-```

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e4ea1ca3/core/conn/spj_mgmt/pom.xml
----------------------------------------------------------------------
diff --git a/core/conn/spj_mgmt/pom.xml b/core/conn/spj_mgmt/pom.xml
deleted file mode 100644
index 8b08de4..0000000
--- a/core/conn/spj_mgmt/pom.xml
+++ /dev/null
@@ -1,63 +0,0 @@
-<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";>
-       <!-- 
-       * @@@ 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 @@@
-       -->
-       <modelVersion>4.0.0</modelVersion>
-       <groupId>org.trafodion</groupId>
-       <artifactId>lib_mgmt</artifactId>
-       <version>${env.TRAFODION_VER}</version>
-       <dependencies>
-               <dependency>
-                       <groupId>org.slf4j</groupId>
-                       <artifactId>slf4j-simple</artifactId>
-                       <version>1.7.12</version>
-                       <scope>provided</scope>
-               </dependency>
-       </dependencies>
-
-       <build>
-               <plugins>
-                       <plugin>
-                               <groupId>org.apache.maven.plugins</groupId>
-                               <artifactId>maven-assembly-plugin</artifactId>
-                               <version>2.3</version>
-                               <configuration>
-                                       
<appendAssemblyId>false</appendAssemblyId>
-                                       <descriptorRefs>
-                                               
<descriptorRef>jar-with-dependencies</descriptorRef>
-                                       </descriptorRefs>
-                               </configuration>
-                               <executions>
-                                       <execution>
-                                               <id>make-assembly</id>
-                                               <phase>package</phase>
-                                               <goals>
-                                                       <goal>assembly</goal>
-                                               </goals>
-                                       </execution>
-                               </executions>
-                       </plugin>
-               </plugins>
-       </build>
-
-</project>

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e4ea1ca3/core/conn/spj_mgmt/src/main/java/org/trafodion/libmgmt/FileMgmt.java
----------------------------------------------------------------------
diff --git 
a/core/conn/spj_mgmt/src/main/java/org/trafodion/libmgmt/FileMgmt.java 
b/core/conn/spj_mgmt/src/main/java/org/trafodion/libmgmt/FileMgmt.java
deleted file mode 100644
index ed6a725..0000000
--- a/core/conn/spj_mgmt/src/main/java/org/trafodion/libmgmt/FileMgmt.java
+++ /dev/null
@@ -1,434 +0,0 @@
-/**
-* @@@ 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 @@@
- */
-package org.trafodion.libmgmt;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.RandomAccessFile;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class FileMgmt {
-       private static final Logger LOG = 
LoggerFactory.getLogger(FileMgmt.class);
-       private static final String url = "jdbc:default:connection";
-       // 100Mb
-       private static final long MAX_JAR_FILE_SIZE = 104857600;
-       private static final SimpleDateFormat format = new 
SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-       private static final int MaxDataSize = 102400;
-       private static final String CHARTSET = "ISO-8859-1";
-
-       /**
-        * Print help info
-        * 
-        * @param helps:
-        *            INOUT parameter like PUT/LS/...
-        */
-       public static void help(String[] helps) {
-               String[] help = new String[] {
-                               "PUT - Upload a JAR. SHOWDDL PROCEDURE 
DEFAULT_SPJ.PUT for more info.",
-                               "LS - List JARs. SHOWDDL PROCEDURE 
DEFAULT_SPJ.LS for more info.",
-                               "LSALL - List all JARs. SHOWDDL PROCEDURE 
DEFAULT_SPJ.LSALL for more info.",
-                               "RM - Remove a JAR. SHOWDDL PROCEDURE 
DEFAULT_SPJ.RM for more info.",
-                               "RMREX - Remove JARs by a perticular pattern. 
SHOWDDL PROCEDURE DEFAULT_SPJ.RMREX for more info.",
-                               "GETFILE - Download a JAR. SHOWDDL PROCEDURE 
DEFAULT_SPJ.GETFILE for more info."
-               };
-               List<String> index = new ArrayList<String>(help.length);
-               index.add("PUT");
-               index.add("LS");
-               index.add("LSALL");
-               index.add("RM");
-               index.add("RMREX");
-               index.add("GETFILE");
-               String tmp = helps[0].trim().toUpperCase();
-               helps[0] = "HELP:\r\n";
-               switch (index.indexOf(tmp)) {
-               case 0:
-                       helps[0] = help[0];
-                       break;
-               case 1:
-                       helps[0] = help[1];
-                       break;
-               case 2:
-                       helps[0] = help[2];
-                       break;
-               case 3:
-                       helps[0] = help[3];
-                       break;
-               case 4:
-                       helps[0] = help[4];
-                       break;
-               case 5:
-                       helps[0] = help[5];
-                       break;
-               default:
-                       for (String h : help) {
-                               helps[0] += h + "\r\n";
-                       }
-
-               }
-
-       }
-
-       public static void syncJar(String userPath, String fileName) throws 
SQLException, IOException {
-               checkFileName(fileName);
-               LOG.info("syncJars " + fileName);
-               String nodes = System.getenv("MY_NODES");
-               if (nodes != null && !"".equals(nodes.trim())) {
-                       execShell("pdcp " + nodes + " " + userPath + 
fileName.trim() + " " + userPath + " ");
-                       execShell("pdsh " + nodes + " chmod 755 " + userPath + 
fileName.trim());
-               }
-       }
-
-       private static String execShell(String cmd) throws IOException {
-               Process p = Runtime.getRuntime().exec(cmd);
-               if (p != null) {
-                       StringBuilder sb = new StringBuilder();
-                       InputStream in = null;
-                       try {
-                               in = p.getInputStream();
-                               int c = -1;
-                               while ((c = in.read()) != -1) {
-                                       sb.append((char) c);
-                               }
-                       } finally {
-                               if (in != null)
-                                       in.close();
-                       }
-                       try {
-                               in = p.getErrorStream();
-                               int c = -1;
-                               boolean flag = true;
-                               while ((c = in.read()) != -1) {
-                                       if (flag) {
-                                               sb.append("\r\n");
-                                       } else {
-                                               flag = false;
-                                       }
-                                       sb.append((char) c);
-                               }
-                       } finally {
-                               if (in != null)
-                                       in.close();
-                       }
-                       return sb.toString();
-               }
-               return null;
-       }
-
-       /**
-        * Download a JAR file
-        * 
-        * @param fileName
-        * @param offset
-        * @param fileData
-        * @throws SQLException
-        * @throws IOException
-        */
-       public static void get(String fileName, int offset, String[] fileData, 
long[] fileLength)
-                       throws SQLException, IOException {
-               checkFileName(fileName);
-               Connection conn = getConn();
-               LOG.info("Get " + fileName);
-               String userPath = getCodeFilePath(conn);
-               close(conn);
-               File file = new File(userPath + fileName);
-               if (!file.exists()) {
-                       throw new SQLException("No such file[" + fileName + 
"]");
-               }
-               RandomAccessFile rAFile = null;
-               try {
-                       rAFile = new RandomAccessFile(file, "r");
-                       rAFile.seek(offset);
-                       byte bArray[] = new byte[MaxDataSize];
-                       int bytesRead = rAFile.read(bArray, 0, MaxDataSize);
-                       if (bytesRead != -1) {
-                               fileData[0] = new String(Arrays.copyOf(bArray, 
bytesRead), CHARTSET);
-                               fileLength[0] = file.length();
-                               LOG.info("Download: " + fileName + ", offset:" 
+ offset + ",compressed length:" + fileData[0].length()
-                                               + ",file length:" + 
fileLength[0]);
-                       }
-               } finally {
-                       if (rAFile != null) {
-                               try {
-                                       rAFile.close();
-                               } catch (Exception e) {
-                                       LOG.warn("Something wrong while close 
file[" + fileName + "] stream: " + e.getMessage());
-                               }
-                       }
-               }
-
-       }
-
-       /**
-        * Remove exact file
-        * 
-        * @param fileName
-        * @throws SQLException
-        */
-       public static void rm(String fileName) throws SQLException {
-               checkFileName(fileName);
-               Connection conn = getConn();
-               LOG.info("Remove " + fileName);
-               String userPath = getCodeFilePath(conn);
-               close(conn);
-               File file = new File(userPath + fileName);
-               if (file.exists()) {
-                       file.delete();
-                       LOG.info("Remove " + fileName + " successfully!");
-                       return;
-               } else {
-                       throw new SQLException("No such file[" + fileName + 
"]");
-               }
-       }
-
-       /**
-        * Remove files via regular formulation
-        * 
-        * @param pattern:
-        *            to be deleted
-        * @param names
-        *            : file names to be deleted
-        * @throws SQLException
-        */
-       public static void rmRex(String pattern, String[] names) throws 
SQLException {
-               checkFileName(pattern);
-               Connection conn = getConn();
-               LOG.info("Try to remove files[" + pattern + "]");
-               String userPath = getCodeFilePath(conn);
-               close(conn);
-               File[] files = getFiles(pattern, new File(userPath));
-               StringBuilder sb = new StringBuilder();
-               sb.append("<rmRex>");
-               sb.append(toXML(files, "rmList"));
-               sb.append("<message>");
-               boolean hasError = false;
-               for (File f : files) {
-                       try {
-                               f.delete();
-                       } catch (Exception e) {
-                               hasError = true;
-                               LOG.error(e.getMessage(), e);
-                               sb.append("<error fileName='" + f.getName() + 
"'>" + e.getMessage() + "</error>");
-                       }
-               }
-               if (!hasError) {
-                       sb.append("Remove the files successfully!");
-               }
-               sb.append("</message>");
-               sb.append("</rmRex>");
-               names[0] = sb.toString();
-               LOG.info("Done for removing files[" + pattern + "].");
-       }
-
-       public static void lsAll(String[] names) throws SQLException {
-               ls("*", names);
-       }
-
-       /**
-        * list the Jars matching PATTERN
-        * 
-        * @param pattern:
-        * @param names
-        * @throws SQLException
-        */
-       public static void ls(String pattern, String[] names) throws 
SQLException {
-               checkFileName(pattern);
-               Connection conn = getConn();
-               LOG.info("List files[" + pattern + "]");
-               String userPath = getCodeFilePath(conn);
-               close(conn);
-               File dir = new File(userPath);
-               if (!dir.exists() || !dir.isDirectory()) {
-                       LOG.error("Directory [" + userPath + "] is not found!");
-                       throw new SQLException("Directory [" + userPath + "] is 
not found!");
-               }
-               if (pattern == null) {
-                       LOG.error("File pattern should not be empty!");
-                       throw new SQLException("Pattern is empty!");
-               }
-               File[] files = getFiles(pattern, dir);
-               names[0] = toXML(files, "ls");
-       }
-
-       /**
-        * upload a JAR file
-        * 
-        * @param fileData
-        * @param fileName
-        * @param appendFlag
-        *            0: append; otherwise overwrite
-        * @throws SQLException
-        */
-       public static void put(String fileData, String fileName, int 
appendFlag) throws SQLException {
-               checkFileName(fileName);
-               try {
-                       byte[] data = fileData.getBytes(CHARTSET);
-
-                       Connection conn = getConn();
-                       LOG.info("Put " + fileName + ", length: " + data.length 
+ ", file string length:" + fileData.length());
-                       String userPath = getCodeFilePath(conn);
-                       close(conn);
-                       String fname = userPath + fileName;
-                       checkFile(fname, data.length);
-                       FileOutputStream fos = null;
-                       try {
-                               fos = new FileOutputStream(fname, (appendFlag 
== 0));
-                               fos.write(Arrays.copyOf(data, data.length));
-                               fos.flush();
-                       } finally {
-                               if (fos != null)
-                                       fos.close();
-                       }
-
-                       syncJar(userPath, fileName);
-
-               } catch (Throwable t) {
-                       LOG.error(t.getMessage(), t);
-                       throw new SQLException(t.getMessage());
-               }
-       }
-
-       private static void checkFileName(String fileName) throws SQLException {
-               if (fileName.contains("/") || fileName.contains("\\"))
-                       throw new SQLException("Illegal file name: " + fileName
-                                       + ". File name must not contain 
\"/\".");
-       }
-
-       private static void checkFile(String fname, int dataSize) throws 
SQLException {
-               File jar = new File(fname);
-               if (jar.length() + dataSize > MAX_JAR_FILE_SIZE) {
-                       LOG.error("Jar file size is over the threshold[100Mb]");
-                       throw new SQLException("Jar file size is over the 
threshold[100Mb]");
-               }
-       }
-
-       private static String getCodeFilePath(Connection conn) throws 
SQLException {
-               String user = getCurrentUser(conn);
-               String root = System.getenv("MY_SQROOT");
-               if (root == null || "".equals(root.trim())) {
-                       LOG.error("Cant get your traf installation path!");
-                       throw new SQLException("Cant get your traf installation 
path!");
-               }
-               File file = new File(root + "/udr/lib/" + user);
-               if (!file.exists()) {
-                       file.mkdirs();
-               } else if (!file.isDirectory()) {
-                       throw new SQLException("User Directory is not valide or 
you dont have permission!");
-               }
-               LOG.info("SPJ JARs location: " + file.getAbsolutePath());
-               return file.getAbsolutePath() + "/";
-       }
-
-       private static Connection getConn() throws SQLException {
-               Connection conn = null;
-               try {
-                       conn = DriverManager.getConnection(url);
-                       LOG.info("Create connection successfully.  " + conn);
-               } catch (Throwable t) {
-                       LOG.error("Error encountered while getting connection 
", t);
-                       throw new SQLException(t.getMessage());
-               }
-               return conn;
-       }
-
-       private static String getCurrentUser(Connection conn) throws 
SQLException {
-               Statement st = null;
-               ResultSet rs = null;
-               String user = null;
-               try {
-                       st = conn.createStatement();
-                       rs = st.executeQuery("values(session_user)");
-                       if (rs.next()) {
-                               user = rs.getString(1);
-                       }
-               } catch (Exception e) {
-                       LOG.error(e.getMessage(), e);
-                       throw new SQLException(e);
-               } finally {
-                       if (rs != null) {
-                               try {
-                                       rs.close();
-                               } catch (Exception e) {
-                                       LOG.warn(e.getMessage(), e);
-                               }
-                       }
-                       if (st != null) {
-                               try {
-                                       st.close();
-                               } catch (Exception e) {
-                                       LOG.warn(e.getMessage(), e);
-                               }
-                       }
-               }
-               
-               return user.replaceAll("[\\\\/]", "_");
-       }
-
-       private static File[] getFiles(String pattern, File dir) {
-               final String p = pattern.replaceAll("\\*", 
".*").trim().toUpperCase();
-               return dir.listFiles(new FileFilter() {
-
-                       @Override
-                       public boolean accept(File name) {
-                               if (name == null || !name.isFile()) {
-                                       return false;
-                               }
-                               return 
name.getName().trim().toUpperCase().matches(p);
-                       }
-               });
-       }
-
-       private static String toXML(File[] files, String root) {
-               StringBuilder sb = new StringBuilder();
-               sb.append("<" + root + ">");
-               for (File f : files) {
-                       sb.append("<file name='" + f.getName() + "' 
lastModifyTime='" + format.format(new Date(f.lastModified()))
-                                       + "' size='" + f.length() + "'/>");
-               }
-               sb.append("</" + root + ">");
-               return sb.toString();
-       }
-
-       private static void close(Connection conn) {
-               try {
-                       conn.close();
-                       LOG.info("Closed connection");
-               } catch (Exception e) {
-                       LOG.warn(e.getMessage());
-               }
-       }
-}

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e4ea1ca3/core/conn/spj_mgmt/src/main/resources/init_libmgmt.sh
----------------------------------------------------------------------
diff --git a/core/conn/spj_mgmt/src/main/resources/init_libmgmt.sh 
b/core/conn/spj_mgmt/src/main/resources/init_libmgmt.sh
deleted file mode 100644
index 9dd16b1..0000000
--- a/core/conn/spj_mgmt/src/main/resources/init_libmgmt.sh
+++ /dev/null
@@ -1,155 +0,0 @@
-#!/bin/bash
-# @@@ 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 @@@
-
-SERVER_JAR=${MY_SQROOT}/export/lib/spj_mgmt.jar
-CI=sqlci
-CATALOG_NAME=TRAFODION
-CIS_SCHEMA="_LIBMGR_"
-DB__LIBMGRROLE=DB__LIBMGRROLE
-
-function dropAndCreateSchema {
-    echo "Creating Schema for SPJ_MGMT"
-    ${CI} << sqlciEOF
-
-      cqd CAT_IGNORE_ALREADY_EXISTS_ERROR 'on';
-      cqd CAT_IGNORE_DOES_NOT_EXIST_ERROR 'on';
-
-      DROP SCHEMA $CATALOG_NAME.$CIS_SCHEMA CASCADE;
-      CREATE SCHEMA $CATALOG_NAME.$CIS_SCHEMA;
-
-      cqd CAT_IGNORE_ALREADY_EXISTS_ERROR 'off';
-      cqd CAT_IGNORE_DOES_NOT_EXIST_ERROR 'off';
-
-      exit;
-sqlciEOF
-}
-
-function createProcedures {
-
-    echo "Creating Procedures in  schema '$CATALOG_NAME.$CIS_SCHEMA' "
-    ${CI} << procEOF
-
-      cqd CAT_IGNORE_ALREADY_EXISTS_ERROR 'on';
-      cqd CAT_IGNORE_DOES_NOT_EXIST_ERROR 'on';
-
-      -- Creating Procedures 
-      set schema $CATALOG_NAME.$CIS_SCHEMA; 
-
-      DROP LIBRARY SPJMGMT CASCADE;
-      CREATE LIBRARY SPJMGMT FILE '${SERVER_JAR}';
-      CREATE ROLE ${DB__LIBMGRROLE};
-   
-      CREATE PROCEDURE HELP (
-      INOUT COMMANDNAME VARCHAR(2560) CHARACTER SET ISO88591)
-      EXTERNAL NAME 'org.trafodion.libmgmt.FileMgmt.help (java.lang.String[])'
-      EXTERNAL SECURITY DEFINER
-      LIBRARY SPJMGMT
-      LANGUAGE JAVA
-      PARAMETER STYLE JAVA
-      READS SQL DATA
-      ;
-      GRANT EXECUTE ON PROCEDURE HELP TO ${DB__LIBMGRROLE};
-      
-      CREATE PROCEDURE PUT (
-      IN FILEDATA VARCHAR(102400) CHARACTER SET ISO88591,
-      IN FILENAME VARCHAR(256) CHARACTER SET ISO88591,
-      IN CREATEFLAG INTEGER)
-      EXTERNAL NAME 
'org.trafodion.libmgmt.FileMgmt.put(java.lang.String,java.lang.String,int)'
-      EXTERNAL SECURITY DEFINER
-      LIBRARY SPJMGMT
-      LANGUAGE JAVA
-      PARAMETER STYLE JAVA
-      READS SQL DATA
-      ;
-      GRANT EXECUTE ON PROCEDURE PUT TO ${DB__LIBMGRROLE};
-      
-      CREATE PROCEDURE LS (
-      IN FILENAME VARCHAR(256) CHARACTER SET ISO88591,
-      OUT FILENAMES VARCHAR(10240) CHARACTER SET ISO88591)
-      EXTERNAL NAME 
'org.trafodion.libmgmt.FileMgmt.ls(java.lang.String,java.lang.String[])'
-      EXTERNAL SECURITY DEFINER
-      LIBRARY SPJMGMT
-      LANGUAGE JAVA
-      PARAMETER STYLE JAVA
-      READS SQL DATA
-      ;
-      GRANT EXECUTE ON PROCEDURE LS TO ${DB__LIBMGRROLE};
-      
-      CREATE PROCEDURE LSALL (
-      OUT FILENAMES VARCHAR(10240) CHARACTER SET ISO88591)
-      EXTERNAL NAME 'org.trafodion.libmgmt.FileMgmt.lsAll(java.lang.String[])'
-      EXTERNAL SECURITY DEFINER
-      LIBRARY SPJMGMT
-      LANGUAGE JAVA
-      PARAMETER STYLE JAVA
-      READS SQL DATA
-      ;
-      GRANT EXECUTE ON PROCEDURE LSALL TO ${DB__LIBMGRROLE};
-      
-      CREATE PROCEDURE RM (
-      IN FILENAME VARCHAR(256) CHARACTER SET ISO88591)
-      EXTERNAL NAME 'org.trafodion.libmgmt.FileMgmt.rm(java.lang.String)'
-      EXTERNAL SECURITY DEFINER
-      LIBRARY SPJMGMT
-      LANGUAGE JAVA
-      PARAMETER STYLE JAVA
-      READS SQL DATA
-      ;
-      GRANT EXECUTE ON PROCEDURE RM TO ${DB__LIBMGRROLE};
-      
-      CREATE PROCEDURE RMREX (
-      IN FILENAME VARCHAR(256) CHARACTER SET ISO88591,
-      OUT FILENAMES VARCHAR(10240) CHARACTER SET ISO88591)
-      EXTERNAL NAME 'org.trafodion.libmgmt.FileMgmt.rmRex(java.lang.String, 
java.lang.String[])'
-      EXTERNAL SECURITY DEFINER
-      LIBRARY SPJMGMT
-      LANGUAGE JAVA
-      PARAMETER STYLE JAVA
-      READS SQL DATA
-      ;
-      GRANT EXECUTE ON PROCEDURE RMREX TO ${DB__LIBMGRROLE};
-
-      CREATE PROCEDURE GETFILE (
-      IN FILENAME VARCHAR(256) CHARACTER SET UTF8,
-      IN OFFSET INTEGER,
-      OUT FILEDATA VARCHAR(51200) CHARACTER SET UTF8,
-      OUT DATALENGTH LARGEINT)
-      EXTERNAL NAME 'org.trafodion.libmgmt.FileMgmt.get 
(java.lang.String,int,java.lang.String[],long[])'
-      EXTERNAL SECURITY DEFINER
-      LIBRARY SPJMGMT
-      LANGUAGE JAVA
-      PARAMETER STYLE JAVA
-      READS SQL DATA
-      ;
-      GRANT EXECUTE ON PROCEDURE GETFILE TO ${DB__LIBMGRROLE};
-      
-      cqd CAT_IGNORE_ALREADY_EXISTS_ERROR 'off';
-      cqd CAT_IGNORE_DOES_NOT_EXIST_ERROR 'off';
-
-      exit;
-procEOF
-    
-}
-
-dropAndCreateSchema
-createProcedures
-echo "Successfully completed installation of SPJs."

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e4ea1ca3/core/conn/spj_mgmt/src/test/java/com/trafodion/libmgmt/JarFileMgmtTest.java
----------------------------------------------------------------------
diff --git 
a/core/conn/spj_mgmt/src/test/java/com/trafodion/libmgmt/JarFileMgmtTest.java 
b/core/conn/spj_mgmt/src/test/java/com/trafodion/libmgmt/JarFileMgmtTest.java
deleted file mode 100644
index 2636316..0000000
--- 
a/core/conn/spj_mgmt/src/test/java/com/trafodion/libmgmt/JarFileMgmtTest.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/**
-* @@@ 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 @@@
- */
-package com.trafodion.libmgmt;
-
-public class JarFileMgmtTest {
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e4ea1ca3/core/sql/lib_mgmt/.gitignore
----------------------------------------------------------------------
diff --git a/core/sql/lib_mgmt/.gitignore b/core/sql/lib_mgmt/.gitignore
new file mode 100644
index 0000000..c541155
--- /dev/null
+++ b/core/sql/lib_mgmt/.gitignore
@@ -0,0 +1,4 @@
+/target/
+/bin/
+/.classpath
+/.project

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e4ea1ca3/core/sql/lib_mgmt/Makefile
----------------------------------------------------------------------
diff --git a/core/sql/lib_mgmt/Makefile b/core/sql/lib_mgmt/Makefile
new file mode 100644
index 0000000..a32c511
--- /dev/null
+++ b/core/sql/lib_mgmt/Makefile
@@ -0,0 +1,34 @@
+# @@@ 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 @@@
+
+INSTALL_LIBDIR := ${MY_SQROOT}/export/lib
+INSTALL_SCRIPTSDIR := ${MY_SQROOT}/sql/scripts
+CP :=/bin/cp -f
+all:
+       @$(MAVEN) package
+       ${CP} target/spj_mgmt-*.jar ${INSTALL_LIBDIR}/lib_mgmt.jar
+       ${CP} src/main/resources/init_libmgmt.sh ${INSTALL_SCRIPTSDIR}/
+       @chmod +x ${INSTALL_SCRIPTSDIR}/init_libmgmt.sh
+clean:
+       @rm ${INSTALL_LIBDIR}/lib_mgmt.jar
+       @rm -f ${INSTALL_SCRIPTSDIR}/init_libmgmt.sh
+       @$(MAVEN) clean
+cleanall: clean

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e4ea1ca3/core/sql/lib_mgmt/README.md
----------------------------------------------------------------------
diff --git a/core/sql/lib_mgmt/README.md b/core/sql/lib_mgmt/README.md
new file mode 100644
index 0000000..7228a65
--- /dev/null
+++ b/core/sql/lib_mgmt/README.md
@@ -0,0 +1,24 @@
+##How to build and initialize default SPJs
+###Build
+```  
+cd $MY_SQROOT/../conn/spj_init    
+make clean && make all  
+```
+###Initialization
+```  
+cds  
+./init_spj.sql  
+```  
+###SPJ Example
+```
+DEFAULT_SPJ.HELP(INOUT COMMANDNAME VARCHAR)  
+E.g.   
+trafci>set param ?p1 help;  
+trafci>call DEFAULT_SPJ.HELP(?p1)  
+PUT - Upload a JAR. SHOWDDL PRODURE DEFAULT_SPJ.PUT for more info.  
+LS - List JARs. SHOWDDL PRODURE DEFAULT_SPJ.LS for more info.  
+LSALL - List all JARs. SHOWDDL PRODURE DEFAULT_SPJ.LSALL for more info.  
+RM - Remove a JAR. SHOWDDL PRODURE DEFAULT_SPJ.RM for more info.  
+RMREX - Remove JARs by a perticular pattern. SHOWDDL PRODURE DEFAULT_SPJ.RMREX 
for more info.  
+GETFILE - Upload a JAR. SHOWDDL PRODURE DEFAULT_SPJ.GETFILE for more info.  
+```

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e4ea1ca3/core/sql/lib_mgmt/pom.xml
----------------------------------------------------------------------
diff --git a/core/sql/lib_mgmt/pom.xml b/core/sql/lib_mgmt/pom.xml
new file mode 100644
index 0000000..8b08de4
--- /dev/null
+++ b/core/sql/lib_mgmt/pom.xml
@@ -0,0 +1,63 @@
+<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";>
+       <!-- 
+       * @@@ 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 @@@
+       -->
+       <modelVersion>4.0.0</modelVersion>
+       <groupId>org.trafodion</groupId>
+       <artifactId>lib_mgmt</artifactId>
+       <version>${env.TRAFODION_VER}</version>
+       <dependencies>
+               <dependency>
+                       <groupId>org.slf4j</groupId>
+                       <artifactId>slf4j-simple</artifactId>
+                       <version>1.7.12</version>
+                       <scope>provided</scope>
+               </dependency>
+       </dependencies>
+
+       <build>
+               <plugins>
+                       <plugin>
+                               <groupId>org.apache.maven.plugins</groupId>
+                               <artifactId>maven-assembly-plugin</artifactId>
+                               <version>2.3</version>
+                               <configuration>
+                                       
<appendAssemblyId>false</appendAssemblyId>
+                                       <descriptorRefs>
+                                               
<descriptorRef>jar-with-dependencies</descriptorRef>
+                                       </descriptorRefs>
+                               </configuration>
+                               <executions>
+                                       <execution>
+                                               <id>make-assembly</id>
+                                               <phase>package</phase>
+                                               <goals>
+                                                       <goal>assembly</goal>
+                                               </goals>
+                                       </execution>
+                               </executions>
+                       </plugin>
+               </plugins>
+       </build>
+
+</project>

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e4ea1ca3/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
new file mode 100644
index 0000000..ed6a725
--- /dev/null
+++ b/core/sql/lib_mgmt/src/main/java/org/trafodion/libmgmt/FileMgmt.java
@@ -0,0 +1,434 @@
+/**
+* @@@ 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 @@@
+ */
+package org.trafodion.libmgmt;
+
+import java.io.File;
+import java.io.FileFilter;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.RandomAccessFile;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class FileMgmt {
+       private static final Logger LOG = 
LoggerFactory.getLogger(FileMgmt.class);
+       private static final String url = "jdbc:default:connection";
+       // 100Mb
+       private static final long MAX_JAR_FILE_SIZE = 104857600;
+       private static final SimpleDateFormat format = new 
SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+       private static final int MaxDataSize = 102400;
+       private static final String CHARTSET = "ISO-8859-1";
+
+       /**
+        * Print help info
+        * 
+        * @param helps:
+        *            INOUT parameter like PUT/LS/...
+        */
+       public static void help(String[] helps) {
+               String[] help = new String[] {
+                               "PUT - Upload a JAR. SHOWDDL PROCEDURE 
DEFAULT_SPJ.PUT for more info.",
+                               "LS - List JARs. SHOWDDL PROCEDURE 
DEFAULT_SPJ.LS for more info.",
+                               "LSALL - List all JARs. SHOWDDL PROCEDURE 
DEFAULT_SPJ.LSALL for more info.",
+                               "RM - Remove a JAR. SHOWDDL PROCEDURE 
DEFAULT_SPJ.RM for more info.",
+                               "RMREX - Remove JARs by a perticular pattern. 
SHOWDDL PROCEDURE DEFAULT_SPJ.RMREX for more info.",
+                               "GETFILE - Download a JAR. SHOWDDL PROCEDURE 
DEFAULT_SPJ.GETFILE for more info."
+               };
+               List<String> index = new ArrayList<String>(help.length);
+               index.add("PUT");
+               index.add("LS");
+               index.add("LSALL");
+               index.add("RM");
+               index.add("RMREX");
+               index.add("GETFILE");
+               String tmp = helps[0].trim().toUpperCase();
+               helps[0] = "HELP:\r\n";
+               switch (index.indexOf(tmp)) {
+               case 0:
+                       helps[0] = help[0];
+                       break;
+               case 1:
+                       helps[0] = help[1];
+                       break;
+               case 2:
+                       helps[0] = help[2];
+                       break;
+               case 3:
+                       helps[0] = help[3];
+                       break;
+               case 4:
+                       helps[0] = help[4];
+                       break;
+               case 5:
+                       helps[0] = help[5];
+                       break;
+               default:
+                       for (String h : help) {
+                               helps[0] += h + "\r\n";
+                       }
+
+               }
+
+       }
+
+       public static void syncJar(String userPath, String fileName) throws 
SQLException, IOException {
+               checkFileName(fileName);
+               LOG.info("syncJars " + fileName);
+               String nodes = System.getenv("MY_NODES");
+               if (nodes != null && !"".equals(nodes.trim())) {
+                       execShell("pdcp " + nodes + " " + userPath + 
fileName.trim() + " " + userPath + " ");
+                       execShell("pdsh " + nodes + " chmod 755 " + userPath + 
fileName.trim());
+               }
+       }
+
+       private static String execShell(String cmd) throws IOException {
+               Process p = Runtime.getRuntime().exec(cmd);
+               if (p != null) {
+                       StringBuilder sb = new StringBuilder();
+                       InputStream in = null;
+                       try {
+                               in = p.getInputStream();
+                               int c = -1;
+                               while ((c = in.read()) != -1) {
+                                       sb.append((char) c);
+                               }
+                       } finally {
+                               if (in != null)
+                                       in.close();
+                       }
+                       try {
+                               in = p.getErrorStream();
+                               int c = -1;
+                               boolean flag = true;
+                               while ((c = in.read()) != -1) {
+                                       if (flag) {
+                                               sb.append("\r\n");
+                                       } else {
+                                               flag = false;
+                                       }
+                                       sb.append((char) c);
+                               }
+                       } finally {
+                               if (in != null)
+                                       in.close();
+                       }
+                       return sb.toString();
+               }
+               return null;
+       }
+
+       /**
+        * Download a JAR file
+        * 
+        * @param fileName
+        * @param offset
+        * @param fileData
+        * @throws SQLException
+        * @throws IOException
+        */
+       public static void get(String fileName, int offset, String[] fileData, 
long[] fileLength)
+                       throws SQLException, IOException {
+               checkFileName(fileName);
+               Connection conn = getConn();
+               LOG.info("Get " + fileName);
+               String userPath = getCodeFilePath(conn);
+               close(conn);
+               File file = new File(userPath + fileName);
+               if (!file.exists()) {
+                       throw new SQLException("No such file[" + fileName + 
"]");
+               }
+               RandomAccessFile rAFile = null;
+               try {
+                       rAFile = new RandomAccessFile(file, "r");
+                       rAFile.seek(offset);
+                       byte bArray[] = new byte[MaxDataSize];
+                       int bytesRead = rAFile.read(bArray, 0, MaxDataSize);
+                       if (bytesRead != -1) {
+                               fileData[0] = new String(Arrays.copyOf(bArray, 
bytesRead), CHARTSET);
+                               fileLength[0] = file.length();
+                               LOG.info("Download: " + fileName + ", offset:" 
+ offset + ",compressed length:" + fileData[0].length()
+                                               + ",file length:" + 
fileLength[0]);
+                       }
+               } finally {
+                       if (rAFile != null) {
+                               try {
+                                       rAFile.close();
+                               } catch (Exception e) {
+                                       LOG.warn("Something wrong while close 
file[" + fileName + "] stream: " + e.getMessage());
+                               }
+                       }
+               }
+
+       }
+
+       /**
+        * Remove exact file
+        * 
+        * @param fileName
+        * @throws SQLException
+        */
+       public static void rm(String fileName) throws SQLException {
+               checkFileName(fileName);
+               Connection conn = getConn();
+               LOG.info("Remove " + fileName);
+               String userPath = getCodeFilePath(conn);
+               close(conn);
+               File file = new File(userPath + fileName);
+               if (file.exists()) {
+                       file.delete();
+                       LOG.info("Remove " + fileName + " successfully!");
+                       return;
+               } else {
+                       throw new SQLException("No such file[" + fileName + 
"]");
+               }
+       }
+
+       /**
+        * Remove files via regular formulation
+        * 
+        * @param pattern:
+        *            to be deleted
+        * @param names
+        *            : file names to be deleted
+        * @throws SQLException
+        */
+       public static void rmRex(String pattern, String[] names) throws 
SQLException {
+               checkFileName(pattern);
+               Connection conn = getConn();
+               LOG.info("Try to remove files[" + pattern + "]");
+               String userPath = getCodeFilePath(conn);
+               close(conn);
+               File[] files = getFiles(pattern, new File(userPath));
+               StringBuilder sb = new StringBuilder();
+               sb.append("<rmRex>");
+               sb.append(toXML(files, "rmList"));
+               sb.append("<message>");
+               boolean hasError = false;
+               for (File f : files) {
+                       try {
+                               f.delete();
+                       } catch (Exception e) {
+                               hasError = true;
+                               LOG.error(e.getMessage(), e);
+                               sb.append("<error fileName='" + f.getName() + 
"'>" + e.getMessage() + "</error>");
+                       }
+               }
+               if (!hasError) {
+                       sb.append("Remove the files successfully!");
+               }
+               sb.append("</message>");
+               sb.append("</rmRex>");
+               names[0] = sb.toString();
+               LOG.info("Done for removing files[" + pattern + "].");
+       }
+
+       public static void lsAll(String[] names) throws SQLException {
+               ls("*", names);
+       }
+
+       /**
+        * list the Jars matching PATTERN
+        * 
+        * @param pattern:
+        * @param names
+        * @throws SQLException
+        */
+       public static void ls(String pattern, String[] names) throws 
SQLException {
+               checkFileName(pattern);
+               Connection conn = getConn();
+               LOG.info("List files[" + pattern + "]");
+               String userPath = getCodeFilePath(conn);
+               close(conn);
+               File dir = new File(userPath);
+               if (!dir.exists() || !dir.isDirectory()) {
+                       LOG.error("Directory [" + userPath + "] is not found!");
+                       throw new SQLException("Directory [" + userPath + "] is 
not found!");
+               }
+               if (pattern == null) {
+                       LOG.error("File pattern should not be empty!");
+                       throw new SQLException("Pattern is empty!");
+               }
+               File[] files = getFiles(pattern, dir);
+               names[0] = toXML(files, "ls");
+       }
+
+       /**
+        * upload a JAR file
+        * 
+        * @param fileData
+        * @param fileName
+        * @param appendFlag
+        *            0: append; otherwise overwrite
+        * @throws SQLException
+        */
+       public static void put(String fileData, String fileName, int 
appendFlag) throws SQLException {
+               checkFileName(fileName);
+               try {
+                       byte[] data = fileData.getBytes(CHARTSET);
+
+                       Connection conn = getConn();
+                       LOG.info("Put " + fileName + ", length: " + data.length 
+ ", file string length:" + fileData.length());
+                       String userPath = getCodeFilePath(conn);
+                       close(conn);
+                       String fname = userPath + fileName;
+                       checkFile(fname, data.length);
+                       FileOutputStream fos = null;
+                       try {
+                               fos = new FileOutputStream(fname, (appendFlag 
== 0));
+                               fos.write(Arrays.copyOf(data, data.length));
+                               fos.flush();
+                       } finally {
+                               if (fos != null)
+                                       fos.close();
+                       }
+
+                       syncJar(userPath, fileName);
+
+               } catch (Throwable t) {
+                       LOG.error(t.getMessage(), t);
+                       throw new SQLException(t.getMessage());
+               }
+       }
+
+       private static void checkFileName(String fileName) throws SQLException {
+               if (fileName.contains("/") || fileName.contains("\\"))
+                       throw new SQLException("Illegal file name: " + fileName
+                                       + ". File name must not contain 
\"/\".");
+       }
+
+       private static void checkFile(String fname, int dataSize) throws 
SQLException {
+               File jar = new File(fname);
+               if (jar.length() + dataSize > MAX_JAR_FILE_SIZE) {
+                       LOG.error("Jar file size is over the threshold[100Mb]");
+                       throw new SQLException("Jar file size is over the 
threshold[100Mb]");
+               }
+       }
+
+       private static String getCodeFilePath(Connection conn) throws 
SQLException {
+               String user = getCurrentUser(conn);
+               String root = System.getenv("MY_SQROOT");
+               if (root == null || "".equals(root.trim())) {
+                       LOG.error("Cant get your traf installation path!");
+                       throw new SQLException("Cant get your traf installation 
path!");
+               }
+               File file = new File(root + "/udr/lib/" + user);
+               if (!file.exists()) {
+                       file.mkdirs();
+               } else if (!file.isDirectory()) {
+                       throw new SQLException("User Directory is not valide or 
you dont have permission!");
+               }
+               LOG.info("SPJ JARs location: " + file.getAbsolutePath());
+               return file.getAbsolutePath() + "/";
+       }
+
+       private static Connection getConn() throws SQLException {
+               Connection conn = null;
+               try {
+                       conn = DriverManager.getConnection(url);
+                       LOG.info("Create connection successfully.  " + conn);
+               } catch (Throwable t) {
+                       LOG.error("Error encountered while getting connection 
", t);
+                       throw new SQLException(t.getMessage());
+               }
+               return conn;
+       }
+
+       private static String getCurrentUser(Connection conn) throws 
SQLException {
+               Statement st = null;
+               ResultSet rs = null;
+               String user = null;
+               try {
+                       st = conn.createStatement();
+                       rs = st.executeQuery("values(session_user)");
+                       if (rs.next()) {
+                               user = rs.getString(1);
+                       }
+               } catch (Exception e) {
+                       LOG.error(e.getMessage(), e);
+                       throw new SQLException(e);
+               } finally {
+                       if (rs != null) {
+                               try {
+                                       rs.close();
+                               } catch (Exception e) {
+                                       LOG.warn(e.getMessage(), e);
+                               }
+                       }
+                       if (st != null) {
+                               try {
+                                       st.close();
+                               } catch (Exception e) {
+                                       LOG.warn(e.getMessage(), e);
+                               }
+                       }
+               }
+               
+               return user.replaceAll("[\\\\/]", "_");
+       }
+
+       private static File[] getFiles(String pattern, File dir) {
+               final String p = pattern.replaceAll("\\*", 
".*").trim().toUpperCase();
+               return dir.listFiles(new FileFilter() {
+
+                       @Override
+                       public boolean accept(File name) {
+                               if (name == null || !name.isFile()) {
+                                       return false;
+                               }
+                               return 
name.getName().trim().toUpperCase().matches(p);
+                       }
+               });
+       }
+
+       private static String toXML(File[] files, String root) {
+               StringBuilder sb = new StringBuilder();
+               sb.append("<" + root + ">");
+               for (File f : files) {
+                       sb.append("<file name='" + f.getName() + "' 
lastModifyTime='" + format.format(new Date(f.lastModified()))
+                                       + "' size='" + f.length() + "'/>");
+               }
+               sb.append("</" + root + ">");
+               return sb.toString();
+       }
+
+       private static void close(Connection conn) {
+               try {
+                       conn.close();
+                       LOG.info("Closed connection");
+               } catch (Exception e) {
+                       LOG.warn(e.getMessage());
+               }
+       }
+}

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e4ea1ca3/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
new file mode 100644
index 0000000..9dd16b1
--- /dev/null
+++ b/core/sql/lib_mgmt/src/main/resources/init_libmgmt.sh
@@ -0,0 +1,155 @@
+#!/bin/bash
+# @@@ 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 @@@
+
+SERVER_JAR=${MY_SQROOT}/export/lib/spj_mgmt.jar
+CI=sqlci
+CATALOG_NAME=TRAFODION
+CIS_SCHEMA="_LIBMGR_"
+DB__LIBMGRROLE=DB__LIBMGRROLE
+
+function dropAndCreateSchema {
+    echo "Creating Schema for SPJ_MGMT"
+    ${CI} << sqlciEOF
+
+      cqd CAT_IGNORE_ALREADY_EXISTS_ERROR 'on';
+      cqd CAT_IGNORE_DOES_NOT_EXIST_ERROR 'on';
+
+      DROP SCHEMA $CATALOG_NAME.$CIS_SCHEMA CASCADE;
+      CREATE SCHEMA $CATALOG_NAME.$CIS_SCHEMA;
+
+      cqd CAT_IGNORE_ALREADY_EXISTS_ERROR 'off';
+      cqd CAT_IGNORE_DOES_NOT_EXIST_ERROR 'off';
+
+      exit;
+sqlciEOF
+}
+
+function createProcedures {
+
+    echo "Creating Procedures in  schema '$CATALOG_NAME.$CIS_SCHEMA' "
+    ${CI} << procEOF
+
+      cqd CAT_IGNORE_ALREADY_EXISTS_ERROR 'on';
+      cqd CAT_IGNORE_DOES_NOT_EXIST_ERROR 'on';
+
+      -- Creating Procedures 
+      set schema $CATALOG_NAME.$CIS_SCHEMA; 
+
+      DROP LIBRARY SPJMGMT CASCADE;
+      CREATE LIBRARY SPJMGMT FILE '${SERVER_JAR}';
+      CREATE ROLE ${DB__LIBMGRROLE};
+   
+      CREATE PROCEDURE HELP (
+      INOUT COMMANDNAME VARCHAR(2560) CHARACTER SET ISO88591)
+      EXTERNAL NAME 'org.trafodion.libmgmt.FileMgmt.help (java.lang.String[])'
+      EXTERNAL SECURITY DEFINER
+      LIBRARY SPJMGMT
+      LANGUAGE JAVA
+      PARAMETER STYLE JAVA
+      READS SQL DATA
+      ;
+      GRANT EXECUTE ON PROCEDURE HELP TO ${DB__LIBMGRROLE};
+      
+      CREATE PROCEDURE PUT (
+      IN FILEDATA VARCHAR(102400) CHARACTER SET ISO88591,
+      IN FILENAME VARCHAR(256) CHARACTER SET ISO88591,
+      IN CREATEFLAG INTEGER)
+      EXTERNAL NAME 
'org.trafodion.libmgmt.FileMgmt.put(java.lang.String,java.lang.String,int)'
+      EXTERNAL SECURITY DEFINER
+      LIBRARY SPJMGMT
+      LANGUAGE JAVA
+      PARAMETER STYLE JAVA
+      READS SQL DATA
+      ;
+      GRANT EXECUTE ON PROCEDURE PUT TO ${DB__LIBMGRROLE};
+      
+      CREATE PROCEDURE LS (
+      IN FILENAME VARCHAR(256) CHARACTER SET ISO88591,
+      OUT FILENAMES VARCHAR(10240) CHARACTER SET ISO88591)
+      EXTERNAL NAME 
'org.trafodion.libmgmt.FileMgmt.ls(java.lang.String,java.lang.String[])'
+      EXTERNAL SECURITY DEFINER
+      LIBRARY SPJMGMT
+      LANGUAGE JAVA
+      PARAMETER STYLE JAVA
+      READS SQL DATA
+      ;
+      GRANT EXECUTE ON PROCEDURE LS TO ${DB__LIBMGRROLE};
+      
+      CREATE PROCEDURE LSALL (
+      OUT FILENAMES VARCHAR(10240) CHARACTER SET ISO88591)
+      EXTERNAL NAME 'org.trafodion.libmgmt.FileMgmt.lsAll(java.lang.String[])'
+      EXTERNAL SECURITY DEFINER
+      LIBRARY SPJMGMT
+      LANGUAGE JAVA
+      PARAMETER STYLE JAVA
+      READS SQL DATA
+      ;
+      GRANT EXECUTE ON PROCEDURE LSALL TO ${DB__LIBMGRROLE};
+      
+      CREATE PROCEDURE RM (
+      IN FILENAME VARCHAR(256) CHARACTER SET ISO88591)
+      EXTERNAL NAME 'org.trafodion.libmgmt.FileMgmt.rm(java.lang.String)'
+      EXTERNAL SECURITY DEFINER
+      LIBRARY SPJMGMT
+      LANGUAGE JAVA
+      PARAMETER STYLE JAVA
+      READS SQL DATA
+      ;
+      GRANT EXECUTE ON PROCEDURE RM TO ${DB__LIBMGRROLE};
+      
+      CREATE PROCEDURE RMREX (
+      IN FILENAME VARCHAR(256) CHARACTER SET ISO88591,
+      OUT FILENAMES VARCHAR(10240) CHARACTER SET ISO88591)
+      EXTERNAL NAME 'org.trafodion.libmgmt.FileMgmt.rmRex(java.lang.String, 
java.lang.String[])'
+      EXTERNAL SECURITY DEFINER
+      LIBRARY SPJMGMT
+      LANGUAGE JAVA
+      PARAMETER STYLE JAVA
+      READS SQL DATA
+      ;
+      GRANT EXECUTE ON PROCEDURE RMREX TO ${DB__LIBMGRROLE};
+
+      CREATE PROCEDURE GETFILE (
+      IN FILENAME VARCHAR(256) CHARACTER SET UTF8,
+      IN OFFSET INTEGER,
+      OUT FILEDATA VARCHAR(51200) CHARACTER SET UTF8,
+      OUT DATALENGTH LARGEINT)
+      EXTERNAL NAME 'org.trafodion.libmgmt.FileMgmt.get 
(java.lang.String,int,java.lang.String[],long[])'
+      EXTERNAL SECURITY DEFINER
+      LIBRARY SPJMGMT
+      LANGUAGE JAVA
+      PARAMETER STYLE JAVA
+      READS SQL DATA
+      ;
+      GRANT EXECUTE ON PROCEDURE GETFILE TO ${DB__LIBMGRROLE};
+      
+      cqd CAT_IGNORE_ALREADY_EXISTS_ERROR 'off';
+      cqd CAT_IGNORE_DOES_NOT_EXIST_ERROR 'off';
+
+      exit;
+procEOF
+    
+}
+
+dropAndCreateSchema
+createProcedures
+echo "Successfully completed installation of SPJs."

http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/e4ea1ca3/core/sql/lib_mgmt/src/test/java/com/trafodion/libmgmt/JarFileMgmtTest.java
----------------------------------------------------------------------
diff --git 
a/core/sql/lib_mgmt/src/test/java/com/trafodion/libmgmt/JarFileMgmtTest.java 
b/core/sql/lib_mgmt/src/test/java/com/trafodion/libmgmt/JarFileMgmtTest.java
new file mode 100644
index 0000000..2636316
--- /dev/null
+++ b/core/sql/lib_mgmt/src/test/java/com/trafodion/libmgmt/JarFileMgmtTest.java
@@ -0,0 +1,27 @@
+/**
+* @@@ 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 @@@
+ */
+package com.trafodion.libmgmt;
+
+public class JarFileMgmtTest {
+
+}

Reply via email to