You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by sa...@apache.org on 2014/04/14 20:30:47 UTC
[45/90] [abbrv] [partial] AIRAVATA-1124
http://git-wip-us.apache.org/repos/asf/airavata/blob/0e2c10f5/modules/registry/airavata-registry-service/src/main/java/org/apache/airavata/registry/services/utils/DatabaseCreator.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-registry-service/src/main/java/org/apache/airavata/registry/services/utils/DatabaseCreator.java b/modules/registry/airavata-registry-service/src/main/java/org/apache/airavata/registry/services/utils/DatabaseCreator.java
deleted file mode 100644
index 7782964..0000000
--- a/modules/registry/airavata-registry-service/src/main/java/org/apache/airavata/registry/services/utils/DatabaseCreator.java
+++ /dev/null
@@ -1,348 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-package org.apache.airavata.registry.services.utils;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.SQLWarning;
-import java.sql.Statement;
-import java.util.StringTokenizer;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This class creates the database tables required for messagebox and messagebroker with default configuration this
- * class creates embedded derby database in local file system. User can specify required database in appropriate
- * properties files.
- */
-public class DatabaseCreator {
-
- public enum DatabaseType {
- derby("(?i).*derby.*"), mysql("(?i).*mysql.*"), other("");
-
- private String pattern;
-
- private DatabaseType(String matchingPattern) {
- this.pattern = matchingPattern;
- }
-
- public String getMatchingPattern() {
- return this.pattern;
- }
- }
-
- private static DatabaseType[] supportedDatabase = new DatabaseType[] { DatabaseType.derby, DatabaseType.mysql };
-
- private static Logger log = LoggerFactory.getLogger(DatabaseCreator.class);
- private static final String delimiter = ";";
-
- /**
- * Creates database
- *
- * @throws Exception
- */
- public static void createRegistryDatabase(Connection conn) throws Exception {
- createDatabase("data", conn);
- }
-
-
-
- /**
- * Checks whether database tables are created by using select * on given table name
- *
- * @param tableName
- * Table which should be existed
- * @return <code>true</core> if checkSQL is success, else <code>false</code> .
- */
- public static boolean isDatabaseStructureCreated(String tableName, Connection conn) {
- try {
-
- log.debug("Running a query to test the database tables existence.");
-
- // check whether the tables are already created with a query
- Statement statement = null;
- try {
- statement = conn.createStatement();
- ResultSet rs = statement.executeQuery("select * from " + tableName);
- if (rs != null) {
- rs.close();
- }
- } finally {
- try {
- if (statement != null) {
- statement.close();
- }
- } catch (SQLException e) {
- return false;
- }
- }
- } catch (SQLException e) {
- return false;
- }
-
- return true;
- }
-
- /**
- * executes given sql
- *
- * @param sql
- * @throws Exception
- */
- private static void executeSQL(String sql, Connection conn) throws Exception {
- // Check and ignore empty statements
- if ("".equals(sql.trim())) {
- return;
- }
-
- Statement statement = null;
- try {
- log.debug("SQL : " + sql);
-
- boolean ret;
- int updateCount = 0, updateCountTotal = 0;
- statement = conn.createStatement();
- ret = statement.execute(sql);
- updateCount = statement.getUpdateCount();
- do {
- if (!ret) {
- if (updateCount != -1) {
- updateCountTotal += updateCount;
- }
- }
- ret = statement.getMoreResults();
- if (ret) {
- updateCount = statement.getUpdateCount();
- }
- } while (ret);
-
- log.debug(sql + " : " + updateCountTotal + " rows affected");
-
- SQLWarning warning = conn.getWarnings();
- while (warning != null) {
- log.info(warning + " sql warning");
- warning = warning.getNextWarning();
- }
- conn.clearWarnings();
- } catch (SQLException e) {
- if (e.getSQLState().equals("X0Y32")) {
- // eliminating the table already exception for the derby
- // database
- log.info("Table Already Exists", e);
- } else {
- throw new Exception("Error occurred while executing : " + sql, e);
- }
- } finally {
- if (statement != null) {
- try {
- statement.close();
- } catch (SQLException e) {
- log.error("Error occurred while closing result set.", e);
- }
- }
- }
- }
-
- /**
- * computes relatational database type using database name
- *
- * @return DatabaseType
- * @throws Exception
- *
- */
- public static DatabaseType getDatabaseType(Connection conn) throws Exception {
- try {
- if (conn != null && (!conn.isClosed())) {
- DatabaseMetaData metaData = conn.getMetaData();
- String databaseProductName = metaData.getDatabaseProductName();
- return checkType(databaseProductName);
- }
- } catch (SQLException e) {
- String msg = "Failed to create Airavatadatabase." + e.getMessage();
- log.error(msg, e);
- throw new Exception(msg, e);
- }
- return DatabaseType.other;
- }
-
- /**
- * Overloaded method with String input
- *
- * @return DatabaseType
- * @throws Exception
- *
- */
- public static DatabaseType getDatabaseType(String dbUrl) throws Exception {
- return checkType(dbUrl);
- }
-
- private static DatabaseType checkType(String text) throws Exception {
- try {
- if (text != null) {
- for (DatabaseType type : supportedDatabase) {
- if (text.matches(type.getMatchingPattern()))
- return type;
- }
- }
- String msg = "Unsupported database: " + text
- + ". Database will not be created automatically by the Airavata. "
- + "Please create the database using appropriate database scripts for " + "the database.";
- throw new Exception(msg);
-
- } catch (SQLException e) {
- String msg = "Failed to create Airavatadatabase." + e.getMessage();
- log.error(msg, e);
- throw new Exception(msg, e);
- }
- }
-
- /**
- * Get scripts location which is prefix + "-" + databaseType + ".sql"
- *
- * @param prefix
- * @param databaseType
- * @return script location
- */
- private static String getScriptLocation(String prefix, DatabaseType databaseType) {
- String scriptName = prefix + "-" + databaseType + ".sql";
- log.debug("Loading database script from :" + scriptName);
- return "database_scripts" + File.separator + scriptName;
- }
-
- private static void createDatabase(String prefix, Connection conn) throws Exception {
- Statement statement = null;
- try {
- conn.setAutoCommit(false);
- statement = conn.createStatement();
- executeSQLScript(getScriptLocation(prefix, DatabaseCreator.getDatabaseType(conn)), conn);
- conn.commit();
- log.debug("Tables are created successfully.");
- } catch (SQLException e) {
- String msg = "Failed to create database tables for Airavata resource store. " + e.getMessage();
- log.error(msg, e);
- conn.rollback();
- throw new Exception(msg, e);
- } finally {
- conn.setAutoCommit(true);
- try {
- if (statement != null) {
- statement.close();
- }
- } catch (SQLException e) {
- log.error("Failed to close statement.", e);
- }
- }
- }
-
- private static void executeSQLScript(String dbscriptName, Connection conn) throws Exception {
- StringBuffer sql = new StringBuffer();
- BufferedReader reader = null;
-
- try {
- InputStream is = DatabaseCreator.class.getClassLoader().getResourceAsStream(dbscriptName);
- reader = new BufferedReader(new InputStreamReader(is));
- String line;
- while ((line = reader.readLine()) != null) {
- line = line.trim();
- if (line.startsWith("//")) {
- continue;
- }
- if (line.startsWith("--")) {
- continue;
- }
- StringTokenizer st = new StringTokenizer(line);
- if (st.hasMoreTokens()) {
- String token = st.nextToken();
- if ("REM".equalsIgnoreCase(token)) {
- continue;
- }
- }
- sql.append(" ").append(line);
-
- // SQL defines "--" as a comment to EOL
- // and in Oracle it may contain a hint
- // so we cannot just remove it, instead we must end it
- if (line.indexOf("--") >= 0) {
- sql.append("\n");
- }
- if ((checkStringBufferEndsWith(sql, delimiter))) {
- executeSQL(sql.substring(0, sql.length() - delimiter.length()), conn);
- sql.replace(0, sql.length(), "");
- }
- }
- // Catch any statements not followed by ;
- if (sql.length() > 0) {
- executeSQL(sql.toString(), conn);
- }
- } catch (IOException e) {
- log.error("Error occurred while executing SQL script for creating Airavata database", e);
- throw new Exception("Error occurred while executing SQL script for creating Airavata database", e);
-
- } finally {
- if (reader != null) {
- reader.close();
- }
- }
- }
-
- /**
- * Checks that a string buffer ends up with a given string. It may sound trivial with the existing JDK API but the
- * various implementation among JDKs can make those methods extremely resource intensive and perform poorly due to
- * massive memory allocation and copying. See
- *
- * @param buffer
- * the buffer to perform the check on
- * @param suffix
- * the suffix
- * @return <code>true</code> if the character sequence represented by the argument is a suffix of the character
- * sequence represented by the StringBuffer object; <code>false</code> otherwise. Note that the result will
- * be <code>true</code> if the argument is the empty string.
- */
- public static boolean checkStringBufferEndsWith(StringBuffer buffer, String suffix) {
- if (suffix.length() > buffer.length()) {
- return false;
- }
- // this loop is done on purpose to avoid memory allocation performance
- // problems on various JDKs
- // StringBuffer.lastIndexOf() was introduced in jdk 1.4 and
- // implementation is ok though does allocation/copying
- // StringBuffer.toString().endsWith() does massive memory
- // allocation/copying on JDK 1.5
- // See http://issues.apache.org/bugzilla/show_bug.cgi?id=37169
- int endIndex = suffix.length() - 1;
- int bufferIndex = buffer.length() - 1;
- while (endIndex >= 0) {
- if (buffer.charAt(bufferIndex) != suffix.charAt(endIndex)) {
- return false;
- }
- bufferIndex--;
- endIndex--;
- }
- return true;
- }
-}
http://git-wip-us.apache.org/repos/asf/airavata/blob/0e2c10f5/modules/registry/airavata-registry-service/src/main/java/org/apache/airavata/registry/services/utils/JdbcStorage.java
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-registry-service/src/main/java/org/apache/airavata/registry/services/utils/JdbcStorage.java b/modules/registry/airavata-registry-service/src/main/java/org/apache/airavata/registry/services/utils/JdbcStorage.java
deleted file mode 100644
index ff97f31..0000000
--- a/modules/registry/airavata-registry-service/src/main/java/org/apache/airavata/registry/services/utils/JdbcStorage.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- *
- * 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.
- *
-*/
-package org.apache.airavata.registry.services.utils;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class JdbcStorage {
- private static Logger log = LoggerFactory.getLogger(JdbcStorage.class);
-
- private ConnectionPool connectionPool;
-
- public JdbcStorage(String jdbcUrl, String jdbcDriver) {
- // default init connection and max connection
- this(3, 50, jdbcUrl, jdbcDriver, true);
- }
-
- public JdbcStorage(int initCon, int maxCon, String url, String driver, boolean enableTransactions) {
- try {
- if (enableTransactions) {
- connectionPool = new ConnectionPool(driver, url, initCon, maxCon, true, false,
- Connection.TRANSACTION_SERIALIZABLE);
- } else {
- connectionPool = new ConnectionPool(driver, url, initCon, maxCon, true);
- }
- } catch (Exception e) {
- throw new RuntimeException("Failed to create database connection pool.", e);
- }
- }
-
- /**
- * Check if this connection pool is auto commit or not
- *
- * @return
- */
- public boolean isAutoCommit() {
- return connectionPool.isAutoCommit();
- }
-
- public void commit(Connection conn) {
- try {
- if (conn != null && !conn.getAutoCommit()) {
- conn.commit();
- }
- } catch (SQLException sqle) {
- log.error("Cannot commit data", sqle);
- }
- }
-
- public void commitAndFree(Connection conn) {
- commit(conn);
- closeConnection(conn);
- }
-
- public void rollback(Connection conn) {
- try {
- if (conn != null && !conn.getAutoCommit()) {
- conn.rollback();
- }
- } catch (SQLException sqle) {
- log.error("Cannot Rollback data", sqle);
- }
- }
-
- public void rollbackAndFree(Connection conn) {
- rollback(conn);
- closeConnection(conn);
- }
-
- public Connection connect() {
-
- Connection conn = null;
- try {
- conn = connectionPool.getConnection();
- } catch (SQLException e) {
- e.printStackTrace();
- log.error(e.getMessage(), e);
- }
- return conn;
- }
-
- /**
- * This method is provided so that you can have better control over the statement. For example: You can use
- * stmt.setString to convert quotation mark automatically in an UPDATE statement
- *
- * NOTE: Statement is closed after execution
- */
- public int executeUpdateAndClose(PreparedStatement stmt) throws SQLException {
- int rows = 0;
- try {
- rows = stmt.executeUpdate();
- if (rows == 0) {
- log.info("Problem: 0 rows affected by insert/update/delete statement.");
- }
- } finally {
- stmt.close();
- }
- return rows;
- }
-
- public int countRow(String tableName, String columnName) throws SQLException {
- String query = new String("SELECT COUNT(" + columnName + ") FROM " + tableName);
- int count = -1;
- Connection conn = null;
- PreparedStatement stmt = null;
- try {
- conn = connectionPool.getConnection();
- stmt = conn.prepareStatement(query);
- ResultSet rs = stmt.executeQuery();
- rs.next();
- count = rs.getInt(1);
- commit(conn);
- } catch (SQLException sql) {
- rollback(conn);
- throw sql;
- } finally {
- try {
- if (stmt != null && !stmt.isClosed()) {
- stmt.close();
- }
- } finally {
- closeConnection(conn);
- }
- }
- return count;
- }
-
- public void quietlyClose(Connection conn, Statement... stmts) {
- if (stmts != null) {
- for (Statement stmt : stmts) {
- try {
- if (stmt != null && !stmt.isClosed()) {
- stmt.close();
- }
- } catch (SQLException sql) {
- log.error(sql.getMessage(), sql);
- }
- }
- }
- closeConnection(conn);
- }
-
- public void closeConnection(Connection conn) {
- if (conn != null) {
- connectionPool.free(conn);
- }
- }
-
- public void closeAllConnections() {
- if (connectionPool != null)
- connectionPool.dispose();
- }
-
- public void shutdown() {
- connectionPool.shutdown();
- }
-}
http://git-wip-us.apache.org/repos/asf/airavata/blob/0e2c10f5/modules/registry/airavata-registry-service/src/main/resources/services.xml
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-registry-service/src/main/resources/services.xml b/modules/registry/airavata-registry-service/src/main/resources/services.xml
deleted file mode 100644
index 4b7102b..0000000
--- a/modules/registry/airavata-registry-service/src/main/resources/services.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--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. -->
-<service name="RegistryService" class="org.apache.airavata.registry.services.RegistryService" >
- <Description>
- Provide Simple Service for Testing Purpose including addition, subtraction, multiplication, array-generator
- </Description>
- <messageReceivers>
- <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver" />
- <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/>
- </messageReceivers>
- <parameter name="ServiceClass" locked="false">org.apache.airavata.registry.services.RegistryService</parameter>
-</service>
http://git-wip-us.apache.org/repos/asf/airavata/blob/0e2c10f5/modules/registry/airavata-registry-test/pom.xml
----------------------------------------------------------------------
diff --git a/modules/registry/airavata-registry-test/pom.xml b/modules/registry/airavata-registry-test/pom.xml
deleted file mode 100644
index 7abac97..0000000
--- a/modules/registry/airavata-registry-test/pom.xml
+++ /dev/null
@@ -1,112 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--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. -->
-
-<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/maven-v4_0_0.xsd">
-
- <parent>
- <groupId>org.apache.airavata</groupId>
- <artifactId>registry</artifactId>
- <version>0.12-SNAPSHOT</version>
- <relativePath>../pom.xml</relativePath>
- </parent>
-
- <modelVersion>4.0.0</modelVersion>
- <artifactId>airavata-registry-test</artifactId>
- <packaging>jar</packaging>
- <name>Airavata Registry Test</name>
- <url>http://airavata.apache.org/</url>
-
- <dependencies>
- <dependency>
- <groupId>org.apache.airavata</groupId>
- <artifactId>airavata-gfac-schema-utils</artifactId>
- <version>${project.version}</version>
- </dependency>
- <!--dependency>
- <groupId>org.apache.airavata</groupId>
- <artifactId>airavata-common-utils</artifactId>
- <version>${project.version}</version>
- </dependency-->
- <!-- Test -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <!--<dependency>-->
- <!--<groupId>org.apache.openjpa</groupId>-->
- <!--<artifactId>openjpa-all</artifactId>-->
- <!--<version>2.2.0</version>-->
- <!--</dependency>-->
- <dependency>
- <groupId>org.apache.airavata</groupId>
- <artifactId>airavata-registry-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- <!--dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
- <version>5.1.6</version>
- </dependency-->
- <dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derby</artifactId>
- <version>${derby.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derbyclient</artifactId>
- <version>${derby.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derbynet</artifactId>
- <version>${derby.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.derby</groupId>
- <artifactId>derbytools</artifactId>
- <version>${derby.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.airavata</groupId>
- <artifactId>airavata-jpa-registry</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.airavata</groupId>
- <artifactId>airavata-data-models</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
- <!--dependency>
- <groupId>org.apache.airavata</groupId>
- <artifactId>airavata-workflow-model-core</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency-->
- <!--dependency>
- <groupId>org.apache.airavata</groupId>
- <artifactId>airavata-registry-service</artifactId>
- <version>${project.version}</version>
- </dependency-->
- <dependency>
- <groupId>org.apache.airavata</groupId>
- <artifactId>airavata-client-configuration</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
-</project>