From 59a9d9aa1bd9cd629f743aed680d74363ec4504d Mon Sep 17 00:00:00 2001 From: lresende Date: Thu, 1 Apr 2010 00:43:23 +0000 Subject: 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 --- .../apache/tuscany/das/rdb/impl/ChangeFactory.java | 82 ++++++++++++---------- 1 file changed, 46 insertions(+), 36 deletions(-) (limited to 'das-java') 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() { -- cgit v1.2.3