You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by lr...@apache.org on 2007/10/25 00:54:00 UTC

svn commit: r588070 - in /incubator/tuscany/java/sca/samples/store: pom.xml src/main/java/services/CatalogImpl.java src/main/java/util/ src/main/java/util/CreateDB.java src/main/resources/derbydb/ store.sql

Author: lresende
Date: Wed Oct 24 15:54:00 2007
New Revision: 588070

URL: http://svn.apache.org/viewvc?rev=588070&view=rev
Log:
Removing the derby database, and using maven and a simple createDB to create the store database

Added:
    incubator/tuscany/java/sca/samples/store/src/main/java/util/
    incubator/tuscany/java/sca/samples/store/src/main/java/util/CreateDB.java   (with props)
    incubator/tuscany/java/sca/samples/store/store.sql
Removed:
    incubator/tuscany/java/sca/samples/store/src/main/resources/derbydb/
Modified:
    incubator/tuscany/java/sca/samples/store/pom.xml
    incubator/tuscany/java/sca/samples/store/src/main/java/services/CatalogImpl.java

Modified: incubator/tuscany/java/sca/samples/store/pom.xml
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/store/pom.xml?rev=588070&r1=588069&r2=588070&view=diff
==============================================================================
--- incubator/tuscany/java/sca/samples/store/pom.xml (original)
+++ incubator/tuscany/java/sca/samples/store/pom.xml Wed Oct 24 15:54:00 2007
@@ -100,6 +100,42 @@
     
     <build>
        <finalName>${artifactId}</finalName>
+       
+       <plugins>
+           <plugin>
+                <groupId>org.codehaus.mojo</groupId>
+                <artifactId>sql-maven-plugin</artifactId>
+                <version>1.0</version>
+
+                <dependencies>
+                    <dependency>
+                        <groupId>org.apache.derby</groupId>
+                        <artifactId>derby</artifactId>
+                        <version>10.1.2.1</version>
+                    </dependency>
+                </dependencies>
+
+                <executions>
+                    <execution>
+                        <id>create-db</id>
+                        <phase>generate-resources</phase>
+                        <goals>
+                            <goal>execute</goal>
+                        </goals>
+                        <configuration>
+                            <driver>org.apache.derby.jdbc.EmbeddedDriver</driver>
+                            <url>jdbc:derby:target/store_db;create=true</url>
+                            <autocommit>true</autocommit>
+                            <onError>continue</onError>
+                            <delimiter>;</delimiter>
+                            <srcFiles>
+                                <srcFile>${pom.basedir}/store.sql</srcFile>
+                            </srcFiles>
+                        </configuration>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
     </build>
 
 </project>

Modified: incubator/tuscany/java/sca/samples/store/src/main/java/services/CatalogImpl.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/store/src/main/java/services/CatalogImpl.java?rev=588070&r1=588069&r2=588070&view=diff
==============================================================================
--- incubator/tuscany/java/sca/samples/store/src/main/java/services/CatalogImpl.java (original)
+++ incubator/tuscany/java/sca/samples/store/src/main/java/services/CatalogImpl.java Wed Oct 24 15:54:00 2007
@@ -56,11 +56,11 @@
             Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
             
             conn = DriverManager.getConnection(
-                    "jdbc:derby:target/classes/derbydb",
+                    "jdbc:derby:target/store_db",
                     "",
                     "");
             
-            pstmt = conn.prepareStatement("select * from \"Catalog\"",
+            pstmt = conn.prepareStatement("select * from \"CATALOG\"",
                     ResultSet.TYPE_SCROLL_INSENSITIVE,
                     ResultSet.CONCUR_READ_ONLY);
             

Added: incubator/tuscany/java/sca/samples/store/src/main/java/util/CreateDB.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/store/src/main/java/util/CreateDB.java?rev=588070&view=auto
==============================================================================
--- incubator/tuscany/java/sca/samples/store/src/main/java/util/CreateDB.java (added)
+++ incubator/tuscany/java/sca/samples/store/src/main/java/util/CreateDB.java Wed Oct 24 15:54:00 2007
@@ -0,0 +1,95 @@
+/*
+ * 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 util;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+
+public class CreateDB {
+
+    public static void main(String[] args) {
+        Connection connection = null;
+        PreparedStatement preparedStatement = null;
+        
+        try {
+            //initialize driver and register it with DriverManager
+            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
+            
+            //connect and create the db if not present
+            connection = DriverManager.getConnection(
+                    "jdbc:derby:target/store_db;create=true",
+                    "",
+                    "");
+            
+            
+            try {
+                preparedStatement = connection.prepareStatement("DROP TABLE CATALOG");
+                preparedStatement.execute();
+            }catch(Exception e) {
+                //ignore to avoid erros when db is being created from scratch
+            }
+            
+            
+            preparedStatement = connection.prepareStatement("CREATE TABLE CATALOG("
+                                                            + "id             NUMERIC(5 , 0) NOT NULL,"
+                                                            + "product_name   VARCHAR(30),"
+                                                            + "currency_code  CHAR(3),"
+                                                            + "price          REAL,"
+                                                            + "primary key (id)"
+                                                            + ")");
+            preparedStatement.execute();
+
+            preparedStatement = connection.prepareStatement("INSERT INTO CATALOG VALUES(0,'Apple', 'USD', 2.99)");
+            preparedStatement.execute();
+
+            preparedStatement = connection.prepareStatement("INSERT INTO CATALOG VALUES(1,'Orange', 'USD', 3.55)");
+            preparedStatement.execute();
+
+            preparedStatement = connection.prepareStatement("INSERT INTO CATALOG VALUES(2,'Pear', 'USD', 1.55)");
+            preparedStatement.execute();
+
+            
+            
+        } catch (SQLException ex) {         
+            ex.printStackTrace();
+        }catch (ClassNotFoundException ex) {
+            ex.printStackTrace();
+        } finally {
+            if (preparedStatement!=null) {
+                try {
+                    preparedStatement.close();
+                } catch (SQLException ex) {
+                    ex.printStackTrace();
+                }
+            }
+            
+            if (connection!=null) {
+                try {
+                    connection.close();
+                } catch (SQLException ex) {
+                    ex.printStackTrace();
+                }
+            }
+        }
+    }
+
+}

Propchange: incubator/tuscany/java/sca/samples/store/src/main/java/util/CreateDB.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sca/samples/store/src/main/java/util/CreateDB.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sca/samples/store/store.sql
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/samples/store/store.sql?rev=588070&view=auto
==============================================================================
--- incubator/tuscany/java/sca/samples/store/store.sql (added)
+++ incubator/tuscany/java/sca/samples/store/store.sql Wed Oct 24 15:54:00 2007
@@ -0,0 +1,18 @@
+DROP TABLE CATALOG;
+
+CREATE TABLE CATALOG(
+   id             NUMERIC(5 , 0) NOT NULL,
+   product_name   VARCHAR(30),
+   currency_code  CHAR(3),
+   price          REAL,
+   primary key (id)
+);
+
+
+
+INSERT INTO CATALOG
+ VALUES(0,'Apple', 'USD', 2.99);
+INSERT INTO CATALOG
+ VALUES(1,'Orange', 'USD', 3.55);
+INSERT INTO CATALOG
+ VALUES(2,'Pear', 'USD', 1.55);
\ No newline at end of file



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org