diff options
Diffstat (limited to 'tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl')
32 files changed, 0 insertions, 3074 deletions
diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ApplyChangesCommandImpl.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ApplyChangesCommandImpl.java deleted file mode 100644 index 79baf3c299..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ApplyChangesCommandImpl.java +++ /dev/null @@ -1,111 +0,0 @@ -/** - * - * 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.sql.Connection; -import java.sql.DriverManager; - -import org.apache.tuscany.das.rdb.ApplyChangesCommand; -import org.apache.tuscany.das.rdb.Command; -import org.apache.tuscany.das.rdb.config.Config; -import org.apache.tuscany.das.rdb.config.ConnectionProperties; -import org.apache.tuscany.das.rdb.config.wrapper.MappingWrapper; -import org.apache.tuscany.das.rdb.util.DebugUtil; - -import commonj.sdo.DataObject; -import commonj.sdo.Type; - -/** - * - */ -public class ApplyChangesCommandImpl extends BaseCommandImpl implements ApplyChangesCommand { - - private static final boolean debug = false; - - private ChangeSummarizer summarizer = new ChangeSummarizer(); - - public ApplyChangesCommandImpl() { - } - - public ApplyChangesCommandImpl(Config config){ - this.configWrapper = new MappingWrapper(config); - if (config.getConnectionProperties() != null) - setConnection(config.getConnectionProperties()); - } - - public ApplyChangesCommandImpl(Config config, Connection connection){ - this.configWrapper = new MappingWrapper(config); - setConnection(connection); - } - - public void setConnection(ConnectionImpl connection) { - summarizer.setConnection(connection); - } - - 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 addCreateCommand(Type type, Command cmd) { - summarizer.addCreateCommand(type, cmd); - } - - public void addUpdateCommand(Type type, Command cmd) { - summarizer.addUpdateCommand(type, cmd); - } - - public void addDeleteCommand(Type type, Command cmd) { - summarizer.addDeleteCommand(type, cmd); - } - - public void execute(DataObject root) { - DebugUtil.debugln(getClass(), debug, "Executing ApplyChangesCmd"); - - if (summarizer.getConnection() == null) - throw new RuntimeException("A connection must be provided"); - - if (!root.equals(root.getDataGraph().getRootObject())) - throw new RuntimeException("'root' argument must be the root of the datagraph"); - - summarizer.setMapping(configWrapper); - - Changes changes = summarizer.loadChanges(root); - - boolean success = false; - try { - changes.execute(); - success = true; - } finally { - if (success) - summarizer.getConnection().cleanUp(); - else - summarizer.getConnection().errorCleanUp(); - } - } - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/BaseCommandImpl.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/BaseCommandImpl.java deleted file mode 100644 index e827426383..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/BaseCommandImpl.java +++ /dev/null @@ -1,68 +0,0 @@ -/** - * - * 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.sql.Connection; - -import org.apache.tuscany.das.rdb.Key; -import org.apache.tuscany.das.rdb.config.wrapper.MappingWrapper; - -public abstract class BaseCommandImpl { - - 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); - } - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ChangeFactory.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ChangeFactory.java deleted file mode 100644 index c56c55c636..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ChangeFactory.java +++ /dev/null @@ -1,199 +0,0 @@ -/** -* -* 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.util.Iterator; - -import org.apache.tuscany.das.rdb.SDODataTypes; -import org.apache.tuscany.das.rdb.config.Table; -import org.apache.tuscany.das.rdb.config.wrapper.MappingWrapper; -import org.apache.tuscany.das.rdb.config.wrapper.TableWrapper; -import org.apache.tuscany.das.rdb.generator.impl.CudGenerator; -import org.apache.tuscany.das.rdb.util.DebugUtil; - -import commonj.sdo.DataObject; -import commonj.sdo.Property; -import commonj.sdo.Type; - -public class ChangeFactory { - - private final Type type; - - private InsertCommandImpl createCommand; - - private UpdateCommandImpl updateCommand; - - private DeleteCommandImpl deleteCommand; - - private static final boolean debug = false; - - private CudGenerator cudGenerator; - - private final MappingWrapper mapping; - - private final ConnectionImpl connection; - - public ChangeFactory(Type type, MappingWrapper mapping, ConnectionImpl connection) { - this.type = type; - this.mapping = mapping; - this.connection = connection; - } - - public Type getType() { - return this.type; - } - - public void setCreateCommand(InsertCommandImpl cmd) { - createCommand = cmd; - } - - public void setUpdateCommand(UpdateCommandImpl cmd) { - DebugUtil.debugln(getClass(), debug, "Setting Update Command to " + cmd); - updateCommand = cmd; - } - - public void setDeleteCommand(DeleteCommandImpl cmd) { - deleteCommand = cmd; - } - - private CudGenerator getCudGenerator() { - if (this.cudGenerator == null) - this.cudGenerator = new CudGenerator(); - return this.cudGenerator; - } - - ChangeOperation createUpdateOperation(DataObject changedObject, String propagatedID) { - return new UpdateOperation(getUpdateCommand(changedObject), changedObject, propagatedID); - } - ChangeOperation createUpdateOperation(DataObject changedObject) { - return createUpdateOperation(changedObject, null); - } - - ChangeOperation createDeleteOperation(DataObject changedObject) { - return new DeleteOperation(getDeleteCommand(changedObject), changedObject); - } - - ChangeOperation createInsertOperation(DataObject changedObject, String propagatedID) { - return new CreateOperation(getCreateCommand(changedObject), changedObject, propagatedID); - } - - ChangeOperation createInsertOperation(DataObject changedObject) { - return createInsertOperation(changedObject, null); - } - - - private InsertCommandImpl getCreateCommand(DataObject changedObject) { - - if ( createCommand == null ) { - Table table = mapping.getTableByPropertyName(changedObject.getType().getName()); - if (table == null ) { - if (changedObject.getType().getProperty("ID") != null ) { - // If the table is not defined in the config, assume it has a primary key of "ID" - mapping.addPrimaryKey(changedObject.getType().getName() + ".ID"); - table = mapping.getTableByPropertyName(changedObject.getType().getName()); - } else { - throw new RuntimeException("Table " + changedObject.getType().getName() + " was changed in the DataGraph but is not present in the Config"); - } - } - - - String createStatement = table.getCreate(); - if ( createStatement == null ) { - createCommand = getCudGenerator().getInsertCommand(mapping, changedObject, table); - } else { - createCommand = new InsertCommandImpl(createStatement); - Iterator i = getCudGenerator().getCreateParameters(mapping, changedObject, table).iterator(); - while (i.hasNext()) { - Property p = (Property)i.next(); - createCommand.addParameter(p.getName(), p.getType()); - } - } - createCommand.setConnection(connection); - createCommand.configWrapper = mapping; - } - return createCommand; - } - - private DeleteCommandImpl getDeleteCommand(DataObject changedObject) { - - if ( deleteCommand == null ) { - Table table = mapping.getTableByPropertyName(changedObject.getType().getName()); - if (table == null ) { - if (changedObject.getType().getProperty("ID") != null ) { - // If the table is not defined in the config, assume it has a primary key of "ID" - mapping.addPrimaryKey(changedObject.getType().getName() + ".ID"); - table = mapping.getTableByPropertyName(changedObject.getType().getName()); - } else { - throw new RuntimeException("Table " + changedObject.getType().getName() + " was changed in the DataGraph but is not present in the Config"); - } - } - - String deleteStatement = table.getDelete(); - if ( deleteStatement == null ) { - deleteCommand = getCudGenerator().getDeleteCommand(table); - } else { - deleteCommand = new DeleteCommandImpl(deleteStatement); - Iterator i = getCudGenerator().getDeleteParameters(table).iterator(); - while (i.hasNext()) { - deleteCommand.addParameter((String)i.next(), SDODataTypes.OBJECT); - } - } - deleteCommand.setConnection(connection); - } - return deleteCommand; - } - - private UpdateCommandImpl getUpdateCommand(DataObject changedObject) { - - if ( updateCommand == null ) { - Table table = mapping.getTableByPropertyName(changedObject.getType().getName()); - if (table == null ) { - if (changedObject.getType().getProperty("ID") != null ) { - // If the table is not defined in the config, assume it has a primary key of "ID" - mapping.addPrimaryKey(changedObject.getType().getName() + ".ID"); - table = mapping.getTableByPropertyName(changedObject.getType().getName()); - } else { - throw new RuntimeException("Table " + changedObject.getType().getName() + " was changed in the DataGraph but is not present in the Config"); - } - } - String updateStatement = table.getUpdate(); - if ( updateStatement == null ) { - updateCommand = getCudGenerator().getUpdateCommand(mapping, changedObject,table); - } else { - TableWrapper t = new TableWrapper(table); - if ( t.getCollisionColumn() != null ) - updateCommand = new OptimisticWriteCommandImpl(updateStatement); - else - updateCommand = new UpdateCommandImpl(updateStatement); - - - updateCommand.addParameters(getCudGenerator().getUpdateParameters(changedObject, table)); - - } - updateCommand.setConnection(connection); - updateCommand.configWrapper = mapping; - } - DebugUtil.debugln(getClass(), debug, "Returning updateCommand: " + updateCommand); - return updateCommand; - } - - public MappingWrapper getConfig() { - return this.mapping; - } - - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ChangeOperation.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ChangeOperation.java deleted file mode 100644 index c5221dda5c..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ChangeOperation.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * - * 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.util.Iterator; - -import org.apache.tuscany.das.rdb.Parameter; -import org.apache.tuscany.das.rdb.util.DebugUtil; - -import commonj.sdo.DataObject; - -/** - */ -public abstract class ChangeOperation { - - private final WriteCommandImpl writeCommand; - - protected DatabaseObject dObject; - - private static final boolean debug = false; - - protected String propagatedID = null; - - private boolean isInsert = false; - - public ChangeOperation(DeleteCommandImpl command) { - writeCommand = command; - } - - public ChangeOperation(InsertCommandImpl command, DataObject changedObject) { - writeCommand = command; - dObject = new DatabaseObject(command.getMappingModel(), changedObject); - this.isInsert = true; - } - - public ChangeOperation(UpdateCommandImpl command, DataObject changedObject) { - writeCommand = command; - dObject = new DatabaseObject(command.getMappingModel(), changedObject); - } - - public void execute() { - DebugUtil.debugln(getClass(), debug, "Executing change operation"); - - Iterator i = writeCommand.getParameters().iterator(); - while (i.hasNext()) { - Parameter parm = (Parameter) i.next(); - DebugUtil.debugln(getClass(), debug, "setting " + parm.getName() + " to " + dObject.get(parm.getName())); - parm.setValue(dObject.get(parm.getName())); - } - - writeCommand.execute(); - - if ( isInsert && ( propagatedID != null )) { - DebugUtil.debugln(getClass(), debug, "Propagating key " + propagatedID); - int id = writeCommand.getGeneratedKey(); - dObject.setPropagatedID(propagatedID, id); - } - } - - public String getTableName() { - return dObject.getTableName(); - } - - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ChangeSummarizer.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ChangeSummarizer.java deleted file mode 100644 index 10984d9d4b..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ChangeSummarizer.java +++ /dev/null @@ -1,266 +0,0 @@ -/** -* -* 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.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; - -import org.apache.tuscany.das.rdb.Command; -import org.apache.tuscany.das.rdb.Key; -import org.apache.tuscany.das.rdb.config.Column; -import org.apache.tuscany.das.rdb.config.Relationship; -import org.apache.tuscany.das.rdb.config.Table; -import org.apache.tuscany.das.rdb.config.wrapper.MappingWrapper; -import org.apache.tuscany.das.rdb.config.wrapper.QualifiedColumn; -import org.apache.tuscany.das.rdb.config.wrapper.RelationshipWrapper; -import org.apache.tuscany.das.rdb.config.wrapper.TableWrapper; -import org.apache.tuscany.das.rdb.util.DebugUtil; -import org.apache.tuscany.sdo.impl.ChangeSummaryImpl; - -import commonj.sdo.ChangeSummary; -import commonj.sdo.DataObject; -import commonj.sdo.Property; -import commonj.sdo.Type; - -public class ChangeSummarizer { - - private static final boolean debug = false; - - private Changes changes = new Changes(); - - private FactoryRegistry registry; - - private MappingWrapper mapping = new MappingWrapper(); - - private ConnectionImpl connection; - - private HashMap generatedKeys = new HashMap(); - - public ChangeSummarizer() { - // Empty Constructor - } - - public Changes loadChanges(DataObject root) { - ChangeSummary changeSummary = root.getDataGraph().getChangeSummary(); - if (changeSummary.isLogging()) - ((ChangeSummaryImpl) changeSummary).summarize(); - - List changedObjects = changeSummary.getChangedDataObjects(); - DebugUtil.debugln(getClass(), debug, - "List of changed objects contains " + changedObjects.size() - + " object(s)"); - - changes.setInsertOrder(mapping.getInsertOrder()); - changes.setDeleteOrder(mapping.getDeleteOrder()); - - Iterator i = changedObjects.iterator(); - while (i.hasNext()) { - DataObject o = (DataObject) i.next(); - - if (!(o.equals(root))) { - createChange(changeSummary, o); - } - } - - return changes; - } - - public void createChange(ChangeSummary changeSummary, - DataObject changedObject) { - - if (changeSummary.isCreated(changedObject)) { - DebugUtil.debugln(getClass(), debug, "Change is a create"); - if (!changeSummary.isDeleted(changedObject)) { - ChangeFactory factory = getRegistry().getFactory( - changedObject.getType()); - String propagatedID = (String) generatedKeys.get(changedObject - .getType().getName()); - changes.addInsert(factory.createInsertOperation(changedObject, - propagatedID)); - } - } else if (changeSummary.isDeleted(changedObject)) { - ChangeFactory factory = getRegistry().getFactory( - changedObject.getType()); - DebugUtil.debugln(getClass(), debug, "Change is a delete"); - changes.addDelete(factory.createDeleteOperation(changedObject)); - } else { - // bumpCollisionField(changedObject); - DebugUtil.debugln(getClass(), debug, "Change is a modify"); - List attrList = changeSummary.getOldValues(changedObject); - if (hasAttributeChange(attrList)) { - ChangeFactory factory = getRegistry().getFactory( - changedObject.getType()); - DebugUtil.debugln(getClass(), debug, "Attribute Change for " - + changedObject.getType().getName()); - String propagatedID = (String) generatedKeys.get(changedObject - .getType().getName()); - changes.addUpdate(factory.createUpdateOperation(changedObject, - propagatedID)); - } else { - // Reference change - List values = changeSummary.getOldValues(changedObject); - Iterator i = values.iterator(); - while (i.hasNext()) { - ChangeSummary.Setting setting = (ChangeSummary.Setting) i - .next(); - - if (!setting.getProperty().getType().isDataType()) { - DebugUtil.debugln(getClass(), debug, - "Reference change for " - + changedObject.getType().getName()); - - Property ref = setting.getProperty(); - - DebugUtil.debugln(getClass(), debug, ref.getName()); - if (hasState(ref, changedObject) ) { - ChangeFactory factory = getRegistry().getFactory( - changedObject.getType()); - changes.addUpdate(factory - .createUpdateOperation(changedObject)); - } - - } - } - } - } - - } - - private boolean hasState(Property ref, DataObject changedObject) { - if ( ref.getOpposite().isMany() ) { - return true; - } else { - MappingWrapper mw = this.mapping; - if ( mw.getConfig() == null ) - mw = registry.getFactory(changedObject.getType()).getConfig(); - if ( mw.getConfig() == null ) - return false; - - Relationship rel = mw.getRelationshipByReference(ref); - - if ( !rel.isMany()) { - // This is a one-one relationship - Table t = mapping.getTableByPropertyName(changedObject.getType().getName()); - TableWrapper tw = new TableWrapper(t); - RelationshipWrapper rw = new RelationshipWrapper(rel); - if (( rel.getForeignKeyTable().equals(t.getName())) && - ( Collections.disjoint(tw.getPrimaryKeyProperties(),rw.getForeignKeys()) )) - return true; - - } - - } - return false; - } - - private boolean hasAttributeChange(List theChanges) { - Iterator i = theChanges.iterator(); - while (i.hasNext()) { - ChangeSummary.Setting setting = (ChangeSummary.Setting) i.next(); - if (setting.getProperty().getType().isDataType()) - return true; - } - return false; - } - - public void addCreateCommand(Type type, Command cmd) { - ChangeFactory cf = getRegistry().getFactory(type); - cf.setCreateCommand((InsertCommandImpl) cmd); - ((CommandImpl) cmd).setConnection(connection); - } - - public void addUpdateCommand(Type type, Command cmd) { - ChangeFactory cf = getRegistry().getFactory(type); - cf.setUpdateCommand((UpdateCommandImpl) cmd); - ((CommandImpl) cmd).setConnection(connection); - } - - public void addDeleteCommand(Type type, Command cmd) { - ChangeFactory cf = getRegistry().getFactory(type); - cf.setDeleteCommand((DeleteCommandImpl) cmd); - ((CommandImpl) cmd).setConnection(connection); - - } - - private FactoryRegistry getRegistry() { - if (this.registry == null) { - this.registry = new FactoryRegistry(mapping, connection); - } - return this.registry; - } - - public void setConnection(ConnectionImpl connection) { - this.connection = connection; - } - - public void setMapping(MappingWrapper map) { - this.mapping = map; - - if ( mapping.getConfig() == null ) - return; - - Iterator i = mapping.getConfig().getTable().iterator(); - while (i.hasNext()) { - Table t = (Table) i.next(); - Iterator columns = t.getColumn().iterator(); - while ( columns.hasNext()) { - Column c = (Column) columns.next(); - if ( c.isPrimaryKey() && c.isGenerated()) { - DebugUtil.debugln(getClass(), debug, "adding generated key " - + t.getName() + "." - + c.getName()); - generatedKeys.put(t.getName(), c.getName()); - } - } - } - } - - public void addRelationship(String parentName, String childName) { - mapping.addRelationship(parentName, childName); - } - - public void addPrimaryKey(String columnName) { - mapping.addPrimaryKey(columnName); - } - - public void addCollisionColumn(String columnName) { - mapping.addCollisionColumn(columnName); - } - - public void addPrimarykey(Key key) { - mapping.addPrimaryKey(key); - } - - public void addGeneratedPrimaryKey(String columnName) { - QualifiedColumn col = new QualifiedColumn(columnName); - generatedKeys.put(col.getTableName(), col.getColumnName()); - mapping.addGeneratedPrimaryKey(columnName); - } - - public void addConverter(String name, String converterName) { - mapping.addConverter(name, converterName); - } - - public ConnectionImpl getConnection() { - return this.connection; - } - - - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Changes.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Changes.java deleted file mode 100644 index 77198fe589..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Changes.java +++ /dev/null @@ -1,80 +0,0 @@ -/** - * - * 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.util.ArrayList; -import java.util.Iterator; - -/** - * Mangages a set of graph-change operations. This simple implementaiton can be - * replaced with a version that provides R/I sorting - * - */ -public class Changes { - - private InsertList inserts = new InsertList(); - private UpdateList updates = new UpdateList(); - private DeleteList deletes = new DeleteList(); - - - public void addInsert(ChangeOperation c) { - inserts.add(c); - } - - public void addUpdate(ChangeOperation c) { - updates.add(c); - } - - public void addDelete(ChangeOperation c) { - deletes.add(c); - } - - /** - * Execute all my change - */ - public void execute() { - - Iterator i = inserts.getSortedList().iterator(); - while ( i.hasNext() ) { - ChangeOperation c = (ChangeOperation) i.next(); - c.execute(); - } - - i = updates.getSortedList().iterator(); - while ( i.hasNext() ) { - ChangeOperation c = (ChangeOperation) i.next(); - c.execute(); - } - - - i = deletes.getSortedList().iterator(); - while (i.hasNext() ) { - ChangeOperation c = (ChangeOperation) i.next(); - c.execute(); - } - - } - - public void setInsertOrder(ArrayList insertOrder) { - inserts.setOrder(insertOrder); - } - - public void setDeleteOrder(ArrayList deleteOrder) { - deletes.setOrder(deleteOrder); - } - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CommandFactoryImpl.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CommandFactoryImpl.java deleted file mode 100644 index 25c2223f13..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CommandFactoryImpl.java +++ /dev/null @@ -1,77 +0,0 @@ -/** - * - * 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 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.util.ConfigUtil; - -public class CommandFactoryImpl implements CommandFactory { - - public Command createCommand(String sql) { - return baseCreateCommand(sql, null); - } - - public Command createCommand(String sql, InputStream configStream) { - return baseCreateCommand(sql, ConfigUtil.loadConfig(configStream)); - } - - public Command createCommand(String sql, Config config) { - return baseCreateCommand(sql, config); - } - - public ApplyChangesCommand createApplyChangesCommand() { - return new ApplyChangesCommandImpl(); - } - - public ApplyChangesCommand createApplyChangesCommand(InputStream configStream) throws IOException { - return new ApplyChangesCommandImpl(ConfigUtil.loadConfig(configStream)); - } - - public ApplyChangesCommand createApplyChangesCommand(Config config) { - return new ApplyChangesCommandImpl(config); - } - - // 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, config); - default: - throw new Error("SQL => " + sql + " is not valid"); - } - - } - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CommandGroupFactoryImpl.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CommandGroupFactoryImpl.java deleted file mode 100644 index 196751857e..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CommandGroupFactoryImpl.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * - * 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.InputStream; - -import org.apache.tuscany.das.rdb.CommandGroup; -import org.apache.tuscany.das.rdb.CommandGroupFactory; - -public class CommandGroupFactoryImpl implements CommandGroupFactory { - - - public CommandGroup createCommandGroup(InputStream configStream) { - return new CommandGroupImpl(configStream); - } - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CommandGroupImpl.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CommandGroupImpl.java deleted file mode 100644 index aeaf3a7c57..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CommandGroupImpl.java +++ /dev/null @@ -1,207 +0,0 @@ -/** - * - * 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.InputStream; -import java.sql.Connection; -import java.sql.DriverManager; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Map; - -import javax.naming.InitialContext; -import javax.naming.NamingException; -import javax.sql.DataSource; - -import org.apache.tuscany.das.rdb.ApplyChangesCommand; -import org.apache.tuscany.das.rdb.Command; -import org.apache.tuscany.das.rdb.CommandGroup; -import org.apache.tuscany.das.rdb.config.Config; -import org.apache.tuscany.das.rdb.config.ConnectionProperties; -import org.apache.tuscany.das.rdb.util.ConfigUtil; - -/** - * An ConfiguredCommandFactory produces instances of Command and - * ApplyChangesCommand. This factory is initialized with a configuration that - * defines the commands it produces. - * - */ -public class CommandGroupImpl implements CommandGroup { - - private Config config; - - private Connection connection; - - private Map commands = new HashMap(); - - public CommandGroupImpl(InputStream stream) { - super(); - config = ConfigUtil.loadConfig(stream); - initialize(); - } - - private void initialize() { - - Iterator i = config.getCommand().iterator(); - while (i.hasNext()) { - org.apache.tuscany.das.rdb.config.Command commandConfig = (org.apache.tuscany.das.rdb.config.Command) i - .next(); - String kind = commandConfig.getKind(); - if (kind.equalsIgnoreCase("select")) - //TODO - Need to refactor Command heirarchy based on Datasource - if (config.getConnectionProperties() != null) - commands.put(commandConfig.getName(), new ReadCommandImpl(commandConfig.getSQL(), config, getConnection())); - else - commands.put(commandConfig.getName(), new ReadCommandImpl(commandConfig.getSQL(), config)); - else if (kind.equalsIgnoreCase("update")) - commands.put(commandConfig.getName(), new UpdateCommandImpl(commandConfig.getSQL())); - else if (kind.equalsIgnoreCase("insert")) - commands.put(commandConfig.getName(), new InsertCommandImpl(commandConfig.getSQL())); - else if (kind.equalsIgnoreCase("delete")) - commands.put(commandConfig.getName(), new DeleteCommandImpl(commandConfig.getSQL())); - else - throw new Error("Invalid kind of command: " + kind); - - } - - } - - /* - * (non-Javadoc) - * - * @see org.apache.tuscany.das.rdb.CommandGroup#getApplyChangesCommand() - */ - public ApplyChangesCommand getApplyChangesCommand() { - ApplyChangesCommand cmd = new ApplyChangesCommandImpl(config, connection); - return cmd; - } - - /* - * (non-Javadoc) - * - * @see org.apache.tuscany.das.rdb.CommandGroup#getCommand(java.lang.String) - */ - public Command getCommand(String name) { - if (!commands.containsKey(name)) - throw new RuntimeException("CommandGroup has no command named: " + name); - Command cmd = (Command) commands.get(name); - cmd.setConnection(getConnection()); - return cmd; - } - - - public void setConnection(Connection connection) { - this.connection = connection; - } - - public Connection getConnection() { - if (connection == null) - initializeConnection(); - return connection; - } - - private void initializeConnection() { - - ConnectionProperties cp = config.getConnectionProperties(); - if (cp == null) - throw new Error( - "No connection properties have been configured and no connection has been provided"); - - if (cp.getDataSource() != null) - initViaDataSource(cp); - else - initViaDriverManager(cp); - - } - - private void initViaDriverManager(ConnectionProperties cp) { - Connection connection = null; - - try { - Class.forName(cp.getDriverClassName()); - if (cp.getDriverUserName() == null) - connection = DriverManager.getConnection(cp.getDriverURL()); - else - connection = DriverManager.getConnection(cp.getDriverURL(), cp.getDriverUserName(), cp - .getDriverPassword()); - connection.setAutoCommit(false); - setConnection(connection); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - - } - - // TODO - Refactor to eliminate common initialization code after connection - // is got - private void initViaDataSource(ConnectionProperties cp) { - - Connection connection = null; - - InitialContext ctx; - try { - ctx = new InitialContext(); - } catch (NamingException e) { - throw new Error(e); - } - try { - // TODO - I think we should rename this getDataSourceURL? - DataSource ds = (DataSource) ctx.lookup(cp.getDataSource()); - try { - connection = ds.getConnection(); - connection.setAutoCommit(false); - setConnection(connection); - } catch (SQLException e) { - throw new Error(e); - } - } catch (NamingException e) { - throw new Error(e); - } - - } - - public void releaseResources() { - - if (managingConnections()) - closeConnection(); - } - - private void closeConnection() { - if (connection != null) - try { - connection.close(); - connection = null; - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - /** - * If the config has connection properties then we are "manageing" the - * connection via DriverManager or DataSource - */ - private boolean managingConnections() { - - if (config.getConnectionProperties() == null) - return false; - else - return true; - - } - -}
\ No newline at end of file diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CommandImpl.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CommandImpl.java deleted file mode 100644 index 2ac9e324da..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CommandImpl.java +++ /dev/null @@ -1,145 +0,0 @@ -/** - * - * 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.net.URL; -import java.util.List; - -import org.apache.tuscany.das.rdb.Command; -import org.apache.tuscany.das.rdb.Parameter; -import org.apache.tuscany.das.rdb.ResultSetShape; - -import commonj.sdo.DataObject; -import commonj.sdo.Type; -import commonj.sdo.helper.XSDHelper; - -public abstract class CommandImpl extends BaseCommandImpl implements Command { - - protected Statement statement; - - protected Parameters parameters = new Parameters(); - - protected static final boolean debug = false; - - protected ResultSetShape resultSetShape; - - public CommandImpl(String sqlString) { - statement = new Statement(sqlString); - - try { - URL url = getClass().getResource("/xml/sdoJava.xsd"); - if (url == null) - throw new RuntimeException( - "Could not find resource: xml/sdoJava.xsd"); - - InputStream inputStream = url.openStream(); - XSDHelper.INSTANCE.define(inputStream, url.toString()); - inputStream.close(); - } catch ( IOException ex ) { - throw new RuntimeException(ex); - } - - } - - public abstract void execute(); - - public abstract DataObject executeQuery(); - - public void setParameterValue(String name, Object value) { - parameters.setParameter(name, value); - } - - public void setParameterValue(int index, Object value) { - parameters.setParameter(index, value); - } - - public void setParameterType(String name, Type dataType) { - parameters.setParameterWithType(name, dataType); - } - - public void setParameterType(int index, Type dataType) { - parameters.setParameterWithType(index, dataType); - } - - public void addParameter(int index, Type sdoType) { - addParameter(index, Parameter.IN, sdoType); - } - - public void addParameter(int index, int direction, Type sdoType) { - parameters.findOrCreateParameterWithIndex(index, direction, sdoType); - } - - public void addParameter(String name, Type sdoType) { - addParameter(name, Parameter.IN, sdoType); - } - - public void addParameter(String name, int direction, Type sdoType) { - parameters.setParameterWithType(name, sdoType); - } - - public void addParameter(Parameter param) { - parameters.add(param); - } - - public Parameter getParameter(String name) { - return parameters.get(name); - } - - public Parameter getParameter(int index) { - return parameters.get(index); - - } - - public List getParameters() { - return parameters.parameterList(); - } - - public Object getParameterValue(String name) { - Parameter p = parameters.get(name); - if (p == null) - throw new RuntimeException("Parameter with name " + name - + " not found"); - - return p; - } - - public Object getParameterValue(int index) { - return parameters.parameterWithIndex(index).getValue(); - } - - public void setConnection(ConnectionImpl connection) { - statement.setConnection(connection); - } - - protected ConnectionImpl getConnection() { - return statement.getConnection(); - } - - - - public void setResultSetShape(ResultSetShape shape) { - this.resultSetShape = shape; - } - - - public void close() { - statement.close(); - } - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ConnectionImpl.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ConnectionImpl.java deleted file mode 100644 index 2da21bf930..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ConnectionImpl.java +++ /dev/null @@ -1,95 +0,0 @@ -/** - * - * 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.sql.CallableStatement; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; - -import org.apache.tuscany.das.rdb.util.DebugUtil; - - -public class ConnectionImpl { - - private Connection connection; - private static final boolean debug = false; - - private boolean managingTransaction = true; - - public ConnectionImpl(Connection connection) { - this.connection = connection; - - try { - if (connection.getAutoCommit()) - throw new RuntimeException("AutoCommit must be off!"); - } catch (SQLException e) { - throw new RuntimeException(e); - } - - } - - public Connection getJDBCConnection() { - return connection; - } - - public void cleanUp() { - try { - if (managingTransaction) { - DebugUtil.debugln(getClass(), debug, "Committing Transaction"); - connection.commit(); - } - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - public void errorCleanUp() { - try { - if (managingTransaction) { - DebugUtil.debugln(getClass(), debug, "Rolling back Transaction"); - connection.rollback(); - } - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - public PreparedStatement prepareStatement(QueryString queryString) - throws SQLException { - DebugUtil.debugln(getClass(), debug, "Preparing Statement: " + queryString.getPreparedString()); - return connection.prepareStatement(queryString.getPreparedString(), java.sql.Statement.RETURN_GENERATED_KEYS); - } - - public PreparedStatement preparePagedStatement(QueryString queryString) throws SQLException { - DebugUtil.debugln(getClass(), debug, "Preparing Statement: " + queryString.getPreparedString()); - return connection.prepareStatement(queryString.getPreparedString(), ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); - } - - public void setManageTransactions(boolean manageTransactions) { - managingTransaction = manageTransactions; - - } - - public CallableStatement prepareCall(QueryString queryString) throws SQLException { - return connection.prepareCall(queryString.getPreparedString()); - } - - - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CreateOperation.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CreateOperation.java deleted file mode 100644 index 5c70dc1e6f..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/CreateOperation.java +++ /dev/null @@ -1,29 +0,0 @@ -/** - * - * 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 commonj.sdo.DataObject; - -public class CreateOperation extends ChangeOperation { - - public CreateOperation(InsertCommandImpl command, DataObject changedObject, String ID) { - super(command, changedObject); - this.propagatedID = ID; - } - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/DatabaseObject.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/DatabaseObject.java deleted file mode 100644 index eaf56a6c2c..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/DatabaseObject.java +++ /dev/null @@ -1,148 +0,0 @@ -/** - * - * 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.util.HashMap; -import java.util.Iterator; -import java.util.List; - -import org.apache.tuscany.das.rdb.config.Column; -import org.apache.tuscany.das.rdb.config.Config; -import org.apache.tuscany.das.rdb.config.KeyPair; -import org.apache.tuscany.das.rdb.config.Relationship; -import org.apache.tuscany.das.rdb.config.Table; -import org.apache.tuscany.das.rdb.config.wrapper.MappingWrapper; -import org.apache.tuscany.das.rdb.util.DebugUtil; - -import commonj.sdo.DataObject; -import commonj.sdo.Property; - -/** - * DatabaseObject wraps DataObject. If a field is an FK field, it will return - * the value from the parent. - * - * - */ -public class DatabaseObject { - - private final MappingWrapper mappingWrapper; - - private final DataObject dataObject; - - private Property parentReference; - - private static final boolean debug = false; - - private HashMap keyMappings = new HashMap(); - - public DatabaseObject(Config model, DataObject changedObject) { - this.mappingWrapper = new MappingWrapper(model); - this.dataObject = changedObject; - initialize(); - } - - // Initialize Key Mappings - private void initialize() { - if (mappingWrapper.getConfig() != null) { - List relationships = mappingWrapper.getConfig().getRelationship(); - Iterator i = relationships.iterator(); - while (i.hasNext()) { - Relationship r = (Relationship) i.next(); - DebugUtil.debugln(getClass(), debug, "Initializing relationship: " + r.getName()); - if (r.getForeignKeyTable().equals(getTypeName())) { - List pairs = r.getKeyPair(); - Iterator iter = pairs.iterator(); - while (iter.hasNext()) { - KeyPair pair = (KeyPair) iter.next(); - keyMappings.put(pair.getForeignKeyColumn(), r); - } - } - } - } - } - - public Object get(String parameter) { - - if (isPartOfPrimaryKey(parameter)) - return dataObject.get(parameter); - - Relationship r = (Relationship) keyMappings.get(parameter); - if (r == null) - return dataObject.get(parameter); - - Property parentRef = getParentReference(r.getPrimaryKeyTable()); - DataObject parent = dataObject.getDataObject(parentRef); - if (parent == null) - return null; - String parentKey = getParentKey(r, parameter); - return parent.get(parentKey); - - } - - private String getParentKey(Relationship r, String parameter) { - List keyPairs = r.getKeyPair(); - Iterator i = keyPairs.iterator(); - while (i.hasNext()) { - KeyPair pair = (KeyPair) i.next(); - if (pair.getForeignKeyColumn().equals(parameter)) - return pair.getPrimaryKeyColumn(); - } - return null; - } - - public Property getParentReference(String parentName) { - if (this.parentReference == null) { - - Iterator i = dataObject.getType().getProperties().iterator(); - while (i.hasNext()) { - Property ref = (Property) i.next(); - if ((!ref.getType().isDataType()) && (ref.getType().getName().equals(parentName))) { - this.parentReference = ref; - } - } - } - return this.parentReference; - } - - public String getTableName() { - if (mappingWrapper.getConfig() != null) - return mappingWrapper.getTableByPropertyName(getTypeName()).getName(); - else - return null; - } - - public String getTypeName() { - return dataObject.getType().getName(); - } - - public void setPropagatedID(String propagatedID, int id) { - dataObject.setInt(propagatedID, id); - } - - private boolean isPartOfPrimaryKey(String parameter) { - if (mappingWrapper.getConfig() == null) - return false; - Table t = mappingWrapper.getTable(getTableName()); - if (t == null) - return false; - Column c = mappingWrapper.getColumnByPropertyName(t, parameter); - if (c == null) - return false; - return c.isPrimaryKey(); - } - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/DeleteCommandImpl.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/DeleteCommandImpl.java deleted file mode 100644 index 3502784b6f..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/DeleteCommandImpl.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * - * 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; - -public class DeleteCommandImpl extends WriteCommandImpl { - - public DeleteCommandImpl(String sqlString) { - super(sqlString); - } - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/DeleteList.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/DeleteList.java deleted file mode 100644 index 8650c6119c..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/DeleteList.java +++ /dev/null @@ -1,72 +0,0 @@ -/** - * - * 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.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; - -/** - * DeleteList will sort delete operations so that child objects are deleted - * before their parents - * - * - */ -public class DeleteList { - - private HashMap opsByTableName = new HashMap(); - - private ArrayList order; - - private ArrayList deleteOperations = new ArrayList(); - - public DeleteList() { - super(); - } - - public void add(ChangeOperation op) { - if (( order == null ) || ( op.getTableName() == null ) ) { - deleteOperations.add(op); - } else { - String name = op.getTableName(); - ArrayList ops = (ArrayList) opsByTableName.get(name); - if (ops == null) - ops = new ArrayList(); - - ops.add(op); - opsByTableName.put(name, ops); - } - } - - public Collection getSortedList() { - if (( order != null ) && ( opsByTableName.keySet().size() > 0) ) { - Iterator i = this.order.iterator(); - while (i.hasNext()) { - String name = (String) i.next(); - deleteOperations.addAll((Collection) opsByTableName.get(name)); - } - } - - return deleteOperations; - } - - public void setOrder(ArrayList deleteOrder) { - this.order = deleteOrder; - } - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/DeleteOperation.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/DeleteOperation.java deleted file mode 100644 index 7b71e0ace9..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/DeleteOperation.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * - * 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 org.apache.tuscany.das.rdb.util.DataObjectUtil; - -import commonj.sdo.DataObject; - -public class DeleteOperation extends ChangeOperation { - - - /** - * @param command - * @param changedObject - * Objects deleted from the graph have lost their "settings" and must - * be restored - */ - public DeleteOperation(DeleteCommandImpl command, DataObject changedObject) { - super(command); - this.dObject = new DatabaseObject(command.getMappingModel(),DataObjectUtil.getRestoredCopy(changedObject)); - - } - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/FactoryRegistry.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/FactoryRegistry.java deleted file mode 100644 index ce09c748f4..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/FactoryRegistry.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * - * 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.util.HashMap; - -import org.apache.tuscany.das.rdb.config.wrapper.MappingWrapper; -import org.apache.tuscany.das.rdb.util.DebugUtil; - -import commonj.sdo.Type; - -public class FactoryRegistry { - - private HashMap registry = new HashMap(); - private static final boolean debug = false; - private final MappingWrapper mapping; - private final ConnectionImpl connection; - - public FactoryRegistry(MappingWrapper mapping, ConnectionImpl connection) { - this.mapping = mapping; - this.connection = connection; - } - - public ChangeFactory getFactory(Type type) { - ChangeFactory factory = (ChangeFactory)registry.get(type); - if ( factory == null ) { - DebugUtil.debugln(getClass(), debug, "Creating new ChangeFactory for type " + type.getName()); - factory = new ChangeFactory(type, mapping, connection); - registry.put(type, factory); - } - return factory; - } - - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/InsertCommandImpl.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/InsertCommandImpl.java deleted file mode 100644 index 9c890c7106..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/InsertCommandImpl.java +++ /dev/null @@ -1,79 +0,0 @@ -/** - * - * 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.sql.SQLException; - -public class InsertCommandImpl extends WriteCommandImpl { - - private int generatedKey; - - private boolean hasGeneratedKey = false; - - public InsertCommandImpl(String sqlString) { - super(sqlString); - } - - protected boolean isInsert() { - return true; - } - - public int getGeneratedKey() { - - if (hasGeneratedKey) - return generatedKey; - - throw new RuntimeException("No generated key is available"); - } - - public Object getParameterValue(String name) { - - if (name.equals("generated_key")) - if (hasGeneratedKey) - return new Integer(generatedKey); - else - throw new RuntimeException("No generated key available"); - - return super.getParameterValue(name); - } - - protected void subtypeProcessing() throws SQLException { - loadGeneratedKey(); - } - - private void loadGeneratedKey() throws SQLException { - Integer key = statement.getGeneratedKey(); - if (key != null) { - hasGeneratedKey = true; - generatedKey = key.intValue(); - } - - } - - public String toString() { - - String superString = super.toString(); - StringBuffer buffer = new StringBuffer(superString); - - buffer.append("\nGenerating key: " + hasGeneratedKey); - if (hasGeneratedKey) - buffer.append("\nGenerated key: " + generatedKey); - - return buffer.toString(); - } - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/InsertList.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/InsertList.java deleted file mode 100644 index dee6546cfe..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/InsertList.java +++ /dev/null @@ -1,82 +0,0 @@ -/** - * - * 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.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; - -import org.apache.tuscany.das.rdb.util.DebugUtil; - -/** - * InsertList will sort ChangeOperation objects so that parents are inserted - * before children - * - * - */ -public class InsertList { - - private HashMap opsByTableName = new HashMap(); - - private ArrayList insertOperations = new ArrayList(); - - private ArrayList order; - - private static final boolean debug = false; - - public void add(ChangeOperation op) { - DebugUtil.debugln(getClass(), debug, "Adding insert operation "); - // If nothing has been added yet, or this is no ordering, simply - // add the operation to the list - if ((order.size() == 0) || (op.getTableName() == null)) { - insertOperations.add(op); - } else { - String name = op.getTableName(); - ArrayList ops = (ArrayList) opsByTableName.get(name); - if (ops == null) - ops = new ArrayList(); - - ops.add(op); - opsByTableName.put(name, ops); - } - } - - public Collection getSortedList() { - DebugUtil.debugln(getClass(), debug, "Getting sorted insert list"); - if ((order.size() > 0) && opsByTableName.keySet().size() > 0) { - Iterator i = this.order.iterator(); - while (i.hasNext()) { - String name = (String) i.next(); - DebugUtil.debugln(getClass(), debug, - "Adding operations for table " + name); - // A null here means a table is in the config but hasn't been changed here - if (opsByTableName.get(name) != null) - insertOperations.addAll((Collection) opsByTableName - .get(name)); - } - } - DebugUtil.debugln(getClass(), debug, "Returning " - + insertOperations.size() + " insert operations"); - return insertOperations; - } - - public void setOrder(ArrayList insertOrder) { - this.order = insertOrder; - } - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/OptimisticWriteCommandImpl.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/OptimisticWriteCommandImpl.java deleted file mode 100644 index 22ff822bb0..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/OptimisticWriteCommandImpl.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * - * 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.sql.SQLException; - -public class OptimisticWriteCommandImpl extends UpdateCommandImpl { - - public OptimisticWriteCommandImpl(String sqlString) { - super(sqlString); - } - - public void execute() { - - boolean success = false; - try { - int rowsAffected = statement.executeUpdate(parameters); - success = true; - if ( rowsAffected == 0 ) - throw new RuntimeException("OCC Exception"); - } catch (SQLException e) { - throw new RuntimeException(e); - } finally { - if (success) - statement.getConnection().cleanUp(); - else - statement.getConnection().errorCleanUp(); - } - - } -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/PagerImpl.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/PagerImpl.java deleted file mode 100644 index 32b17ef3e7..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/PagerImpl.java +++ /dev/null @@ -1,64 +0,0 @@ -/** - * - * 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 org.apache.tuscany.das.rdb.Command; -import org.apache.tuscany.das.rdb.Pager; - -import commonj.sdo.DataObject; - -public class PagerImpl implements Pager { - - private final ReadCommandImpl command; - private final int size; - private int idx = 1; - - public PagerImpl(Command command, int size) { - this.command = (ReadCommandImpl)command; - this.command.enablePaging(); - this.size = size; - } - - public DataObject next() { - int start = idx; - int end = idx + size; - idx += size; - command.setStartRow(start); - command.setEndRow(end); - return command.executeQuery(); - } - - public DataObject getPage(int page) { - int end = (page * size) + 1; - int start = end - size; - idx = end; - command.setStartRow(start); - command.setEndRow(end); - return command.executeQuery(); - } - - public DataObject previous() { - int start = idx - (2 * size); - if ( start < 1 ) - start = 1; - int end = start + size; - idx = end; - command.setStartRow(start); - command.setEndRow(end); - return command.executeQuery(); - } -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ParameterImpl.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ParameterImpl.java deleted file mode 100644 index 4528661b2c..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ParameterImpl.java +++ /dev/null @@ -1,107 +0,0 @@ -/** - * - * 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 org.apache.tuscany.das.rdb.Converter; -import org.apache.tuscany.das.rdb.Parameter; - -import commonj.sdo.Type; - -public class ParameterImpl implements Parameter { - - private int index; - private Type type; - private String name; - private Object value; - private int direction = IN; - private Converter converter; - - public ParameterImpl() { - super(); - } - - public ParameterImpl(String name) { - this.name = name; - } - - public ParameterImpl(int index) { - this.index = index; - } - - public void setType(Type type) { - this.type = type; - } - - public void setIndex(int index) { - if ( index == 0 ) - throw new RuntimeException("Index of zero not allowed"); - this.index = index; - } - - public void setName(String name) { - this.name = name; - } - - public void setValue(Object value) { - this.value = value; - } - - public void setDirection(int direction) { - this.direction = direction; - } - - public Type getType() { - return this.type; - } - - public int getIndex() { - return this.index; - } - - public String getName() { - return this.name; - } - - public Object getValue() { - if ( getConverter() != null ) { - return getConverter().getColumnValue(this.value); - } else { - return this.value; - } - } - - public int getDirection() { - return this.direction; - } - - public void setConverter(Converter converter) { - this.converter = converter; - } - - public Converter getConverter() { - return this.converter; - } - - - public String toString() { - StringBuffer buffer = new StringBuffer(); - buffer.append("Index: " + getIndex()); - buffer.append("\nName: " + getName()); - buffer.append("\nValue: " + getValue()); - return buffer.toString(); - } -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Parameters.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Parameters.java deleted file mode 100644 index 4ea42f41b2..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Parameters.java +++ /dev/null @@ -1,150 +0,0 @@ -/** - * - * 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.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; - -import org.apache.tuscany.das.rdb.Parameter; -import org.apache.tuscany.das.rdb.SDODataTypes; -import org.apache.tuscany.das.rdb.util.DebugUtil; - -import commonj.sdo.Type; - -public class Parameters { - - private ArrayList parameters = new ArrayList(); - - private ArrayList inParams = new ArrayList(); - - private ArrayList outParams = new ArrayList(); - - private HashMap parametersByName = new HashMap(); - - private static boolean debug = false; - - public Parameters() { - super(); - } - - public Parameter get(String name) { - return (Parameter) parametersByName.get(name); - } - - public Parameter get(int index) { - return (Parameter) parameters.get(index); - } - - public List outParams() { - return outParams; - } - - public List inParams() { - return inParams; - } - - private void addParameter(Parameter param) { - if (param.getDirection() == Parameter.IN) - inParams.add(param); - else if ((param.getDirection() == Parameter.OUT) - || (param.getDirection() == Parameter.IN_OUT)) - outParams.add(param); - - this.parameters.add(param); - parametersByName.put(param.getName(), param); - } - - public void add(Parameter param) { - addParameter(param); - } - - public Parameter findOrCreateParameterNamed(String name) { - Parameter param = get(name); - if (param == null) { - param = new ParameterImpl(name); - addParameter(param); - } - return param; - } - - public Parameter findOrCreateParameterWithIndex(int index, int direction, - Type sdoType) { - Iterator i = parameters.iterator(); - while (i.hasNext()) { - Parameter param = (Parameter) i.next(); - - if (param.getIndex() == index) - return param; - } - DebugUtil.debugln(getClass(), debug, - "Creating new parameter with index " + index); - Parameter newParam = new ParameterImpl(index); - newParam.setDirection(direction); - newParam.setType(sdoType); - addParameter(newParam); - return newParam; - } - - public List parameterList() { - return parameters; - } - - public Parameter findOrCreateParameterWithIndex(int index) { - return findOrCreateParameterWithIndex(index, Parameter.IN, - SDODataTypes.OBJECT); - } - - public void setParameter(int index, Object value) { - Parameter param = findOrCreateParameterWithIndex(index); - param.setValue(value); - } - - public void setParameter(String name, Object value) { - if (name == null) - throw new RuntimeException("Null parameter name not allowed"); - Parameter param = findOrCreateParameterNamed(name); - param.setValue(value); - } - - public void setParameterWithType(String name, Type sdoType) { - if (name == null) - throw new RuntimeException("Null parameter name not allowed"); - Parameter p = findOrCreateParameterNamed(name); - p.setType(sdoType); - } - - public void setParameterWithType(int index, Type sdoType) { - if (index == 0) - throw new RuntimeException("Null parameter index not allowed"); - Parameter p = findOrCreateParameterWithIndex(index); - p.setType(sdoType); - } - - public Parameter parameterWithIndex(int index) { - Iterator i = parameters.iterator(); - while (i.hasNext()) { - Parameter param = (Parameter) i.next(); - - if (param.getIndex() == index) - return param; - } - return null; - } - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/QueryString.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/QueryString.java deleted file mode 100644 index 8304457a72..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/QueryString.java +++ /dev/null @@ -1,87 +0,0 @@ -/** - * - * 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.util.HashMap; -import java.util.Iterator; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import org.apache.tuscany.das.rdb.util.DebugUtil; - - -public class QueryString { - - private final String unmodifiedQueryString; - private final String preparedString; - private HashMap parameters = new HashMap(); - private static final boolean debug = false; - - public QueryString(String originalString) { - this.unmodifiedQueryString = originalString; - this.preparedString = replaceNamesAndSetIndexes(originalString); - } - - public String getPreparedString() { - return this.preparedString; - } - - public String getUnmodifiedString() { - return this.unmodifiedQueryString; - } - - public int getParameterIndex(String name) { - DebugUtil.debugln(getClass(), debug, "Looking for parameter index for: " + name); - //System.out.println(toString()); - return ((Integer)parameters.get(name)).intValue(); - } - - private String replaceNamesAndSetIndexes(String query) { - DebugUtil.debugln(getClass(), debug, "Parameterizing query: " + query); - Pattern p = Pattern.compile(":[\\S&&[^,()]]*"); - Matcher m = p.matcher(query); - - int index = 1; - while (m.find()) { - parameters.put(m.group().substring(1), new Integer(index)); - query = m.replaceFirst("?"); - m = p.matcher(query); - index++; - } - - DebugUtil.debugln(getClass(), debug, "Parameterized query: " + query); - return query; - } - - - public String toString() { - StringBuffer buffer = new StringBuffer(); - buffer.append("\nOriginal SQL: "); - buffer.append(unmodifiedQueryString); - buffer.append("\nPrepared SQL: "); - buffer.append(preparedString); - buffer.append("\nParameters: "); - Iterator i = parameters.keySet().iterator(); - while ( i.hasNext() ) { - String key = (String)i.next(); - buffer.append("\n"); - buffer.append(key); - } - return buffer.toString(); - } - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ReadCommandImpl.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ReadCommandImpl.java deleted file mode 100644 index 708fd88b38..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ReadCommandImpl.java +++ /dev/null @@ -1,168 +0,0 @@ -/** - * - * 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.sql.Connection; -import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.List; - -import org.apache.tuscany.das.rdb.config.Config; -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; -import org.apache.tuscany.das.rdb.graphbuilder.impl.ResultSetProcessor; -import org.apache.tuscany.sdo.util.SDOUtil; - -import commonj.sdo.ChangeSummary; -import commonj.sdo.DataGraph; -import commonj.sdo.DataObject; -import commonj.sdo.Type; - -public class ReadCommandImpl extends CommandImpl { - - private Type schema; - - private int startRow = 1; - - private int endRow = Integer.MAX_VALUE; - - public ReadCommandImpl(String sqlString) { - super(sqlString); - } - - public ReadCommandImpl(String sqlString, Config mapping) { - this(sqlString); - if (mapping != null) - setMappingModel(mapping); - } - - //TODO - Need to refactor based on use of DataSource and CommandGroup - public ReadCommandImpl(String sqlString, Config mapping, Connection connection) { - this(sqlString); - setConnection(connection); - 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); - - // Create the DataGraph - DataGraph g = SDOUtil.createDataGraph(); - - // Create the root object - g.createRootObject(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 void setMappingModel(Config config) { - configWrapper = new MappingWrapper(config); - //TODO - need to refactor and take into regression that lost ability to use Datasource - if (getConnection() == null) - 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(); - } - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/SDODataTypeHelper.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/SDODataTypeHelper.java deleted file mode 100644 index 7afa3b8563..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/SDODataTypeHelper.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * - * 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.sql.Types; - -import org.apache.tuscany.das.rdb.SDODataTypes; - -import commonj.sdo.Type; - -public class SDODataTypeHelper { - - static public int sqlTypeFor(Type sdoType) { - if ( sdoType == SDODataTypes.BOOLEAN) - return Types.BOOLEAN; - else if ( sdoType == SDODataTypes.STRING) - return Types.VARCHAR; - else if ( sdoType == SDODataTypes.BYTE) - return Types.TINYINT; - else if ( sdoType == SDODataTypes.BYTES) - return Types.BINARY; - else if ( sdoType == SDODataTypes.CHARACTER) - return Types.CHAR; - else if ( sdoType == SDODataTypes.DATE) - return Types.DATE; - else if ( sdoType == SDODataTypes.DATETIME) - return Types.DATE; - else if ( sdoType == SDODataTypes.DAY ) - return java.sql.Types.BINARY; - else if ( sdoType == SDODataTypes.DECIMAL ) - return java.sql.Types.DECIMAL; - else if ( sdoType == SDODataTypes.DOUBLE ) - return java.sql.Types.DOUBLE; - else if ( sdoType == SDODataTypes.DURATION ) - return java.sql.Types.VARCHAR; - else if ( sdoType == SDODataTypes.FLOAT ) - return java.sql.Types.REAL; - else if ( sdoType == SDODataTypes.INT ) - return java.sql.Types.INTEGER; - else if ( sdoType == SDODataTypes.INTEGER ) - return java.sql.Types.INTEGER; - else if ( sdoType == SDODataTypes.LONG ) - return java.sql.Types.BIGINT; - else if ( sdoType == SDODataTypes.MONTH ) - return java.sql.Types.VARCHAR; - else if ( sdoType == SDODataTypes.MONTHDAY ) - return java.sql.Types.VARCHAR; - else if ( sdoType == SDODataTypes.OBJECT ) - return java.sql.Types.JAVA_OBJECT; - else if ( sdoType == SDODataTypes.SHORT ) - return java.sql.Types.SMALLINT; - else if ( sdoType == SDODataTypes.STRING ) - return java.sql.Types.VARCHAR; - else if ( sdoType == SDODataTypes.STRINGS ) - return java.sql.Types.OTHER; - else if ( sdoType == SDODataTypes.TIME ) - return java.sql.Types.VARCHAR; - else if ( sdoType == SDODataTypes.URI ) - return java.sql.Types.VARCHAR; - else if ( sdoType == SDODataTypes.YEAR ) - return java.sql.Types.VARCHAR; - else if ( sdoType == SDODataTypes.YEARMONTH ) - return java.sql.Types.VARCHAR; - else if ( sdoType == SDODataTypes.YEARMONTHDAY ) - return java.sql.Types.VARCHAR; - else if ( sdoType == SDODataTypes.BOOLEANOBJECT ) - return java.sql.Types.BOOLEAN; - else if ( sdoType == SDODataTypes.BYTEOBJECT ) - return java.sql.Types.TINYINT; - else if ( sdoType == SDODataTypes.CHARACTEROBJECT ) - return java.sql.Types.CHAR; - else if ( sdoType == SDODataTypes.DOUBLEOBJECT ) - return java.sql.Types.DOUBLE; - else if ( sdoType == SDODataTypes.FLOATOBJECT ) - return java.sql.Types.REAL; - else if ( sdoType == SDODataTypes.INTEGEROBJECT ) - return java.sql.Types.INTEGER; - else if ( sdoType == SDODataTypes.LONGOBJECT ) - return java.sql.Types.BIGINT; - else if ( sdoType == SDODataTypes.SHORTOBJECT ) - return java.sql.Types.SMALLINT; - else - throw new RuntimeException("Not a valid SDO Type " + sdoType); - - } -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/SPCommandImpl.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/SPCommandImpl.java deleted file mode 100644 index 0fb647815d..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/SPCommandImpl.java +++ /dev/null @@ -1,73 +0,0 @@ -/** - * - * 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.sql.ResultSet; -import java.sql.SQLException; - -import org.apache.tuscany.das.rdb.config.Config; -import org.apache.tuscany.das.rdb.util.DebugUtil; - -import commonj.sdo.DataObject; - -public class SPCommandImpl extends ReadCommandImpl { - - public SPCommandImpl(String sqlString) { - super(sqlString); - } - - public SPCommandImpl(String sqlString, Config config) { - super(sqlString, config); - } - - public DataObject executeQuery() { - - boolean success = false; - try { - ResultSet rs = statement.executeCall(parameters); - success = true; - - return buildGraph(rs); - } catch (SQLException e) { - DebugUtil.debugln(getClass(), debug, e); - throw new RuntimeException(e); - } finally { - if (success) - statement.getConnection().cleanUp(); - else - statement.getConnection().errorCleanUp(); - } - } - - public void execute() { - - boolean success = false; - try { - statement.executeUpdateCall(parameters); - success = true; - } catch (SQLException e) { - throw new RuntimeException(e); - } finally { - if (success) - statement.getConnection().cleanUp(); - else - statement.getConnection().errorCleanUp(); - } - - } - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Statement.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Statement.java deleted file mode 100644 index 6bc18dc229..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/Statement.java +++ /dev/null @@ -1,206 +0,0 @@ -/** - * - * 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.sql.CallableStatement; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.Iterator; - -import org.apache.tuscany.das.rdb.Parameter; -import org.apache.tuscany.das.rdb.util.DebugUtil; - -//TODO - Can use some refactoring. Much code is duplicated in "execute" methods -public class Statement { - - protected final QueryString queryString; - - protected ConnectionImpl jdbcConnection; - - private static final boolean debug = false; - - private PreparedStatement preparedStatement; - - private boolean isPaging = false; - - public Statement(String sqlString) { - this.queryString = new QueryString(sqlString); - } - - public ResultSet executeQuery(Parameters parameters) throws SQLException { - - PreparedStatement ps = getPreparedStatement(); - ps = setParameters(ps, parameters); - ResultSet rs = ps.executeQuery(); - - return rs; - } - - public ResultSet executeCall(Parameters parameters) throws SQLException { - try { - CallableStatement cs = jdbcConnection.prepareCall(queryString); - - Iterator inParams = parameters.inParams().iterator(); - while (inParams.hasNext()) { - Parameter param = (Parameter) inParams.next(); - if (param.getIndex() == 0) - param.setIndex(queryString.getParameterIndex(param.getName())); - cs.setObject(param.getIndex(), param.getValue()); - } - - // register out parameters - Iterator outParams = parameters.outParams().iterator(); - while (outParams.hasNext()) { - Parameter param = (Parameter) outParams.next(); - if (param.getIndex() == 0) - param.setIndex(queryString.getParameterIndex(param.getName())); - DebugUtil.debugln(getClass(), debug, "Registering parameter " + param.getName()); - cs.registerOutParameter(param.getIndex(), SDODataTypeHelper.sqlTypeFor(param.getType())); - } - - // Using execute because Derby does not currenlty support - // executeQuery - // for SP - cs.execute(); - ResultSet results = cs.getResultSet(); - - Iterator i = parameters.outParams().iterator(); - while (i.hasNext()) { - Parameter param = (Parameter) i.next(); - param.setValue(cs.getObject(param.getIndex())); - } - - return results; - } catch (SQLException ex) { - ex.printStackTrace(); - throw ex; - } - - } - - public void executeUpdateCall(Parameters parameters) throws SQLException { - CallableStatement cs = jdbcConnection.prepareCall(queryString); - - Iterator inParams = parameters.inParams().iterator(); - while (inParams.hasNext()) { - Parameter param = (Parameter) inParams.next(); - if (param.getIndex() == 0) - param.setIndex(queryString.getParameterIndex(param.getName())); - cs.setObject(param.getIndex(), param.getValue()); - } - - // register out parameters - Iterator outParams = parameters.outParams().iterator(); - while (outParams.hasNext()) { - Parameter param = (Parameter) outParams.next(); - if (param.getIndex() == 0) - param.setIndex(queryString.getParameterIndex(param.getName())); - DebugUtil.debugln(getClass(), debug, "Registering parameter " + param.getName()); - cs.registerOutParameter(param.getIndex(), SDODataTypeHelper.sqlTypeFor(param.getType())); - } - - cs.execute(); - - Iterator out = parameters.outParams().iterator(); - while (out.hasNext()) { - Parameter param = (Parameter) out.next(); - param.setValue(cs.getObject(param.getIndex())); - } - - } - - /** - * TODO - We need to look at using specific ps.setXXX methods when a type - * has been specified and try setObject otherwise. - */ - public int executeUpdate(Parameters parameters) throws SQLException { - DebugUtil.debugln(getClass(), debug, "Executing statement " + queryString.getPreparedString()); - PreparedStatement ps = getPreparedStatement(); - Iterator i = parameters.inParams().iterator(); - while (i.hasNext()) { - Parameter param = (Parameter) i.next(); - if (param.getIndex() == 0) - param.setIndex(queryString.getParameterIndex(param.getName())); - Object value = param.getValue(); - DebugUtil.debugln(getClass(), debug, "Setting parameter " + param.getIndex() + " to " + value); - if (value == null) { - ps.setNull(param.getIndex(), SDODataTypeHelper.sqlTypeFor(param.getType())); - } else { - ps.setObject(param.getIndex(), value); - } - } - return ps.executeUpdate(); - } - - protected PreparedStatement setParameters(PreparedStatement ps, Parameters parameters) - throws SQLException { - Iterator i = parameters.inParams().iterator(); - while (i.hasNext()) { - Parameter param = (Parameter) i.next(); - if (param.getIndex() == 0) - param.setIndex(queryString.getParameterIndex(param.getName())); - ps.setObject(param.getIndex(), param.getValue()); - } - return ps; - } - - public void setConnection(ConnectionImpl jdbcConnection) { - this.jdbcConnection = jdbcConnection; - } - - public ConnectionImpl getConnection() { - return this.jdbcConnection; - } - - private PreparedStatement getPreparedStatement() throws SQLException { - DebugUtil.debugln(getClass(), debug, "Getting prepared statement"); - if (preparedStatement == null) - if (isPaging) - preparedStatement = jdbcConnection.preparePagedStatement(queryString); - else - preparedStatement = jdbcConnection.prepareStatement(queryString); - - return preparedStatement; - } - - public Integer getGeneratedKey() throws SQLException { - - ResultSet rs = getPreparedStatement().getGeneratedKeys(); - if (rs.next()) - return new Integer(rs.getInt(1)); - - return null; - } - - protected void enablePaging() { - isPaging = true; - } - - public void close() { - - if (this.preparedStatement != null) { - try { - preparedStatement.close(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - } - - } - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/UpdateCommandImpl.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/UpdateCommandImpl.java deleted file mode 100644 index 7fffe97d5d..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/UpdateCommandImpl.java +++ /dev/null @@ -1,25 +0,0 @@ -/** - * - * 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; - -public class UpdateCommandImpl extends WriteCommandImpl { - - public UpdateCommandImpl(String sqlString) { - super(sqlString); - } - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/UpdateList.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/UpdateList.java deleted file mode 100644 index 1ab2f16fca..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/UpdateList.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * - * 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.util.ArrayList; -import java.util.Collection; - -/** - * Updates don't have to be sorted, so this class is a simple wrapper of ArrayList. - * - */ -public class UpdateList { - - private ArrayList updates = new ArrayList(); - - public UpdateList() { - super(); - } - - public void add(ChangeOperation c) { - updates .add(c); - } - - public Collection getSortedList() { - return updates; - } - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/UpdateOperation.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/UpdateOperation.java deleted file mode 100644 index cbe73a16e4..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/UpdateOperation.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * - * 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 commonj.sdo.DataObject; - - -public class UpdateOperation extends ChangeOperation { - - public UpdateOperation(UpdateCommandImpl command, DataObject changedObject, String id) { - super(command, changedObject); - this.propagatedID = id; - } - -} diff --git a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/WriteCommandImpl.java b/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/WriteCommandImpl.java deleted file mode 100644 index ff1ac385d4..0000000000 --- a/tags/java-M1-final/java/das/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/WriteCommandImpl.java +++ /dev/null @@ -1,97 +0,0 @@ -/** -* -* 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.sql.SQLException; -import java.util.Collection; -import java.util.Iterator; - -import org.apache.tuscany.das.rdb.Parameter; -import org.apache.tuscany.das.rdb.config.Config; - -import commonj.sdo.DataObject; -import commonj.sdo.Type; - -public abstract class WriteCommandImpl extends CommandImpl { - - - public WriteCommandImpl(String sqlString) { - super(sqlString); - } - - public void execute() { - - boolean success = false; - try { - statement.executeUpdate(parameters); - subtypeProcessing(); - success = true; - } catch (SQLException e) { - throw new RuntimeException(e); - } finally { - if (success) - statement.getConnection().cleanUp(); - else - statement.getConnection().errorCleanUp(); - } - - } - - public DataObject executeQuery() { - throw new UnsupportedOperationException(); - } - - public Config getMappingModel() { - return configWrapper.getConfig(); - } - - - /** - * Subclasses add specific bahavior - * Default is to do nothing - */ - protected void subtypeProcessing() throws SQLException { - if ( false ) - throw new SQLException(); - } - - public void setDataObjectModel(Type schema) { - // don't really care what the model is here - } - - public String toString() { - - StringBuffer buffer = new StringBuffer(); - buffer.append("\nSQL: " + statement.queryString.getUnmodifiedString()); - buffer.append("\nModified SQL: " + statement.queryString.getPreparedString()); - return buffer.toString(); - } - - public int getGeneratedKey() { - throw new RuntimeException("No generated key is available"); - } - - public void addParameters(Collection updateParameters) { - Iterator i = updateParameters.iterator(); - while ( i.hasNext()) { - Parameter p = (Parameter) i.next(); - addParameter(p); - } - } - - -} |