[exo-jcr-commits] exo-jcr SVN: r2090 - in core/trunk/exo.core.component.database: src/main/java/org/exoplatform/services/database/creator and 2 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Mon Mar 22 05:54:46 EDT 2010


Author: tolusha
Date: 2010-03-22 05:54:46 -0400 (Mon, 22 Mar 2010)
New Revision: 2090

Added:
   core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java
   core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreatorException.java
   core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBCreator.java
Removed:
   core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBScriptExecutor.java
   core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBScriptExecutorException.java
   core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBScriptExecutor.java
Modified:
   core/trunk/exo.core.component.database/pom.xml
   core/trunk/exo.core.component.database/src/test/resources/conf/standalone/test-configuration.xml
Log:
EXOJCR-573: rename DBScriptExecutor to DBCreator

Modified: core/trunk/exo.core.component.database/pom.xml
===================================================================
--- core/trunk/exo.core.component.database/pom.xml	2010-03-22 09:35:46 UTC (rev 2089)
+++ core/trunk/exo.core.component.database/pom.xml	2010-03-22 09:54:46 UTC (rev 2090)
@@ -102,7 +102,7 @@
             </exclusion>
          </exclusions> 
       </dependency>
-   </dependencies>
+  </dependencies>
    
    <build>
       <pluginManagement>
@@ -113,7 +113,7 @@
                <configuration>
                   <excludes>
                      <exclude>**/DBCreatorTest.java</exclude>
-                     <exclude>**/TestDBScriptExecutor.java</exclude>
+                     <exclude>**/TestDBCreator.java</exclude>
                   </excludes>
                </configuration>
             </plugin>

Added: core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java
===================================================================
--- core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java	                        (rev 0)
+++ core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreator.java	2010-03-22 09:54:46 UTC (rev 2090)
@@ -0,0 +1,376 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.database.creator;
+
+import org.exoplatform.container.configuration.ConfigurationException;
+import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.container.xml.PropertiesParam;
+
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+/**
+ * @author <a href="anatoliy.bazko at exoplatform.org">Anatoliy Bazko</a>
+ * @version $Id: DBCreator.java 111 2010-11-11 11:11:11Z tolusha $
+ */
+public class DBCreator
+{
+
+   /**
+    * Database template.
+    */
+   public static final String DATABASE_TEMPLATE = "${database}";
+
+   /**
+    * User name template.
+    */
+   public static final String USERNAME_TEMPLATE = "${username}";
+
+   /**
+    * Password template.
+    */
+   public static final String PASSWORD_TEMPLATE = "${password}";
+
+   /**
+    * Driver class name.
+    */
+   protected final String driver;
+
+   /**
+    * Server url.
+    */
+   protected final String serverUrl;
+
+   /**
+    * User name with administrative rights for connection to server.
+    */
+   protected final String adminName;
+
+   /**
+    * User's password.
+    */
+   protected final String adminPwd;
+
+   /**
+    * Internal login connection property needed for Oracle.
+    */
+   protected final String internal_logon;
+
+   /**
+    * DDL script database creation.
+    */
+   protected final String dbScript;
+
+   /**
+    * User name for new database.
+    */
+   protected final String dbUserName;
+
+   /**
+    * User's password.
+    */
+   protected final String dbPassword;
+
+   /**
+    * DBCreator constructor.
+    * 
+    * @param params
+    *          Initializations parameters
+    */
+   public DBCreator(InitParams params) throws ConfigurationException
+   {
+      if (params == null)
+      {
+         throw new ConfigurationException("Initializations parameters expected");
+      }
+
+      PropertiesParam prop = params.getPropertiesParam("db-connection");
+
+      if (prop != null)
+      {
+         this.driver = prop.getProperty("driverClassName");
+         if (driver == null)
+         {
+            throw new ConfigurationException("driverClassName expected in db-connection properties section");
+         }
+
+         this.serverUrl = prop.getProperty("url");
+         if (serverUrl == null)
+         {
+            throw new ConfigurationException("url expected in db-connection properties section");
+         }
+
+         this.adminName = prop.getProperty("username");
+         if (adminName == null)
+         {
+            throw new ConfigurationException("username expected in db-connection properties section");
+         }
+
+         this.adminPwd = prop.getProperty("password");
+         if (adminPwd == null)
+         {
+            throw new ConfigurationException("password expected in db-connection properties section");
+         }
+
+         this.internal_logon = prop.getProperty("internal_logon");
+      }
+      else
+      {
+         throw new ConfigurationException("db-connection properties expected in initializations parameters");
+      }
+
+      prop = params.getPropertiesParam("db-creation");
+      if (prop != null)
+      {
+         String scriptPath = prop.getProperty("scriptPath");
+         if (scriptPath != null)
+         {
+            try
+            {
+               dbScript = readScriptResource(scriptPath);
+            }
+            catch (IOException e)
+            {
+               throw new ConfigurationException("Can't read script resource " + scriptPath, e);
+            }
+         }
+         else
+         {
+            throw new ConfigurationException("scriptPath expected in db-creation properties section");
+         }
+
+         this.dbUserName = prop.getProperty("username");
+         if (dbUserName == null)
+         {
+            throw new ConfigurationException("username expected in db-creation properties section");
+         }
+
+         this.dbPassword = prop.getProperty("password");
+         if (dbPassword == null)
+         {
+            throw new ConfigurationException("password expected in db-creation properties section");
+         }
+      }
+      else
+      {
+         throw new ConfigurationException("db-creation properties expected in initializations parameters");
+      }
+   }
+
+   /**
+    * Execute DDL script for new database creation. Database name are passed as parameter, 
+    * user name and password are passed via configuration. In script database name, user name 
+    * and password defined via templates as ${database}, ${username} and ${password} respectively.
+    * At execution time method replaces templates by real values.
+    * 
+    * @param dbName
+    *          new database name
+    * @throws DBCreatorException
+    *          if any error occurs 
+    */
+   public DBConnectionInfo createDatabase(String dbName) throws DBCreatorException
+   {
+      Connection conn = null;
+      try
+      {
+         Class.forName(driver);
+
+         //         Properties props = new java.util.Properties();
+         //         props.put("user", adminName);
+         //         props.put("password", adminPwd);
+         //         if (internal_logon != null)
+         //         {
+         //            props.put("internal_logon", internal_logon);
+         //         }
+         //         conn = DriverManager.getConnection(serverUrl, props);
+         conn = DriverManager.getConnection(serverUrl, adminName, adminPwd);
+      }
+      catch (SQLException e)
+      {
+         throw new DBCreatorException("Can't establish the JDBC connection to database " + serverUrl, e);
+      }
+      catch (ClassNotFoundException e)
+      {
+         throw new DBCreatorException("Can't load the JDBC driver " + driver, e);
+      }
+
+      String dbProductName;
+      try
+      {
+         dbProductName = conn.getMetaData().getDatabaseProductName();
+
+         if (dbProductName.startsWith("Microsoft SQL Server") || dbProductName.startsWith("Adaptive Server Anywhere")
+            || dbProductName.equals("Sybase SQL Server") || dbProductName.equals("Adaptive Server Enterprise"))
+         {
+            executeAutoCommitMode(conn, dbName);
+         }
+         else
+         {
+            executeBatchMode(conn, dbName);
+         }
+      }
+      catch (SQLException e)
+      {
+         String errorTrace = "";
+         while (e != null)
+         {
+            errorTrace += e.getMessage() + "; ";
+            e = e.getNextException();
+         }
+
+         throw new DBCreatorException("Can't execute SQL script " + errorTrace);
+      }
+      finally
+      {
+         try
+         {
+            conn.close();
+         }
+         catch (SQLException e)
+         {
+            throw new DBCreatorException("Can't close connection", e);
+         }
+      }
+
+      // try to solve database url connection depending on specific database
+      String dbUrl = serverUrl;
+      if (dbProductName.startsWith("Microsoft SQL Server"))
+      {
+         dbUrl = dbUrl + (dbUrl.endsWith(";") ? "" : ";") + "databaseName=" + dbName + ";";
+      }
+      else if (dbProductName.equals("Oracle"))
+      {
+         // do nothing
+      }
+      else
+      {
+         dbUrl = dbUrl + (dbUrl.endsWith("/") ? "" : "/") + dbName;
+      }
+
+      return new DBConnectionInfo(driver, dbUrl, dbUserName, dbPassword);
+   }
+
+   /**
+    * Executes DDL script in generic batch mode.
+    * 
+    * @param conn
+    *          connection to server
+    * @param dbName
+    *          database name
+    * @throws SQLException
+    *          if any errors occurs
+    */
+   private void executeBatchMode(Connection conn, String dbName) throws SQLException
+   {
+      Statement statement = conn.createStatement();
+      for (String scr : dbScript.split(";"))
+      {
+         scr = scr.replace(DATABASE_TEMPLATE, dbName);
+         scr = scr.replace(USERNAME_TEMPLATE, dbUserName);
+         scr = scr.replace(PASSWORD_TEMPLATE, dbPassword);
+
+         String s = cleanWhitespaces(scr.trim());
+         if (s.length() > 0)
+         {
+            statement.addBatch(s);
+         }
+      }
+      statement.executeBatch();
+   }
+
+   /**
+    * Executes DDL script with autocommit mode set true. Actually need for MSSQL and Sybase database servers.
+    * After execution "create database" command newly created database not available for "use" command and
+    * therefore you can't create user inside.  
+    * 
+    * @param conn
+    *          connection to server
+    * @param dbName
+    *          database name
+    * @throws SQLException
+    *          if any errors occurs
+    */
+   private void executeAutoCommitMode(Connection conn, String dbName) throws SQLException
+   {
+      conn.setAutoCommit(true);
+      for (String scr : dbScript.split(";"))
+      {
+         scr = scr.replace(DATABASE_TEMPLATE, dbName);
+         scr = scr.replace(USERNAME_TEMPLATE, dbUserName);
+         scr = scr.replace(PASSWORD_TEMPLATE, dbPassword);
+
+         String s = cleanWhitespaces(scr.trim());
+         if (s.length() > 0)
+         {
+            conn.createStatement().executeUpdate(s);
+         }
+      }
+   }
+
+   /**
+    * Read SQL script from file resource.
+    */
+   protected String readScriptResource(String path) throws IOException
+   {
+      InputStream is = new FileInputStream(path);
+      InputStreamReader isr = new InputStreamReader(is);
+      try
+      {
+         StringBuilder sbuff = new StringBuilder();
+         char[] buff = new char[is.available()];
+         int r = 0;
+         while ((r = isr.read(buff)) > 0)
+         {
+            sbuff.append(buff, 0, r);
+         }
+
+         return sbuff.toString();
+      }
+      finally
+      {
+         is.close();
+      }
+   }
+
+   /**
+    * Clean whitespace.
+    */
+   private String cleanWhitespaces(String string)
+   {
+      if (string != null)
+      {
+         char[] cc = string.toCharArray();
+         for (int ci = cc.length - 1; ci > 0; ci--)
+         {
+            if (Character.isWhitespace(cc[ci]))
+            {
+               cc[ci] = ' ';
+            }
+         }
+         return new String(cc);
+      }
+      return string;
+   }
+}

Added: core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreatorException.java
===================================================================
--- core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreatorException.java	                        (rev 0)
+++ core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBCreatorException.java	2010-03-22 09:54:46 UTC (rev 2090)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.database.creator;
+
+/**
+ * @author <a href="anatoliy.bazko at exoplatform.org">Anatoliy Bazko</a>
+ * @version $Id: DBCreatorException.java 111 2010-11-11 11:11:11Z tolusha $
+ */
+public class DBCreatorException extends Exception
+{
+
+   /**
+    * DBCreationException constructor.
+    */
+   public DBCreatorException(Throwable e)
+   {
+      super(e);
+   }
+
+   /**
+    * DBCreationException constructor.
+    */
+   public DBCreatorException(String message, Throwable e)
+   {
+      super(message, e);
+   }
+
+   /**
+    * DBCreationException constructor.
+    */
+   public DBCreatorException(String message)
+   {
+      super(message);
+   }
+}

Deleted: core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBScriptExecutor.java
===================================================================
--- core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBScriptExecutor.java	2010-03-22 09:35:46 UTC (rev 2089)
+++ core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBScriptExecutor.java	2010-03-22 09:54:46 UTC (rev 2090)
@@ -1,376 +0,0 @@
-/*
- * Copyright (C) 2010 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.services.database.creator;
-
-import org.exoplatform.container.configuration.ConfigurationException;
-import org.exoplatform.container.xml.InitParams;
-import org.exoplatform.container.xml.PropertiesParam;
-
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Properties;
-
-/**
- * @author <a href="anatoliy.bazko at exoplatform.org">Anatoliy Bazko</a>
- * @version $Id: DBCreator.java 111 2010-11-11 11:11:11Z tolusha $
- */
-public class DBScriptExecutor
-{
-
-   /**
-    * Database template.
-    */
-   public static final String DATABASE_TEMPLATE = "${database}";
-
-   /**
-    * User name template.
-    */
-   public static final String USERNAME_TEMPLATE = "${username}";
-
-   /**
-    * Password template.
-    */
-   public static final String PASSWORD_TEMPLATE = "${password}";
-
-   /**
-    * Driver class name.
-    */
-   protected final String driver;
-
-   /**
-    * Server url.
-    */
-   protected final String serverUrl;
-
-   /**
-    * User name with administrative rights for connection to server.
-    */
-   protected final String adminName;
-
-   /**
-    * User's password.
-    */
-   protected final String adminPwd;
-
-   /**
-    * Internal login connection property needed for Oracle.
-    */
-   protected final String internal_logon;
-
-   /**
-    * DDL script database creation.
-    */
-   protected final String dbScript;
-
-   /**
-    * User name for new database.
-    */
-   protected final String dbUserName;
-
-   /**
-    * User's password.
-    */
-   protected final String dbPassword;
-
-   /**
-    * DBScriptExecutor constructor.
-    * 
-    * @param params
-    *          Initializations parameters
-    */
-   public DBScriptExecutor(InitParams params) throws ConfigurationException
-   {
-      if (params == null)
-      {
-         throw new ConfigurationException("Initializations parameters expected");
-      }
-
-      PropertiesParam prop = params.getPropertiesParam("db-connection");
-
-      if (prop != null)
-      {
-         this.driver = prop.getProperty("driverClassName");
-         if (driver == null)
-         {
-            throw new ConfigurationException("driverClassName expected in db-connection properties section");
-         }
-
-         this.serverUrl = prop.getProperty("url");
-         if (serverUrl == null)
-         {
-            throw new ConfigurationException("url expected in db-connection properties section");
-         }
-
-         this.adminName = prop.getProperty("username");
-         if (adminName == null)
-         {
-            throw new ConfigurationException("username expected in db-connection properties section");
-         }
-
-         this.adminPwd = prop.getProperty("password");
-         if (adminPwd == null)
-         {
-            throw new ConfigurationException("password expected in db-connection properties section");
-         }
-
-         this.internal_logon = prop.getProperty("internal_logon");
-      }
-      else
-      {
-         throw new ConfigurationException("db-connection properties expected in initializations parameters");
-      }
-
-      prop = params.getPropertiesParam("db-creation");
-      if (prop != null)
-      {
-         String scriptPath = prop.getProperty("scriptPath");
-         if (scriptPath != null)
-         {
-            try
-            {
-               dbScript = readScriptResource(scriptPath);
-            }
-            catch (IOException e)
-            {
-               throw new ConfigurationException("Can't read script resource " + scriptPath, e);
-            }
-         }
-         else
-         {
-            throw new ConfigurationException("scriptPath expected in db-creation properties section");
-         }
-
-         this.dbUserName = prop.getProperty("username");
-         if (dbUserName == null)
-         {
-            throw new ConfigurationException("username expected in db-creation properties section");
-         }
-
-         this.dbPassword = prop.getProperty("password");
-         if (dbPassword == null)
-         {
-            throw new ConfigurationException("password expected in db-creation properties section");
-         }
-      }
-      else
-      {
-         throw new ConfigurationException("db-creation properties expected in initializations parameters");
-      }
-   }
-
-   /**
-    * Execute DDL script for new database creation. Database name are passed as parameter, 
-    * user name and password are passed via configuration. In script database name, user name 
-    * and password defined via templates as ${database}, ${username} and ${password} respectively.
-    * At execution time method replaces templates by real values.
-    * 
-    * @param dbName
-    *          new database name
-    * @throws DBScriptExecutorException
-    *          if any error occurs 
-    */
-   public DBConnectionInfo createDatabase(String dbName) throws DBScriptExecutorException
-   {
-      Connection conn = null;
-      try
-      {
-         Class.forName(driver);
-
-         Properties props = new java.util.Properties();
-         props.put("user", adminName);
-         props.put("password", adminPwd);
-         if (internal_logon != null)
-         {
-            props.put("internal_logon", internal_logon);
-         }
-         conn = DriverManager.getConnection(serverUrl, props);
-      }
-      catch (SQLException e)
-      {
-         throw new DBScriptExecutorException("Can't establish the JDBC connection to database " + serverUrl, e);
-      }
-      catch (ClassNotFoundException e)
-      {
-         throw new DBScriptExecutorException("Can't load the JDBC driver " + driver, e);
-      }
-
-      String dbProductName;
-      try
-      {
-         dbProductName = conn.getMetaData().getDatabaseProductName();
-
-         if (dbProductName.startsWith("Microsoft SQL Server") || dbProductName.startsWith("Adaptive Server Anywhere")
-            || dbProductName.equals("Sybase SQL Server") || dbProductName.equals("Adaptive Server Enterprise"))
-         {
-            executeAutoCommitMode(conn, dbName);
-         }
-         else
-         {
-            executeBatchMode(conn, dbName);
-         }
-      }
-      catch (SQLException e)
-      {
-         String errorTrace = "";
-         while (e != null)
-         {
-            errorTrace += e.getMessage() + "; ";
-            e = e.getNextException();
-         }
-
-         throw new DBScriptExecutorException("Can't execute SQL script " + errorTrace);
-      }
-      finally
-      {
-         try
-         {
-            conn.close();
-         }
-         catch (SQLException e)
-         {
-            throw new DBScriptExecutorException("Can't close connection", e);
-         }
-      }
-
-      // try to solve database url connection depending on specific database
-      String dbUrl = serverUrl;
-      if (dbProductName.startsWith("Microsoft SQL Server"))
-      {
-         dbUrl = dbUrl + (dbUrl.endsWith(";") ? "" : ";") + "databaseName=" + dbName + ";";
-      }
-      else if (dbProductName.equals("Oracle"))
-      {
-         // do nothing
-      }
-      else
-      {
-         dbUrl = dbUrl + (dbUrl.endsWith("/") ? "" : "/") + dbName;
-      }
-
-      return new DBConnectionInfo(driver, dbUrl, dbUserName, dbPassword);
-   }
-
-   /**
-    * Executes DDL script in generic batch mode.
-    * 
-    * @param conn
-    *          connection to server
-    * @param dbName
-    *          database name
-    * @throws SQLException
-    *          if any errors occurs
-    */
-   private void executeBatchMode(Connection conn, String dbName) throws SQLException
-   {
-      Statement statement = conn.createStatement();
-      for (String scr : dbScript.split(";"))
-      {
-         scr = scr.replace(DATABASE_TEMPLATE, dbName);
-         scr = scr.replace(USERNAME_TEMPLATE, dbUserName);
-         scr = scr.replace(PASSWORD_TEMPLATE, dbPassword);
-
-         String s = cleanWhitespaces(scr.trim());
-         if (s.length() > 0)
-         {
-            statement.addBatch(s);
-         }
-      }
-      statement.executeBatch();
-   }
-
-   /**
-    * Executes DDL script with autocommit mode set true. Actually need for MSSQL and Sybase database servers.
-    * After execution "create database" command newly created database not available for "use" command and
-    * therefore you can't create user inside.  
-    * 
-    * @param conn
-    *          connection to server
-    * @param dbName
-    *          database name
-    * @throws SQLException
-    *          if any errors occurs
-    */
-   private void executeAutoCommitMode(Connection conn, String dbName) throws SQLException
-   {
-      conn.setAutoCommit(true);
-      for (String scr : dbScript.split(";"))
-      {
-         scr = scr.replace(DATABASE_TEMPLATE, dbName);
-         scr = scr.replace(USERNAME_TEMPLATE, dbUserName);
-         scr = scr.replace(PASSWORD_TEMPLATE, dbPassword);
-
-         String s = cleanWhitespaces(scr.trim());
-         if (s.length() > 0)
-         {
-            conn.createStatement().executeUpdate(s);
-         }
-      }
-   }
-
-   /**
-    * Read SQL script from file resource.
-    */
-   protected String readScriptResource(String path) throws IOException
-   {
-      InputStream is = new FileInputStream(path);
-      InputStreamReader isr = new InputStreamReader(is);
-      try
-      {
-         StringBuilder sbuff = new StringBuilder();
-         char[] buff = new char[is.available()];
-         int r = 0;
-         while ((r = isr.read(buff)) > 0)
-         {
-            sbuff.append(buff, 0, r);
-         }
-
-         return sbuff.toString();
-      }
-      finally
-      {
-         is.close();
-      }
-   }
-
-   /**
-    * Clean whitespace.
-    */
-   private String cleanWhitespaces(String string)
-   {
-      if (string != null)
-      {
-         char[] cc = string.toCharArray();
-         for (int ci = cc.length - 1; ci > 0; ci--)
-         {
-            if (Character.isWhitespace(cc[ci]))
-            {
-               cc[ci] = ' ';
-            }
-         }
-         return new String(cc);
-      }
-      return string;
-   }
-}

Deleted: core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBScriptExecutorException.java
===================================================================
--- core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBScriptExecutorException.java	2010-03-22 09:35:46 UTC (rev 2089)
+++ core/trunk/exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/DBScriptExecutorException.java	2010-03-22 09:54:46 UTC (rev 2090)
@@ -1,51 +0,0 @@
-/*
- * Copyright (C) 2010 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.services.database.creator;
-
-/**
- * @author <a href="anatoliy.bazko at exoplatform.org">Anatoliy Bazko</a>
- * @version $Id: DBCreatorException.java 111 2010-11-11 11:11:11Z tolusha $
- */
-public class DBScriptExecutorException extends Exception
-{
-
-   /**
-    * DBCreationException constructor.
-    */
-   public DBScriptExecutorException(Throwable e)
-   {
-      super(e);
-   }
-
-   /**
-    * DBCreationException constructor.
-    */
-   public DBScriptExecutorException(String message, Throwable e)
-   {
-      super(message, e);
-   }
-
-   /**
-    * DBCreationException constructor.
-    */
-   public DBScriptExecutorException(String message)
-   {
-      super(message);
-   }
-}

Added: core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBCreator.java
===================================================================
--- core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBCreator.java	                        (rev 0)
+++ core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBCreator.java	2010-03-22 09:54:46 UTC (rev 2090)
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2010 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.database;
+
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.services.database.creator.DBConnectionInfo;
+import org.exoplatform.services.database.creator.DBCreator;
+import org.exoplatform.services.naming.InitialContextBinder;
+import org.exoplatform.services.naming.InitialContextInitializer;
+
+import java.sql.Connection;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.sql.DataSource;
+
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="anatoliy.bazko at exoplatform.org">Anatoliy Bazko</a>
+ * @version $Id: TestDBCreator.java 111 2010-11-11 11:11:11Z tolusha $
+ */
+public class TestDBCreator extends TestCase
+{
+
+   protected DBCreator dbCreator;
+
+   private InitialContextBinder initialContextBinder;
+
+   private InitialContextInitializer initContext;
+
+   public void setUp() throws Exception
+   {
+      PortalContainer container = PortalContainer.getInstance();
+
+      dbCreator = (DBCreator)container.getComponentInstanceOfType(DBCreator.class);
+      initContext = (InitialContextInitializer)container.getComponentInstanceOfType(InitialContextInitializer.class);
+      initialContextBinder = (InitialContextBinder)container.getComponentInstanceOfType(InitialContextBinder.class);
+   }
+
+   public void testDBCreate() throws Exception
+   {
+      assertNotNull(dbCreator);
+
+      DBConnectionInfo dbInfo = dbCreator.createDatabase("testdb");
+
+      Map<String, String> refAddr = new HashMap<String, String>();
+      refAddr.put("driverClassName", dbInfo.getDriver());
+      refAddr.put("url", dbInfo.getUrl());
+      refAddr.put("username", dbInfo.getUsername());
+      refAddr.put("password", dbInfo.getPassword());
+
+      initialContextBinder.bind("testjdbcjcr", "javax.sql.DataSource",
+         "org.apache.commons.dbcp.BasicDataSourceFactory", null, refAddr);
+
+      DataSource ds = (DataSource)initContext.getInitialContext().lookup("testjdbcjcr");
+      assertNotNull(ds);
+
+      Connection conn = ds.getConnection();
+      assertNotNull(conn);
+   }
+}

Deleted: core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBScriptExecutor.java
===================================================================
--- core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBScriptExecutor.java	2010-03-22 09:35:46 UTC (rev 2089)
+++ core/trunk/exo.core.component.database/src/test/java/org/exoplatform/services/database/TestDBScriptExecutor.java	2010-03-22 09:54:46 UTC (rev 2090)
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2010 eXo Platform SAS.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-package org.exoplatform.services.database;
-
-import org.exoplatform.container.PortalContainer;
-import org.exoplatform.services.database.creator.DBConnectionInfo;
-import org.exoplatform.services.database.creator.DBScriptExecutor;
-import org.exoplatform.services.naming.InitialContextBinder;
-import org.exoplatform.services.naming.InitialContextInitializer;
-
-import java.sql.Connection;
-import java.util.HashMap;
-import java.util.Map;
-
-import javax.sql.DataSource;
-
-import junit.framework.TestCase;
-
-/**
- * @author <a href="anatoliy.bazko at exoplatform.org">Anatoliy Bazko</a>
- * @version $Id: TestDBCreator.java 111 2010-11-11 11:11:11Z tolusha $
- */
-public class TestDBScriptExecutor extends TestCase
-{
-
-   protected DBScriptExecutor dbExecutor;
-
-   private InitialContextBinder initialContextBinder;
-
-   private InitialContextInitializer initContext;
-
-   public void setUp() throws Exception
-   {
-      PortalContainer container = PortalContainer.getInstance();
-
-      dbExecutor = (DBScriptExecutor)container.getComponentInstanceOfType(DBScriptExecutor.class);
-      initContext = (InitialContextInitializer)container.getComponentInstanceOfType(InitialContextInitializer.class);
-      initialContextBinder = (InitialContextBinder)container.getComponentInstanceOfType(InitialContextBinder.class);
-   }
-
-   public void testDBCreate() throws Exception
-   {
-      assertNotNull(dbExecutor);
-
-      DBConnectionInfo dbInfo = dbExecutor.createDatabase("testdb");
-
-      Map<String, String> refAddr = new HashMap<String, String>();
-      refAddr.put("driverClassName", dbInfo.getDriver());
-      refAddr.put("url", dbInfo.getUrl());
-      refAddr.put("username", dbInfo.getUsername());
-      refAddr.put("password", dbInfo.getPassword());
-
-      initialContextBinder.bind("testjdbcjcr", "javax.sql.DataSource",
-         "org.apache.commons.dbcp.BasicDataSourceFactory", null, refAddr);
-
-      DataSource ds = (DataSource)initContext.getInitialContext().lookup("testjdbcjcr");
-      assertNotNull(ds);
-
-      Connection conn = ds.getConnection();
-      assertNotNull(conn);
-   }
-}

Modified: core/trunk/exo.core.component.database/src/test/resources/conf/standalone/test-configuration.xml
===================================================================
--- core/trunk/exo.core.component.database/src/test/resources/conf/standalone/test-configuration.xml	2010-03-22 09:35:46 UTC (rev 2089)
+++ core/trunk/exo.core.component.database/src/test/resources/conf/standalone/test-configuration.xml	2010-03-22 09:54:46 UTC (rev 2090)
@@ -51,8 +51,8 @@
    </component>
 
    <component> 
-      <key>org.exoplatform.services.database.creator.DBScriptExecutor</key>
-      <type>org.exoplatform.services.database.creator.DBScriptExecutor</type>
+      <key>org.exoplatform.services.database.creator.DBCreator</key>
+      <type>org.exoplatform.services.database.creator.DBCreator</type>
       <init-params>
          <properties-param>
             <name>db-connection</name>
@@ -65,7 +65,7 @@
          <properties-param>
             <name>db-creation</name>
             <description>database creation properties</description>
-            <property name="scriptPath" value="script.sql" />
+            <property name="scriptPath" value="test.sql" />
             <property name="username" value="testuser" />
             <property name="password" value="testpwd" />
          </properties-param> 



More information about the exo-jcr-commits mailing list