summaryrefslogtreecommitdiffstats
path: root/das-java/tags/1.0-incubating-beta1-rc3/samples/customer/src/main/java/org/apache/tuscany/samples
diff options
context:
space:
mode:
Diffstat (limited to 'das-java/tags/1.0-incubating-beta1-rc3/samples/customer/src/main/java/org/apache/tuscany/samples')
-rw-r--r--das-java/tags/1.0-incubating-beta1-rc3/samples/customer/src/main/java/org/apache/tuscany/samples/das/customer/CustomerClient.java227
-rw-r--r--das-java/tags/1.0-incubating-beta1-rc3/samples/customer/src/main/java/org/apache/tuscany/samples/das/databaseSetup/DB2Setup.java225
-rw-r--r--das-java/tags/1.0-incubating-beta1-rc3/samples/customer/src/main/java/org/apache/tuscany/samples/das/databaseSetup/DatabaseSetup.java206
-rw-r--r--das-java/tags/1.0-incubating-beta1-rc3/samples/customer/src/main/java/org/apache/tuscany/samples/das/databaseSetup/DerbySetup.java209
-rw-r--r--das-java/tags/1.0-incubating-beta1-rc3/samples/customer/src/main/java/org/apache/tuscany/samples/das/databaseSetup/MySQLSetup.java211
5 files changed, 0 insertions, 1078 deletions
diff --git a/das-java/tags/1.0-incubating-beta1-rc3/samples/customer/src/main/java/org/apache/tuscany/samples/das/customer/CustomerClient.java b/das-java/tags/1.0-incubating-beta1-rc3/samples/customer/src/main/java/org/apache/tuscany/samples/das/customer/CustomerClient.java
deleted file mode 100644
index b9557f0f9e..0000000000
--- a/das-java/tags/1.0-incubating-beta1-rc3/samples/customer/src/main/java/org/apache/tuscany/samples/das/customer/CustomerClient.java
+++ /dev/null
@@ -1,227 +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.tuscany.samples.das.customer;
-
-import java.io.InputStream;
-import java.util.List;
-
-import org.apache.tuscany.das.rdb.Command;
-import org.apache.tuscany.das.rdb.DAS;
-import org.apache.tuscany.das.rdb.config.Config;
-import org.apache.tuscany.das.rdb.util.ConfigUtil;
-import org.apache.tuscany.samples.das.databaseSetup.DB2Setup;
-import org.apache.tuscany.samples.das.databaseSetup.DerbySetup;
-import org.apache.tuscany.samples.das.databaseSetup.MySQLSetup;
-
-import commonj.sdo.DataObject;
-
-public class CustomerClient {
- private DAS das = null;
- public static final String DERBY = "derby";
- public static final String MYSQL = "mysql";
- public static final String DB2 = "db2";
-
- private CustomerClient(){
- }
-
- /**If database is present connect to it and create necessary tables, procedures, data etc.
- * If database is not present create database and then create the above elements. Create database
- * is implemented for MySQL and Derby (not for IBM DB2).
- */
-
- protected boolean checkIfDBPresent(String dbType, String dbName, String user, String password){
- try {
- if(dbType.equals(DERBY)){
- new DerbySetup(dbName+"-"+user+"-"+password);
- }
-
- if(dbType.equals(DB2)){
- new DB2Setup(dbName+"-"+user+"-"+password);
- }
-
- if(dbType.equals(MYSQL)){
- new MySQLSetup(dbName+"-"+user+"-"+password);
- }
-
- } catch(Exception e){
- e.printStackTrace();
- }
-
- return true;
- }
-
- private void init(String configFile){
- try{
- this.das = DAS.FACTORY.createDAS(getConfig(configFile));
- }catch(Exception e){
- e.printStackTrace();
- }
- }
-
- public static void main(String[] args){
- String configFile = "Customers.xml";//this can be from input params too as below
-
- if(args != null && args.length >0){
- configFile = args[0];
- }
-
- CustomerClient cclient = new CustomerClient();
-
- Config config = ConfigUtil.loadConfig(cclient.getClass().getClassLoader().getResourceAsStream(configFile));
-
- String dbType = null;
- String dbURL = null;
- String user = null;
- String password = null;
-
- if(config.getConnectionInfo().getConnectionProperties().getDriverClass().indexOf(DERBY) != -1){
- dbType = DERBY;
- }
-
- if(config.getConnectionInfo().getConnectionProperties().getDriverClass().indexOf(MYSQL) != -1){
- dbType = MYSQL;
- }
-
- if(config.getConnectionInfo().getConnectionProperties().getDriverClass().indexOf(DB2) != -1){
- dbType = DB2;
- }
-
- //get connection info from config
- dbURL = config.getConnectionInfo().getConnectionProperties().getDatabaseURL();
- user = config.getConnectionInfo().getConnectionProperties().getUserName();
- password = config.getConnectionInfo().getConnectionProperties().getPassword();
-
- System.out.println("connection info from config***************");
- System.out.println("dbName:"+dbURL+" user:"+user+" password:"+password);
- System.out.println("******************************************");
- //dt create/connect/create schema
- cclient.checkIfDBPresent(dbType, dbURL, user, password);
-
- //get das handle
- cclient.init(configFile);
-
- //test select
- System.out.println("Result:select all customers");
- printList(cclient.getCustomers());
-
- //test insert
- System.out.println("Result:insert new customer");
- cclient.addCustomer();
- printList(cclient.getCustomers());
-
- //test update
- System.out.println("Result:update first customer");
- cclient.changeFirstCustomerName();
- printList(cclient.getCustomers());
-
- //test delete
- System.out.println("Result:delete last customer");
- cclient.deleteCustomer();
- printList(cclient.getCustomers());
- }
-
- /**
- * display result
- * @param customers
- */
- public static void printList(List customers){
- for(int i=0; i<customers.size(); i++){
- System.out.println(" ID:"+(((DataObject)customers.get(i)).getInt("ID"))+
- " LASTNAME:"+(((DataObject)customers.get(i)).getString("LASTNAME"))+
- " ADDRESS:"+(((DataObject)customers.get(i)).getString("ADDRESS")));
- }
- }
-
- /**
- * select
- * @return
- */
- public final List getCustomers() {
-
- Command read = das.getCommand("AllCustomers");
- DataObject root = read.executeQuery();
- return root.getList("CUSTOMER");
- }
-
- /**
- * insert
- *
- */
- public final void addCustomer() {
- Command read = das.getCommand("AllCustomers");
- DataObject root = read.executeQuery();
-
- DataObject newCustomer = root.createDataObject("CUSTOMER");
- newCustomer.setInt("ID", 5);
- newCustomer.setString("LASTNAME", "Jenny");
- newCustomer.setString("ADDRESS", "USA");
-
- das.applyChanges(root);
- }
-
- /**
- * delete
- *
- */
- public final void deleteCustomer() {
- Command readAll = das.getCommand("AllCustomers");
- DataObject root = readAll.executeQuery();
-
- List allCustomers = root.getList("CUSTOMER");
-
- DataObject lastCustomer = (DataObject)allCustomers.get(allCustomers.size()-1);
- if(lastCustomer != null){
- System.out.println("Deleting customer named: " + lastCustomer.getString("LASTNAME"));
- lastCustomer.delete();
- }
-
- das.applyChanges(root);
- }
-
- /**
- * update
- *
- */
- public final void changeFirstCustomerName() {
- Command readAll = das.getCommand("AllCustomers");
- DataObject root = readAll.executeQuery();
-
- DataObject firstCustomer = root.getDataObject("CUSTOMER[1]");
- firstCustomer.set("LASTNAME", "BlueBerry");
-
- das.applyChanges(root);
- }
-
- /**
- * cleanup
- *
- */
- public void releaseResources() {
- das.releaseResources();
- }
-
- /**Utilities
- *
- * @param fileName
- * @return
- */
- private InputStream getConfig(String fileName) {
- return getClass().getClassLoader().getResourceAsStream(fileName);
- }
-} \ No newline at end of file
diff --git a/das-java/tags/1.0-incubating-beta1-rc3/samples/customer/src/main/java/org/apache/tuscany/samples/das/databaseSetup/DB2Setup.java b/das-java/tags/1.0-incubating-beta1-rc3/samples/customer/src/main/java/org/apache/tuscany/samples/das/databaseSetup/DB2Setup.java
deleted file mode 100644
index 97cda531bb..0000000000
--- a/das-java/tags/1.0-incubating-beta1-rc3/samples/customer/src/main/java/org/apache/tuscany/samples/das/databaseSetup/DB2Setup.java
+++ /dev/null
@@ -1,225 +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.tuscany.samples.das.databaseSetup;
-
-import java.sql.SQLException;
-
-public class DB2Setup extends DatabaseSetup {
-
- public DB2Setup(String databaseInfo){
- super(databaseInfo);
- }
-
- protected void initConnectionProtocol(String databaseURL){
- this.platformName=DB2;
- this.driverName = "com.ibm.db2.jcc.DB2Driver";
- this.databaseURL = databaseURL;
- }
-
- public void setUp(){
- try{
- super.setUp();
-
- try {
- s = connection.createStatement();
-
- dropTriggers();
- dropSequences();
- dropTables();
- dropProcedures();
-
- createSequences();
- createTables();
- createTriggers();
- createProcedures();
- connection.commit();
-
- insertData();
- connection.commit();
- } catch (SQLException e) {
- connection.rollback();
- }
- }catch(Exception e){
- e.printStackTrace();
- }
-
- System.out.println("Database setup complete!");
- }
-
- private void insertData(){
- System.out.println("Inserting data in tables");
-
- String[] statements = {"INSERT INTO CUSTOMER VALUES (1,'John','USA')",
- "INSERT INTO CUSTOMER VALUES (2,'Amita','INDIA')",
- "INSERT INTO CUSTOMER VALUES (3,'Patrick','UK')",
- "INSERT INTO CUSTOMER VALUES (4,'Jane','UN')"};
-
- for (int i = 0; i < statements.length; i++) {
- try {
- s.execute(statements[i]);
- } catch (SQLException e) {
- // If the table does not exist then ignore the exception on drop
- if ((!e.getMessage().contains("does not exist")) && (!e.getMessage().contains("Unknown table"))
- && (!e.getMessage().contains("42704"))) {
- throw new RuntimeException(e);
- }
- }
- }
- }
-
- private void dropTables() {
- System.out.println("Dropping tables");
-
- String[] statements = {
- "DROP TABLE CUSTOMER"
- };
-
- for (int i = 0; i < statements.length; i++) {
- try {
- s.execute(statements[i]);
- } catch (SQLException e) {
- // If the table does not exist then ignore the exception on drop
- if ((!e.getMessage().contains("does not exist")) && (!e.getMessage().contains("Unknown table"))
- && (!e.getMessage().contains("42704"))) {
- throw new RuntimeException(e);
- }
- }
- }
- }
-
- protected void dropTriggers() {
-
- }
-
- protected void createTriggers() {
-
- }
-
- protected void dropSequences() {
-
- }
-
- protected void createSequences() {
-
- }
-
- protected void dropProcedures() {
-
- System.out.println("Dropping procedures");
-
- String[] statements = {
-
- "DROP PROCEDURE GETNAMEDCUSTOMERS"
-
- };
-
- for (int i = 0; i < statements.length; i++) {
- try {
- s.execute(statements[i]);
- } catch (SQLException e) {
- // If the proc does not exist then ignore the exception on drop
- if (!e.getMessage().contains("does not exist") && !e.getMessage().contains("42704")) {
- throw new RuntimeException(e);
- }
- }
- }
- }
-
- private void createTables() {
-
- System.out.println("Creating tables");
-
- try {
-
- s.execute(getCreateCustomer());
-
- } catch (SQLException e) {
- throw new RuntimeException(e);
- }
- }
-
- protected void createProcedures() {
-
- System.out.println("Creating procedures");
- try {
-
- s.execute("CREATE PROCEDURE GETNAMEDCUSTOMERS(theName VARCHAR(100), OUT theCount INTEGER) "
- + "PARAMETER STYLE JAVA LANGUAGE JAVA READS SQL DATA DYNAMIC RESULT SETS 1 EXTERNAL NAME "
- + "'org.apache.tuscany.samples.das.orders.MyStoredProcs.getNamedCustomers'");
- // TODO - "GETNAMEDCUSTOMERS" is failing on DB2 with SQLCODE: 42723. Need to investigate
- } catch (SQLException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
-
-
- //
- // This section povides methods that return strings for table creation.
- // Platform-specific sublcasses
- // can override these as necessary
- //
-
- protected String getCreateCustomer() {
- return "CREATE TABLE CUSTOMER (" + getIntegerColumn("ID") + " PRIMARY KEY NOT NULL, "
- + getStringColumn("LASTNAME", 30)
- + " DEFAULT 'Garfugengheist', " + getStringColumn("ADDRESS", 30) + ")";
- }
-
-
- // /////////////////
-
- protected String getForeignKeyConstraint(String pkTable, String pkColumn, String foreignKey) {
- StringBuffer buffer = new StringBuffer();
- buffer.append("CONSTRAINT FK1 FOREIGN KEY (");
- buffer.append(foreignKey);
- buffer.append(") REFERENCES ");
- buffer.append(pkTable);
- buffer.append("(");
- buffer.append(pkColumn);
- buffer.append(") ON DELETE NO ACTION ON UPDATE NO ACTION");
- return buffer.toString();
- }
-
- protected String getStringColumn(String name, int length) {
- return name + ' ' + stringType + "(" + Integer.valueOf(length).toString() + ")";
- }
-
- protected String getIntegerColumn(String name) {
- return name + ' ' + integerType;
- }
-
- protected String getGeneratedKeyClause() {
- return "GENERATED ALWAYS AS IDENTITY";
- }
-
- protected String getDecimalColumn(String name, int size1, int size2) {
- return name + ' ' + decimalType + "(" + Integer.valueOf(size1).toString() + ','
- + Integer.valueOf(size2).toString() + ")";
- }
-
- protected String getFloatColumn(String name) {
- return name + ' ' + floatType;
- }
-
- protected String getTimestampColumn(String name) {
- return name + ' ' + timestampType;
- }
-
-}
diff --git a/das-java/tags/1.0-incubating-beta1-rc3/samples/customer/src/main/java/org/apache/tuscany/samples/das/databaseSetup/DatabaseSetup.java b/das-java/tags/1.0-incubating-beta1-rc3/samples/customer/src/main/java/org/apache/tuscany/samples/das/databaseSetup/DatabaseSetup.java
deleted file mode 100644
index 4195dbcac7..0000000000
--- a/das-java/tags/1.0-incubating-beta1-rc3/samples/customer/src/main/java/org/apache/tuscany/samples/das/databaseSetup/DatabaseSetup.java
+++ /dev/null
@@ -1,206 +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.tuscany.samples.das.databaseSetup;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.Properties;
-import java.util.StringTokenizer;
-
-public class DatabaseSetup{
- protected Statement s;
- protected String platformName = "Not initialized";
- protected String driverName = "Not initialized";
- protected String databaseURL = "Not initialized";
- protected String databaseName = null;
- protected String userName;
- protected String password;
-
- // Data Types
- public static final String stringType = "VARCHAR";
- public static final String integerType = "INT";
- public static final String timestampType = "TIMESTAMP";
- public static final String floatType = "FLOAT";
- public static final String decimalType = "DECIMAL";
- protected Connection connection;
-
- //database types
- public static final String DERBY = "derby";
- public static final String MYSQL = "mysql";
- public static final String DB2 = "db2";
-
- public DatabaseSetup(String databaseInfo){
- StringTokenizer strTok = new StringTokenizer(databaseInfo, "-");
-
- if(strTok.hasMoreTokens()){
- databaseName = strTok.nextToken();
- }
-
- if(strTok.hasMoreTokens()){
- userName = strTok.nextToken();
- }
-
- if(strTok.hasMoreTokens()){
- password = strTok.nextToken();
- }
-
- initConnectionProtocol(databaseName);
- initConnection();
- try{
- this.setUp();
- }catch(Exception e){
- e.printStackTrace();
- }
- }
-
- protected void initConnectionProtocol( String databaseName){
- }
-
- private void initConnection() {
-
- try {
- Class.forName(driverName).newInstance();
- Properties props = new Properties();
- //System.out.println("platform name:"+this.platformName);
-
- if(this.platformName.equals(DERBY)){
- if (userName != null) {
- //System.out.println("derby trying for "+userName+","+password+","+databaseURL);
- connection = DriverManager.getConnection(databaseURL, userName, password);
- } else {
- //System.out.println("derby trying for "+databaseURL);
- connection = DriverManager.getConnection(databaseURL);
- }
- }
- if(this.platformName.equals(DB2)){
- if (userName != null && password != null) {
- props.put("user", userName);
- props.put("password", password);
-
- //System.out.println("db2 trying for "+databaseURL+"user,pwd"+userName+","+password);
- connection = DriverManager.getConnection(databaseURL, props);
- }else{
- //System.out.println("db2 trying for "+databaseURL);
- connection = DriverManager.getConnection(databaseURL);
- }
- }
- if(this.platformName.equals(MYSQL)){
- databaseURL=databaseURL+"?user="+userName+"&password="+password+"&createDatabaseIfNotExist="+"true";
- //System.out.println("mysql trying for "+userName+","+password+","+databaseURL);
- connection = DriverManager.getConnection(databaseURL, props);
- }
-
- connection.setAutoCommit(true);
- } catch (SQLException e) {
- e.printStackTrace();
- if (e.getNextException() != null) {
- e.getNextException().printStackTrace();
- } else {
- e.printStackTrace();
- }
-
- throw new RuntimeException(e);
- } catch (IllegalAccessException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- } catch (InstantiationException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
-
- public Connection getConnection(){
- return this.connection;
- }
-
- protected void setUp() throws Exception {
- System.out.println("Setting up for " + platformName + " run!");
- }
-
- private void insertData(){
- }
-
- private void dropTables() {
- }
-
- protected void dropTriggers() {
- }
-
- protected void createTriggers() {
- }
-
- protected void dropSequences() {
- }
-
- protected void createSequences() {
- }
-
- protected void dropProcedures() {
- }
-
- private void createTables() {
- }
-
- protected void createProcedures() {
- }
-
- //
- // This section povides methods that return strings for table creation.
- // Platform-specific sublcasses
- // can override these as necessary
- //
-
- protected String getCreateCustomer() {
- return null;
- }
- // /////////////////
-
- protected String getForeignKeyConstraint(String pkTable, String pkColumn, String foreignKey) {
- return null;
- }
-
- protected String getStringColumn(String name, int length) {
- return null;
- }
-
- protected String getIntegerColumn(String name) {
- return null;
- }
-
- protected String getGeneratedKeyClause() {
- return null;
- }
-
- protected String getDecimalColumn(String name, int size1, int size2) {
- return null;
- }
-
- protected String getFloatColumn(String name) {
- return null;
- }
-
- protected String getTimestampColumn(String name) {
- return null;
- }
-} \ No newline at end of file
diff --git a/das-java/tags/1.0-incubating-beta1-rc3/samples/customer/src/main/java/org/apache/tuscany/samples/das/databaseSetup/DerbySetup.java b/das-java/tags/1.0-incubating-beta1-rc3/samples/customer/src/main/java/org/apache/tuscany/samples/das/databaseSetup/DerbySetup.java
deleted file mode 100644
index 18a9c4de91..0000000000
--- a/das-java/tags/1.0-incubating-beta1-rc3/samples/customer/src/main/java/org/apache/tuscany/samples/das/databaseSetup/DerbySetup.java
+++ /dev/null
@@ -1,209 +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.tuscany.samples.das.databaseSetup;
-
-import java.sql.SQLException;
-
-public class DerbySetup extends DatabaseSetup {
-
- public DerbySetup(String databaseInfo){
- super(databaseInfo);
- }
-
- protected void initConnectionProtocol(String databaseURL){
- this.platformName=DERBY;
- this.driverName = "org.apache.derby.jdbc.EmbeddedDriver";
- this.databaseURL = databaseURL;
- }
-
- public void setUp(){
- try{
- super.setUp();
-
- try {
- s = connection.createStatement();
-
- dropTriggers();
- dropSequences();
- dropTables();
- dropProcedures();
-
- createSequences();
- createTables();
- createTriggers();
- createProcedures();
- connection.commit();
-
- insertData();
- connection.commit();
- } catch (SQLException e) {
- connection.rollback();
- }
- }catch(Exception e){
- e.printStackTrace();
- }
-
- System.out.println("Database setup complete!");
- }
-
- private void insertData(){
- System.out.println("Inserting data in tables");
-
- String[] statements = {"INSERT INTO CUSTOMER VALUES (1,'John','USA')",
- "INSERT INTO CUSTOMER VALUES (2,'Amita','INDIA')",
- "INSERT INTO CUSTOMER VALUES (3,'Patrick','UK')",
- "INSERT INTO CUSTOMER VALUES (4,'Jane','UN')"};
-
- for (int i = 0; i < statements.length; i++) {
- try {
- s.execute(statements[i]);
- } catch (SQLException e) {
- // If the table does not exist then ignore the exception on drop
- if ((!e.getMessage().contains("does not exist")) && (!e.getMessage().contains("Unknown table"))
- && (!e.getMessage().contains("42704"))) {
- throw new RuntimeException(e);
- }
- }
- }
- }
-
- private void dropTables() {
- System.out.println("Dropping tables");
- String[] statements = {"DROP TABLE CUSTOMER" };
-
- for (int i = 0; i < statements.length; i++) {
- try {
- s.execute(statements[i]);
- } catch (SQLException e) {
- // If the table does not exist then ignore the exception on drop
- if ((!e.getMessage().contains("does not exist")) && (!e.getMessage().contains("Unknown table"))
- && (!e.getMessage().contains("42704"))) {
- throw new RuntimeException(e);
- }
- }
- }
- }
-
- protected void dropTriggers() {
-
- }
-
- protected void createTriggers() {
-
- }
-
- protected void dropSequences() {
-
- }
-
- protected void createSequences() {
-
- }
-
- protected void dropProcedures() {
-
- System.out.println("Dropping procedures");
-
- String[] statements = {"DROP PROCEDURE GETNAMEDCUSTOMERS"};
-
- for (int i = 0; i < statements.length; i++) {
- try {
- s.execute(statements[i]);
- } catch (SQLException e) {
- // If the proc does not exist then ignore the exception on drop
- if (!e.getMessage().contains("does not exist") && !e.getMessage().contains("42704")) {
- throw new RuntimeException(e);
- }
- }
- }
- }
-
- private void createTables() {
- System.out.println("Creating tables");
-
- try {
- s.execute(getCreateCustomer());
- } catch (SQLException e) {
- throw new RuntimeException(e);
- }
- }
-
- protected void createProcedures() {
-
- System.out.println("Creating procedures");
- try {
-
- s.execute("CREATE PROCEDURE GETNAMEDCUSTOMERS(theName VARCHAR(100), OUT theCount INTEGER) "
- + "PARAMETER STYLE JAVA LANGUAGE JAVA READS SQL DATA DYNAMIC RESULT SETS 1 EXTERNAL NAME "
- + "'org.apache.tuscany.samples.das.orders.MyStoredProcs.getNamedCustomers'");
- } catch (SQLException e) {
- e.printStackTrace();
- throw new RuntimeException(e);
- }
- }
-
- //
- // This section povides methods that return strings for table creation.
- // Platform-specific sublcasses
- // can override these as necessary
- //
-
- protected String getCreateCustomer() {
- return "CREATE TABLE CUSTOMER (" + getIntegerColumn("ID") + " PRIMARY KEY NOT NULL, "
- + getStringColumn("LASTNAME", 30)
- + " DEFAULT 'Garfugengheist', " + getStringColumn("ADDRESS", 30) + ")";
- }
-
- protected String getForeignKeyConstraint(String pkTable, String pkColumn, String foreignKey) {
- StringBuffer buffer = new StringBuffer();
- buffer.append("CONSTRAINT FK1 FOREIGN KEY (");
- buffer.append(foreignKey);
- buffer.append(") REFERENCES ");
- buffer.append(pkTable);
- buffer.append("(");
- buffer.append(pkColumn);
- buffer.append(") ON DELETE NO ACTION ON UPDATE NO ACTION");
- return buffer.toString();
- }
-
- protected String getStringColumn(String name, int length) {
- return name + ' ' + stringType + "(" + Integer.valueOf(length).toString() + ")";
- }
-
- protected String getIntegerColumn(String name) {
- return name + ' ' + integerType;
- }
-
- protected String getGeneratedKeyClause() {
- return "GENERATED ALWAYS AS IDENTITY";
- }
-
- protected String getDecimalColumn(String name, int size1, int size2) {
- return name + ' ' + decimalType + "(" + Integer.valueOf(size1).toString() + ','
- + Integer.valueOf(size2).toString() + ")";
- }
-
- protected String getFloatColumn(String name) {
- return name + ' ' + floatType;
- }
-
- protected String getTimestampColumn(String name) {
- return name + ' ' + timestampType;
- }
-}
diff --git a/das-java/tags/1.0-incubating-beta1-rc3/samples/customer/src/main/java/org/apache/tuscany/samples/das/databaseSetup/MySQLSetup.java b/das-java/tags/1.0-incubating-beta1-rc3/samples/customer/src/main/java/org/apache/tuscany/samples/das/databaseSetup/MySQLSetup.java
deleted file mode 100644
index a10f2aa7c3..0000000000
--- a/das-java/tags/1.0-incubating-beta1-rc3/samples/customer/src/main/java/org/apache/tuscany/samples/das/databaseSetup/MySQLSetup.java
+++ /dev/null
@@ -1,211 +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.tuscany.samples.das.databaseSetup;
-
-import java.sql.SQLException;
-
-public class MySQLSetup extends DatabaseSetup {
-
- public MySQLSetup(String databaseInfo){
- super(databaseInfo);
- }
-
- protected void initConnectionProtocol(String databaseURL){
- this.platformName=MYSQL;
- this.driverName = "com.mysql.jdbc.Driver";
- this.databaseURL = databaseURL;
- }
-
- public void setUp(){
- try{
- super.setUp();
-
- try {
- s = connection.createStatement();
-
- dropTriggers();
- dropSequences();
- dropTables();
- dropProcedures();
-
- createSequences();
- createTables();
- createTriggers();
- createProcedures();
- insertData();
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }catch(Exception e){
- e.printStackTrace();
- }
-
- System.out.println("Database setup complete!");
- }
-
- private void insertData(){
- System.out.println("Inserting data in tables");
-
- String[] statements = {"INSERT INTO CUSTOMER VALUES (1,'John','USA')",
- "INSERT INTO CUSTOMER VALUES (2,'Amita','INDIA')",
- "INSERT INTO CUSTOMER VALUES (3,'Patrick','UK')",
- "INSERT INTO CUSTOMER VALUES (4,'Jane','UN')"};
-
- for (int i = 0; i < statements.length; i++) {
- try {
- s.execute(statements[i]);
- } catch (SQLException e) {
- // If the table does not exist then ignore the exception on drop
- if ((!e.getMessage().contains("does not exist")) && (!e.getMessage().contains("Unknown table"))
- && (!e.getMessage().contains("42704"))) {
- throw new RuntimeException(e);
- }
- }
- }
- }
-
- private void dropTables() {
- System.out.println("Dropping tables");
-
- String[] statements = {"DROP TABLE CUSTOMER"};
-
- for (int i = 0; i < statements.length; i++) {
- try {
- s.execute(statements[i]);
- } catch (SQLException e) {
- // If the table does not exist then ignore the exception on drop
- if ((!e.getMessage().contains("does not exist")) && (!e.getMessage().contains("Unknown table"))
- && (!e.getMessage().contains("42704"))) {
- throw new RuntimeException(e);
- }
- }
- }
- }
-
- protected void dropTriggers() {
-
- }
-
- protected void createTriggers() {
-
- }
-
- protected void dropSequences() {
-
- }
-
- protected void createSequences() {
-
- }
-
- protected void dropProcedures() {
-
- System.out.println("Dropping procedures");
-
- String[] statements = {"DROP PROCEDURE GETNAMEDCUSTOMERS"};
-
- for (int i = 0; i < statements.length; i++) {
- try {
- s.execute(statements[i]);
- } catch (SQLException e) {
- // If the proc does not exist then ignore the exception on drop
- if (!e.getMessage().contains("does not exist") && !e.getMessage().contains("42704")) {
- throw new RuntimeException(e);
- }
- }
- }
- }
-
- private void createTables() {
- System.out.println("Creating tables");
-
- try {
-
- s.execute(getCreateCustomer());
-
- } catch (SQLException e) {
- throw new RuntimeException(e);
- }
- }
-
- //
- // This section povides methods that return strings for table creation.
- // Platform-specific sublcasses
- // can override these as necessary
- //
-
- protected String getCreateCustomer() {
- return "CREATE TABLE CUSTOMER (" + getIntegerColumn("ID") + " PRIMARY KEY NOT NULL, "
- + getStringColumn("LASTNAME", 30)
- + " DEFAULT 'Garfugengheist', " + getStringColumn("ADDRESS", 30) + ")";
- }
-
- // /////////////////
-
- protected String getForeignKeyConstraint(String pkTable, String pkColumn, String foreignKey) {
- StringBuffer buffer = new StringBuffer();
- buffer.append("CONSTRAINT FK1 FOREIGN KEY (");
- buffer.append(foreignKey);
- buffer.append(") REFERENCES ");
- buffer.append(pkTable);
- buffer.append("(");
- buffer.append(pkColumn);
- buffer.append(") ON DELETE NO ACTION ON UPDATE NO ACTION");
- return buffer.toString();
- }
-
- protected String getStringColumn(String name, int length) {
- return name + ' ' + stringType + "(" + Integer.valueOf(length).toString() + ")";
- }
-
- protected String getIntegerColumn(String name) {
- return name + ' ' + integerType;
- }
-
- protected String getDecimalColumn(String name, int size1, int size2) {
- return name + ' ' + decimalType + "(" + Integer.valueOf(size1).toString() + ','
- + Integer.valueOf(size2).toString() + ")";
- }
-
- protected String getFloatColumn(String name) {
- return name + ' ' + floatType;
- }
-
- protected String getTimestampColumn(String name) {
- return name + ' ' + timestampType;
- }
-
- protected void createProcedures() {
- String createGetNamedCustomers = "CREATE PROCEDURE `dastest`.`GETNAMEDCUSTOMERS`(IN thename VARCHAR(30), "
- + "OUT theCount INTEGER ) " + " BEGIN "
- + " SELECT * FROM CUSTOMER AS CUSTOMER WHERE LASTNAME = theName; "
- + " SET theCount = (SELECT COUNT(*) FROM CUSTOMER WHERE LASTNAME = theName); " + " END ";
-
- System.out.println("Creating procedures");
- try {
- s.execute(createGetNamedCustomers);
- } catch (SQLException e) {
- throw new RuntimeException(e);
- }
- }
-
- protected String getGeneratedKeyClause() {
- return "AUTO_INCREMENT";
- }
-}