Author: kwilliams
Date: Wed Apr 19 11:08:03 2006
New Revision: 395330
URL: http://svn.apache.org/viewcvs?rev=395330&view=rev
Log:
Some minor refactoring and cleanup of dead code
Modified:
incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/CommandFactory.java
incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/BaseCommandImpl.java
incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CommandFactoryImpl.java
incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ReadCommandImpl.java
incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/SPCommandImpl.java
Modified:
incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/CommandFactory.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/CommandFactory.java?rev=395330&r1=395329&r2=395330&view=diff
==============================================================================
---
incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/CommandFactory.java
(original)
+++
incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/CommandFactory.java
Wed Apr 19 11:08:03 2006
@@ -19,6 +19,8 @@
import java.io.IOException;
import java.io.InputStream;
+import org.apache.tuscany.das.rdb.config.Config;
+
/**
* A CommandFactory produces [EMAIL PROTECTED] Command} and [EMAIL PROTECTED]
ApplyChangesCommand}
* instances.
@@ -27,40 +29,65 @@
*/
public interface CommandFactory {
- /**
- * Creates a Command based on the provided SQL statement
- *
- * @param sql
- * The SQL statement
- * @return returns a Command instance
- */
- public Command createCommand(String sql);
-
- /**
- * Creates a Command based on the provided SQL statement and
configuration
- *
- * @param sql
- * The SQL statement
- * @param mappingModel
- * The congiguration as XML file stream
- * @return returns a COmmand instance
- */
- public Command createCommand(String sql, InputStream mappingModel);
-
- /**
- * Creates an [EMAIL PROTECTED] instance
- * @return Returns the ApplyChangesCommand instance
- */
- public ApplyChangesCommand createApplyChangesCommand();
-
- /**
- * Creates an [EMAIL PROTECTED] instance with the provided configuration
- * @param mappingModel The provided configuration as a stream over an
xml file
- * @return Returns an ApplyChangesCOmmand in stance
- * @throws IOException
- */
- public ApplyChangesCommand createApplyChangesCommand(
- InputStream mappingModel) throws IOException;
+ /**
+ * Creates a Command based on the provided SQL statement
+ *
+ * @param sql
+ * The SQL statement
+ * @return returns a Command instance
+ */
+ public Command createCommand(String sql);
+
+ /**
+ * Creates a Command based on the provided SQL statement and configuration
+ *
+ * @param sql
+ * The SQL statement
+ * @param mappingModel
+ * The congiguration as XML file stream
+ * @return returns a COmmand instance
+ */
+ public Command createCommand(String sql, InputStream config);
+
+ /**
+ * Creates a Command based on the provided SQL statement and configuration
+ *
+ * @param sql
+ * The SQL statement
+ * @param config
+ * The congiguration as Config instance
+ * @return returns a COmmand instance
+ */
+ public Command createCommand(String sql, Config config);
+
+ /**
+ * Creates an [EMAIL PROTECTED] instance
+ *
+ * @return Returns the ApplyChangesCommand instance
+ */
+ public ApplyChangesCommand createApplyChangesCommand();
+
+ /**
+ * Creates an [EMAIL PROTECTED] instance with the provided
+ * configuration
+ *
+ * @param config
+ * The provided configuration as a stream over an xml file
+ * @return Returns an ApplyChangesCOmmand in stance
+ * @throws IOException
+ */
+ public ApplyChangesCommand createApplyChangesCommand(InputStream config)
throws IOException;
+
+ /**
+ * Creates an [EMAIL PROTECTED] instance with the provided
+ * configuration
+ *
+ * @param config
+ * The provided configuration as a Config instance
+ * @return Returns an ApplyChangesCommand in stance
+ * @throws IOException
+ */
+ public ApplyChangesCommand createApplyChangesCommand(Config config);
}
Modified:
incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/BaseCommandImpl.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/BaseCommandImpl.java?rev=395330&r1=395329&r2=395330&view=diff
==============================================================================
---
incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/BaseCommandImpl.java
(original)
+++
incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/BaseCommandImpl.java
Wed Apr 19 11:08:03 2006
@@ -1,53 +1,59 @@
-
package org.apache.tuscany.das.rdb.impl;
+import java.io.IOException;
+import java.io.InputStream;
import java.sql.Connection;
import org.apache.tuscany.das.rdb.Key;
+import org.apache.tuscany.das.rdb.config.Config;
+import org.apache.tuscany.das.rdb.config.ConfigFactory;
import org.apache.tuscany.das.rdb.config.wrapper.MappingWrapper;
+import org.apache.tuscany.sdo.util.SDOUtil;
+
+import commonj.sdo.helper.XMLHelper;
public abstract class BaseCommandImpl {
- protected MappingWrapper configWrapper = new MappingWrapper();
+ protected MappingWrapper configWrapper = new MappingWrapper();
- public void setConnection(Connection connection) {
- setConnection(new ConnectionImpl(connection));
- }
-
- public void setConnection(Connection connection, boolean manageTransaction)
{
- ConnectionImpl c = new ConnectionImpl(connection);
- c.setManageTransactions(manageTransaction);
- setConnection(c);
- }
-
- public abstract void setConnection(ConnectionImpl c);
-
- public void addRelationship(String parentName, String childName) {
- configWrapper.addRelationship(parentName, childName);
- }
-
- public void addRelationship(Key parentKey, Key childKey) {
- configWrapper.addRelationship(parentKey, childKey);
- }
-
- public void addPrimaryKey(String pk) {
- configWrapper.addPrimaryKey(pk);
- }
-
- public void addPrimaryKey(Key pk) {
- configWrapper.addPrimaryKey(pk);
- }
-
- public void addConverter(String name, String converter) {
- configWrapper.addConverter(name, converter);
- }
-
- public void addCollisionColumn(String columnName) {
- configWrapper.addCollisionColumn(columnName);
- }
-
- public void addGeneratedPrimaryKey(String columnName) {
- configWrapper.addGeneratedPrimaryKey(columnName);
- }
+ public void setConnection(Connection connection) {
+ setConnection(new ConnectionImpl(connection));
+ }
+
+ public void setConnection(Connection connection, boolean
manageTransaction) {
+ ConnectionImpl c = new ConnectionImpl(connection);
+ c.setManageTransactions(manageTransaction);
+ setConnection(c);
+ }
+
+ public abstract void setConnection(ConnectionImpl c);
+
+ public void addRelationship(String parentName, String childName) {
+ configWrapper.addRelationship(parentName, childName);
+ }
+
+ public void addRelationship(Key parentKey, Key childKey) {
+ configWrapper.addRelationship(parentKey, childKey);
+ }
+
+ public void addPrimaryKey(String pk) {
+ configWrapper.addPrimaryKey(pk);
+ }
+
+ public void addPrimaryKey(Key pk) {
+ configWrapper.addPrimaryKey(pk);
+ }
+
+ public void addConverter(String name, String converter) {
+ configWrapper.addConverter(name, converter);
+ }
+
+ public void addCollisionColumn(String columnName) {
+ configWrapper.addCollisionColumn(columnName);
+ }
+
+ public void addGeneratedPrimaryKey(String columnName) {
+ configWrapper.addGeneratedPrimaryKey(columnName);
+ }
}
Modified:
incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CommandFactoryImpl.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CommandFactoryImpl.java?rev=395330&r1=395329&r2=395330&view=diff
==============================================================================
---
incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CommandFactoryImpl.java
(original)
+++
incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CommandFactoryImpl.java
Wed Apr 19 11:08:03 2006
@@ -18,63 +18,76 @@
import java.io.IOException;
import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
import org.apache.tuscany.das.rdb.ApplyChangesCommand;
import org.apache.tuscany.das.rdb.Command;
import org.apache.tuscany.das.rdb.CommandFactory;
+import org.apache.tuscany.das.rdb.config.Config;
+import org.apache.tuscany.das.rdb.config.ConfigFactory;
+import org.apache.tuscany.sdo.util.SDOUtil;
+import commonj.sdo.helper.XMLHelper;
public class CommandFactoryImpl implements CommandFactory {
-
- protected Map namedCommands = new HashMap();
- public Command createCommand(String sql) {
- return createCommand(sql, null);
- }
-
- public Command createCommand(String sql, InputStream model) {
-
- sql = sql.trim(); //Remove leading white space
- char firstChar = Character.toUpperCase(sql.charAt(0));
- switch (firstChar) {
- case 'S':
- return new ReadCommandImpl(sql, model);
- case 'I':
- return new InsertCommandImpl(sql);
- case 'U':
- return new UpdateCommandImpl(sql);
- case 'D':
- return new DeleteCommandImpl(sql);
- case '{':
- return new SPCommandImpl(sql);
- default:
- throw new Error("SQL => " + sql + " is not valid");
- }
-
- }
-
- public Command createReadCommand(String sql) {
- return new ReadCommandImpl(sql);
- }
-
- public Command createReadCommand(String sql, InputStream model) {
- return new ReadCommandImpl(sql, model);
- }
-
- public ApplyChangesCommand createApplyChangesCommand() {
- return new ApplyChangesCommandImpl();
- }
-
- public ApplyChangesCommand createApplyChangesCommand(
- InputStream mappingModel) throws IOException {
- return new ApplyChangesCommandImpl(mappingModel);
- }
-
- public Command getCommand (String name) {
- return (Command) namedCommands.get(name);
- }
-
-
+ public Command createCommand(String sql) {
+ return baseCreateCommand(sql, null);
+ }
+
+ public Command createCommand(String sql, InputStream configStream) {
+ return baseCreateCommand(sql, loadConfig(configStream));
+ }
+
+ public Command createCommand(String sql, Config config) {
+ return baseCreateCommand(sql, config);
+ }
+
+ public ApplyChangesCommand createApplyChangesCommand() {
+ return new ApplyChangesCommandImpl();
+ }
+
+ public ApplyChangesCommand createApplyChangesCommand(InputStream
mappingModel) throws IOException {
+ return new ApplyChangesCommandImpl(mappingModel);
+ }
+
+ public ApplyChangesCommand createApplyChangesCommand(Config config) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ // Utilities
+
+ private Command baseCreateCommand(String sql, Config config) {
+
+ sql = sql.trim(); // Remove leading white space
+ char firstChar = Character.toUpperCase(sql.charAt(0));
+ switch (firstChar) {
+ case 'S':
+ return new ReadCommandImpl(sql, config);
+ case 'I':
+ return new InsertCommandImpl(sql);
+ case 'U':
+ return new UpdateCommandImpl(sql);
+ case 'D':
+ return new DeleteCommandImpl(sql);
+ case '{':
+ return new SPCommandImpl(sql);
+ default:
+ throw new Error("SQL => " + sql + " is not valid");
+ }
+
+ }
+
+ private Config loadConfig(InputStream configStream) {
+
+ SDOUtil.registerStaticTypes(ConfigFactory.class);
+ XMLHelper helper = XMLHelper.INSTANCE;
+
+ try {
+ Config config = (Config) helper.load(configStream).getRootObject();
+ return config;
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
}
Modified:
incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ReadCommandImpl.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ReadCommandImpl.java?rev=395330&r1=395329&r2=395330&view=diff
==============================================================================
---
incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ReadCommandImpl.java
(original)
+++
incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ReadCommandImpl.java
Wed Apr 19 11:08:03 2006
@@ -1,23 +1,21 @@
/**
-*
-* Copyright 2005 The Apache Software Foundation or its licensors, as
applicable.
-*
-* Licensed 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.
-*/
+ *
+ * Copyright 2005 The Apache Software Foundation or its licensors, as
applicable.
+ *
+ * Licensed 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.impl;
-import java.io.IOException;
-import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
@@ -26,7 +24,6 @@
import java.util.List;
import org.apache.tuscany.das.rdb.config.Config;
-import org.apache.tuscany.das.rdb.config.ConfigFactory;
import org.apache.tuscany.das.rdb.config.ConnectionProperties;
import org.apache.tuscany.das.rdb.config.wrapper.MappingWrapper;
import org.apache.tuscany.das.rdb.graphbuilder.impl.GraphBuilderMetadata;
@@ -41,166 +38,138 @@
import commonj.sdo.DataGraph;
import commonj.sdo.DataObject;
import commonj.sdo.Type;
-import commonj.sdo.helper.XMLHelper;
public class ReadCommandImpl extends CommandImpl {
- private Type schema;
+ private Type schema;
- private int startRow = 1;
+ private int startRow = 1;
- private int endRow = Integer.MAX_VALUE;
+ private int endRow = Integer.MAX_VALUE;
- public ReadCommandImpl(String sqlString) {
- super(sqlString);
- }
-
- public ReadCommandImpl(String sqlString, InputStream modelStream) {
- this(sqlString);
- if (modelStream != null)
- setMappingModel(modelStream);
- }
-
- public ReadCommandImpl(String sqlString, Config mapping) {
- this(sqlString);
- if (mapping != null)
- setMappingModel(mapping);
- }
-
- public void execute() {
- throw new UnsupportedOperationException();
- }
-
- public DataObject executeQuery() {
-
- if (statement.getConnection() == null)
- throw new RuntimeException(
- "A DASConnection object must be
specified before executing the query.");
-
- boolean success = false;
- try {
- ResultSet rs = statement.executeQuery(parameters);
- success = true;
- return buildGraph(rs);
- } catch (SQLException e) {
- throw new RuntimeException(e);
- } finally {
- if (success)
- statement.getConnection().cleanUp();
- else
- statement.getConnection().errorCleanUp();
- }
- }
-
- protected DataObject buildGraph(ResultSet result) throws SQLException {
-
- List results = new ArrayList();
- results.add(result);
-
- // Before we use the mappingModel, do some checking/updating. If
- // inferrable information
- // isn't specified, add it in.
-
-
- GraphBuilderMetadata gbmd = new GraphBuilderMetadata(results,
- getSchema(), configWrapper.getConfig(),
resultSetShape);
-
- DataGraph g = createEDataGraph(gbmd.getSchema());
- ChangeSummary summary = g.getChangeSummary();
-
- ResultSetProcessor rsp = new
ResultSetProcessor(g.getRootObject(), gbmd);
- rsp.processResults(getStartRow(), getEndRow());
-
- summary.beginLogging();
-
- return g.getRootObject();
- }
-
- private Type getSchema() {
- return (Type) schema;
- }
-
- protected int getStartRow() {
- return startRow;
- }
-
- protected int getEndRow() {
- return endRow;
- }
-
- protected void setStartRow(int startRow) {
- this.startRow = startRow;
- }
-
- protected void setEndRow(int endRow) {
- this.endRow = endRow;
- }
-
- private DataGraph createEDataGraph(Type type) {
-
- DataGraph g = SDOUtil.createDataGraph();
-
- // Create a ResourceSet to contain the DataGraph
- ResourceSet resourceSet = DataObjectUtil.createResourceSet();
-
- // Create a Resource to hold the schema
-
- Resource r =
resourceSet.createResource(URI.createURI(type.getURI()));
- r.getContents().add(g);
-
- // Create the root object
- g.createRootObject(type);
-
- return g;
- }
-
- private void setMappingModel(Config mapping) {
- configWrapper = new MappingWrapper(mapping);
- }
-
- public void setMappingModel(InputStream stream) {
-
- SDOUtil.registerStaticTypes(ConfigFactory.class);
- XMLHelper helper = XMLHelper.INSTANCE;
-
-// ExtendedMetaData metadata = ExtendedMetaData.INSTANCE;
-// metadata.putPackage(null, ConfigPackageImpl.eINSTANCE);
-
- try {
- Config config = (Config)
helper.load(stream).getRootObject();
- configWrapper = new MappingWrapper(config);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
-
-
- if (configWrapper.getConfig().getConnectionProperties() != null)
-
setConnection(configWrapper.getConfig().getConnectionProperties());
-
- }
-
- public void setConnection(ConnectionProperties c) {
- try {
- Connection connection = null;
- Class.forName(c.getDriverClassName());
- if (c.getDriverUserName() == null)
- connection =
DriverManager.getConnection(c.getDriverURL());
- else
- connection =
DriverManager.getConnection(c.getDriverURL(), c
- .getDriverUserName(),
c.getDriverPassword());
- connection.setAutoCommit(false);
- setConnection(connection);
- } catch (Exception ex) {
- throw new RuntimeException(ex);
- }
- }
-
- public void setDataObjectModel(Type schema) {
- this.schema = schema;
- }
-
- protected void enablePaging() {
- statement.enablePaging();
- }
+ public ReadCommandImpl(String sqlString) {
+ super(sqlString);
+ }
+
+ public ReadCommandImpl(String sqlString, Config mapping) {
+ this(sqlString);
+ if (mapping != null)
+ setMappingModel(mapping);
+ }
+
+ public void execute() {
+ throw new UnsupportedOperationException();
+ }
+
+ public DataObject executeQuery() {
+
+ if (statement.getConnection() == null)
+ throw new RuntimeException("A DASConnection object must be
specified before executing the query.");
+
+ boolean success = false;
+ try {
+ ResultSet rs = statement.executeQuery(parameters);
+ success = true;
+ return buildGraph(rs);
+ } catch (SQLException e) {
+ throw new RuntimeException(e);
+ } finally {
+ if (success)
+ statement.getConnection().cleanUp();
+ else
+ statement.getConnection().errorCleanUp();
+ }
+ }
+
+ protected DataObject buildGraph(ResultSet result) throws SQLException {
+
+ List results = new ArrayList();
+ results.add(result);
+
+ // Before we use the mappingModel, do some checking/updating. If
+ // inferrable information
+ // isn't specified, add it in.
+
+ GraphBuilderMetadata gbmd = new GraphBuilderMetadata(results,
getSchema(), configWrapper.getConfig(),
+ resultSetShape);
+
+ DataGraph g = createEDataGraph(gbmd.getSchema());
+ ChangeSummary summary = g.getChangeSummary();
+
+ ResultSetProcessor rsp = new ResultSetProcessor(g.getRootObject(),
gbmd);
+ rsp.processResults(getStartRow(), getEndRow());
+
+ summary.beginLogging();
+
+ return g.getRootObject();
+ }
+
+ private Type getSchema() {
+ return (Type) schema;
+ }
+
+ protected int getStartRow() {
+ return startRow;
+ }
+
+ protected int getEndRow() {
+ return endRow;
+ }
+
+ protected void setStartRow(int startRow) {
+ this.startRow = startRow;
+ }
+
+ protected void setEndRow(int endRow) {
+ this.endRow = endRow;
+ }
+
+ private DataGraph createEDataGraph(Type type) {
+
+ DataGraph g = SDOUtil.createDataGraph();
+
+ // Create a ResourceSet to contain the DataGraph
+ ResourceSet resourceSet = DataObjectUtil.createResourceSet();
+
+ // Create a Resource to hold the schema
+
+ Resource r = resourceSet.createResource(URI.createURI(type.getURI()));
+ r.getContents().add(g);
+
+ // Create the root object
+ g.createRootObject(type);
+
+ return g;
+ }
+
+ private void setMappingModel(Config config) {
+ configWrapper = new MappingWrapper(config);
+ if (config.getConnectionProperties() != null)
+ setConnection(config.getConnectionProperties());
+ }
+
+ public void setConnection(ConnectionProperties c) {
+ try {
+ Connection connection = null;
+ Class.forName(c.getDriverClassName());
+ if (c.getDriverUserName() == null)
+ connection = DriverManager.getConnection(c.getDriverURL());
+ else
+ connection = DriverManager.getConnection(c.getDriverURL(),
c.getDriverUserName(), c
+ .getDriverPassword());
+ connection.setAutoCommit(false);
+ setConnection(connection);
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+
+ public void setDataObjectModel(Type schema) {
+ this.schema = schema;
+ }
+
+ protected void enablePaging() {
+ statement.enablePaging();
+ }
}
Modified:
incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/SPCommandImpl.java
URL:
http://svn.apache.org/viewcvs/incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/SPCommandImpl.java?rev=395330&r1=395329&r2=395330&view=diff
==============================================================================
---
incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/SPCommandImpl.java
(original)
+++
incubator/tuscany/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/SPCommandImpl.java
Wed Apr 19 11:08:03 2006
@@ -16,7 +16,6 @@
*/
package org.apache.tuscany.das.rdb.impl;
-import java.io.InputStream;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -28,10 +27,6 @@
public SPCommandImpl(String sqlString) {
super(sqlString);
- }
-
- public SPCommandImpl(String sqlString, InputStream modelStream) {
- super(sqlString, modelStream);
}
public DataObject executeQuery() {