diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2010-04-01 00:43:23 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2010-04-01 00:43:23 +0000 |
commit | 59a9d9aa1bd9cd629f743aed680d74363ec4504d (patch) | |
tree | dcd557ad2893f1df612b5fd5021e687a848050cc /das-java/trunk/rdb/src | |
parent | 2cc659c93be71ef7b69205eb65412b0cf83ee721 (diff) |
TUSCANY-3524 - Applying patch from Florian Pinel to fix issue with command caching in ChangeFactory
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@929760 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'das-java/trunk/rdb/src')
-rw-r--r-- | das-java/trunk/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ChangeFactory.java | 82 |
1 files changed, 46 insertions, 36 deletions
diff --git a/das-java/trunk/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ChangeFactory.java b/das-java/trunk/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ChangeFactory.java index f8c669ed43..2e94b5e32a 100644 --- a/das-java/trunk/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ChangeFactory.java +++ b/das-java/trunk/rdb/src/main/java/org/apache/tuscany/das/rdb/impl/ChangeFactory.java @@ -87,7 +87,7 @@ public class ChangeFactory { } private InsertCommandImpl getCreateCommand(DataObject changedObject) { - + InsertCommandImpl command = null; if (createCommand == null) { Table table = mapping.getTableByTypeName(changedObject.getType().getName()); if (table == null) { @@ -104,14 +104,18 @@ public class ChangeFactory { Create create = table.getCreate(); if (create == null) { - createCommand = InsertGenerator.INSTANCE.getInsertCommand(mapping, changedObject, table); + command = InsertGenerator.INSTANCE.getInsertCommand(mapping, changedObject, table); } else { + // command can be cached createCommand = new InsertCommandImpl(create); + command = createCommand; } - createCommand.setConnection(connection); - createCommand.configWrapper = mapping; + command.setConnection(connection); + command.configWrapper = mapping; + } else { + command = createCommand; } - return createCommand; + return command; } private DeleteCommandImpl getDeleteCommand(DataObject changedObject) { @@ -143,43 +147,49 @@ public class ChangeFactory { } private UpdateCommandImpl getUpdateCommand(DataObject changedObject) { - - Table table = mapping.getTableByTypeName(changedObject.getType().getName()); - if (table == null) { - if (changedObject.getType().getProperty("ID") != null) { - mapping.addPrimaryKey(changedObject.getType().getName() + ".ID"); - table = mapping.getTableByTypeName(changedObject.getType().getName()); - } else { - throw new RuntimeException("Table " + changedObject.getType().getName() - + " was changed in the DataGraph but is not present in the Config"); - } - } - Update update = table.getUpdate(); - if (update == null) { - updateCommand = UpdateGenerator.INSTANCE.getUpdateCommand(mapping, changedObject, table); - } else { - TableWrapper t = new TableWrapper(table); - if (t.getCollisionColumn() != null) { - updateCommand = new OptimisticWriteCommandImpl(update); - } else { - updateCommand = new UpdateCommandImpl(update); - } - } - - if (updateCommand != null) { - updateCommand.setConnection(connection); - updateCommand.configWrapper = mapping; + UpdateCommandImpl command = null; + if (updateCommand == null) { + Table table = mapping.getTableByTypeName(changedObject.getType().getName()); + if (table == null) { + if (changedObject.getType().getProperty("ID") != null) { + mapping.addPrimaryKey(changedObject.getType().getName() + ".ID"); + table = mapping.getTableByTypeName(changedObject.getType().getName()); + } else { + throw new RuntimeException("Table " + changedObject.getType().getName() + + " was changed in the DataGraph but is not present in the Config"); + } + } + Update update = table.getUpdate(); + if (update == null) { + command = UpdateGenerator.INSTANCE.getUpdateCommand(mapping, changedObject, table); + } else { + // command can be cached + TableWrapper t = new TableWrapper(table); + if (t.getCollisionColumn() != null) { + updateCommand = new OptimisticWriteCommandImpl(update); + } else { + updateCommand = new UpdateCommandImpl(update); + } + command = updateCommand; + } + + if (command != null) { + command.setConnection(connection); + command.configWrapper = mapping; + } else { + if(this.logger.isDebugEnabled()) { + this.logger.debug("Update command is NULL"); + } + } } else { - if(this.logger.isDebugEnabled()) { - this.logger.debug("Update command is NULL"); - } + command = updateCommand; } if (this.logger.isDebugEnabled()) { - this.logger.debug("Returning updateCommand: " + updateCommand); + this.logger.debug("Returning updateCommand: " + command); } - return updateCommand; + return command; } public MappingWrapper getConfig() { |