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/12/21 13:39:23 UTC

svn commit: r606177 - in /incubator/tuscany/java/sca/samples/store: pom.xml src/main/java/services/CatalogImpl.java store.sql

Author: lresende
Date: Fri Dec 21 04:39:22 2007
New Revision: 606177

URL: http://svn.apache.org/viewvc?rev=606177&view=rev
Log:
Simplifying store sample not to use a database and to be more aligned with the "getting started guide"
For database, please see tutorial store scenarios

Removed:
    incubator/tuscany/java/sca/samples/store/store.sql
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=606177&r1=606176&r2=606177&view=diff
==============================================================================
--- incubator/tuscany/java/sca/samples/store/pom.xml (original)
+++ incubator/tuscany/java/sca/samples/store/pom.xml Fri Dec 21 04:39:22 2007
@@ -84,12 +84,6 @@
         </dependency>
 
         <dependency>
-            <groupId>org.apache.derby</groupId>
-            <artifactId>derby</artifactId>
-            <version>10.1.2.1</version>
-        </dependency>
-
-        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
             <version>4.2</version>
@@ -100,42 +94,6 @@
     
     <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:${pom.basedir}/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=606177&r1=606176&r2=606177&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 Fri Dec 21 04:39:22 2007
@@ -6,115 +6,44 @@
  * 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.
+ * under the License.    
  */
 
 package services;
 
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
 
+import org.osoa.sca.annotations.Init;
 import org.osoa.sca.annotations.Property;
 import org.osoa.sca.annotations.Reference;
 
 public class CatalogImpl implements Catalog {
     @Property
     public String currencyCode = "USD";
-    
     @Reference
     public CurrencyConverter currencyConverter;
-    
-    private String currencySymbol;
-    
+    private List<String> catalog = new ArrayList<String>();
+
+    @Init
+    public void init() {
+        String currencySymbol = currencyConverter.getCurrencySymbol(currencyCode);
+        catalog.add("Apple - " + currencySymbol + currencyConverter.getConversion("USD", currencyCode, 2.99f));
+        catalog.add("Orange - " + currencySymbol + currencyConverter.getConversion("USD", currencyCode, 3.55f));
+        catalog.add("Pear - " + currencySymbol + currencyConverter.getConversion("USD", currencyCode, 1.55f));
+    }
+
     public String[] get() {
-        
-        String[] catalogArray = null;
-        
-        String itemName;
-        float itemPrice;
-        String itemCurrencyCode;
-        
-        Connection conn = null;
-        PreparedStatement pstmt = null;
-        ResultSet rs = null;
-        
-        currencySymbol = currencyConverter.getCurrencySymbol(currencyCode);
-        
-        try {
-            //initialize driver and register it with DriverManager
-            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
-            
-            conn = DriverManager.getConnection(
-                    "jdbc:derby:target/store_db",
-                    "",
-                    "");
-            
-            pstmt = conn.prepareStatement("select * from \"CATALOG\"",
-                    ResultSet.TYPE_SCROLL_INSENSITIVE,
-                    ResultSet.CONCUR_READ_ONLY);
-            
-            rs = pstmt.executeQuery();
-            rs.last();
-            
-            catalogArray = new String[rs.getRow()];
-            
-            do {
-                itemName = rs.getString(2);
-                itemPrice = rs.getFloat(4);
-                itemCurrencyCode = rs.getString(3);
-                
-                catalogArray[rs.getRow()-1] = new String(itemName+" - "+
-                        currencySymbol+" "+
-                        currencyConverter.getConversion(itemCurrencyCode, currencyCode, itemPrice));
-                
-            } while(rs.previous());
-            
-        } catch (SQLException ex) {         
-            ex.printStackTrace();
-        }catch (ClassNotFoundException ex) {
-            ex.printStackTrace();
-        } finally {
-            cleanup(conn,pstmt,rs);
-        }
-        
+        String[] catalogArray = new String[catalog.size()];
+        catalog.toArray(catalogArray);
         return catalogArray;
-    }
-    
-    private void cleanup(Connection conn, PreparedStatement pstmt, ResultSet rs) {
-        
-        if (rs!=null) {
-            try {
-                rs.close();
-            } catch (SQLException ex) {
-                ex.printStackTrace();
-            }
-        }
-        
-        if (pstmt!=null) {
-            try {
-                pstmt.close();
-            } catch (SQLException ex) {
-                ex.printStackTrace();
-            }
-        }
-        
-        if (conn!=null) {
-            try {
-                conn.close();
-            } catch (SQLException ex) {
-                ex.printStackTrace();
-            }
-        }
     }
 }



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