summaryrefslogtreecommitdiffstats
path: root/java/das/tools/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/das/tools/src')
-rw-r--r--java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/Column.java57
-rw-r--r--java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/DBSchema.java45
-rw-r--r--java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/DBToSchemaFile.java119
-rw-r--r--java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/DBToXSDGenerator.java88
-rw-r--r--java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/ForeignKey.java51
-rw-r--r--java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/ForeignKeyRef.java44
-rw-r--r--java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/ModelXSDGenOption.java134
-rw-r--r--java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/SQLTypeChecker.java186
-rw-r--r--java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/SchemaFileToXSD.java200
-rw-r--r--java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/Table.java66
-rw-r--r--java/das/tools/src/test/java/org/apache/tuscany/das/rdb/test/DBToXSDTests.java142
-rw-r--r--java/das/tools/src/test/resources/DBConnectionConfig.xml31
-rw-r--r--java/das/tools/src/test/resources/dbConfig.xml34
13 files changed, 1197 insertions, 0 deletions
diff --git a/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/Column.java b/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/Column.java
new file mode 100644
index 0000000000..cbadde0717
--- /dev/null
+++ b/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/Column.java
@@ -0,0 +1,57 @@
+/*
+ * 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.das.rdb.util;
+
+public class Column {
+ private String name;
+ private String type;
+ private boolean isPK;
+ private boolean isRequired;
+
+ protected String getName() {
+ return name;
+ }
+ protected void setName(String name) {
+ this.name = name;
+ }
+ protected String getType() {
+ return type;
+ }
+ protected void setType(String type) {
+ this.type = type;
+ }
+ protected boolean isPK() {
+ return isPK;
+ }
+ protected void setPK(boolean isPK) {
+ this.isPK = isPK;
+ }
+ protected boolean isRequired() {
+ return isRequired;
+ }
+ protected void setRequired(boolean isRequired) {
+ this.isRequired = isRequired;
+ }
+
+ public String toString() {
+ StringBuffer dbSchemaStr = new StringBuffer();
+ dbSchemaStr.append("Name:"+this.getName()+", Type:"+this.getType()+", isPK:"+this.isPK()+", isRequired:"+this.isRequired()+"\n");
+ return dbSchemaStr.toString();
+ }
+}
diff --git a/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/DBSchema.java b/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/DBSchema.java
new file mode 100644
index 0000000000..4ae038b24d
--- /dev/null
+++ b/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/DBSchema.java
@@ -0,0 +1,45 @@
+/*
+ * 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.das.rdb.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class DBSchema {
+ private List tables = new ArrayList();
+
+ protected List getTables() {
+ return tables;
+ }
+
+ protected void setTables(List tables) {
+ this.tables = tables;
+ }
+
+ public String toString() {
+ StringBuffer dbSchemaStr = new StringBuffer();
+ dbSchemaStr.append("_____DB SChema_______\n");
+ for(int i=0; i<this.tables.size(); i++) {
+ Table curTable = (Table)this.tables.get(i);
+ dbSchemaStr.append(curTable);
+ }
+
+ return dbSchemaStr.toString();
+ }
+}
diff --git a/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/DBToSchemaFile.java b/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/DBToSchemaFile.java
new file mode 100644
index 0000000000..7288252ae4
--- /dev/null
+++ b/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/DBToSchemaFile.java
@@ -0,0 +1,119 @@
+/*
+ * 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.das.rdb.util;
+
+import java.io.File;
+import java.io.InputStreamReader;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.log4j.Logger;
+import org.apache.torque.task.TorqueJDBCTransformTask;
+import org.apache.tools.ant.Project;
+
+public class DBToSchemaFile {
+ private static final Logger logger = Logger.getLogger(DBToSchemaFile.class);
+ private static ModelXSDGenOption mo = null;//schemaFileName should not be null. id modelFileName null STDOUT
+
+ protected static void schemaFileFromDB() throws Exception {
+ Project p = new Project();
+ p.setBaseDir(new File("."));
+ TorqueJDBCTransformTask tsk = new TorqueJDBCTransformTask();
+ tsk.setProject(p);
+ tsk.setDbDriver(mo.getDriverClass());
+ tsk.setDbUrl(mo.getDatabaseURL());
+ tsk.setSameJavaName(true);
+ tsk.setDbSchema(mo.getSchemaName());
+ tsk.setTaskName("jdbc");
+ tsk.setDbUser(mo.getUserName());
+ tsk.setDbPassword(mo.getPassword());
+ if(!mo.getSchemaFile().trim().equals("")) {
+ File schemaFile = new File( mo.getSchemaFile());
+ schemaFile.createNewFile();
+ }
+ tsk.setOutputFile(mo.getSchemaFile());
+ tsk.execute();
+ }
+
+ protected static void read(String dbInfoFileName) throws Exception {
+ XMLInputFactory xmlFactory = XMLInputFactory.newInstance();
+
+ XMLStreamReader reader = xmlFactory.createXMLStreamReader(new InputStreamReader(DBToXSDGenerator.getStream(dbInfoFileName)));
+ mo = new ModelXSDGenOption();
+ while (true) {
+ int event = reader.next();
+ if(javax.xml.stream.XMLStreamConstants.END_DOCUMENT == event) {
+ break;
+ }
+
+ switch (event) {
+ case javax.xml.stream.XMLStreamConstants.START_ELEMENT: {
+ if (reader.getName().getLocalPart().equals("ConnectionProperties")) {
+ mo.setDriverClass(reader.getAttributeValue(null, "driverClass"));
+ mo.setDatabaseURL(reader.getAttributeValue(null, "databaseURL"));
+ mo.setSchemaName(reader.getAttributeValue(null, "schemaName"));
+ mo.setUserName(reader.getAttributeValue(null, "userName"));
+ if(mo.getUserName() == null)
+ mo.setUserName("");
+ mo.setPassword(reader.getAttributeValue(null, "password"));
+ if(mo.getPassword() == null)
+ mo.setPassword("");
+ } else if (reader.getName().getLocalPart().equals("ConnectionInfo")) {
+ //ignore
+ } else if (reader.getName().getLocalPart().equals("Config")) {
+ //ignore
+ } else if (reader.getName().getLocalPart().equals("OutFiles")) {
+ mo.setSchemaFile(reader.getAttributeValue(null, "schemaFile"));
+ mo.setModelFile(reader.getAttributeValue(null, "modelFile"));
+ } else {
+ throw new RuntimeException("not got dbInfo - tableNames List or connectionInfo:"+reader.getName()+":");
+ }
+ break;
+ }
+ }
+ }
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("driverClass:"+mo.getDriverClass());
+ logger.debug("url:"+mo.getDatabaseURL());
+ logger.debug("schemaName:"+mo.getSchemaName());
+ logger.debug("schemaFileName:"+mo.getSchemaFile());
+ logger.debug("modelFileName:"+mo.getModelFile());
+ logger.debug("userName:"+mo.getUserName());
+ logger.debug("password:"+mo.getPassword());
+ }
+
+ if(mo.getDriverClass() == null || mo.getDatabaseURL() == null || mo.getSchemaName() == null || mo.getSchemaFile() == null
+ || mo.getModelFile() == null) {
+ throw new RuntimeException("Required inputs missing - check driverClass, url, schemaName, schemaFile, modelFile!");
+ }
+
+ return;
+ }
+
+ public static ModelXSDGenOption getMo() {
+ return mo;
+ }
+
+ public static void setMo(ModelXSDGenOption mo) {
+ DBToSchemaFile.mo = mo;
+ }
+
+}
diff --git a/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/DBToXSDGenerator.java b/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/DBToXSDGenerator.java
new file mode 100644
index 0000000000..a5e510dedf
--- /dev/null
+++ b/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/DBToXSDGenerator.java
@@ -0,0 +1,88 @@
+/*
+ * 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.das.rdb.util;
+
+import java.io.InputStream;
+
+public class DBToXSDGenerator {
+ /**
+ * Output is dbSchemaFile as specified in dbInfoFileName.schemaFile
+ * @param dbInfoFileName name of file which contains db connection info and output files names for dbschema and model
+ * @throws Exception
+ */
+ public static void getSchemaFileFromDB(String dbInfoFileName) throws Exception {
+ DBToSchemaFile.read(dbInfoFileName);
+ DBToSchemaFile.schemaFileFromDB();
+ }
+
+ /**
+ * If user supplies schemaFileName and modelFileName will use it instead of the one from DBToSchemaFile.
+ * schemaFile should exist. If modelFileName is null, will use STDOUT.
+ * @param schemaFileName the result of Torque output
+ * @throws Exception
+ */
+ public static void getModelFileFromSchemaFile(String schemaFileName, String modelFileName) throws Exception {
+ if(schemaFileName == null || schemaFileName.trim().equals("")) {
+ throw new RuntimeException("Null or empty schemaFileName");
+ }
+
+ SchemaFileToXSD.convert(schemaFileName, modelFileName);
+ }
+
+ /**
+ * If user supplies schemaFileName and modelFileName through ModelXSDGenOption, will use it instead of
+ * the one from DBToSchemaFile. schemaFile should exist. If modelFileName is null, will use STDOUT.
+ * @param ModelXSDGenOption
+ * @throws Exception
+ */
+ public static void getModelFileFromSchemaFile(ModelXSDGenOption mo) throws Exception {
+ getModelFileFromSchemaFile(mo.getSchemaFile(), mo.getModelFile());
+ }
+
+ /**
+ * All in one
+ * @param dbInfoFileName e.g. DBConnectionConfig.xml
+ * @throws Exception
+ */
+ public static void getModelFileFromDB(String dbInfoFileName) throws Exception {
+ DBToSchemaFile.read(dbInfoFileName);
+ DBToSchemaFile.schemaFileFromDB();
+ getModelFileFromSchemaFile(DBToSchemaFile.getMo());
+ }
+
+ /**
+ * Useful for plugin
+ */
+ public static void getModelFileFromDB(ModelXSDGenOption mo) throws Exception {
+ if(mo.getSchemaFile() == null || mo.getSchemaFile().trim().equals("") ||
+ mo.getDriverClass() == null || mo.getDriverClass().trim().equals("") ||
+ mo.getDatabaseURL() == null || mo.getDatabaseURL().trim().equals("") ||
+ mo.getSchemaName() == null || mo.getSchemaName().trim().equals("")) {
+ throw new RuntimeException("Required inputs missing - check driverClass, url, schemaName, schemaFile!");
+ }
+
+ DBToSchemaFile.setMo(mo);
+ DBToSchemaFile.schemaFileFromDB();
+ getModelFileFromSchemaFile(DBToSchemaFile.getMo().getSchemaFile(), DBToSchemaFile.getMo().getModelFile());
+ }
+
+ protected static InputStream getStream(String fileName) {
+ return Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
+ }
+}
diff --git a/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/ForeignKey.java b/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/ForeignKey.java
new file mode 100644
index 0000000000..d602a30194
--- /dev/null
+++ b/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/ForeignKey.java
@@ -0,0 +1,51 @@
+/*
+ * 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.das.rdb.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ForeignKey {
+ private String foreignTableName;
+ private List fkRefs = new ArrayList();
+
+ protected String getForeignTableName() {
+ return foreignTableName;
+ }
+ protected void setForeignTableName(String foreignTableName) {
+ this.foreignTableName = foreignTableName;
+ }
+ protected List getFkRefs() {
+ return fkRefs;
+ }
+ protected void setFkRefs(List fkRefs) {
+ this.fkRefs = fkRefs;
+ }
+
+ public String toString() {
+ StringBuffer dbSchemaStr = new StringBuffer();
+ dbSchemaStr.append("_____Foreign Key_______"+this.foreignTableName+"\n");
+ for(int i=0; i<fkRefs.size(); i++) {
+ ForeignKeyRef curFkRef = (ForeignKeyRef)fkRefs.get(i);
+ dbSchemaStr.append(curFkRef);
+ }
+
+ return dbSchemaStr.toString();
+ }
+}
diff --git a/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/ForeignKeyRef.java b/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/ForeignKeyRef.java
new file mode 100644
index 0000000000..4be4f7435a
--- /dev/null
+++ b/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/ForeignKeyRef.java
@@ -0,0 +1,44 @@
+/*
+ * 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.das.rdb.util;
+
+public class ForeignKeyRef {
+ private String foreign;
+ private String local;
+
+ protected String getForeign() {
+ return foreign;
+ }
+ protected void setForeign(String foreign) {
+ this.foreign = foreign;
+ }
+ protected String getLocal() {
+ return local;
+ }
+ protected void setLocal(String local) {
+ this.local = local;
+ }
+
+ public String toString() {
+ StringBuffer dbSchemaStr = new StringBuffer();
+ dbSchemaStr.append("Foreign:"+this.foreign+", Local:"+this.local+"\n");
+
+ return dbSchemaStr.toString();
+ }
+}
diff --git a/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/ModelXSDGenOption.java b/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/ModelXSDGenOption.java
new file mode 100644
index 0000000000..24c848c33f
--- /dev/null
+++ b/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/ModelXSDGenOption.java
@@ -0,0 +1,134 @@
+/**
+ *
+ * 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.das.rdb.util;
+
+import java.io.File;
+
+public class ModelXSDGenOption {
+
+ /**
+ * Name of the schema file
+ *
+ * @parameter
+ */
+ private String schemaFile;
+
+ /**
+ * Name of the model file
+ *
+ * @parameter
+ */
+ private String modelFile;
+
+ /**
+ * Name of the DBDriver class Name
+ *
+ * @parameter
+ */
+ private String driverClass;
+
+ /**
+ * Name of the DB URL
+ *
+ * @parameter
+ */
+ private String databaseURL;
+
+ /**
+ * Name of the DB Schema Name
+ *
+ * @parameter
+ */
+ private String schemaName;
+
+ /**
+ * Optional user name.
+ *
+ * @parameter
+ */
+ private String userName;
+
+ /**
+ * Optional password.
+ *
+ * @parameter
+ */
+ private String password;
+
+ public ModelXSDGenOption() {
+ }
+
+ public String getSchemaFile() {
+ return schemaFile;
+ }
+
+ public void setSchemaFile(String schemaFile) {
+ this.schemaFile = schemaFile;
+ }
+
+ public String getModelFile() {
+ return modelFile;
+ }
+
+ public void setModelFile(String modelFile) {
+ this.modelFile = modelFile;
+ }
+
+ public String getDriverClass() {
+ return driverClass;
+ }
+
+ public void setDriverClass(String driverClass) {
+ this.driverClass = driverClass;
+ }
+
+ public String getDatabaseURL() {
+ return databaseURL;
+ }
+
+ public void setDatabaseURL(String databaseURL) {
+ this.databaseURL = databaseURL;
+ }
+
+ public String getSchemaName() {
+ return schemaName;
+ }
+
+ public void setSchemaName(String schemaName) {
+ this.schemaName = schemaName;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ public void setPassword(String password) {
+ this.password = password;
+ }
+
+}
diff --git a/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/SQLTypeChecker.java b/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/SQLTypeChecker.java
new file mode 100644
index 0000000000..73fe977719
--- /dev/null
+++ b/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/SQLTypeChecker.java
@@ -0,0 +1,186 @@
+/*
+ * 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.das.rdb.util;
+
+import java.sql.Types;
+
+public class SQLTypeChecker {
+
+ public static int getSQLTypeFromString(String sqlTypeString) {
+ if(sqlTypeString.equals("CHAR")) return Types.CHAR;
+ if(sqlTypeString.equals("VARCHAR")) return Types.VARCHAR;
+ if(sqlTypeString.equals("LONGVARCHAR")) return Types.LONGVARCHAR;
+ if(sqlTypeString.equals("NUMERIC")) return Types.NUMERIC;
+ if(sqlTypeString.equals("DECIMAL")) return Types.DECIMAL;
+ if(sqlTypeString.equals("BIT")) return Types.BIT;
+ if(sqlTypeString.equals("BOOLEAN")) return Types.BOOLEAN;
+ if(sqlTypeString.equals("TINYINT")) return Types.TINYINT;
+ if(sqlTypeString.equals("SMALLINT")) return Types.SMALLINT;
+ if(sqlTypeString.equals("INTEGER")) return Types.INTEGER;
+ if(sqlTypeString.equals("BIGINT")) return Types.BIGINT;
+ if(sqlTypeString.equals("REAL")) return Types.REAL;
+ if(sqlTypeString.equals("FLOAT")) return Types.FLOAT;
+ if(sqlTypeString.equals("DOUBLE")) return Types.DOUBLE;
+ if(sqlTypeString.equals("BINARY")) return Types.BINARY;
+ if(sqlTypeString.equals("VARBINARY")) return Types.VARBINARY;
+ if(sqlTypeString.equals("LONGVARBINARY")) return Types.LONGVARBINARY;
+ if(sqlTypeString.equals("DATE")) return Types.DATE;
+ if(sqlTypeString.equals("TIME")) return Types.TIME;
+ if(sqlTypeString.equals("TIMESTAMP")) return Types.TIMESTAMP;
+ if(sqlTypeString.equals("CLOB")) return Types.CLOB;
+ if(sqlTypeString.equals("BLOB")) return Types.BLOB;
+ if(sqlTypeString.equals("ARRAY")) return Types.ARRAY;
+ if(sqlTypeString.equals("DISTINCT")) return Types.DISTINCT;
+ if(sqlTypeString.equals("STRUCT")) return Types.STRUCT;
+ if(sqlTypeString.equals("REF")) return Types.REF;
+ if(sqlTypeString.equals("DATALINK")) return Types.DATALINK;
+ if(sqlTypeString.equals("JAVA_OBJECT")) return Types.JAVA_OBJECT;
+ return Types.OTHER;
+ }
+
+ /*xsd : SDO
+ anySimpleType Object
+ anyType DataObject
+ anyURI URI
+ base64Binary Bytes
+ boolean Boolean
+ byte Byte
+ date YearMonthDay
+ dateTime DateTime
+ decimal Decimal
+ double Double
+ duration Duration
+ ENTITIES Strings
+ ENTITY String
+ float Float
+ gDay Day
+ gMonth Month
+ gMonthDay MonthDay
+ gYear Year
+ gYearMonth YearMonth
+ hexBinary Bytes
+ ID String
+ IDREF String
+ IDREFS Strings
+ int Int
+ integer Integer
+ language String
+ long Long
+ Name String
+ NCName String
+ negativeInteger Integer
+ NMTOKEN String
+ NMTOKENS Strings
+ nonNegativeInteger Integer
+ nonPositiveInteger Integer
+ normalizedString String
+ NOTATION String
+ positiveInteger Integer
+ QName URI
+ short Short
+ string String
+ time Time
+ token String
+ unsignedByte Short
+ unsignedInt long
+ unsignedLong Integer
+ unsignedShort Int*/
+ static final String anySimpleTypeXSD = "anySimpleType";
+ static final String anyTypeXSD = "anyType";
+ static final String anyURIXSD = "anyURI";
+ static final String base64BinaryXSD = "base64Binary";
+ static final String booleanXSD = "boolean";
+ static final String byteXSD = "byte";
+ static final String dateXSD = "date";
+ static final String dateTimeXSD = "dateTime";
+ static final String decimalXSD = "decimal";
+ static final String doubleXSD = "double";
+ static final String durationXSD = "duration";
+ static final String ENTITIESXSD = "ENTITIES";
+ static final String ENTITYXSD = "ENTITY";
+ static final String floatXSD = "float";
+ static final String gDayXSD = "gDay";
+ static final String gMonthXSD = "gMonth";
+ static final String gMonthDayXSD = "gMonthDay";
+ static final String gYearXSD = "gYear";
+ static final String gYearMonthXSD = "gYearMonth";
+ static final String hexBinaryXSD = "hexBinary";
+ static final String IDXSD = "ID";
+ static final String IDREFXSD = "IDREF";
+ static final String IDREFSXSD = "IDREF";
+ static final String intXSD = "int";
+ static final String integerXSD = "integer";
+ static final String languageXSD = "language";
+ static final String longXSD = "long";
+ static final String NameXSD = "Name";
+ static final String NCNameXSD = "NCName";
+ static final String negativeIntegerXSD = "negativeInteger";
+ static final String NMTOKENXSD = "NMTOKEN";
+ static final String NMTOKENSXSD = "NMTOKENS";
+ static final String nonNegativeIntegerXSD = "nonNegativeInteger";
+ static final String nonPositiveIntegerXSD = "nonPositiveInteger";
+ static final String normalizedStringXSD = "normalizedString";
+ static final String NOTATIONXSD = "NOTATION";
+ static final String positiveIntegerXSD = "positiveInteger";
+ static final String QNameXSD = "QName";
+ static final String shortXSD = "short";
+ static final String stringXSD = "string";
+ static final String timeXSD = "time";
+ static final String tokenXSD = "token";
+ static final String unsignedByteXSD = "unsignedByte";
+ static final String unsignedIntXSD = "unsignedInt";
+ static final String unsignedLongXSD = "unsignedLong";
+ static final String unsignedShortXSD = "unsignedShort";
+
+ public static String xsdTypeForSDOType(String sdoTypeName) {
+ if(sdoTypeName.equals("Object")) return anySimpleTypeXSD;
+ if(sdoTypeName.equals("DataObject")) return anyTypeXSD;
+ if(sdoTypeName.equals("URI")) return anyURIXSD;
+ if(sdoTypeName.equals("Bytes")) return base64BinaryXSD;
+ if(sdoTypeName.equals("Boolean")) return booleanXSD;
+ if(sdoTypeName.equals("boolean")) return booleanXSD;
+ if(sdoTypeName.equals("Byte")) return byteXSD;
+ if(sdoTypeName.equals("YearMonthDay")) return dateXSD;
+ if(sdoTypeName.equals("DateTime")) return dateTimeXSD;
+ if(sdoTypeName.equals("Date")) return dateTimeXSD;
+ if(sdoTypeName.equals("Decimal")) return decimalXSD;
+ if(sdoTypeName.equals("Double")) return doubleXSD;
+ if(sdoTypeName.equals("double")) return doubleXSD;
+ if(sdoTypeName.equals("Duration")) return durationXSD;
+ if(sdoTypeName.equals("Strings")) return ENTITIESXSD;
+ if(sdoTypeName.equals("String")) return stringXSD;
+ if(sdoTypeName.equals("Float")) return floatXSD;
+ if(sdoTypeName.equals("float")) return floatXSD;
+ if(sdoTypeName.equals("Day")) return gDayXSD;
+ if(sdoTypeName.equals("Month")) return gMonthXSD;
+ if(sdoTypeName.equals("MonthDay")) return gMonthDayXSD;
+ if(sdoTypeName.equals("Year")) return gYearXSD;
+ if(sdoTypeName.equals("YearMonth")) return gYearMonthXSD;
+ if(sdoTypeName.equals("Bytes")) return hexBinaryXSD;
+ if(sdoTypeName.equals("Int")) return intXSD;
+ if(sdoTypeName.equals("IntObject")) return intXSD;
+ if(sdoTypeName.equals("Integer")) return integerXSD;
+ if(sdoTypeName.equals("Long")) return longXSD;
+ if(sdoTypeName.equals("long")) return longXSD;
+ if(sdoTypeName.equals("Short")) return shortXSD;
+ if(sdoTypeName.equals("Time")) return timeXSD;
+ if(sdoTypeName.equals("long")) return unsignedIntXSD;
+ return "";
+ }
+}
diff --git a/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/SchemaFileToXSD.java b/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/SchemaFileToXSD.java
new file mode 100644
index 0000000000..54cd0aa02b
--- /dev/null
+++ b/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/SchemaFileToXSD.java
@@ -0,0 +1,200 @@
+/*
+ * 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.das.rdb.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+import java.util.ArrayList;
+import java.util.Hashtable;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.log4j.Logger;
+import org.apache.tuscany.das.rdb.graphbuilder.schema.ResultSetTypeMap;
+
+import commonj.sdo.Type;
+
+public class SchemaFileToXSD {
+ private static final Logger logger = Logger.getLogger(SchemaFileToXSD.class);
+ private static XMLInputFactory xmlFactory;
+
+ protected static DBSchema read(XMLStreamReader reader) throws Exception {
+ DBSchema dbSchema = new DBSchema();
+ Table table = null;
+ Column column = null;
+ ForeignKey fk = null;
+ ForeignKeyRef fkRef = null;
+
+ while (true) {
+ int event = reader.next();
+ if(javax.xml.stream.XMLStreamConstants.END_DOCUMENT == event) {
+ break;
+ }
+
+ switch (event) {
+ case javax.xml.stream.XMLStreamConstants.START_ELEMENT:
+ if (reader.getName().getLocalPart().equals("table")) {
+ table = new Table();
+ table.setName(reader.getAttributeValue(null, "name"));
+ } else if (reader.getName().getLocalPart().equals("column")) {
+ column = new Column();
+ column.setName(reader.getAttributeValue(null, "name"));
+ column.setPK(Boolean.getBoolean(reader.getAttributeValue(null, "primaryKey")));
+ column.setRequired(Boolean.getBoolean(reader.getAttributeValue(null, "required")));
+ column.setType(reader.getAttributeValue(null, "type"));
+ }
+ else if (reader.getName().getLocalPart().equals("foreign-key")) {
+ fk = new ForeignKey();
+ fk.setForeignTableName(reader.getAttributeValue(null,"foreignTable"));
+ }
+ else if (reader.getName().getLocalPart().equals("reference")) {
+ fkRef = new ForeignKeyRef();
+ fkRef.setForeign(reader.getAttributeValue(null,"foreign"));
+ fkRef.setLocal(reader.getAttributeValue(null,"local"));
+ }
+ else if (reader.getName().getLocalPart().equals("database")) {
+ //ignore
+ } else {
+ throw new RuntimeException("not valid element:"+reader.getName()+":");
+ }
+ break;
+
+ case javax.xml.stream.XMLStreamConstants.END_ELEMENT:
+ if (reader.getName().getLocalPart().equals("table")) {
+ dbSchema.getTables().add(table);
+ }
+
+ if (reader.getName().getLocalPart().equals("column")) {
+ if(table != null) {
+ table.getColumns().add(column);
+ }
+ }
+
+ if (reader.getName().getLocalPart().equals("reference")) {
+ if(fk != null) {
+ fk.getFkRefs().add(fkRef);
+ }
+ }
+
+ if (reader.getName().getLocalPart().equals("foreign-key")) {
+ if(table != null) {
+ table.getFks().add(fk);
+ }
+ }
+
+ break;
+ }
+ }
+
+ if (logger.isDebugEnabled()) {
+ logger.debug(dbSchema);
+ }
+
+ return dbSchema;
+ }
+
+ protected static void convert(String schemaFileName, String xsdModelFileName) throws Exception{
+ xmlFactory = XMLInputFactory.newInstance();
+
+ File schemaFile = new File(schemaFileName);
+ FileInputStream flStrm = new FileInputStream(schemaFile);
+
+ XMLStreamReader reader = xmlFactory.createXMLStreamReader(new InputStreamReader(flStrm));
+
+ DBSchema dbSchema = read(reader);
+ flStrm.close();
+ generateXSD(dbSchema, xsdModelFileName);
+ }
+
+ protected static void generateXSD(DBSchema dbSchema, String xsdModelFileName) throws Exception {
+ boolean writeFilesToDir = false;
+ String startLine = "<xsd:schema xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:this=\"http:///org.apache.tuscany.das.rdb.test/schemaModel.xsd\" targetNamespace=\"http:///org.apache.tuscany.das.rdb.test/schemaModel.xsd\">\n";
+ String endLine = "</xsd:schema>";
+
+ if(xsdModelFileName != null && !xsdModelFileName.trim().equals("")) {
+ writeFilesToDir = true;
+ }
+
+ //get all FKs to form a Map - PKtable -> FKTable , e.g. if CITIES has FK such that CITIES.STATE_ID is STATES.ID, then
+ //the map shall have STATES -> CITIES, TABLE2,...
+ Hashtable pkTofkTable = new Hashtable();
+
+ for(int i=0; i<dbSchema.getTables().size(); i++) {
+ Table curTable = (Table)dbSchema.getTables().get(i);
+ for(int k=0; k<curTable.getFks().size(); k++) {
+ ForeignKey curFK = (ForeignKey)curTable.getFks().get(k);
+ String pkTableName = curFK.getForeignTableName();
+
+ if(pkTofkTable.get(pkTableName) == null) {
+ pkTofkTable.put(pkTableName, new ArrayList());
+ }
+ ((ArrayList)pkTofkTable.get(pkTableName)).add(curTable.getName());
+ }
+ }
+
+ String srcCode = startLine;
+
+ for(int i=0; i<dbSchema.getTables().size(); i++) {
+ Table curTable = (Table)dbSchema.getTables().get(i);
+ srcCode = srcCode + "<xsd:complexType name=\""+curTable.getName()+"\">\n";
+ srcCode = srcCode + " <xsd:sequence>\n";
+
+ for(int j=0; j<curTable.getColumns().size(); j++) {
+ Column curColumn = (Column)curTable.getColumns().get(j);
+ srcCode = srcCode + " <xsd:element name=\""+ curColumn.getName();
+
+ if(curColumn.isRequired()) {
+ srcCode = srcCode + " nillable=\"false\"";
+ }
+
+ Type sdoType = ResultSetTypeMap.INSTANCE.getType(SQLTypeChecker.getSQLTypeFromString(curColumn.getType()), true);
+
+ srcCode = srcCode + " type=\"xsd:"+SQLTypeChecker.xsdTypeForSDOType(sdoType.getName())+"\"/>\n";
+ }
+
+ if(pkTofkTable.get(curTable.getName()) != null) {
+ ArrayList fkTables = (ArrayList)pkTofkTable.get(curTable.getName());
+
+ for(int k=0; k<fkTables.size(); k++) {
+ srcCode = srcCode + " <xsd:element maxOccurs=\"unbounded\" name=\""+ fkTables.get(k)+"\" type=\"this:"+fkTables.get(k)+"\"/>\n";
+ }
+ }
+
+ srcCode = srcCode + " </xsd:sequence>\n";
+ srcCode = srcCode + "</xsd:complexType>\n\n";
+ }
+
+ srcCode = srcCode + endLine;
+
+ File javaFile = new File(xsdModelFileName);
+ javaFile.createNewFile();
+ PrintStream flStrm = new PrintStream(javaFile);
+
+ if(writeFilesToDir) {
+ flStrm.print(srcCode);
+ flStrm.flush();
+ flStrm.close();
+ } else {
+ System.out.print(srcCode);
+ }
+ }
+} \ No newline at end of file
diff --git a/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/Table.java b/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/Table.java
new file mode 100644
index 0000000000..c41085cf2f
--- /dev/null
+++ b/java/das/tools/src/main/java/org/apache/tuscany/das/rdb/util/Table.java
@@ -0,0 +1,66 @@
+/*
+ * 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.das.rdb.util;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class Table {
+ private String name;
+ private List columns = new ArrayList();
+ private List fks = new ArrayList();
+
+ protected String getName() {
+ return name;
+ }
+ protected void setName(String name) {
+ this.name = name;
+ }
+ protected List getColumns() {
+ return columns;
+ }
+ protected void setColumns(List columns) {
+ this.columns = columns;
+ }
+ protected List getFks() {
+ return fks;
+ }
+ protected void setFks(List fks) {
+ this.fks = fks;
+ }
+
+ public String toString() {
+ StringBuffer dbSchemaStr = new StringBuffer();
+ dbSchemaStr.append("_____Table_______"+this.name+"\n");
+ dbSchemaStr.append("_____Columns_______\n");
+ for(int i=0; i<this.columns.size(); i++) {
+ Column curColumn = (Column)this.columns.get(i);
+ dbSchemaStr.append(curColumn);
+ }
+
+ if(this.fks.size() > 0)
+ dbSchemaStr.append("_____FKs_______\n");
+ for(int i=0; i<this.fks.size(); i++) {
+ ForeignKey curFk = (ForeignKey)this.fks.get(i);
+ dbSchemaStr.append(curFk);
+ }
+
+ return dbSchemaStr.toString();
+ }
+}
diff --git a/java/das/tools/src/test/java/org/apache/tuscany/das/rdb/test/DBToXSDTests.java b/java/das/tools/src/test/java/org/apache/tuscany/das/rdb/test/DBToXSDTests.java
new file mode 100644
index 0000000000..aba4eba68f
--- /dev/null
+++ b/java/das/tools/src/test/java/org/apache/tuscany/das/rdb/test/DBToXSDTests.java
@@ -0,0 +1,142 @@
+/*
+ * 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.das.rdb.test;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+
+import junit.framework.TestCase;
+
+import org.apache.tuscany.das.rdb.dbconfig.DBInitializer;
+import org.apache.tuscany.das.rdb.util.DBToXSDGenerator;
+/**
+ * Tests the DB Schema to Model XSD converter tool
+ */
+public class DBToXSDTests extends TestCase {
+ protected void setUp() throws Exception {
+ super.setUp();
+ DBInitializer dbInitializer = new DBInitializer("dbConfig.xml");
+ dbInitializer.initializeDatabase(true);
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ static public String getContents(File aFile) {
+ //...checks on aFile are elided
+ StringBuffer contents = new StringBuffer();
+
+ //declared here only to make visible to finally clause
+ BufferedReader input = null;
+ try {
+ //use buffering, reading one line at a time
+ //FileReader always assumes default encoding is OK!
+ input = new BufferedReader( new FileReader(aFile) );
+ String line = null; //not declared within while loop
+ /*
+ * readLine is a bit quirky :
+ * it returns the content of a line MINUS the newline.
+ * it returns null only for the END of the stream.
+ * it returns an empty String if two newlines appear in a row.
+ */
+ while (( line = input.readLine()) != null){
+ contents.append(line);
+ contents.append(System.getProperty("line.separator"));
+ }
+ }
+ catch (FileNotFoundException ex) {
+ ex.printStackTrace();
+ }
+ catch (IOException ex){
+ ex.printStackTrace();
+ }
+ finally {
+ try {
+ if (input!= null) {
+ //flush and close both "input" and its underlying FileReader
+ input.close();
+ }
+ }
+ catch (IOException ex) {
+ ex.printStackTrace();
+ }
+ }
+ return contents.toString();
+ }
+
+ String compare1 = "<table javaName=\"STATES\" name=\"STATES\">";
+ String compare2 = "<table javaName=\"CITIES\" name=\"CITIES\">";
+ String compare3 = "<xsd:complexType name=\"CITIES\">";
+ String compare4 = "<xsd:complexType name=\"STATES\">";
+
+ public void testDBToSchemaFile() throws Exception {
+ DBToXSDGenerator.getSchemaFileFromDB("DBConnectionConfig.xml");
+ File file = new File("target/dbSchema.txt");
+ if(file.isFile()) {
+ String schemaContent = getContents(file);
+ if(schemaContent.indexOf(compare1) != -1 && schemaContent.indexOf(compare2) != -1) {
+ assertTrue(true);
+ }
+ } else {
+ fail("SchemaFile does not exists or has improper contents!");
+ }
+ }
+
+ public void testSchemaFileToXSD() throws Exception {
+ DBToXSDGenerator.getModelFileFromSchemaFile("target/dbSchema.txt", "target/schemaModel.xsd");
+
+ File modelfile = new File("target/schemaModel.xsd");
+ if(modelfile.isFile()) {
+ String modelContent = getContents(modelfile);
+ if(modelContent.indexOf(compare3) != -1 && modelContent.indexOf(compare4) != -1) {
+ assertTrue(true);
+ }
+ } else {
+ fail("ModelFile does not exists or has improper contents!");
+ }
+ }
+
+ public void testDBToXSD() throws Exception {
+ DBToXSDGenerator.getModelFileFromDB("DBConnectionConfig.xml");
+
+ File file = new File("target/dbSchema.txt");
+ if(file.isFile()) {
+ String schemaContent = getContents(file);
+ if(schemaContent.indexOf(compare1) != -1 && schemaContent.indexOf(compare2) != -1) {
+ assertTrue(true);
+ }
+ } else {
+ fail("SchemaFile does not exists or has improper contents!");
+ }
+
+ File modelfile = new File("target/schemaModel.xsd");
+ if(modelfile.isFile()) {
+ String modelContent = getContents(modelfile);
+ if(modelContent.indexOf(compare3) != -1 && modelContent.indexOf(compare4) != -1) {
+ assertTrue(true);
+ }
+ } else {
+ fail("ModelFile does not exists or has improper contents!");
+ }
+ }
+}
diff --git a/java/das/tools/src/test/resources/DBConnectionConfig.xml b/java/das/tools/src/test/resources/DBConnectionConfig.xml
new file mode 100644
index 0000000000..c00bd462db
--- /dev/null
+++ b/java/das/tools/src/test/resources/DBConnectionConfig.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ 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.
+-->
+<Config xmlns="http:///org.apache.tuscany.das.rdb/config.xsd">
+
+ <!--Uncomment below for derby test-->
+ <ConnectionInfo>
+ <ConnectionProperties
+ driverClass="org.apache.derby.jdbc.EmbeddedDriver"
+ databaseURL="jdbc:derby:target/dastest;create=true" schemaName="APP"
+ />
+ </ConnectionInfo>
+ <OutFiles schemaFile="target/dbSchema.txt"
+ modelFile="target/schemaModel.xsd" />
+</Config>
diff --git a/java/das/tools/src/test/resources/dbConfig.xml b/java/das/tools/src/test/resources/dbConfig.xml
new file mode 100644
index 0000000000..b990d5cd0f
--- /dev/null
+++ b/java/das/tools/src/test/resources/dbConfig.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="ASCII"?>
+<!--
+ 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.
+-->
+<DBConfig xmlns="http:///org.apache.tuscany.das.rdb/dbconfig.xsd">
+ <ConnectionInfo>
+ <ConnectionProperties
+ driverClass="org.apache.derby.jdbc.EmbeddedDriver"
+ databaseURL="jdbc:derby:target/dastest; create = true"
+ />
+ </ConnectionInfo>
+ <Table name="STATES"
+ SQLCreate="CREATE TABLE STATES (ID INT PRIMARY KEY NOT NULL, NAME VARCHAR(2))">
+ </Table>
+ <Table name="CITIES"
+ SQLCreate="CREATE TABLE CITIES (ID INT PRIMARY KEY NOT NULL, NAME VARCHAR(50), STATES_ID INTEGER,
+ CONSTRAINT FK1 FOREIGN KEY (STATES_ID) REFERENCES STATES (ID) ON DELETE NO ACTION ON UPDATE NO ACTION)">
+ </Table>
+</DBConfig>