branch feature/3860_introduce_topiasqlbatchsupport updated (36cc01c -> 1f6318e)
This is an automated email from the git hooks/post-receive script. New change to branch feature/3860_introduce_topiasqlbatchsupport in repository topia. See http://git.nuiton.org/topia.git omits 36cc01c Add javadoc omits c7fe4fc Add missing license headers omits a70e884 Add a configuration object for Topia Sql batch service and use it omits e57b090 Add TopiaSqlBatchService and his default implementation omits a36739d Add delete tables action omits 716a078 Add update tables action omits e6ff976 Add replicate tables action omits 8da3fb2 Add drop schem action omits 3bd7535 Add create schema actions omits d254cc8 Add Sql action abstract classes omits 4f594a9 Add TopiaSqlTable API omits b866192 Add new topia-sql-batch module omits 12d177e Add withShell method on metadata entity omits a36406f Generate metadata model location path omits da2bcfd Add also getEntityEnum by name in TopiaEntityEnumProvider omits b8ff4e8 Introduce TopiaMetadataModelGenerator and include it into default Topia templates omits 4c7bf77 Introduce TopiaMetadataModelSupport and add this new support to TopiaApplicationContext omits e2c019a Use gson to load and store TopiaMetadataModel omits 7a4fee1 Introduce TopiaMetadataModel adds cb26887 Adding attribute in tag value search (See #3862) adds cc288bd Fixes #3862 Merge branch 'feature/3862_fix_hibernateAttributeType_tag_value_usage' into develop new 2fcfe60 Introduce TopiaMetadataModel new 455365c Use gson to load and store TopiaMetadataModel new e2f1936 Introduce TopiaMetadataModelSupport and add this new support to TopiaApplicationContext new c81d5b3 Introduce TopiaMetadataModelGenerator and include it into default Topia templates new da1870e Add also getEntityEnum by name in TopiaEntityEnumProvider new 3317d1f Generate metadata model location path new f1f64dd Add withShell method on metadata entity new a7bdec3 Add new topia-sql-batch module new 3ff485d Add TopiaSqlTable API new f107b9c Add Sql action abstract classes new 08f9f33 Add create schema actions new 321c842 Add drop schem action new 933912b Add replicate tables action new c618b87 Add update tables action new 7e1c40f Add delete tables action new e2d15ef Add TopiaSqlBatchService and his default implementation new 3be1a24 Add a configuration object for Topia Sql batch service and use it new 29ed734 Add missing license headers new 7d394c1 Add javadoc new 1f6318e Do not create drop schema in CreateSchemaAction This update added new revisions after undoing existing revisions. That is to say, some revisions that were in the old version of the branch are not in the new version. This situation occurs when a user --force pushes a change and generates a repository containing something like this: * -- * -- B -- O -- O -- O (36cc01c) \ N -- N -- N refs/heads/feature/3860_introduce_topiasqlbatchsupport (1f6318e) You should already have received notification emails for all of the O revisions, and so the following emails describe only the N revisions from the common base, B. Any revisions marked "omits" are not gone; other references still refer to them. Any revisions marked "discards" are gone forever. The 20 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 1f6318e6be01b6bc9a6fef5773cd048cc9346588 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Jan 9 17:23:16 2016 +0100 Do not create drop schema in CreateSchemaAction commit 7d394c1abbd7a34a45b3b2d9677c663795de74a7 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Jan 8 13:42:26 2016 +0100 Add javadoc commit 29ed7349275e772fadba2f024423b11d78595b71 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 5 22:12:29 2016 +0100 Add missing license headers commit 3be1a247a86035d6edd9c469e7304b14eb7fb1b4 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 5 20:10:16 2016 +0100 Add a configuration object for Topia Sql batch service and use it commit e2d15ef2de22d7ceba86e87803d22ade899669b2 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 5 08:29:01 2016 +0100 Add TopiaSqlBatchService and his default implementation commit 7e1c40f680188d671f52e302c74746db8e1b09c0 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 5 08:27:40 2016 +0100 Add delete tables action commit c618b87f1a51770e09a558a6a5c2e8eb5c6813e0 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 5 08:27:25 2016 +0100 Add update tables action commit 933912b823ff681ef3636d04ea6db14d497a9364 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 5 08:27:10 2016 +0100 Add replicate tables action commit 321c8424c7c0c42edefcf9246712eedfd6a54c18 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 5 08:26:53 2016 +0100 Add drop schem action commit 08f9f336c9cd017f64f86facad3af0f0abb6b48c Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 5 08:26:39 2016 +0100 Add create schema actions commit f107b9c3456af57478d18f17fd4df0ecffdbfda3 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 5 08:26:11 2016 +0100 Add Sql action abstract classes commit 3ff485df15ec5d70dbcd71ef628d00a8a9fd4efa Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 5 08:25:22 2016 +0100 Add TopiaSqlTable API commit a7bdec3b47fa6f01f88cca718772ed4a53fe9ac4 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 5 08:24:59 2016 +0100 Add new topia-sql-batch module commit f1f64ddc23b10613ac787c5ea412154957982004 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Jan 4 20:45:41 2016 +0100 Add withShell method on metadata entity commit 3317d1f4d1f034cc46f2503d04f45cbab27698fe Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Jan 4 20:44:35 2016 +0100 Generate metadata model location path commit da1870e5f0e9896c9fb620af941c215644d4af6e Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Jan 4 17:26:50 2016 +0100 Add also getEntityEnum by name in TopiaEntityEnumProvider commit c81d5b315d5cb9df21bd6578cd19b2b383135d99 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Jan 4 13:39:07 2016 +0100 Introduce TopiaMetadataModelGenerator and include it into default Topia templates commit e2f193647326f2ac4a9cfdf5f002a50bc103b0a7 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Jan 4 13:36:34 2016 +0100 Introduce TopiaMetadataModelSupport and add this new support to TopiaApplicationContext commit 455365cd0e23ac1c9296ee43d3f8c04ede41c498 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Jan 4 13:35:18 2016 +0100 Use gson to load and store TopiaMetadataModel commit 2fcfe607e8b2876b610294bb72784eae2c56673f Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Jan 4 13:33:37 2016 +0100 Introduce TopiaMetadataModel Summary of changes: .../nuiton/topia/service/sql/batch/actions/CreateSchemaAction.java | 3 ++- .../src/main/java/org/nuiton/topia/templates/TopiaTagValues.java | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/3860_introduce_topiasqlbatchsupport in repository topia. See http://git.nuiton.org/topia.git commit 2fcfe607e8b2876b610294bb72784eae2c56673f Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Jan 4 13:33:37 2016 +0100 Introduce TopiaMetadataModel --- .../persistence/metadata/TopiaMetadataEntity.java | 123 ++++++++++++ .../persistence/metadata/TopiaMetadataModel.java | 62 ++++++ .../metadata/TopiaMetadataModelVisitor.java | 219 +++++++++++++++++++++ 3 files changed, 404 insertions(+) diff --git a/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataEntity.java b/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataEntity.java new file mode 100644 index 0000000..cf7fdcb --- /dev/null +++ b/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataEntity.java @@ -0,0 +1,123 @@ +package org.nuiton.topia.persistence.metadata; + +import com.google.common.base.MoreObjects; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.Objects; + +/** + * Created on 03/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public class TopiaMetadataEntity { + + private static final Log log = LogFactory.getLog(TopiaMetadataEntity.class); + + protected final String type; + protected final Map<String, String> associations = new LinkedHashMap<>(); + protected final Map<String, String> reversedAssociations = new LinkedHashMap<>(); + protected final Map<String, String> nmAssociations = new LinkedHashMap<>(); + protected final Map<String, String> required = new LinkedHashMap<>(); + + public TopiaMetadataEntity(String type) { + this.type = type; + } + + public String getType() { + return type; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + TopiaMetadataEntity that = (TopiaMetadataEntity) o; + return Objects.equals(type, that.type); + } + + @Override + public int hashCode() { + return Objects.hash(type); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("type", type) + .toString(); + } + + public Map<String, String> getReversedAssociations() { + return reversedAssociations; + } + + public Map<String, String> getNmAssociations() { + return nmAssociations; + } + + public Map<String, String> getAssociations() { + return associations; + } + + public Map<String, String> getRequired() { + return required; + } + + public void addAssociation(TopiaMetadataEntity associationClazz, String name) { + log.info(getType() + "/" + name + "→" + associationClazz.getType()); + associations.put(name, associationClazz.getType()); + } + + public void addReversedAssociation(TopiaMetadataEntity associationClazz, String name) { + log.info(getType() + "/" + name + "→" + associationClazz.getType()); + reversedAssociations.put(name, associationClazz.getType()); + } + + public void addNmAssociation(TopiaMetadataEntity associationClazz, String name) { + log.info(getType() + "/" + name + "→" + associationClazz.getType()); + nmAssociations.put(name, associationClazz.getType()); + } + + public void addRequired(TopiaMetadataEntity attributeClazz, String name) { + log.info(getType() + "/" + name + "→" + attributeClazz.getType()); + required.put(name, attributeClazz.getType()); + } + + public TopiaMetadataEntity copy() { + TopiaMetadataEntity copy = new TopiaMetadataEntity(type); + copy.associations.putAll(associations); + copy.reversedAssociations.putAll(reversedAssociations); + copy.nmAssociations.putAll(nmAssociations); + copy.required.putAll(required); + return copy; + } + + public void accept(TopiaMetadataModelVisitor visitor, TopiaMetadataModel metadataModel) { + visitor.visitEntiyStart(metadataModel, this); + for (Map.Entry<String, String> entry : reversedAssociations.entrySet()) { + String propertyName = entry.getKey(); + String propertyType = entry.getValue(); + visitor.visitReversedAssociation(metadataModel, this, propertyName, metadataModel.getEntity(propertyType)); + } + for (Map.Entry<String, String> entry : associations.entrySet()) { + String propertyName = entry.getKey(); + String propertyType = entry.getValue(); + visitor.visitAssociation(metadataModel, this, propertyName, metadataModel.getEntity(propertyType)); + } + for (Map.Entry<String, String> entry : nmAssociations.entrySet()) { + String propertyName = entry.getKey(); + String propertyType = entry.getValue(); + visitor.visitNmAssociation(metadataModel, this, propertyName, metadataModel.getEntity(propertyType)); + } + for (Map.Entry<String, String> entry : required.entrySet()) { + String propertyName = entry.getKey(); + String propertyType = entry.getValue(); + visitor.visitRequired(metadataModel, this, propertyName, metadataModel.getEntity(propertyType)); + } + visitor.visitEntiyEnd(metadataModel, this); + } +} diff --git a/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataModel.java b/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataModel.java new file mode 100644 index 0000000..70cc470 --- /dev/null +++ b/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataModel.java @@ -0,0 +1,62 @@ +package org.nuiton.topia.persistence.metadata; + +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.net.URL; +import java.util.LinkedHashMap; +import java.util.Map; + +/** + * Created on 03/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public class TopiaMetadataModel { + + private static final Log log = LogFactory.getLog(TopiaMetadataModel.class); + + protected final Map<String, TopiaMetadataEntity> entities = new LinkedHashMap<>(); + + public TopiaMetadataEntity getEntity(String type) { + return entities.get(type); + } + + public Optional<TopiaMetadataEntity> getOptionalEntity(String type) { + return Optional.fromNullable(getEntity(type)); + } + + public void accept(TopiaMetadataModelVisitor visitor) { + visitor.visitModelStart(this); + for (TopiaMetadataEntity entity : entities.values()) { + entity.accept(visitor, this); + } + visitor.visitModelEnd(this); + } + + public TopiaMetadataEntity newEntity(String type) { + Preconditions.checkState(!entities.containsKey(type), type + " already in cache"); + TopiaMetadataEntity clazz = new TopiaMetadataEntity(type); + entities.put(type, clazz); + log.info(clazz.getType()); + return clazz; + } + + public static TopiaMetadataModel load(URL url) throws IOException { + try (Reader reader = new InputStreamReader(url.openStream())) { + + Gson gson = new GsonBuilder().create(); + TopiaMetadataModel metadataModel = gson.fromJson(reader, TopiaMetadataModel.class); + return metadataModel; + + } + } + +} diff --git a/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataModelVisitor.java b/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataModelVisitor.java new file mode 100644 index 0000000..b3c55c5 --- /dev/null +++ b/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataModelVisitor.java @@ -0,0 +1,219 @@ +package org.nuiton.topia.persistence.metadata; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.LinkedHashSet; +import java.util.Set; + +/** + * Created on 04/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public interface TopiaMetadataModelVisitor { + + void visitModelStart(TopiaMetadataModel metadataModel); + + void visitModelEnd(TopiaMetadataModel metadataModel); + + void visitEntiyStart(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity); + + void visitEntiyEnd(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity); + + void visitReversedAssociation(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType); + + void visitAssociation(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType); + + void visitNmAssociation(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType); + + void visitRequired(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType); + + class TopiaMetadataModelVisitorAdapter implements TopiaMetadataModelVisitor { + + @Override + public void visitModelStart(TopiaMetadataModel metadataModel) { + + } + + @Override + public void visitModelEnd(TopiaMetadataModel metadataModel) { + + } + + @Override + public void visitEntiyStart(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity) { + + } + + @Override + public void visitEntiyEnd(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity) { + + } + + @Override + public void visitReversedAssociation(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) { + + } + + @Override + public void visitAssociation(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) { + + } + + @Override + public void visitNmAssociation(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) { + + } + + @Override + public void visitRequired(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) { + + } + + } + + class PrintVisitor implements TopiaMetadataModelVisitor { + + private final Log log = LogFactory.getLog(TopiaMetadataModelVisitor.class); + protected final boolean deepVisit; + protected final String eol; + protected final StringBuilder builder; + + protected String prefix = ""; + + class DeepVisitor extends TopiaMetadataModelVisitorAdapter { + + String prefix; + Set<String> visited = new LinkedHashSet<>(); + + public DeepVisitor(String prefix) { + this.prefix = prefix; + } + + @Override + public void visitEntiyStart(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity) { + prefix += " "; + appendPrefix("E → ").append(metadataEntity).append(eol); + } + + @Override + public void visitEntiyEnd(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity) { + appendPrefix("E ← ").append(metadataEntity).append(eol); + prefix = prefix.substring(2); + } + + @Override + public void visitReversedAssociation(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) { + appendPrefix("ReversedAssociation: ").append(metadataEntity).append("/").append(propertyName).append("→").append(propertyType.getType()).append(eol); + if (visited.add(propertyType.getType())) { + propertyType.accept(this, metadataModel); + } + } + + @Override + public void visitAssociation(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) { + appendPrefix("Association: ").append(metadataEntity).append("/").append(propertyName).append("→").append(propertyType.getType()).append(eol); + if (visited.add(propertyType.getType())) { + propertyType.accept(this, metadataModel); + } + } + + @Override + public void visitNmAssociation(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) { + appendPrefix("NmAssociation: ").append(metadataEntity).append("/").append(propertyName).append("→").append(propertyType.getType()).append(eol); + if (visited.add(propertyType.getType())) { + propertyType.accept(this, metadataModel); + } + } + + @Override + public void visitRequired(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) { + appendPrefix("Required: ").append(metadataEntity).append("/").append(propertyName).append("→").append(propertyType.getType()).append(eol); + if (visited.add(propertyType.getType())) { + propertyType.accept(this, metadataModel); + } + } + + protected StringBuilder appendPrefix(String prefix) { + return builder.append(this.prefix).append(prefix); + } + + } + + public PrintVisitor(boolean deepVisit, String eol) { + this.deepVisit = deepVisit; + this.eol = eol; + this.builder = new StringBuilder(); + } + + @Override + public void visitModelStart(TopiaMetadataModel metadataModel) { + appendPrefix("M → ").append(metadataModel).append(eol); + } + + @Override + public void visitModelEnd(TopiaMetadataModel metadataModel) { + appendPrefix("M ← ").append(metadataModel).append(eol); + + } + + @Override + public void visitEntiyStart(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity) { + + if (deepVisit) { + metadataEntity.accept(new DeepVisitor(prefix), metadataModel); + }else { + prefix += " "; + appendPrefix("E → ").append(metadataEntity).append(eol); + } + } + + @Override + public void visitEntiyEnd(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity) { + if (!deepVisit) { + appendPrefix("E ← ").append(metadataEntity).append(eol); + prefix = prefix.substring(2); + } + } + + @Override + public void visitReversedAssociation(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) { + if (!deepVisit) { + appendPrefix("ReversedAssociation: ").append(metadataEntity).append("/").append(propertyName).append("→").append(propertyType.getType()).append(eol); + } + } + + @Override + public void visitAssociation(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) { + if (!deepVisit) { + appendPrefix("Association: ").append(metadataEntity).append("/").append(propertyName).append("→").append(propertyType.getType()).append(eol); + } + } + + @Override + public void visitNmAssociation(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) { + if (!deepVisit) { + appendPrefix("NmAssociation: ").append(metadataEntity).append("/").append(propertyName).append("→").append(propertyType.getType()).append(eol); + } + } + + @Override + public void visitRequired(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) { + if (!deepVisit) { + appendPrefix("Required: ").append(metadataEntity).append("/").append(propertyName).append("→").append(propertyType.getType()).append(eol); + } + } + + @Override + public String toString() { + return builder.toString(); + } + + protected StringBuilder appendPrefix(String prefix) { + return builder.append(this.prefix).append(prefix); + } + + } + +} -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/3860_introduce_topiasqlbatchsupport in repository topia. See http://git.nuiton.org/topia.git commit 455365cd0e23ac1c9296ee43d3f8c04ede41c498 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Jan 4 13:35:18 2016 +0100 Use gson to load and store TopiaMetadataModel --- pom.xml | 5 +++++ topia-persistence/pom.xml | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/pom.xml b/pom.xml index b2a0128..39f8865 100644 --- a/pom.xml +++ b/pom.xml @@ -373,6 +373,11 @@ <artifactId>guava</artifactId> <version>${guavaVersion}</version> </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <version>2.5</version> + </dependency> <!-- Commons libs --> diff --git a/topia-persistence/pom.xml b/topia-persistence/pom.xml index e2736a1..40831fa 100644 --- a/topia-persistence/pom.xml +++ b/topia-persistence/pom.xml @@ -59,6 +59,11 @@ </dependency> <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + </dependency> + + <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-collections4</artifactId> </dependency> -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/3860_introduce_topiasqlbatchsupport in repository topia. See http://git.nuiton.org/topia.git commit e2f193647326f2ac4a9cfdf5f002a50bc103b0a7 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Jan 4 13:36:34 2016 +0100 Introduce TopiaMetadataModelSupport and add this new support to TopiaApplicationContext --- .../topia/persistence/TopiaApplicationContext.java | 3 +- .../internal/AbstractTopiaApplicationContext.java | 12 +++++++ .../support/TopiaMetadataModelSupportImpl.java | 38 ++++++++++++++++++++++ .../support/TopiaMetadataModelSupport.java | 14 ++++++++ 4 files changed, 66 insertions(+), 1 deletion(-) diff --git a/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaApplicationContext.java b/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaApplicationContext.java index eac951b..588c3fb 100644 --- a/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaApplicationContext.java +++ b/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaApplicationContext.java @@ -26,6 +26,7 @@ package org.nuiton.topia.persistence; import com.google.common.collect.ImmutableSet; import org.nuiton.topia.persistence.support.TopiaListenableSupport; +import org.nuiton.topia.persistence.support.TopiaMetadataModelSupport; import org.nuiton.topia.persistence.support.TopiaServiceSupport; import java.io.Closeable; @@ -65,7 +66,7 @@ import java.util.List; * @since 3.0 */ public interface TopiaApplicationContext<K extends TopiaPersistenceContext> - extends TopiaListenableSupport, TopiaServiceSupport, Closeable { + extends TopiaListenableSupport, TopiaServiceSupport, TopiaMetadataModelSupport, Closeable { /** * Creates a new instance of XxxTopiaPersistenceContext (where <code>Xxx</code> is the project name). This is the diff --git a/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaApplicationContext.java b/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaApplicationContext.java index f0c7be8..6a02b0d 100644 --- a/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaApplicationContext.java +++ b/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaApplicationContext.java @@ -52,7 +52,10 @@ import org.nuiton.topia.persistence.event.TopiaSchemaListener; import org.nuiton.topia.persistence.event.TopiaTransactionListener; import org.nuiton.topia.persistence.event.TopiaTransactionVetoable; import org.nuiton.topia.persistence.internal.support.TopiaFiresSupport; +import org.nuiton.topia.persistence.internal.support.TopiaMetadataModelSupportImpl; import org.nuiton.topia.persistence.internal.support.TopiaServiceSupportImpl; +import org.nuiton.topia.persistence.metadata.TopiaMetadataModel; +import org.nuiton.topia.persistence.support.TopiaMetadataModelSupport; import org.nuiton.topia.persistence.support.TopiaServiceSupport; import org.nuiton.topia.persistence.util.TopiaUtil; @@ -87,6 +90,8 @@ public abstract class AbstractTopiaApplicationContext<K extends TopiaPersistence protected TopiaServiceSupport topiaServiceSupport; + protected TopiaMetadataModelSupport topiaMetadataModelSupport; + protected HibernateProvider hibernateProvider; protected TopiaHibernateSessionRegistry sessionRegistry; @@ -127,6 +132,7 @@ public abstract class AbstractTopiaApplicationContext<K extends TopiaPersistence topiaFiresSupport = new TopiaFiresSupport(); sessionRegistry = new TopiaHibernateSessionRegistry(); + topiaMetadataModelSupport = new TopiaMetadataModelSupportImpl(this); // First initialize all the services initServices(); @@ -520,4 +526,10 @@ public abstract class AbstractTopiaApplicationContext<K extends TopiaPersistence public boolean isOpened() { return ! isClosed(); } + + @Override + public TopiaMetadataModel getMetadataModel() { + return topiaMetadataModelSupport.getMetadataModel(); + } + } diff --git a/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/TopiaMetadataModelSupportImpl.java b/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/TopiaMetadataModelSupportImpl.java new file mode 100644 index 0000000..4fdd915 --- /dev/null +++ b/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/TopiaMetadataModelSupportImpl.java @@ -0,0 +1,38 @@ +package org.nuiton.topia.persistence.internal.support; + +import org.nuiton.topia.persistence.TopiaApplicationContext; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; +import org.nuiton.topia.persistence.metadata.TopiaMetadataModel; +import org.nuiton.topia.persistence.support.TopiaMetadataModelSupport; + +import java.io.IOException; + +/** + * Created on 04/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public class TopiaMetadataModelSupportImpl implements TopiaMetadataModelSupport { + + private final String metadataModelPath; + + protected TopiaMetadataModel metadataModel; + + public <K extends TopiaPersistenceContext> TopiaMetadataModelSupportImpl(TopiaApplicationContext topiaApplicationContext) { + this.metadataModelPath = String.format("/%s/%sTopiaMetadataModel.json", topiaApplicationContext.getClass().getPackage().getName().replace(".", "/"), topiaApplicationContext.getModelName()); + } + + @Override + public TopiaMetadataModel getMetadataModel() { + if (metadataModel == null) { + try { + metadataModel = TopiaMetadataModel.load(getClass().getResource(metadataModelPath)); + } catch (IOException e) { + throw new TopiaException(e); + } + } + return metadataModel; + } + +} diff --git a/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaMetadataModelSupport.java b/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaMetadataModelSupport.java new file mode 100644 index 0000000..bc148ed --- /dev/null +++ b/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaMetadataModelSupport.java @@ -0,0 +1,14 @@ +package org.nuiton.topia.persistence.support; + +import org.nuiton.topia.persistence.metadata.TopiaMetadataModel; + +/** + * Created on 02/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public interface TopiaMetadataModelSupport { + + TopiaMetadataModel getMetadataModel(); + +} -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/3860_introduce_topiasqlbatchsupport in repository topia. See http://git.nuiton.org/topia.git commit c81d5b315d5cb9df21bd6578cd19b2b383135d99 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Jan 4 13:39:07 2016 +0100 Introduce TopiaMetadataModelGenerator and include it into default Topia templates --- topia-templates/pom.xml | 4 + .../topia/templates/TopiaMetaTransformer.java | 3 +- .../templates/TopiaMetadataModelGenerator.java | 242 +++++++++++++++++++++ .../topia/templates/TopiaTemplateHelper.java | 10 +- 4 files changed, 256 insertions(+), 3 deletions(-) diff --git a/topia-templates/pom.xml b/topia-templates/pom.xml index 58d75be..e5e2fd2 100644 --- a/topia-templates/pom.xml +++ b/topia-templates/pom.xml @@ -67,6 +67,10 @@ <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> </dependency> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + </dependency> <dependency> <groupId>org.apache.commons</groupId> diff --git a/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaMetaTransformer.java b/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaMetaTransformer.java index 4da8fcd..890a11c 100644 --- a/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaMetaTransformer.java +++ b/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaMetaTransformer.java @@ -69,7 +69,8 @@ public class TopiaMetaTransformer extends AbstractMetaTransformer<ObjectModel> { EntityDaoTransformer.class, EntityEnumTransformer.class, ApplicationContextTransformer.class, - PersistenceContextTransformer.class + PersistenceContextTransformer.class, + TopiaMetadataModelGenerator.class ); } diff --git a/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaMetadataModelGenerator.java b/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaMetadataModelGenerator.java new file mode 100644 index 0000000..6e6e27b --- /dev/null +++ b/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaMetadataModelGenerator.java @@ -0,0 +1,242 @@ +package org.nuiton.topia.templates; + +import com.google.common.base.Optional; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.eugene.GeneratorUtil; +import org.nuiton.eugene.models.object.ObjectModel; +import org.nuiton.eugene.models.object.ObjectModelAttribute; +import org.nuiton.eugene.models.object.ObjectModelClass; +import org.nuiton.eugene.models.object.ObjectModelGenerator; +import org.nuiton.topia.persistence.metadata.TopiaMetadataModelVisitor; +import org.nuiton.topia.persistence.metadata.TopiaMetadataEntity; +import org.nuiton.topia.persistence.metadata.TopiaMetadataModel; + +import java.io.IOException; +import java.io.Writer; +import java.util.Collection; +import java.util.List; + +/*{generator option: parentheses = true}*/ +/*{generator option: writeString = output.write}*/ + +/** + * Created on 03/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.templates.TopiaMetadataModelGenerator" + */ +public class TopiaMetadataModelGenerator extends ObjectModelGenerator { + + private static final Log log = LogFactory.getLog(TopiaMetadataModelGenerator.class); + + protected TopiaTemplateHelper templateHelper; + + protected TopiaTagValues topiaTagValues; + + private String entityEnumName; + + @Override + public void generateFromModel(Writer output, ObjectModel input) throws IOException { + + if (templateHelper == null) { + templateHelper = new TopiaTemplateHelper(model); + } + if (topiaTagValues == null) { + topiaTagValues = templateHelper.getTopiaTagValues(); + } + + List<ObjectModelClass> entityClasses = templateHelper.getEntityClasses(model, true); + + TopiaMetadataModel metadataModel = new TopiaMetadataModel(); + for (ObjectModelClass entityClass : entityClasses) { + buildMetadataEntity(entityClass, metadataModel); + } + + if (log.isDebugEnabled()) { + TopiaMetadataModelVisitor.PrintVisitor visitor = new TopiaMetadataModelVisitor.PrintVisitor(true, "\n"); + metadataModel.accept(visitor); + log.info("MetadataModel:\n" + visitor); + } + + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + gson.toJson(metadataModel, output); + + } + + @Override + public String getFilenameForModel(ObjectModel model) { + if (templateHelper == null) { + templateHelper = new TopiaTemplateHelper(model); + } + return templateHelper.getTopiaMetadataModelFilePath(this, model); + } + + // protected void generateAddTableMethodContent(StringBuilder content, TopiaMetadataEntity clazz, Set<TopiaMetadataEntity> alreadyDone) { +// +// String clazzName = clazz.getName(); +// +// for (TopiaMetadataEntity reverseAssociationClazz : clazz.getReversedAssociations().values()) { +// +// if (alreadyDone.contains(reverseAssociationClazz)) { +// continue; +// } +// alreadyDone.add(reverseAssociationClazz); +// +// String reverseAssociationName = reverseAssociationClazz.getName(); +// +// if (reverseAssociationClazz.isEmpty()) { +// content.append("" +// +// .addReverseJoinTable(<%=entityEnumName%>.<%=reverseAssociationName%>)} +// ); +// addComment(content, "= " + clazzName); +// } else { +// +// content.append("" +// +// .addAndEnterReverseJoinTable(<%=entityEnumName%>.<%=reverseAssociationName%>)} +// ); +// addComment(content, "→ " + reverseAssociationName); +// generateAddTableMethodContent(content, reverseAssociationClazz, alreadyDone); +// addBackToParent(content, clazzName); +// } +// } +// +// for (TopiaMetadataEntity nmAssociationClazz : clazz.getNmAssociations().values()) { +// +// if (alreadyDone.contains(nmAssociationClazz)) { +// continue; +// } +// alreadyDone.add(nmAssociationClazz); +// +// String nmAssociationName = nmAssociationClazz.getName(); +// +// content.append("" +// +// .addAssociationTable(<%=entityEnumName%>.<%=nmAssociationName%>.name(), true)} +// ); +// addComment(content, "= " + clazzName); +// +// } +// +// for (TopiaMetadataEntity associationClazz : clazz.getAssociations().values()) { +// +// if (alreadyDone.contains(associationClazz)) { +// continue; +// } +// alreadyDone.add(associationClazz); +// +// String associationName = associationClazz.getName(); +// +// if (associationClazz.isEmpty()) { +// +// content.append("" +// +// .addJoinTable(<%=entityEnumName%>.<%=associationName%>)} +// ); +// addComment(content, "= " + clazzName); +// +// } else { +// content.append("" +// +// .addAndEnterJoinTable(<%=entityEnumName%>.<%=associationName%>)} +// ); +// addComment(content, "→ " + associationName); +// generateAddTableMethodContent(content, associationClazz, alreadyDone); +// addBackToParent(content, clazzName); +// +// } +// } +// } +// +// protected void addBackToParent(StringBuilder content, String clazzName) { +// content.append("" +/// +// .backToParent()} +// ); +// addComment(content, "← " + clazzName); +// } +// +// protected void addComment(StringBuilder content, String comment) { +// content.append(" /* ").append(comment).append(" */"); +// } + + protected TopiaMetadataEntity buildMetadataEntity(ObjectModelClass entityClass, TopiaMetadataModel metadataModel) { + + TopiaMetadataEntity metadataEntity; + + String entityClassName = entityClass.getName(); + Optional<TopiaMetadataEntity> optionalClazz = metadataModel.getOptionalEntity(entityClassName); + if (optionalClazz.isPresent()) { + + metadataEntity = optionalClazz.get().copy(); + + } else { + + log.info("Start " + entityClassName); + + metadataEntity = metadataModel.newEntity(entityClassName); + + Collection<ObjectModelAttribute> attributes = entityClass.getAttributes(); + for (ObjectModelAttribute attr : attributes) { + + ObjectModelAttribute reverse = attr.getReverseAttribute(); + + if (!attr.isNavigable() + && !templateHelper.hasUnidirectionalRelationOnAbstractType(reverse, model) + && !attr.hasAssociationClass()) { + continue; + } + + if (attr.getClassifier() == null || !templateHelper.isEntity(attr.getClassifier())) { + continue; + } + + ObjectModelClass attributeClass = model.getClass(attr.getType()); + + Optional<TopiaMetadataEntity> optionalAttributeClass = metadataModel.getOptionalEntity(attributeClass.getName()); + + String name = attr.getName(); + + TopiaMetadataEntity attributeClazz; + if (optionalAttributeClass.isPresent()) { + attributeClazz = optionalAttributeClass.get().copy(); + } else { + attributeClazz = buildMetadataEntity(attributeClass, metadataModel); + } + + if (GeneratorUtil.isNMultiplicity(attr)) { + if (GeneratorUtil.isNMultiplicity(attr.getReverseMaxMultiplicity()) && !attr.hasAssociationClass()) { + + // many to many + metadataEntity.addNmAssociation(attributeClazz, name); + } else { + + // one to many + metadataEntity.addAssociation(attributeClazz, name); + } + + } else { + if (GeneratorUtil.isNMultiplicity(attr.getReverseMaxMultiplicity()) && !attr.hasAssociationClass()) { + + // many to one + metadataEntity.addRequired(attributeClazz, name); + + } else { + + // one to one + metadataEntity.addReversedAssociation(attributeClazz, name); + } + } + + } + log.info("End " + entityClassName); + } + + return metadataEntity; + } + +} \ No newline at end of file diff --git a/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaTemplateHelper.java b/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaTemplateHelper.java index ec57837..236a1ed 100644 --- a/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaTemplateHelper.java +++ b/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaTemplateHelper.java @@ -29,9 +29,9 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.nuiton.eugene.AbstractGenerator; import org.nuiton.eugene.EugeneStereoTypes; import org.nuiton.eugene.GeneratorUtil; +import org.nuiton.eugene.Template; import org.nuiton.eugene.java.JavaGeneratorUtil; import org.nuiton.eugene.java.ObjectModelTransformerToJava; import org.nuiton.eugene.models.object.ObjectModel; @@ -47,6 +47,7 @@ import org.nuiton.eugene.models.object.ObjectModelParameter; import org.nuiton.eugene.models.tagvalue.TagValueDefinitionProvider; import org.nuiton.eugene.models.tagvalue.TagValueDefinitionProviderManagerExtension; +import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -129,7 +130,7 @@ public class TopiaTemplateHelper { * @param generator le générateur donné * @return le package par défaut du générator donné */ - public String getDefaultPackage(AbstractGenerator<?> generator) { + public String getDefaultPackage(Template<?> generator) { String packageName = generator.getProperty(PROPERTY_DEFAULT_PACKAGE); if (StringUtils.isBlank(packageName)) { packageName = DEFAULT_PACKAGE; @@ -234,6 +235,11 @@ public class TopiaTemplateHelper { return input.getPackageName() + "." + getConcreteDaoName(input); } + public String getTopiaMetadataModelFilePath(Template<?> generator, ObjectModel model) { + String packageName = getDefaultPackage(generator); + return (packageName + '.').replace('.', File.separatorChar) + model.getName() + "TopiaMetadataModel.json"; + } + public String getEntityPackage(ObjectModelTransformerToJava transformer, ObjectModel model, ObjectModelClassifier input) { -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/3860_introduce_topiasqlbatchsupport in repository topia. See http://git.nuiton.org/topia.git commit da1870e5f0e9896c9fb620af941c215644d4af6e Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Jan 4 17:26:50 2016 +0100 Add also getEntityEnum by name in TopiaEntityEnumProvider --- .../org/nuiton/topia/persistence/TopiaEntityEnumProvider.java | 8 ++++++++ .../nuiton/topia/templates/ApplicationContextTransformer.java | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityEnumProvider.java b/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityEnumProvider.java index 9f73520..d9128b0 100644 --- a/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityEnumProvider.java +++ b/topia-persistence/src/main/java/org/nuiton/topia/persistence/TopiaEntityEnumProvider.java @@ -43,4 +43,12 @@ public interface TopiaEntityEnumProvider<T extends TopiaEntityEnum> { */ <E extends TopiaEntity> T getEntityEnum(Class<E> type); + /** + * Method that returns the TopiaEntityEnum corresponding to the given name. + * + * @param name the entity enum name + * @return the found TopiaEntityEnum. Should not be null. + */ + T getEntityEnum(String name); + } diff --git a/topia-templates/src/main/java/org/nuiton/topia/templates/ApplicationContextTransformer.java b/topia-templates/src/main/java/org/nuiton/topia/templates/ApplicationContextTransformer.java index 4bbb5f2..f7de8e8 100644 --- a/topia-templates/src/main/java/org/nuiton/topia/templates/ApplicationContextTransformer.java +++ b/topia-templates/src/main/java/org/nuiton/topia/templates/ApplicationContextTransformer.java @@ -248,6 +248,16 @@ public class ApplicationContextTransformer extends ObjectModelTransformerToJava return <%=entityEnumName%>.valueOf(type); }*/ ); + + op = addOperation(output, "getEntityEnum", entityEnumName, + ObjectModelJavaModifier.PUBLIC); + addAnnotation(output, op, Override.class); + addParameter(op, String.class, "name"); + setOperationBody(op, "" +/*{ + return <%=entityEnumName%>.valueOf(name); + }*/ + ); } protected ObjectModelClass generateImpl(String packageName, -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/3860_introduce_topiasqlbatchsupport in repository topia. See http://git.nuiton.org/topia.git commit 3317d1f4d1f034cc46f2503d04f45cbab27698fe Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Jan 4 20:44:35 2016 +0100 Generate metadata model location path --- .../internal/AbstractTopiaApplicationContext.java | 5 +++-- .../internal/support/TopiaMetadataModelSupportImpl.java | 5 ++--- .../topia/templates/ApplicationContextTransformer.java | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaApplicationContext.java b/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaApplicationContext.java index 6a02b0d..5ae2676 100644 --- a/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaApplicationContext.java +++ b/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/AbstractTopiaApplicationContext.java @@ -52,7 +52,6 @@ import org.nuiton.topia.persistence.event.TopiaSchemaListener; import org.nuiton.topia.persistence.event.TopiaTransactionListener; import org.nuiton.topia.persistence.event.TopiaTransactionVetoable; import org.nuiton.topia.persistence.internal.support.TopiaFiresSupport; -import org.nuiton.topia.persistence.internal.support.TopiaMetadataModelSupportImpl; import org.nuiton.topia.persistence.internal.support.TopiaServiceSupportImpl; import org.nuiton.topia.persistence.metadata.TopiaMetadataModel; import org.nuiton.topia.persistence.support.TopiaMetadataModelSupport; @@ -126,13 +125,15 @@ public abstract class AbstractTopiaApplicationContext<K extends TopiaPersistence init(); } + protected abstract TopiaMetadataModelSupport loadMetadataModelSupport(); + protected void init() { new TopiaConfigurationBuilder().check(configuration); topiaFiresSupport = new TopiaFiresSupport(); sessionRegistry = new TopiaHibernateSessionRegistry(); - topiaMetadataModelSupport = new TopiaMetadataModelSupportImpl(this); + topiaMetadataModelSupport = loadMetadataModelSupport(); // First initialize all the services initServices(); diff --git a/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/TopiaMetadataModelSupportImpl.java b/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/TopiaMetadataModelSupportImpl.java index 4fdd915..3b0ccca 100644 --- a/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/TopiaMetadataModelSupportImpl.java +++ b/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/TopiaMetadataModelSupportImpl.java @@ -1,6 +1,5 @@ package org.nuiton.topia.persistence.internal.support; -import org.nuiton.topia.persistence.TopiaApplicationContext; import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.persistence.TopiaPersistenceContext; import org.nuiton.topia.persistence.metadata.TopiaMetadataModel; @@ -19,8 +18,8 @@ public class TopiaMetadataModelSupportImpl implements TopiaMetadataModelSupport protected TopiaMetadataModel metadataModel; - public <K extends TopiaPersistenceContext> TopiaMetadataModelSupportImpl(TopiaApplicationContext topiaApplicationContext) { - this.metadataModelPath = String.format("/%s/%sTopiaMetadataModel.json", topiaApplicationContext.getClass().getPackage().getName().replace(".", "/"), topiaApplicationContext.getModelName()); + public <K extends TopiaPersistenceContext> TopiaMetadataModelSupportImpl(String packageName, String modelName) { + this.metadataModelPath = String.format("/%s/%sTopiaMetadataModel.json", packageName.replace(".", "/"), modelName); } @Override diff --git a/topia-templates/src/main/java/org/nuiton/topia/templates/ApplicationContextTransformer.java b/topia-templates/src/main/java/org/nuiton/topia/templates/ApplicationContextTransformer.java index f7de8e8..bdc4783 100644 --- a/topia-templates/src/main/java/org/nuiton/topia/templates/ApplicationContextTransformer.java +++ b/topia-templates/src/main/java/org/nuiton/topia/templates/ApplicationContextTransformer.java @@ -38,6 +38,8 @@ import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaEntityEnumProvider; import org.nuiton.topia.persistence.internal.AbstractTopiaApplicationContext; import org.nuiton.topia.persistence.internal.AbstractTopiaPersistenceContextConstructorParameter; +import org.nuiton.topia.persistence.internal.support.TopiaMetadataModelSupportImpl; +import org.nuiton.topia.persistence.support.TopiaMetadataModelSupport; import org.nuiton.topia.persistence.util.EntityOperator; import java.util.Properties; @@ -258,6 +260,19 @@ public class ApplicationContextTransformer extends ObjectModelTransformerToJava return <%=entityEnumName%>.valueOf(name); }*/ ); + + addImport(output, TopiaMetadataModelSupportImpl.class); + String defaultPackageName = getDefaultPackageName(); + + op = addOperation(output, "loadMetadataModelSupport", TopiaMetadataModelSupport.class, + ObjectModelJavaModifier.PROTECTED); + addAnnotation(output, op, Override.class); + setOperationBody(op, "" +/*{ + return new TopiaMetadataModelSupportImpl("<%=defaultPackageName%>", "<%=modelName%>"); + }*/ + ); + } protected ObjectModelClass generateImpl(String packageName, -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/3860_introduce_topiasqlbatchsupport in repository topia. See http://git.nuiton.org/topia.git commit f1f64ddc23b10613ac787c5ea412154957982004 Author: Tony CHEMIT <chemit@codelutin.com> Date: Mon Jan 4 20:45:41 2016 +0100 Add withShell method on metadata entity --- .../org/nuiton/topia/persistence/metadata/TopiaMetadataEntity.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataEntity.java b/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataEntity.java index cf7fdcb..c409592 100644 --- a/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataEntity.java +++ b/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataEntity.java @@ -120,4 +120,8 @@ public class TopiaMetadataEntity { } visitor.visitEntiyEnd(metadataModel, this); } + + public boolean withShell() { + return !(reversedAssociations.isEmpty() && associations.isEmpty() && nmAssociations.isEmpty()); + } } -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/3860_introduce_topiasqlbatchsupport in repository topia. See http://git.nuiton.org/topia.git commit a7bdec3b47fa6f01f88cca718772ed4a53fe9ac4 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 5 08:24:59 2016 +0100 Add new topia-sql-batch module --- pom.xml | 1 + topia-service-sql-batch/LICENSE.txt | 165 +++++++++++++++++ topia-service-sql-batch/README.txt | 2 + topia-service-sql-batch/changelog.txt | 2 + topia-service-sql-batch/pom.xml | 197 +++++++++++++++++++++ .../src/license/THIRD-PARTY.properties | 26 +++ topia-service-sql-batch/src/site/rst/index.rst | 27 +++ topia-service-sql-batch/src/site/site_fr.xml | 52 ++++++ 8 files changed, 472 insertions(+) diff --git a/pom.xml b/pom.xml index 39f8865..36fee7b 100644 --- a/pom.xml +++ b/pom.xml @@ -205,6 +205,7 @@ <module>topia-junit</module> <module>topia-templates</module> <module>topia-it</module> + <module>topia-service-sql-batch</module> <module>topia-service-replication</module> <module>topia-service-migration</module> <module>topia-service-flyway</module> diff --git a/topia-service-sql-batch/LICENSE.txt b/topia-service-sql-batch/LICENSE.txt new file mode 100644 index 0000000..cca7fc2 --- /dev/null +++ b/topia-service-sql-batch/LICENSE.txt @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/> + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/topia-service-sql-batch/README.txt b/topia-service-sql-batch/README.txt new file mode 100644 index 0000000..d2e50d3 --- /dev/null +++ b/topia-service-sql-batch/README.txt @@ -0,0 +1,2 @@ +To deploy new version of pom: mvn deploy +To install localy: mvn install diff --git a/topia-service-sql-batch/changelog.txt b/topia-service-sql-batch/changelog.txt new file mode 100644 index 0000000..ab64e83 --- /dev/null +++ b/topia-service-sql-batch/changelog.txt @@ -0,0 +1,2 @@ +2.2.0 + * initial version \ No newline at end of file diff --git a/topia-service-sql-batch/pom.xml b/topia-service-sql-batch/pom.xml new file mode 100644 index 0000000..2cb0aa2 --- /dev/null +++ b/topia-service-sql-batch/pom.xml @@ -0,0 +1,197 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + #%L + ToPIA :: Service Replication + + $Id$ + $HeadURL$ + %% + Copyright (C) 2004 - 2010 CodeLutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> + +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.nuiton</groupId> + <artifactId>topia</artifactId> + <version>3.1-SNAPSHOT</version> + </parent> + + <groupId>org.nuiton.topia</groupId> + <artifactId>topia-service-sql-batch</artifactId> + <name>ToPIA :: Service Sql batch</name> + <description>Sql batches service</description> + + <dependencies> + + <!-- Sibling dependencies --> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>topia-persistence</artifactId> + <version>${project.version}</version> + <scope>compile</scope> + </dependency> + + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>topia-junit</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>topia-it</artifactId> + <version>${project.version}</version> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + </dependency> + + <dependency> + <groupId>commons-logging</groupId> + <artifactId>commons-logging</artifactId> + </dependency> + + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + </dependency> + + <dependency> + <groupId>org.nuiton</groupId> + <artifactId>nuiton-utils</artifactId> + </dependency> + + <dependency> + <groupId>org.hibernate</groupId> + <artifactId>hibernate-core</artifactId> + </dependency> + + <!-- Depencies for test--> + <dependency> + <groupId>com.h2database</groupId> + <artifactId>h2</artifactId> + </dependency> + + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-lang3</artifactId> + <scope>test</scope> + </dependency> + + <dependency> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-log4j12</artifactId> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + </dependency> + + </dependencies> + + <build> + <plugins> + + <plugin> + <artifactId>maven-jar-plugin</artifactId> + <executions> + <execution> + <id>attach-test</id> + <goals> + <goal>test-jar</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + + <profiles> + <!-- perform only on a release stage when using the maven-release-plugin --> + <profile> + <id>release-profile</id> + <activation> + <property> + <name>performRelease</name> + <value>true</value> + </property> + </activation> + + <build> + <plugins> + + <!-- always compute tests source jar --> + <plugin> + <artifactId>maven-source-plugin</artifactId> + <executions> + <execution> + <id>attach-test-sources</id> + <goals> + <goal>test-jar</goal> + </goals> + </execution> + </executions> + </plugin> + + <!-- always compute tests source jar --> + <plugin> + <artifactId>maven-javadoc-plugin</artifactId> + <executions> + <execution> + <id>attach-test-javadoc</id> + <goals> + <goal>test-jar</goal> + </goals> + </execution> + </executions> + </plugin> + + </plugins> + </build> + </profile> + + <!-- reporting at release time --> + <profile> + <id>reporting</id> + <activation> + <property> + <name>performRelease</name> + <value>true</value> + </property> + </activation> + + <reporting> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>cobertura-maven-plugin</artifactId> + <version>${coberturaPluginVersion}</version> + </plugin> + </plugins> + </reporting> + + </profile> + </profiles> +</project> diff --git a/topia-service-sql-batch/src/license/THIRD-PARTY.properties b/topia-service-sql-batch/src/license/THIRD-PARTY.properties new file mode 100644 index 0000000..b1d20ff --- /dev/null +++ b/topia-service-sql-batch/src/license/THIRD-PARTY.properties @@ -0,0 +1,26 @@ +# Generated by org.codehaus.mojo.license.AddThirdPartyMojo +#------------------------------------------------------------------------------- +# Already used licenses in project : +# - Apache License 2.0 +# - BSD License +# - COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 +# - Common Public License Version 1.0 +# - GNU Lesser General Public License, version 2.1 +# - GNU Library or Lesser General Public License +# - Indiana University Extreme! Lab Software License, vesion 1.1.1 +# - Lesser General Public License (LGPL) v 3.0 +# - Lesser General Public License (LPGL) +# - Lesser General Public License (LPGL) v 2.1 +# - MIT License +# - MPL 1.1 +# - New BSD License +# - The Apache Software License, Version 2.0 +# - The H2 License, Version 1.0 +# - license.txt +#------------------------------------------------------------------------------- +# Please fill the missing licenses for dependencies : +# +# +#Fri Mar 15 12:41:29 CET 2013 +commons-primitives--commons-primitives--1.0=The Apache Software License, Version 2.0 +dom4j--dom4j--1.6.1=BSD License diff --git a/topia-service-sql-batch/src/site/rst/index.rst b/topia-service-sql-batch/src/site/rst/index.rst new file mode 100644 index 0000000..21ede12 --- /dev/null +++ b/topia-service-sql-batch/src/site/rst/index.rst @@ -0,0 +1,27 @@ +.. - +.. * #%L +.. * ToPIA :: Service Sql Batch +.. * %% +.. * Copyright (C) 2016 CodeLutin, Tony Chemit +.. * %% +.. * This program is free software: you can redistribute it and/or modify +.. * it under the terms of the GNU Lesser General Public License as +.. * published by the Free Software Foundation, either version 3 of the +.. * License, or (at your option) any later version. +.. * +.. * This program is distributed in the hope that it will be useful, +.. * but WITHOUT ANY WARRANTY; without even the implied warranty of +.. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +.. * GNU General Lesser Public License for more details. +.. * +.. * You should have received a copy of the GNU General Lesser Public +.. * License along with this program. If not, see +.. * <http://www.gnu.org/licenses/lgpl-3.0.html>. +.. * #L% +.. - + +================================ +ToPIA :: topia-service-sql-batch +================================ + +Ce module fournit des méthodes permettant d'exécuter des commandes sql en lot. diff --git a/topia-service-sql-batch/src/site/site_fr.xml b/topia-service-sql-batch/src/site/site_fr.xml new file mode 100644 index 0000000..d1bc746 --- /dev/null +++ b/topia-service-sql-batch/src/site/site_fr.xml @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + #%L + ToPIA + $Id$ + $HeadURL$ + %% + Copyright (C) 2004 - 2014 CodeLutin + %% + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Lesser Public License for more details. + + You should have received a copy of the GNU General Lesser Public + License along with this program. If not, see + <http://www.gnu.org/licenses/lgpl-3.0.html>. + #L% + --> + +<project name="ToPIA"> + + <bannerLeft> + <src alt="ToPIA">${siteCommonResourcesUrl}/images/logos/topia_224_75.png</src> + <name>${project.name}</name> + <href>index.html</href> + </bannerLeft> + + <body> + + <head> + + <link rel="stylesheet" type="text/css" + href="${siteCommonResourcesUrl}/css/mavenpom-site.css"/> + + </head> + + <breadcrumbs> + <item href="index.html" name="Accueil"/> + </breadcrumbs> + + <menu ref="parent"/> + + <menu ref="reports"/> + + </body> +</project> -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/3860_introduce_topiasqlbatchsupport in repository topia. See http://git.nuiton.org/topia.git commit 3ff485df15ec5d70dbcd71ef628d00a8a9fd4efa Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 5 08:25:22 2016 +0100 Add TopiaSqlTable API --- .../service/sql/batch/tables/TopiaSqlTable.java | 138 +++++++ .../service/sql/batch/tables/TopiaSqlTables.java | 406 +++++++++++++++++++++ .../sql/batch/tables/TopiaSqlTablesFactory.java | 193 ++++++++++ 3 files changed, 737 insertions(+) diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTable.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTable.java new file mode 100644 index 0000000..fd04e9e --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTable.java @@ -0,0 +1,138 @@ +package org.nuiton.topia.service.sql.batch.tables; + +/* + * #%L + * ToPIA :: Service Replication + * %% + * Copyright (C) 2004 - 2015 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import com.google.common.base.MoreObjects; +import com.google.common.collect.ImmutableSet; + +import java.util.Objects; + +/** + * Created on 30/12/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public class TopiaSqlTable { + + /** + * Table schema name. + */ + protected final String schemaName; + + /** + * Table name. + */ + protected final String tableName; + + /** + * Fully table name (including the schema name). + */ + protected final String fullyTableName; + + /** + * From clause. + */ + protected final String fromClause; + + /** + * Where clause alias. + */ + protected final String whereClauseAlias; + + /** + * Join clauses. + */ + protected final ImmutableSet<String> joinClauses; + + public TopiaSqlTable(String schemaName, + String tableName, + String fromClause, + String whereClauseAlias, + ImmutableSet<String> joinClauses) { + this.schemaName = schemaName.toLowerCase(); + this.tableName = tableName.toLowerCase(); + this.fullyTableName = this.schemaName + "." + this.tableName; + this.fromClause = fromClause; + this.whereClauseAlias = whereClauseAlias; + this.joinClauses = joinClauses; + } + + public String getSchemaName() { + return schemaName; + } + + public String getTableName() { + return tableName; + } + + public String getFullyTableName() { + return fullyTableName; + } + + public String getFromClause() { + return fromClause; + } + + public String getWhereClauseAlias() { + return whereClauseAlias; + } + + public String getWhereClause(ImmutableSet<String> ids) { + String result = whereClauseAlias; + if (ids.size() == 1) { + result += " = ?"; + } else { + String in = ""; + for (String ignored : ids) { + in += ", ?"; + } + result += " IN (" + in.substring(2) + ")"; + } + return result; + } + + public ImmutableSet<String> getJoinClauses() { + return joinClauses; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + TopiaSqlTable that = (TopiaSqlTable) o; + return Objects.equals(fullyTableName, that.fullyTableName); + } + + @Override + public int hashCode() { + return Objects.hash(fullyTableName); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("fullyTableName", fullyTableName) + .toString(); + } +} diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTables.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTables.java new file mode 100644 index 0000000..5498284 --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTables.java @@ -0,0 +1,406 @@ +package org.nuiton.topia.service.sql.batch.tables; + +/* + * #%L + * ToPIA :: Service Sql batch + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import com.google.common.base.MoreObjects; +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Lists; +import org.nuiton.topia.persistence.TopiaEntityEnum; + +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.TreeMap; + +/** + * Created on 01/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public class TopiaSqlTables implements Iterable<TopiaSqlTable> { + + protected final ImmutableMap<String, TopiaSqlTable> tablesByFullyTableName; + protected final ImmutableSet<TopiaSqlTable> orderedTables; + + public TopiaSqlTables(ImmutableMap<String, TopiaSqlTable> tablesByFullyTableName, + ImmutableSet<TopiaSqlTable> orderedTables) { + this.tablesByFullyTableName = tablesByFullyTableName; + this.orderedTables = orderedTables; + } + + public static Builder builder() { + return new BuilderImpl(); + } + + public static BuilderStepOnTable builder(TopiaEntityEnum mainEntityEnum) { + return builder().addMainTable(mainEntityEnum); + } + + public TopiaSqlTable getTable(String key) { + return tablesByFullyTableName.get(key); + } + + @Override + public Iterator<TopiaSqlTable> iterator() { + return orderedTables.iterator(); + } + + @Override + public String toString() { + return MoreObjects.toStringHelper(this) + .add("orderedTables", orderedTables) + .toString(); + } + + /** + * Created on 02/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + */ + public interface Builder { + + BuilderStepOnTable addMainTable(TopiaEntityEnum entityEnum); + + TopiaSqlTables build(); + + } + + public interface BuilderStepOnTable extends Builder { + + BuilderStepOnTable addJoinTable(TopiaEntityEnum entityEnum); + + BuilderStepOnTable addAndEnterJoinTable(TopiaEntityEnum entityEnum); + + BuilderStepOnTable addReverseJoinTable(TopiaEntityEnum entityEnum); + + BuilderStepOnTable addAndEnterReverseJoinTable(TopiaEntityEnum entityEnum); + + BuilderStepOnTable addAssociationTable(String associationName); + + BuilderStepOnTable backToParent(); + + BuilderStepOnTable backToTable(TopiaEntityEnum entityEnum); + + BuilderStepOnTable checkCurrentTable(TopiaEntityEnum entityEnum); + } + + + /** + * Created on 01/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + */ + protected static class BuilderImpl implements Builder { + + protected final TreeMap<String, TopiaSqlTable> tablesByFullyTableName; + + protected final TreeMap<Integer, TopiaSqlTable> tablesByOrder; + + protected int internalOrder; + + public BuilderImpl() { + this.tablesByFullyTableName = new TreeMap<>(); + this.tablesByOrder = new TreeMap<>(); + } + + @Override + public BuilderStepOnTable addMainTable(TopiaEntityEnum entityEnum) { + + String schemaName = entityEnum.dbSchemaName().toLowerCase(); + String tableName = entityEnum.dbTableName().toLowerCase(); + + //TODO check that this table is not already registred + String whereClauseAlias = tableName + ".topiaid"; + String fromClause = schemaName + "." + tableName + " " + tableName; + + registerTable(schemaName, + tableName, + whereClauseAlias, + fromClause, + ImmutableSet.<String>of()); + + return new BuilderStepOnTableImpl(null, entityEnum); + } + + @Override + public TopiaSqlTables build() { + + List<Integer> orders = Lists.newArrayList(tablesByOrder.keySet()); + Collections.sort(orders); + ImmutableSet.Builder<TopiaSqlTable> orderedTablesBuilder = ImmutableSet.builder(); + for (Integer order : orders) { + orderedTablesBuilder.add(tablesByOrder.get(order)); + } + + return new TopiaSqlTables(ImmutableMap.copyOf(tablesByFullyTableName), + orderedTablesBuilder.build()); + } + + protected Builder registerTable(String schemaName, + String tableName, + String whereClauseAlias, + String fromClause, + ImmutableSet<String> joinClauses) { + + //TODO check that this table is not already registred + + TopiaSqlTable table = new TopiaSqlTable( + schemaName, + tableName, + fromClause, + whereClauseAlias, + joinClauses); + + tablesByFullyTableName.put(table.getFullyTableName(), table); + tablesByOrder.put(internalOrder++, table); + return this; + } + + protected TopiaSqlTable getTable(String key) { + return tablesByFullyTableName.get(key); + } + + protected TopiaSqlTable getTable(TopiaEntityEnum entityEnum) { + String key = getFullyTableName(entityEnum); + return tablesByFullyTableName.get(key); + } + + protected String getFullyTableName(TopiaEntityEnum entityEnum) { + return entityEnum.dbSchemaName().toLowerCase() + "." + entityEnum.dbTableName().toLowerCase(); + } + + protected String getAssociationTableName(String tableName, String parentTableName) { + String associationTableName; + if (tableName.compareTo(parentTableName) < 0) { + associationTableName = tableName + "_" + parentTableName; + } else { + associationTableName = parentTableName + "_" + tableName; + } + return associationTableName; + } + + protected class BuilderStepOnTableImpl implements Builder, BuilderStepOnTable { + + protected final BuilderStepOnTableImpl parent; + + protected final TopiaEntityEnum tableEntityEnum; + + protected BuilderStepOnTableImpl(BuilderStepOnTableImpl parent, TopiaEntityEnum tableEntityEnum) { + this.parent = parent; + this.tableEntityEnum = tableEntityEnum; + } + + @Override + public BuilderStepOnTable addMainTable(TopiaEntityEnum entityEnum) { + return BuilderImpl.this.addMainTable(entityEnum); + } + + @Override + public TopiaSqlTables build() { + return BuilderImpl.this.build(); + } + + @Override + public BuilderStepOnTable addJoinTable(TopiaEntityEnum entityEnum) { + + TopiaSqlTable parentTable = getTable(); + + String schemaName = entityEnum.dbSchemaName().toLowerCase(); + String tableName = entityEnum.dbTableName().toLowerCase(); + + String parentTableName = parentTable.getTableName(); + + String whereClauseAlias; + String fromClause; + ImmutableSet<String> joinClauses; + + if (parent == null) { + + // parent table is main (no join on it) + // we can directly use the target table to join + + whereClauseAlias = tableName + "." + parentTableName; + fromClause = schemaName + "." + tableName + " " + tableName; + joinClauses = ImmutableSet.of(); + + } else { + + // simple join table + + whereClauseAlias = parentTable.getWhereClauseAlias(); + fromClause = parentTable.getFromClause(); + String joinClause = " INNER JOIN " + schemaName + "." + tableName + " " + tableName + " ON " + tableName + "." + parentTableName + " = " + parentTableName + ".topiaId"; + + joinClauses = addJoinCause(parentTable.getJoinClauses(), joinClause); + + } + + registerTable(schemaName, + tableName, + whereClauseAlias, + fromClause, + joinClauses); + + return this; + } + + @Override + public BuilderStepOnTable addAndEnterJoinTable(TopiaEntityEnum entityEnum) { + addJoinTable(entityEnum); + return new BuilderStepOnTableImpl(this, entityEnum); + } + + @Override + public BuilderStepOnTable addReverseJoinTable(TopiaEntityEnum entityEnum) { + + TopiaSqlTable parentTable = getTable(); + + String schemaName = entityEnum.dbSchemaName().toLowerCase(); + String tableName = entityEnum.dbTableName().toLowerCase(); + String whereClauseAlias = parentTable.getWhereClauseAlias(); + String fromClause = parentTable.getFromClause(); + + String parentTableName = parentTable.getTableName(); + String joinClause = " INNER JOIN " + schemaName + "." + tableName + " " + tableName + " ON " + tableName + ".topiaId = " + parentTableName + "." + tableName; + + ImmutableSet<String> joinClauses = addJoinCause(parentTable.getJoinClauses(), joinClause); + + registerTable( + schemaName, + tableName, + whereClauseAlias, + fromClause, + joinClauses); + + invertOrderWithParent(parentTable, entityEnum); + return this; + + } + + @Override + public BuilderStepOnTable addAndEnterReverseJoinTable(TopiaEntityEnum entityEnum) { + addReverseJoinTable(entityEnum); + return new BuilderStepOnTableImpl(this, entityEnum); + } + + @Override + public BuilderStepOnTable addAssociationTable(String associationName) { + + TopiaSqlTable parentTable = getTable(); + + String schemaName = tableEntityEnum.dbSchemaName().toLowerCase(); + String tableName = getAssociationTableName(associationName.toLowerCase(), parentTable.getTableName()); + String whereClauseAlias = parentTable.getWhereClauseAlias(); + String fromClause = parentTable.getFromClause(); + if (parentTable.getJoinClauses().isEmpty()) { + fromClause = schemaName + "." + tableName; + } + ImmutableSet<String> joinClauses; + + boolean addInnerJoin = parent != null; + if (addInnerJoin) { + + String parentTableName = parentTable.getTableName(); + String joinClause = " INNER JOIN " + schemaName + "." + tableName + " " + tableName + " ON " + tableName + "." + parentTableName + " = " + parentTableName + ".topiaId"; + joinClauses = addJoinCause(parentTable.getJoinClauses(), joinClause); + + } else { + joinClauses = parentTable.getJoinClauses(); + } + + registerTable(schemaName, + tableName, + whereClauseAlias, + fromClause, + joinClauses); + return this; + } + + @Override + public BuilderStepOnTable backToParent() { + Preconditions.checkState(parent != null, "Could not find a parent table"); + return parent; + } + + @Override + public BuilderStepOnTable backToTable(TopiaEntityEnum entityEnum) { + + BuilderStepOnTable table; + if (Objects.equals(tableEntityEnum, entityEnum)) { + table = this; + } else { + Preconditions.checkState(parent != null, "Could not find a perent table of type: " + entityEnum); + table = parent.backToTable(entityEnum); + } + return table; + } + + @Override + public BuilderStepOnTable checkCurrentTable(TopiaEntityEnum entityEnum) { + Preconditions.checkState(tableEntityEnum.equals(entityEnum), "Current table should be " + entityEnum + ", but was " + tableEntityEnum); + return this; + } + + protected TopiaSqlTable getTable() { + return BuilderImpl.this.getTable(tableEntityEnum); + } + + protected int getTableOrder(TopiaSqlTable table) { + + for (Map.Entry<Integer, TopiaSqlTable> entry : tablesByOrder.entrySet()) { + + if (table.equals(entry.getValue())) { + return entry.getKey(); + } + } + + throw new IllegalStateException("Could not find table " + table.getFullyTableName()); + + } + + protected void invertOrderWithParent(TopiaSqlTable parentTable, TopiaEntityEnum entityEnum) { + + int parentTableOrder = getTableOrder(parentTable); + TopiaSqlTable table = BuilderImpl.this.getTable(entityEnum); + int tableOrder = getTableOrder(table); + tablesByOrder.put(parentTableOrder, table); + tablesByOrder.put(tableOrder, parentTable); + } + + protected ImmutableSet<String> addJoinCause(ImmutableSet<String> joinClauses, String joinClause) { + return ImmutableSet + .<String>builder() + .addAll(joinClauses) + .add(joinClause) + .build(); + } + + } + + } +} \ No newline at end of file diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTablesFactory.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTablesFactory.java new file mode 100644 index 0000000..9c4e489 --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTablesFactory.java @@ -0,0 +1,193 @@ +package org.nuiton.topia.service.sql.batch.tables; + +/* + * #%L + * ToPIA :: Service Sql batch + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.persistence.TopiaEntityEnum; +import org.nuiton.topia.persistence.TopiaEntityEnumProvider; +import org.nuiton.topia.persistence.metadata.TopiaMetadataEntity; +import org.nuiton.topia.persistence.metadata.TopiaMetadataModel; +import org.nuiton.topia.persistence.metadata.TopiaMetadataModelVisitor; + +import java.util.LinkedHashSet; +import java.util.Set; + +/** + * Created on 04/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public class TopiaSqlTablesFactory { + + /** + * Logger. + */ + private static final Log log = LogFactory.getLog(TopiaSqlTablesFactory.class); + + protected final TopiaMetadataModel model; + protected final TopiaEntityEnumProvider entityEnumProvider; + + public TopiaSqlTablesFactory(TopiaMetadataModel model, TopiaEntityEnumProvider entityEnumProvider) { + this.model = model; + this.entityEnumProvider = entityEnumProvider; + } + + public TopiaSqlTables newReplicateEntityTables(TopiaSqlTablesPredicate predicate, TopiaEntityEnum... entityEnums) { + + ReplicateTables tablesBuilder = new ReplicateTables(predicate); + return tablesBuilder.getTables(entityEnums); + + } + + public interface TopiaSqlTablesPredicate { + + boolean acceptEntity(TopiaMetadataEntity metadataEntity); + + boolean acceptAssociation(TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType); + + boolean acceptReversedAssociation(TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType); + + boolean acceptNmAssociation(TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType); + + } + + public class ReplicateTables implements TopiaMetadataModelVisitor { + + protected final TopiaSqlTablesPredicate predicate; + protected final Set<TopiaMetadataEntity> dones; + protected TopiaSqlTables.BuilderStepOnTable builder; + protected TopiaSqlTables tables; + + public ReplicateTables(TopiaSqlTablesPredicate predicate) { + this.predicate = predicate; + this.dones = new LinkedHashSet<>(); + } + + public TopiaSqlTables getTables(TopiaEntityEnum... entityEnums) { + visitModelStart(model); + for (TopiaEntityEnum entityEnum : entityEnums) { + TopiaMetadataEntity entity = model.getEntity(entityEnum.name()); + entity.accept(this, model); + } + visitModelEnd(model); + return tables; + } + + @Override + public void visitModelStart(TopiaMetadataModel metadataModel) { + } + + @Override + public void visitModelEnd(TopiaMetadataModel metadataModel) { + tables = builder.build(); + } + + @Override + public void visitEntiyStart(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity) { + + if (predicate.acceptEntity(metadataEntity)) { + + boolean added = dones.add(metadataEntity); + if (added) { + + log.info("E → " + metadataEntity.getType()); + TopiaEntityEnum entityEnum = entityEnumProvider.getEntityEnum(metadataEntity.getType()); + + builder = (builder == null ? TopiaSqlTables.builder() : builder).addMainTable(entityEnum); + } + } + + } + + @Override + public void visitEntiyEnd(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity) { + + if (dones.contains(metadataEntity)) { + log.info("E ← " + metadataEntity.getType()); + } + + } + + @Override + public void visitReversedAssociation(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) { + + if (predicate.acceptReversedAssociation(metadataEntity, propertyName, propertyType)) { + + TopiaEntityEnum entityEnum = entityEnumProvider.getEntityEnum(propertyType.getType()); + boolean withShell = propertyType.withShell(); + log.info(metadataEntity.getType() + "/" + propertyName + "→" + propertyType.getType() + " (withShell: " + withShell + ")"); + + if (withShell) { + builder = builder.addAndEnterReverseJoinTable(entityEnum); + visitChild(propertyType); + } else { + builder = builder.addReverseJoinTable(entityEnum); + } + } + } + + @Override + public void visitAssociation(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) { + + if (predicate.acceptAssociation(metadataEntity, propertyName, propertyType)) { + + TopiaEntityEnum entityEnum = entityEnumProvider.getEntityEnum(propertyType.getType()); + boolean withShell = propertyType.withShell(); + log.info(metadataEntity.getType() + "/" + propertyName + "→" + propertyType.getType() + " (withShell: " + withShell + ")"); + + if (withShell) { + builder = builder.addAndEnterJoinTable(entityEnum); + visitChild(propertyType); + } else { + builder = builder.addJoinTable(entityEnum); + } + } + + } + + @Override + public void visitNmAssociation(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) { + + if (predicate.acceptNmAssociation(metadataEntity, propertyName, propertyType)) { + + log.info(metadataEntity.getType() + "/" + propertyName + "→" + propertyType.getType()); + + builder = builder.addAssociationTable(propertyName); + } + + } + + @Override + public void visitRequired(TopiaMetadataModel metadataModel, TopiaMetadataEntity metadataEntity, String propertyName, TopiaMetadataEntity propertyType) { + } + + protected void visitChild(TopiaMetadataEntity propertyType) { + dones.add(propertyType); + propertyType.accept(this, model); + builder = builder.backToParent(); + } + + } +} -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/3860_introduce_topiasqlbatchsupport in repository topia. See http://git.nuiton.org/topia.git commit f107b9c3456af57478d18f17fd4df0ecffdbfda3 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 5 08:26:11 2016 +0100 Add Sql action abstract classes --- .../sql/batch/actions/AbstractSchemaAction.java | 60 ++++++ .../sql/batch/actions/AbstractSchemaRequest.java | 106 ++++++++++ .../sql/batch/actions/AbstractSqlAction.java | 231 +++++++++++++++++++++ .../sql/batch/actions/AbstractSqlRequest.java | 114 ++++++++++ .../sql/batch/actions/AbstractTablesAction.java | 214 +++++++++++++++++++ .../sql/batch/actions/AbstractTablesRequest.java | 105 ++++++++++ .../batch/actions/TopiaSqlTableSelectArgument.java | 53 +++++ .../src/test/resources/log4j.properties | 34 +++ 8 files changed, 917 insertions(+) diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractSchemaAction.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractSchemaAction.java new file mode 100644 index 0000000..60c9ffa --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractSchemaAction.java @@ -0,0 +1,60 @@ +package org.nuiton.topia.service.sql.batch.actions; + +/* + * #%L + * ToPIA :: Service Sql batch + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.hibernate.dialect.Dialect; + +import java.io.IOException; +import java.nio.file.Path; +import java.sql.SQLException; + +/** + * Created on 01/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public abstract class AbstractSchemaAction<R extends AbstractSchemaRequest> extends AbstractSqlAction<R> { + + protected AbstractSchemaAction(R request) { + super(request); + } + + protected abstract String produceSql(Class<? extends Dialect> dialectType, Path temporaryDirectory) throws IOException; + + @Override + protected final void execute() throws IOException, SQLException { + + String sqlStatements = produceSql(request.getDialect(), request.getTemporaryPath()); + + if (useOutputDb()) { + targetConnection.createStatement().execute(sqlStatements); + } + + if (useOutputWriter()) { + writer.append(sqlStatements); + } + + } + +} diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractSchemaRequest.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractSchemaRequest.java new file mode 100644 index 0000000..5d035e3 --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractSchemaRequest.java @@ -0,0 +1,106 @@ +package org.nuiton.topia.service.sql.batch.actions; + +/* + * #%L + * ToPIA :: Service Sql batch + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Preconditions; +import org.hibernate.dialect.Dialect; +import org.hibernate.dialect.H2Dialect; +import org.hibernate.dialect.PostgreSQL9Dialect; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; + +/** + * Created on 01/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public abstract class AbstractSchemaRequest extends AbstractSqlRequest { + + protected Class<? extends Dialect> dialect; + + protected Path temporaryPath; + + public Class<? extends Dialect> getDialect() { + return dialect; + } + + protected void setDialect(Class<? extends Dialect> dialect) { + this.dialect = dialect; + } + + public Path getTemporaryPath() { + return temporaryPath; + } + + protected void setTemporaryPath(Path temporaryPath) { + this.temporaryPath = temporaryPath; + } + + public abstract static class AbstractSchemaRequestBuilder<R extends AbstractSchemaRequest, B extends AbstractSchemaRequestBuilder<R, B>> extends AbstractSqlRequestBuilder<B, R> { + + protected AbstractSchemaRequestBuilder(R request) { + super(request); + } + + public B forH2() { + setDialect(H2Dialect.class); + return returnThis(); + } + + public B forPostgres() { + setDialect(PostgreSQL9Dialect.class); + return returnThis(); + } + + public B setDialect(Class<? extends Dialect> dialectType) { + request.setDialect(dialectType); + return returnThis(); + } + + public B setTemporaryPath(Path temporaryPath) { + request.setTemporaryPath(temporaryPath); + return returnThis(); + } + + @Override + protected void checkParams() { + super.checkParams(); + Preconditions.checkState(request.getDialect() != null, "No dialect defined"); + + if (request.getTemporaryPath() == null) { + + try { + Path tempDirectory = Files.createTempDirectory(getClass().getSimpleName()); + setTemporaryPath(tempDirectory); + } catch (IOException e) { + throw new RuntimeException("Could not create teomporary path"); + } + + } + } + + } +} diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractSqlAction.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractSqlAction.java new file mode 100644 index 0000000..984b54a --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractSqlAction.java @@ -0,0 +1,231 @@ +package org.nuiton.topia.service.sql.batch.actions; + +/* + * #%L + * ToPIA :: Service Replication + * %% + * Copyright (C) 2004 - 2015 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import com.google.common.collect.ImmutableSet; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.persistence.TopiaApplicationContext; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.persistence.TopiaPersistenceContext; +import org.nuiton.topia.persistence.internal.AbstractTopiaPersistenceContext; +import org.nuiton.topia.persistence.jdbc.JdbcConfiguration; +import org.nuiton.topia.persistence.jdbc.JdbcHelper; +import org.nuiton.topia.persistence.support.TopiaSqlWork; +import org.nuiton.util.TimeLog; + +import java.io.Closeable; +import java.io.IOException; +import java.io.Writer; +import java.sql.Connection; +import java.sql.SQLException; + +/** + * Support to create action. + * <p> + * Created on 29/12/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public abstract class AbstractSqlAction<R extends AbstractSqlRequest> implements Runnable, Closeable { + + protected static final TimeLog TIME_LOG = new TimeLog(AbstractSqlAction.class, 50L, 100L); + /** + * Logger. + */ + private static final Log log = LogFactory.getLog(AbstractSqlAction.class); + protected final R request; + + protected final ImmutableSet<Closeable> closeables; + + protected TopiaPersistenceContext sourcePersistenceContext; + + protected Connection targetConnection; + + protected Writer writer; + + protected long startTime; + + protected long endTime; + + protected AbstractSqlAction(R request) { + this.request = request; + + ImmutableSet.Builder<Closeable> closeableBuilder = ImmutableSet.builder(); + closeableBuilder.add(new Closeable() { + @Override + public void close() throws IOException { + if (sourcePersistenceContext != null) { + sourcePersistenceContext.close(); + } + } + }); + closeableBuilder.add(new Closeable() { + @Override + public void close() throws IOException { + if (targetConnection != null) { + try { + targetConnection.close(); + } catch (SQLException e) { + throw new TopiaException("Could not close targetConnection", e); + } + } + } + }); + this.closeables = closeableBuilder.build(); + } + + protected static void flush(Writer writer) { + try { + writer.flush(); + } catch (IOException e) { + throw new TopiaException("Could not flush writer", e); + } + } + + public R getRequest() { + return request; + } + + protected boolean useOutputWriter() { + return request.getWriter() != null; + } + + protected boolean useOutputDb() { + return request.getTargetTopiaApplicationContext() != null; + } + + protected abstract void execute() throws IOException, SQLException; + + @Override + public final void run() { + + try { + + before(); + execute(); + after(); + + } catch (Exception e) { + fail(e); + } + + } + + public void commit() { + + if (useOutputWriter()) { + flush(writer); + } + + if (useOutputDb()) { + + if (targetConnection != null) { + try { + targetConnection.commit(); + } catch (SQLException e) { + throw new TopiaException("Could not commit", e); + } + } + + } + + } + + @Override + public final void close() { + + Exception error = null; + for (Closeable closeable : closeables) { + try { + closeable.close(); + } catch (Exception e) { + error = e; + log.error("Could not close", e); + } + } + if (error != null) { + throw new RuntimeException("Could not close", error); + } + + } + + protected final void before() throws SQLException { + startTime = TimeLog.getTime(); + + if (useOutputWriter()) { + writer = request.getWriter(); + } + + if (useOutputDb()) { + OpenJdbcHelper jdbcHelper = new OpenJdbcHelper(request.getTargetTopiaApplicationContext().getConfiguration()); + targetConnection = jdbcHelper.openConnection(); + } + + } + + protected void fail(Exception e) { + + endTime = TIME_LOG.log(startTime, "Action failed", getClass().getName()); + + //FIXME + throw new TopiaException(e); + + } + + protected final void after() throws SQLException { + + endTime = TIME_LOG.log(startTime, "Action executed", getClass().getName()); + + } + + protected void executeSqlWork(TopiaSqlWork sqlWork) { + getSourcePersistenceContext().getSqlSupport().doSqlWork(sqlWork); + } + + protected AbstractTopiaPersistenceContext getSourcePersistenceContext() { + if (sourcePersistenceContext == null) { + sourcePersistenceContext = request.getSourceTopiaApplicationContext().newPersistenceContext(); + } + return (AbstractTopiaPersistenceContext) sourcePersistenceContext; + } + + protected ImmutableSet<String> getSchemaNames() { + TopiaApplicationContext<?> sourceTopiaApplicationContext = request.getSourceTopiaApplicationContext(); + return sourceTopiaApplicationContext.getSchemaNames(); + } + + protected static class OpenJdbcHelper extends JdbcHelper { + + public OpenJdbcHelper(JdbcConfiguration jdbcConfiguration) { + super(jdbcConfiguration); + } + + @Override + public Connection openConnection() throws SQLException { + return super.openConnection(); + } + } + +} diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractSqlRequest.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractSqlRequest.java new file mode 100644 index 0000000..bacc2fc --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractSqlRequest.java @@ -0,0 +1,114 @@ +package org.nuiton.topia.service.sql.batch.actions; + +/* + * #%L + * ToPIA :: Service Replication, tony Chemit + * %% + * Copyright (C) 2004 - 2015 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Preconditions; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.persistence.TopiaApplicationContext; + +import java.io.Writer; + +/** + * Support to create action request. + * <p> + * Created on 29/12/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public abstract class AbstractSqlRequest { + + /** + * Logger. + */ + private static final Log log = LogFactory.getLog(AbstractSqlRequest.class); + + protected TopiaApplicationContext sourceTopiaApplicationContext; + + protected TopiaApplicationContext targetTopiaApplicationContext; + + protected Writer writer; + + public TopiaApplicationContext getTargetTopiaApplicationContext() { + return targetTopiaApplicationContext; + } + + protected void setTargetTopiaApplicationContext(TopiaApplicationContext targetTopiaApplicationContext) { + this.targetTopiaApplicationContext = targetTopiaApplicationContext; + } + + public TopiaApplicationContext getSourceTopiaApplicationContext() { + return sourceTopiaApplicationContext; + } + + protected void setSourceTopiaApplicationContext(TopiaApplicationContext sourceTopiaApplicationContext) { + this.sourceTopiaApplicationContext = sourceTopiaApplicationContext; + } + + public Writer getWriter() { + return writer; + } + + protected void setWriter(Writer writer) { + this.writer = writer; + } + + public static abstract class AbstractSqlRequestBuilder<B extends AbstractSqlRequestBuilder, R extends AbstractSqlRequest> { + + protected final R request; + + protected AbstractSqlRequestBuilder(R request) { + this.request = request; + } + + public B from(TopiaApplicationContext sourceTopiaApplicationContext) { + request.setSourceTopiaApplicationContext(sourceTopiaApplicationContext); + return returnThis(); + } + + public B to(TopiaApplicationContext targetTopiaApplicationContext) { + request.setTargetTopiaApplicationContext(targetTopiaApplicationContext); + return returnThis(); + } + + public B to(Writer writer) { + request.setWriter(writer); + return returnThis(); + } + + public R build() { + checkParams(); + return request; + } + + protected void checkParams() { + Preconditions.checkState(request.getSourceTopiaApplicationContext() != null, "No sourceTopiaApplicationContext defined"); + Preconditions.checkState(request.getWriter() != null || request.getTargetTopiaApplicationContext() != null, "No targetTopiaApplicationContext, nor writer defined"); + } + + protected B returnThis() { + return (B) this; + } + } +} diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractTablesAction.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractTablesAction.java new file mode 100644 index 0000000..02ece9e --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractTablesAction.java @@ -0,0 +1,214 @@ +package org.nuiton.topia.service.sql.batch.actions; + +/* + * #%L + * ToPIA :: Service Replication + * %% + * Copyright (C) 2004 - 2015 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.apache.commons.io.output.ByteArrayOutputStream; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.persistence.support.TopiaSqlWork; +import org.nuiton.topia.service.sql.batch.tables.TopiaSqlTable; +import org.nuiton.util.TimeLog; + +import javax.sql.rowset.serial.SerialBlob; +import java.io.IOException; +import java.io.Writer; +import java.sql.Blob; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * Support to create action. + * <p> + * Created on 29/12/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public abstract class AbstractTablesAction<R extends AbstractTablesRequest> extends AbstractSqlAction<R> { + + /** + * Logger. + */ + private static final Log log = LogFactory.getLog(AbstractTablesAction.class); + + protected AbstractTablesAction(R request) { + super(request); + } + + protected abstract void executeOnTable(R request, TopiaSqlTable table, PreparedStatement readStatement) throws SQLException; + + @Override + protected final void execute() { + + for (TopiaSqlTable table : request.getTables()) { + + long startTable = TimeLog.getTime(); + + TopiaSqlWork sqlWork = new ReadSqlWork(request, table); + executeSqlWork(sqlWork); + + TIME_LOG.log(startTable, "Executed on table.", table.getFullyTableName()); + + } + + } + + protected String generateSqlArguments(ResultSet readResultSet, Iterable<String> columnNames) throws SQLException, IOException { + + String statement = ""; + + for (String columnName : columnNames) { + + Object columnValue = readResultSet.getObject(columnName); + if (columnValue == null) { + statement += ", NULL"; + continue; + } + + if (columnValue instanceof String) { + String stringValue = (String) columnValue; + statement += ", '" + stringValue.replaceAll("'", "''") + "'"; + continue; + } + + if (columnValue instanceof Date) { + statement += ", '" + columnValue + "'"; + continue; + } + + if (columnValue instanceof Blob) { + Blob blob = (Blob) columnValue; + SerialBlob serialBlob = new SerialBlob(blob); + try (ByteArrayOutputStream stringWriter = new ByteArrayOutputStream((int) serialBlob.length())) { + stringWriter.write(serialBlob.getBinaryStream()); + statement += ", '" + new String(stringWriter.toByteArray()) + "'"; + } + continue; + } + + statement += ", " + columnValue; + } + + return statement.substring(2); + + } + + protected String generateWildcardArguments(Iterable<String> columnNames) throws SQLException { + + StringBuilder argsBuilder = new StringBuilder(); + + for (String ignored : columnNames) { + argsBuilder.append(", ?"); + } + + return argsBuilder.substring(2); + + } + + protected void flush(PreparedStatement writeStatement, Writer writer, String tableName, long index) throws SQLException { + + if (log.isDebugEnabled()) { + log.debug("Flush for : " + tableName + " (size: " + index + ")"); + } + + if (writeStatement != null) { + writeStatement.executeBatch(); + writeStatement.clearBatch(); + } + + if (writer != null) { + flush(writer); + } + } + + protected List<String> getColumnNames(ResultSetMetaData readResultTatMetaData, int columnCount) throws SQLException { + List<String> builder = new ArrayList<>(columnCount); + for (int i = 1; i <= columnCount; i++) { + builder.add(readResultTatMetaData.getColumnName(i).toLowerCase()); + } + return builder; + } + + protected class ReadSqlWork implements TopiaSqlWork { + + private final R request; + private final TopiaSqlTable table; + + public ReadSqlWork(R request, TopiaSqlTable table) { + this.request = request; + this.table = table; + } + + @Override + public void execute(Connection connection) throws SQLException { + + try (PreparedStatement readStatement = createReadStatement(table, connection)) { + + readStatement.execute(); + + executeOnTable(request, table, readStatement); + + } + + } + + protected PreparedStatement createReadStatement(TopiaSqlTable table, Connection connection) throws SQLException { + + StringBuilder sqlBuilder = new StringBuilder("SELECT " + table.getTableName() + ".*"); + + sqlBuilder.append(" FROM ").append(table.getFromClause()); + for (String joinClause : table.getJoinClauses()) { + sqlBuilder.append(" ").append(joinClause); + } + TopiaSqlTableSelectArgument selectArgument = request.getSelectArgument(); + boolean filter = selectArgument != null; + if (filter) { + sqlBuilder.append(" WHERE ").append(table.getWhereClause(selectArgument.getIds())); + } + + String sql = sqlBuilder.toString(); + if (log.isDebugEnabled()) { + log.debug("Read sql: " + sql); + } + PreparedStatement statement = connection.prepareStatement(sql); + + if (filter) { + int index = 1; + for (String id : selectArgument.getIds()) { + statement.setString(index++, id); + } + } + statement.setFetchSize(request.getFetchSize()); + return statement; + + } + + } + +} diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractTablesRequest.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractTablesRequest.java new file mode 100644 index 0000000..9edad80 --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractTablesRequest.java @@ -0,0 +1,105 @@ +package org.nuiton.topia.service.sql.batch.actions; + +/* + * #%L + * ToPIA :: Service Replication, tony Chemit + * %% + * Copyright (C) 2004 - 2015 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.service.sql.batch.tables.TopiaSqlTables; + +/** + * Support to create action request. + * <p> + * Created on 29/12/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public abstract class AbstractTablesRequest extends AbstractSqlRequest { + + public static final int DEFAULT_FETCH_SIZE = 100; + /** + * Logger. + */ + private static final Log log = LogFactory.getLog(AbstractTablesRequest.class); + protected int fetchSize; + + protected TopiaSqlTableSelectArgument selectArgument; + + protected TopiaSqlTables tables; + + public int getFetchSize() { + return fetchSize; + } + + public void setFetchSize(int fetchSize) { + this.fetchSize = fetchSize; + } + + public TopiaSqlTableSelectArgument getSelectArgument() { + return selectArgument; + } + + public void setSelectArgument(TopiaSqlTableSelectArgument selectArgument) { + this.selectArgument = selectArgument; + } + + public TopiaSqlTables getTables() { + return tables; + } + + public void setTables(TopiaSqlTables tables) { + this.tables = tables; + } + + /** + * Support to create action builder. + * <p> + * Created on 29/12/15. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ + public abstract static class AbstractTablesRequestBuilder<B extends AbstractTablesRequestBuilder, R extends AbstractTablesRequest> extends AbstractSqlRequestBuilder<B, R> { + + protected AbstractTablesRequestBuilder(R sqlActionRequest) { + super(sqlActionRequest); + setFetchSize(DEFAULT_FETCH_SIZE); + } + + public B setTables(TopiaSqlTables tables) { + request.setTables(tables); + return returnThis(); + } + + public B setFetchSize(int fetchSize) { + request.setFetchSize(fetchSize); + return returnThis(); + } + + public B setSelectArgument(TopiaSqlTableSelectArgument arg) { + request.setSelectArgument(arg); + return returnThis(); + } + + } +} diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/TopiaSqlTableSelectArgument.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/TopiaSqlTableSelectArgument.java new file mode 100644 index 0000000..8f6723c --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/TopiaSqlTableSelectArgument.java @@ -0,0 +1,53 @@ +package org.nuiton.topia.service.sql.batch.actions; + +/* + * #%L + * ToPIA :: Service Sql batch + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; + +/** + * Created on 02/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public class TopiaSqlTableSelectArgument { + + protected final ImmutableSet<String> ids; + + protected TopiaSqlTableSelectArgument(Iterable<String> ids) { + this.ids = ImmutableSet.copyOf(ids); + } + + public static TopiaSqlTableSelectArgument of(String... ids) { + return ids.length == 0 ? null : new TopiaSqlTableSelectArgument(Sets.newHashSet(ids)); + } + + public static TopiaSqlTableSelectArgument of(Iterable<String> ids) { + return new TopiaSqlTableSelectArgument(ids); + } + + public ImmutableSet<String> getIds() { + return ids; + } +} diff --git a/topia-service-sql-batch/src/test/resources/log4j.properties b/topia-service-sql-batch/src/test/resources/log4j.properties new file mode 100644 index 0000000..9ee0066 --- /dev/null +++ b/topia-service-sql-batch/src/test/resources/log4j.properties @@ -0,0 +1,34 @@ +### +# #%L +# ToPIA :: Service Replication +# $Id$ +# $HeadURL$ +# %% +# Copyright (C) 2004 - 2014 CodeLutin +# %% +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Lesser Public License for more details. +# +# You should have received a copy of the GNU General Lesser Public +# License along with this program. If not, see +# <http://www.gnu.org/licenses/lgpl-3.0.html>. +# #L% +### +#\u00A0This log is used to display trace in generation + +# Global logging configuration +log4j.rootLogger=WARN, stdout +# Console output... +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) %M - %m%n +# package level +log4j.logger.org.nuiton.topia=INFO +log4j.logger.org.nuiton.topia.service.sql.batch=INFO -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/3860_introduce_topiasqlbatchsupport in repository topia. See http://git.nuiton.org/topia.git commit 08f9f336c9cd017f64f86facad3af0f0abb6b48c Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 5 08:26:39 2016 +0100 Add create schema actions --- .../sql/batch/actions/CreateSchemaAction.java | 89 ++++++++++++++++++++++ .../sql/batch/actions/CreateSchemaRequest.java | 61 +++++++++++++++ 2 files changed, 150 insertions(+) diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/CreateSchemaAction.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/CreateSchemaAction.java new file mode 100644 index 0000000..ec3b881 --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/CreateSchemaAction.java @@ -0,0 +1,89 @@ +package org.nuiton.topia.service.sql.batch.actions; + +/* + * #%L + * ToPIA :: Service Sql batch + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import com.google.common.collect.ImmutableSet; +import org.hibernate.HibernateException; +import org.hibernate.cfg.Configuration; +import org.hibernate.cfg.Environment; +import org.hibernate.dialect.Dialect; +import org.hibernate.tool.hbm2ddl.SchemaExport; +import org.nuiton.topia.persistence.TopiaException; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Properties; + +/** + * Created on 01/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public class CreateSchemaAction extends AbstractSchemaAction<CreateSchemaRequest> { + + public static final String CREATE_SCHEMA_STATEMENT = "CREATE SCHEMA %s;\n"; + + public CreateSchemaAction(CreateSchemaRequest request) { + super(request); + } + + protected String produceSql(Class<? extends Dialect> dialectType, Path temporaryDirectory) throws IOException { + + try { + + Path sqlScriptFile = temporaryDirectory.resolve("replicateSchema_" + System.nanoTime() + ".sql"); + + Configuration hibernateConfiguration = getSourcePersistenceContext().getHibernateSupport().getHibernateConfiguration(); + + Properties properties = new Properties(); + + properties.put(Environment.DIALECT, dialectType.getName()); + + new SchemaExport(hibernateConfiguration, properties) + .setOutputFile(sqlScriptFile.toFile().getAbsolutePath()) + .setDelimiter(";") + .create(false, false); + + String sqlStatements = ""; + if (request.isAddSchema()) { + + ImmutableSet<String> schemaNames = getSchemaNames(); + for (String schemaName : schemaNames) { + sqlStatements += String.format(CREATE_SCHEMA_STATEMENT, schemaName); + } + + } + + sqlStatements += new String(Files.readAllBytes(sqlScriptFile)); + Files.delete(sqlScriptFile); + return sqlStatements; + + } catch (HibernateException eee) { + throw new TopiaException(String.format("Could not create schema for reason: %s", eee.getMessage()), eee); + } + + } + +} diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/CreateSchemaRequest.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/CreateSchemaRequest.java new file mode 100644 index 0000000..3f6acb3 --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/CreateSchemaRequest.java @@ -0,0 +1,61 @@ +package org.nuiton.topia.service.sql.batch.actions; + +/* + * #%L + * ToPIA :: Service Sql batch + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +/** + * Created on 01/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public class CreateSchemaRequest extends AbstractSchemaRequest { + + protected boolean addSchema; + + public static Builder builder() { + return new Builder(); + } + + public boolean isAddSchema() { + return addSchema; + } + + protected void setAddSchema(boolean addSchema) { + this.addSchema = addSchema; + } + + public static class Builder extends AbstractSchemaRequestBuilder<CreateSchemaRequest, Builder> { + + public Builder() { + super(new CreateSchemaRequest()); + } + + public Builder setAddSchema(boolean addSchema) { + request.setAddSchema(addSchema); + return this; + } + + } + + +} -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/3860_introduce_topiasqlbatchsupport in repository topia. See http://git.nuiton.org/topia.git commit 321c8424c7c0c42edefcf9246712eedfd6a54c18 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 5 08:26:53 2016 +0100 Add drop schem action --- .../sql/batch/actions/DropSchemaAction.java | 93 ++++++++++++++++++++++ .../sql/batch/actions/DropSchemaRequest.java | 60 ++++++++++++++ 2 files changed, 153 insertions(+) diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/DropSchemaAction.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/DropSchemaAction.java new file mode 100644 index 0000000..09e9856 --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/DropSchemaAction.java @@ -0,0 +1,93 @@ +package org.nuiton.topia.service.sql.batch.actions; + +/* + * #%L + * ToPIA :: Service Sql batch + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import com.google.common.collect.ImmutableSet; +import org.apache.commons.io.output.WriterOutputStream; +import org.hibernate.HibernateException; +import org.hibernate.cfg.Configuration; +import org.hibernate.cfg.Environment; +import org.hibernate.dialect.Dialect; +import org.hibernate.tool.hbm2ddl.SchemaExport; +import org.nuiton.topia.persistence.TopiaException; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Properties; + +/** + * Created on 01/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public class DropSchemaAction extends AbstractSchemaAction<DropSchemaRequest> { + + public static final String DROP_SCHEMA_STATEMENT = "\nDROP SCHEMA %s;"; + + public DropSchemaAction(DropSchemaRequest request) { + super(request); + } + + @Override + protected String produceSql(Class<? extends Dialect> dialectType, Path temporaryDirectory) throws IOException { + + try { + + Path sqlScriptFile = temporaryDirectory.resolve("replicateSchema_" + System.nanoTime() + ".sql"); + + Configuration hibernateConfiguration = getSourcePersistenceContext().getHibernateSupport().getHibernateConfiguration(); + + Properties properties = new Properties(); + + properties.put(Environment.DIALECT, dialectType.getName()); + + new SchemaExport(hibernateConfiguration, properties) + .setOutputFile(sqlScriptFile.toFile().getAbsolutePath()) + .setDelimiter(";") + .drop(false, false); + + WriterOutputStream out = new WriterOutputStream(writer); + Files.copy(sqlScriptFile, out); + out.flush(); + + String sqlContent = new String(Files.readAllBytes(sqlScriptFile)); + Files.delete(sqlScriptFile); + + if (request.isDropSchema()) { + + ImmutableSet<String> schemaNames = getSchemaNames(); + for (String schemaName : schemaNames) { + sqlContent += String.format(DROP_SCHEMA_STATEMENT, schemaName); + } + } + + return sqlContent; + + } catch (HibernateException eee) { + throw new TopiaException(String.format("Could not create schema for reason: %s", eee.getMessage()), eee); + } + + } +} diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/DropSchemaRequest.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/DropSchemaRequest.java new file mode 100644 index 0000000..d96aa42 --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/DropSchemaRequest.java @@ -0,0 +1,60 @@ +package org.nuiton.topia.service.sql.batch.actions; + +/* + * #%L + * ToPIA :: Service Sql batch + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +/** + * Created on 01/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public class DropSchemaRequest extends AbstractSchemaRequest { + + protected boolean dropSchema; + + public static Builder builder() { + return new Builder(); + } + + public boolean isDropSchema() { + return dropSchema; + } + + protected void setDropSchema(boolean dropSchema) { + this.dropSchema = dropSchema; + } + + public static class Builder extends AbstractSchemaRequestBuilder<DropSchemaRequest, Builder> { + + public Builder() { + super(new DropSchemaRequest()); + } + + public Builder setDropSchema(boolean dropSchema) { + request.setDropSchema(dropSchema); + return this; + } + + } + +} -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/3860_introduce_topiasqlbatchsupport in repository topia. See http://git.nuiton.org/topia.git commit 933912b823ff681ef3636d04ea6db14d497a9364 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 5 08:27:10 2016 +0100 Add replicate tables action --- .../sql/batch/actions/ReplicateTablesAction.java | 144 +++++++++++++++++++++ .../sql/batch/actions/ReplicateTablesRequest.java | 45 +++++++ 2 files changed, 189 insertions(+) diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/ReplicateTablesAction.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/ReplicateTablesAction.java new file mode 100644 index 0000000..537b3c5 --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/ReplicateTablesAction.java @@ -0,0 +1,144 @@ +package org.nuiton.topia.service.sql.batch.actions; + +/* + * #%L + * ToPIA :: Service Sql batch + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.service.sql.batch.tables.TopiaSqlTable; + +import java.io.IOException; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.List; + +/** + * Created on 01/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public class ReplicateTablesAction extends AbstractTablesAction<ReplicateTablesRequest> { + + public static final String INSERT_STATEMENT = "INSERT INTO %s.%s(%s) VALUES (%%s);\n"; + /** + * Logger. + */ + private static final Log log = LogFactory.getLog(ReplicateTablesAction.class); + + public ReplicateTablesAction(ReplicateTablesRequest request) { + super(request); + } + + @Override + protected void executeOnTable(ReplicateTablesRequest request, TopiaSqlTable table, PreparedStatement readStatement) throws SQLException { + + ResultSet readResultSet = readStatement.getResultSet(); + + ResultSetMetaData readResultSetMetaData = readResultSet.getMetaData(); + int columnCount = readResultSetMetaData.getColumnCount(); + + List<String> columnNames = getColumnNames(readResultSetMetaData, columnCount); + + boolean useOutputWriter = useOutputWriter(); + boolean useOutputDb = useOutputDb(); + + PreparedStatement writeStatement = null; + + String insertStatementSql = newInsertStatementSql(table, columnNames); + + if (useOutputDb) { + + String arguments = generateWildcardArguments(columnNames); + String sql = String.format(insertStatementSql, arguments).trim(); + writeStatement = targetConnection.prepareStatement(sql); + + } + + int fetchSize = request.getFetchSize(); + String tableName = table.getFullyTableName(); + + long index = 0; + while (readResultSet.next()) { + + if (log.isTraceEnabled()) { + log.trace("Copy " + readResultSet.getString(1)); + } + + if (useOutputDb) { + + writeStatement.clearParameters(); + for (int i = 1; i <= columnCount; i++) { + Object object = readResultSet.getObject(i); + writeStatement.setObject(i, object); + } + writeStatement.addBatch(); + + } + + if (useOutputWriter) { + + try { + + String arguments = generateSqlArguments(readResultSet, columnNames); + String sql = String.format(insertStatementSql, arguments); + writer.append(sql); + + } catch (IOException e) { + throw new RuntimeException("Could not copyRow", e); + } + + } + + if ((++index % fetchSize) == 0) { + flush(writeStatement, writer, tableName, index); + } + + } + + flush(writeStatement, writer, tableName, index); + + } + + protected String newInsertStatementSql(TopiaSqlTable table, List<String> columnNames) throws SQLException { + + StringBuilder columnNamesBuilder = new StringBuilder(); + + for (String columnName : columnNames) { + columnNamesBuilder.append(", ").append(columnName); + } + + String sql = String.format(INSERT_STATEMENT, + table.getSchemaName(), + table.getTableName(), + columnNamesBuilder.substring(2)); + if (log.isDebugEnabled()) { + log.debug("Insert sql: " + sql); + } + + return sql; + + } + +} diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/ReplicateTablesRequest.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/ReplicateTablesRequest.java new file mode 100644 index 0000000..9e45067 --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/ReplicateTablesRequest.java @@ -0,0 +1,45 @@ +package org.nuiton.topia.service.sql.batch.actions; + +/* + * #%L + * ToPIA :: Service Sql batch + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +/** + * Created on 01/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public class ReplicateTablesRequest extends AbstractTablesRequest { + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends AbstractTablesRequestBuilder<Builder, ReplicateTablesRequest> { + + public Builder() { + super(new ReplicateTablesRequest()); + } + + } +} + -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/3860_introduce_topiasqlbatchsupport in repository topia. See http://git.nuiton.org/topia.git commit c618b87f1a51770e09a558a6a5c2e8eb5c6813e0 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 5 08:27:25 2016 +0100 Add update tables action --- .../sql/batch/actions/UpdateTablesAction.java | 200 +++++++++++++++++++++ .../sql/batch/actions/UpdateTablesRequest.java | 45 +++++ 2 files changed, 245 insertions(+) diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/UpdateTablesAction.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/UpdateTablesAction.java new file mode 100644 index 0000000..edf4bf0 --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/UpdateTablesAction.java @@ -0,0 +1,200 @@ +package org.nuiton.topia.service.sql.batch.actions; + +/* + * #%L + * ToPIA :: Service Sql batch + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import com.google.common.collect.Lists; +import org.apache.commons.io.output.ByteArrayOutputStream; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.service.sql.batch.tables.TopiaSqlTable; + +import javax.sql.rowset.serial.SerialBlob; +import java.io.IOException; +import java.sql.Blob; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.Date; +import java.util.List; + +/** + * Created on 01/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public class UpdateTablesAction extends AbstractTablesAction<UpdateTablesRequest> { + + public static final String UPDATE_STATEMENT = "UPDATE %s.%s %s WHERE topiaid='%%s'"; + /** + * Logger. + */ + private static final Log log = LogFactory.getLog(UpdateTablesAction.class); + + public UpdateTablesAction(UpdateTablesRequest request) { + super(request); + } + + @Override + protected void executeOnTable(UpdateTablesRequest request, TopiaSqlTable table, PreparedStatement readStatement) throws SQLException { + + ResultSet readResultSet = readStatement.getResultSet(); + + ResultSetMetaData readResultSetMetaData = readResultSet.getMetaData(); + int columnCount = readResultSetMetaData.getColumnCount(); + + List<String> columnNames = Lists.newArrayList(getColumnNames(readResultSetMetaData, columnCount)); + + String topiaIdColumnName = TopiaEntity.PROPERTY_TOPIA_ID.toLowerCase(); + int topiaIdColumnIndex = columnNames.indexOf(topiaIdColumnName); + columnNames.remove(topiaIdColumnName); + + boolean useOutputWriter = useOutputWriter(); + boolean useOutputDb = useOutputDb(); + + PreparedStatement writeStatement = null; + + String updateStatementSql = newUpdateStatementSql(table, columnNames); + + if (useOutputDb) { + + String arguments = generateWildcardArguments(columnNames); + String sql = String.format(updateStatementSql, arguments, "?"); + writeStatement = targetConnection.prepareStatement(sql); + + } + + int fetchSize = request.getFetchSize(); + String tableName = table.getFullyTableName(); + + long index = 0; + while (readResultSet.next()) { + + String topiaId = readResultSet.getString(topiaIdColumnIndex); + if (log.isTraceEnabled()) { + log.trace("Update " + readResultSet.getString(1)); + } + + + if (useOutputDb) { + + writeStatement.clearParameters(); + int i = 1; + for (String columnName : columnNames) { + Object object = readResultSet.getObject(columnName); + writeStatement.setObject(i++, object); + } + writeStatement.setString(columnCount + 1, topiaId); + writeStatement.addBatch(); + + } + + if (useOutputWriter) { + + try { + + String arguments = generateArguments(columnNames, readResultSet); + String sql = String.format(updateStatementSql, arguments, topiaId); + writer.append(sql); + + } catch (IOException e) { + throw new RuntimeException("Could not updateRow", e); + } + + } + + if ((++index % fetchSize) == 0) { + flush(writeStatement, writer, tableName, index); + } + + } + + flush(writeStatement, writer, tableName, index); + + } + + protected String generateArguments(Iterable<String> columnNames, ResultSet readResultSet) throws SQLException, IOException { + + String statement = ""; + + for (String columnName : columnNames) { + + statement += ", SET " + columnName + " = "; + Object columnValue = readResultSet.getObject(columnName); + if (columnValue == null) { + statement += "NULL"; + continue; + } + + if (columnValue instanceof String) { + String stringValue = (String) columnValue; + statement += "'" + stringValue.replaceAll("'", "''") + "'"; + continue; + } + + if (columnValue instanceof Date) { + statement += "'" + columnValue + "'"; + continue; + } + + if (columnValue instanceof Blob) { + Blob blob = (Blob) columnValue; + SerialBlob serialBlob = new SerialBlob(blob); + try (ByteArrayOutputStream stringWriter = new ByteArrayOutputStream((int) serialBlob.length())) { + stringWriter.write(serialBlob.getBinaryStream()); + statement += "'" + new String(stringWriter.toByteArray()) + "'"; + } + continue; + } + + statement += columnValue; + + } + + return statement.substring(2); + + } + + protected String newUpdateStatementSql(TopiaSqlTable table, Iterable<String> columnNames) throws SQLException { + + StringBuilder columnNamesBuilder = new StringBuilder(); + + for (String columnName : columnNames) { + columnNamesBuilder.append(", SET ").append(columnName).append(" = ?"); + } + + String sql = String.format(UPDATE_STATEMENT, + table.getSchemaName(), + table.getTableName(), + columnNamesBuilder.substring(2)); + if (log.isDebugEnabled()) { + log.debug("Insert sql: " + sql); + } + + return sql; + + } + +} diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/UpdateTablesRequest.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/UpdateTablesRequest.java new file mode 100644 index 0000000..703b5cd --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/UpdateTablesRequest.java @@ -0,0 +1,45 @@ +package org.nuiton.topia.service.sql.batch.actions; + +/* + * #%L + * ToPIA :: Service Sql batch + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +/** + * Created on 01/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public class UpdateTablesRequest extends AbstractTablesRequest { + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends AbstractTablesRequestBuilder<Builder, UpdateTablesRequest> { + + public Builder() { + super(new UpdateTablesRequest()); + } + + } +} + -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/3860_introduce_topiasqlbatchsupport in repository topia. See http://git.nuiton.org/topia.git commit 7e1c40f680188d671f52e302c74746db8e1b09c0 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 5 08:27:40 2016 +0100 Add delete tables action --- .../sql/batch/actions/DeleteTablesAction.java | 139 +++++++++++++++++++++ .../sql/batch/actions/DeleteTablesRequest.java | 46 +++++++ 2 files changed, 185 insertions(+) diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/DeleteTablesAction.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/DeleteTablesAction.java new file mode 100644 index 0000000..f703ec8 --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/DeleteTablesAction.java @@ -0,0 +1,139 @@ +package org.nuiton.topia.service.sql.batch.actions; + +/* + * #%L + * ToPIA :: Service Sql batch + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.persistence.TopiaEntity; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.service.sql.batch.tables.TopiaSqlTable; + +import java.io.IOException; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.List; + +/** + * Created on 01/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public class DeleteTablesAction extends AbstractTablesAction<DeleteTablesRequest> { + + public static final String DELETE_STATEMENT = "DELETE FROM %s.%s WHERE topiaId = '%%s'"; + /** + * Logger. + */ + private static final Log log = LogFactory.getLog(DeleteTablesAction.class); + + public DeleteTablesAction(DeleteTablesRequest request) { + super(request); + } + + @Override + protected void executeOnTable(DeleteTablesRequest request, TopiaSqlTable table, PreparedStatement readStatement) throws SQLException { + + ResultSet readResultSet = readStatement.getResultSet(); + + ResultSetMetaData readResultSetMetaData = readResultSet.getMetaData(); + int columnCount = readResultSetMetaData.getColumnCount(); + + List<String> columnNames = getColumnNames(readResultSetMetaData, columnCount); + + String topiaIdColumnName = TopiaEntity.PROPERTY_TOPIA_ID.toLowerCase(); + int topiaIdColumnIndex = columnNames.indexOf(topiaIdColumnName); + + boolean useOutputWriter = useOutputWriter(); + boolean useOutputDb = useOutputDb(); + + PreparedStatement writeStatement = null; + + String deleteStatementSql = newDeleteStatementSql(table); + + if (useOutputDb) { + + String sql = String.format(deleteStatementSql, "?"); + writeStatement = targetConnection.prepareStatement(sql); + + } + + int fetchSize = request.getFetchSize(); + String tableName = table.getFullyTableName(); + + long index = 0; + while (readResultSet.next()) { + + String topiaId = readResultSet.getString(topiaIdColumnIndex); + + if (log.isTraceEnabled()) { + log.trace("Delete " + topiaId); + } + + if (useOutputDb) { + + writeStatement.clearParameters(); + writeStatement.setObject(1, topiaId); + writeStatement.addBatch(); + + } + + if (useOutputWriter) { + + try { + + String sql = String.format(deleteStatementSql, topiaId); + writer.append(sql); + + } catch (IOException e) { + throw new TopiaException("Could not deleteRow", e); + } + + } + + if ((++index % fetchSize) == 0) { + flush(writeStatement, writer, tableName, index); + } + + } + + flush(writeStatement, writer, tableName, index); + + } + + protected String newDeleteStatementSql(TopiaSqlTable table) throws SQLException { + + String sql = String.format(DELETE_STATEMENT, + table.getSchemaName(), + table.getTableName()); + if (log.isDebugEnabled()) { + log.debug("Delete sql: " + sql); + } + + return sql; + + } + +} diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/DeleteTablesRequest.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/DeleteTablesRequest.java new file mode 100644 index 0000000..690e67c --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/DeleteTablesRequest.java @@ -0,0 +1,46 @@ +package org.nuiton.topia.service.sql.batch.actions; + +/* + * #%L + * ToPIA :: Service Sql batch + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +/** + * Created on 01/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public class DeleteTablesRequest extends AbstractTablesRequest { + + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends AbstractTablesRequestBuilder<Builder, DeleteTablesRequest> { + + public Builder() { + super(new DeleteTablesRequest()); + } + + } +} + -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/3860_introduce_topiasqlbatchsupport in repository topia. See http://git.nuiton.org/topia.git commit e2d15ef2de22d7ceba86e87803d22ade899669b2 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 5 08:29:01 2016 +0100 Add TopiaSqlBatchService and his default implementation --- .../topia/service/sql/batch/SqlRequests.java | 401 +++++++++++++++++++++ .../service/sql/batch/TopiaSqlBatchService.java | 64 ++++ .../sql/batch/TopiaSqlBatchServiceImpl.java | 175 +++++++++ 3 files changed, 640 insertions(+) diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/SqlRequests.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/SqlRequests.java new file mode 100644 index 0000000..f6f3286 --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/SqlRequests.java @@ -0,0 +1,401 @@ +package org.nuiton.topia.service.sql.batch; + +/* + * #%L + * ToPIA :: Service Sql batch + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import com.google.common.collect.ImmutableSet; +import org.hibernate.dialect.Dialect; +import org.nuiton.topia.persistence.TopiaApplicationContext; +import org.nuiton.topia.service.sql.batch.actions.AbstractSchemaRequest; +import org.nuiton.topia.service.sql.batch.actions.AbstractSqlRequest; +import org.nuiton.topia.service.sql.batch.actions.AbstractTablesRequest; +import org.nuiton.topia.service.sql.batch.actions.CreateSchemaRequest; +import org.nuiton.topia.service.sql.batch.actions.DeleteTablesRequest; +import org.nuiton.topia.service.sql.batch.actions.DropSchemaRequest; +import org.nuiton.topia.service.sql.batch.actions.ReplicateTablesRequest; +import org.nuiton.topia.service.sql.batch.actions.TopiaSqlTableSelectArgument; +import org.nuiton.topia.service.sql.batch.actions.UpdateTablesRequest; +import org.nuiton.topia.service.sql.batch.tables.TopiaSqlTables; + +import java.io.Writer; +import java.nio.file.Path; +import java.util.Iterator; + +/** + * Created on 04/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public class SqlRequests implements Iterable<AbstractSqlRequest> { + + protected final ImmutableSet<AbstractSqlRequest> requests; + + protected SqlRequests(ImmutableSet<AbstractSqlRequest> requests) { + this.requests = requests; + } + + public static Builder builder() { + return new BuilderImpl(); + } + + public static <R extends AbstractSqlRequest> SqlRequests of(R request) { + return builder() + .from(request.getSourceTopiaApplicationContext()) + .to(request.getTargetTopiaApplicationContext()) + .to(request.getWriter()) + .addRequest(request) + .build(); + } + + @Override + public Iterator<AbstractSqlRequest> iterator() { + return requests.iterator(); + } + + public interface Builder extends BuilderAddRequestStep { + + Builder from(TopiaApplicationContext sourceTopiaApplicationContext); + + Builder to(TopiaApplicationContext targetTopiaApplicationContext); + + Builder to(Writer writer); + + } + + interface BuilderAddRequestStep { + + CreateSchemaRequestBuilder createSchemaBuilder(); + + DropSchemaRequestBuilder dropSchemaBuilder(); + + ReplicateTablesRequestBuilder replicateTablesBuilder(); + + UpdateTablesRequestBuilder updateTablesBuilder(); + + DeleteTablesRequestBuilder deleteTablesBuilder(); + + BuilderAddRequestStep addCreateSchema(CreateSchemaRequest request); + + BuilderAddRequestStep addDropSchema(DropSchemaRequest request); + + BuilderAddRequestStep addReplicateTables(ReplicateTablesRequest request); + + BuilderAddRequestStep addUpdateTables(UpdateTablesRequest request); + + BuilderAddRequestStep addDeleteTables(DeleteTablesRequest request); + + <R extends AbstractSqlRequest> BuilderAddRequestStep addRequest(R request); + + Builder flush(); + + SqlRequests build(); + + } + + protected static class BuilderImpl implements Builder { + + protected final ImmutableSet.Builder<AbstractSqlRequest> requestsBuilder = ImmutableSet.builder(); + protected TopiaApplicationContext sourceTopiaApplicationContext; + protected TopiaApplicationContext targetTopiaApplicationContext; + protected Writer writer; + + @Override + public Builder from(TopiaApplicationContext sourceTopiaApplicationContext) { + this.sourceTopiaApplicationContext = sourceTopiaApplicationContext; + return this; + } + + @Override + public Builder to(TopiaApplicationContext targetTopiaApplicationContext) { + this.targetTopiaApplicationContext = targetTopiaApplicationContext; + return this; + } + + @Override + public Builder to(Writer writer) { + this.writer = writer; + return this; + } + + @Override + public SqlRequests build() { + return new SqlRequests(requestsBuilder.build()); + } + + @Override + public <R extends AbstractSqlRequest> Builder addRequest(R request) { + requestsBuilder.add(request); + return this; + } + + @Override + public CreateSchemaRequestBuilder createSchemaBuilder() { + return new CreateSchemaRequestBuilder(this, initBuilder(CreateSchemaRequest.builder())); + } + + @Override + public DropSchemaRequestBuilder dropSchemaBuilder() { + return new DropSchemaRequestBuilder(this, initBuilder(DropSchemaRequest.builder())); + } + + @Override + public ReplicateTablesRequestBuilder replicateTablesBuilder() { + return new ReplicateTablesRequestBuilder(this, initBuilder(new ReplicateTablesRequest.Builder())); + } + + @Override + public UpdateTablesRequestBuilder updateTablesBuilder() { + return new UpdateTablesRequestBuilder(this, initBuilder(new UpdateTablesRequest.Builder())); + } + + @Override + public DeleteTablesRequestBuilder deleteTablesBuilder() { + return new DeleteTablesRequestBuilder(this, initBuilder(new DeleteTablesRequest.Builder())); + } + + @Override + public BuilderAddRequestStep addCreateSchema(CreateSchemaRequest request) { + return addRequest(request); + } + + @Override + public BuilderAddRequestStep addDropSchema(DropSchemaRequest request) { + return addRequest(request); + } + + @Override + public BuilderAddRequestStep addReplicateTables(ReplicateTablesRequest request) { + return addRequest(request); + } + + @Override + public BuilderAddRequestStep addUpdateTables(UpdateTablesRequest request) { + return addRequest(request); + } + + @Override + public BuilderAddRequestStep addDeleteTables(DeleteTablesRequest request) { + return addRequest(request); + } + + @Override + public Builder flush() { + return this; + } + + protected <B extends AbstractSqlRequest.AbstractSqlRequestBuilder<B, ?>> B initBuilder(B builder) { + return builder.from(sourceTopiaApplicationContext) + .to(targetTopiaApplicationContext) + .to(writer); + } + } + + public static class CreateSchemaRequestBuilder extends AbstractSchemaRequestBuilder<CreateSchemaRequest.Builder, CreateSchemaRequestBuilder> { + + public CreateSchemaRequestBuilder(BuilderImpl builder, CreateSchemaRequest.Builder delegate) { + super(builder, delegate); + } + + public CreateSchemaRequestBuilder setAddSchema(boolean addSchema) { + delegate.setAddSchema(addSchema); + return this; + } + + } + + public static class DropSchemaRequestBuilder extends AbstractSchemaRequestBuilder<DropSchemaRequest.Builder, DropSchemaRequestBuilder> { + + public DropSchemaRequestBuilder(BuilderImpl builder, DropSchemaRequest.Builder delegate) { + super(builder, delegate); + } + + public DropSchemaRequestBuilder setDropSchema(boolean dropSchema) { + delegate.setDropSchema(dropSchema); + return this; + } + + } + + public static class ReplicateTablesRequestBuilder extends AbstractTablesRequestBuilder<ReplicateTablesRequest.Builder, ReplicateTablesRequestBuilder> { + + public ReplicateTablesRequestBuilder(BuilderImpl builder, ReplicateTablesRequest.Builder delegate) { + super(builder, delegate); + } + + } + + public static class UpdateTablesRequestBuilder extends AbstractTablesRequestBuilder<UpdateTablesRequest.Builder, UpdateTablesRequestBuilder> { + + public UpdateTablesRequestBuilder(BuilderImpl builder, UpdateTablesRequest.Builder delegate) { + super(builder, delegate); + } + + } + + public static class DeleteTablesRequestBuilder extends AbstractTablesRequestBuilder<DeleteTablesRequest.Builder, DeleteTablesRequestBuilder> { + + public DeleteTablesRequestBuilder(BuilderImpl builder, DeleteTablesRequest.Builder delegate) { + super(builder, delegate); + } + + } + + protected static abstract class RequestBuilderImpl<R extends AbstractSqlRequest.AbstractSqlRequestBuilder, B extends RequestBuilderImpl> implements BuilderAddRequestStep { + + protected final Builder builder; + protected final R delegate; + + protected RequestBuilderImpl(BuilderImpl builder, R delegate) { + this.builder = builder; + this.delegate = delegate; + } + + @Override + public CreateSchemaRequestBuilder createSchemaBuilder() { + return flush().createSchemaBuilder(); + } + + @Override + public DropSchemaRequestBuilder dropSchemaBuilder() { + return flush().dropSchemaBuilder(); + } + + @Override + public ReplicateTablesRequestBuilder replicateTablesBuilder() { + return flush().replicateTablesBuilder(); + } + + @Override + public UpdateTablesRequestBuilder updateTablesBuilder() { + return flush().updateTablesBuilder(); + } + + @Override + public DeleteTablesRequestBuilder deleteTablesBuilder() { + return flush().deleteTablesBuilder(); + } + + @Override + public BuilderAddRequestStep addCreateSchema(CreateSchemaRequest request) { + return flush().addRequest(request); + } + + @Override + public BuilderAddRequestStep addDropSchema(DropSchemaRequest request) { + return flush().addRequest(request); + } + + @Override + public BuilderAddRequestStep addReplicateTables(ReplicateTablesRequest request) { + return flush().addRequest(request); + } + + @Override + public BuilderAddRequestStep addUpdateTables(UpdateTablesRequest request) { + return flush().addRequest(request); + } + + @Override + public BuilderAddRequestStep addDeleteTables(DeleteTablesRequest request) { + return addRequest(request); + } + + @Override + public <R extends AbstractSqlRequest> BuilderAddRequestStep addRequest(R request) { + return builder.addRequest(request); + } + + @Override + public SqlRequests build() { + return flush().build(); + } + + @Override + public Builder flush() { + addRequest(delegate.build()); + return builder; + } + +// protected BuilderAddRequestStep flushCurrentRequest() { +// return addRequest(delegate.build()); +// } + + protected B returnThis() { + return (B) this; + } + + } + + protected static class AbstractSchemaRequestBuilder<R extends AbstractSchemaRequest.AbstractSchemaRequestBuilder, B extends AbstractSchemaRequestBuilder> extends RequestBuilderImpl<R, B> { + + protected AbstractSchemaRequestBuilder(BuilderImpl builder, R delegate) { + super(builder, delegate); + } + + public B forH2() { + delegate.forH2(); + return returnThis(); + } + + public B forPostgres() { + delegate.forPostgres(); + return returnThis(); + } + + public B setDialect(Class<? extends Dialect> dialectType) { + delegate.setDialect(dialectType); + return returnThis(); + } + + public B setTemporaryPath(Path temporaryPath) { + delegate.setTemporaryPath(temporaryPath); + return returnThis(); + } + + } + + protected static class AbstractTablesRequestBuilder<R extends AbstractTablesRequest.AbstractTablesRequestBuilder, B extends AbstractTablesRequestBuilder> extends RequestBuilderImpl<R, B> { + + protected AbstractTablesRequestBuilder(BuilderImpl builder, R delegate) { + super(builder, delegate); + } + + public B setTables(TopiaSqlTables tables) { + delegate.setTables(tables); + return returnThis(); + } + + public B setFetchSize(int fetchSize) { + delegate.setFetchSize(fetchSize); + return returnThis(); + } + + public B setSelectArgument(TopiaSqlTableSelectArgument arg) { + delegate.setSelectArgument(arg); + return returnThis(); + } + + } + + +} diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchService.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchService.java new file mode 100644 index 0000000..3f895ab --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchService.java @@ -0,0 +1,64 @@ +package org.nuiton.topia.service.sql.batch; + +/* + * #%L + * ToPIA :: Service Sql batch + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import org.nuiton.topia.persistence.TopiaService; +import org.nuiton.topia.service.sql.batch.actions.CreateSchemaRequest; +import org.nuiton.topia.service.sql.batch.actions.DeleteTablesRequest; +import org.nuiton.topia.service.sql.batch.actions.DropSchemaRequest; +import org.nuiton.topia.service.sql.batch.actions.ReplicateTablesRequest; +import org.nuiton.topia.service.sql.batch.actions.UpdateTablesRequest; + +/** + * Created on 04/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public interface TopiaSqlBatchService extends TopiaService { + + SqlRequests.Builder requestBuilder(); + + CreateSchemaRequest.Builder createSchemaRequestBuilder(); + + DropSchemaRequest.Builder dropSchemaRequestBuilder(); + + ReplicateTablesRequest.Builder replicateTablesRequestBuilder(); + + UpdateTablesRequest.Builder updateTablesRequestBuilder(); + + DeleteTablesRequest.Builder deleteTablesRequestBuilder(); + + void execute(SqlRequests requests); + + void execute(CreateSchemaRequest request); + + void execute(DropSchemaRequest request); + + void execute(ReplicateTablesRequest request); + + void execute(UpdateTablesRequest request); + + void execute(DeleteTablesRequest request); + +} diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchServiceImpl.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchServiceImpl.java new file mode 100644 index 0000000..1ea5fd2 --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchServiceImpl.java @@ -0,0 +1,175 @@ +package org.nuiton.topia.service.sql.batch; + +/* + * #%L + * ToPIA :: Service Sql batch + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + +import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableMap; +import org.nuiton.topia.persistence.TopiaApplicationContext; +import org.nuiton.topia.persistence.TopiaException; +import org.nuiton.topia.service.sql.batch.actions.AbstractSqlAction; +import org.nuiton.topia.service.sql.batch.actions.AbstractSqlRequest; +import org.nuiton.topia.service.sql.batch.actions.CreateSchemaAction; +import org.nuiton.topia.service.sql.batch.actions.CreateSchemaRequest; +import org.nuiton.topia.service.sql.batch.actions.DeleteTablesAction; +import org.nuiton.topia.service.sql.batch.actions.DeleteTablesRequest; +import org.nuiton.topia.service.sql.batch.actions.DropSchemaAction; +import org.nuiton.topia.service.sql.batch.actions.DropSchemaRequest; +import org.nuiton.topia.service.sql.batch.actions.ReplicateTablesAction; +import org.nuiton.topia.service.sql.batch.actions.ReplicateTablesRequest; +import org.nuiton.topia.service.sql.batch.actions.UpdateTablesAction; +import org.nuiton.topia.service.sql.batch.actions.UpdateTablesRequest; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.Iterator; +import java.util.Map; + +/** + * Created on 04/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 + */ +public class TopiaSqlBatchServiceImpl implements TopiaSqlBatchService { + + private static final ImmutableMap<Class, Class> ACTION_MAPPING = ImmutableMap + .<Class, Class>builder() + .put(CreateSchemaRequest.class, CreateSchemaAction.class) + .put(DropSchemaRequest.class, DropSchemaAction.class) + .put(ReplicateTablesRequest.class, ReplicateTablesAction.class) + .put(UpdateTablesRequest.class, UpdateTablesAction.class) + .put(DeleteTablesRequest.class, DeleteTablesAction.class) + .build(); + private TopiaApplicationContext topiaApplicationContext; + + @Override + public void initTopiaService(TopiaApplicationContext topiaApplicationContext, Map<String, String> serviceConfiguration) { + this.topiaApplicationContext = topiaApplicationContext; + } + + @Override + public void close() { + + } + + @Override + public SqlRequests.Builder requestBuilder() { + return SqlRequests.builder().from(topiaApplicationContext); + } + + @Override + public CreateSchemaRequest.Builder createSchemaRequestBuilder() { + return CreateSchemaRequest.builder().from(topiaApplicationContext); + } + + @Override + public DropSchemaRequest.Builder dropSchemaRequestBuilder() { + return DropSchemaRequest.builder().from(topiaApplicationContext); + } + + @Override + public ReplicateTablesRequest.Builder replicateTablesRequestBuilder() { + return ReplicateTablesRequest.builder().from(topiaApplicationContext); + } + + @Override + public UpdateTablesRequest.Builder updateTablesRequestBuilder() { + return UpdateTablesRequest.builder().from(topiaApplicationContext); + } + + @Override + public DeleteTablesRequest.Builder deleteTablesRequestBuilder() { + return DeleteTablesRequest.builder().from(topiaApplicationContext); + } + + @Override + public void execute(SqlRequests requests) { + + Iterator<AbstractSqlRequest> sqlRequestIterator = requests.iterator(); + while (sqlRequestIterator.hasNext()) { + + AbstractSqlRequest sqlRequest = sqlRequestIterator.next(); + AbstractSqlAction<?> action = createAction(sqlRequest); + + action.run(); + + //FIXME Review transaction management + + boolean needCommit = !sqlRequestIterator.hasNext(); + if (needCommit) { + action.commit(); + } + } + + } + + protected <R extends AbstractSqlRequest, A extends AbstractSqlAction<R>> A createAction(R request) { + + Preconditions.checkNotNull(request, "Request can't be null"); + Class<A> actionType = ACTION_MAPPING.get(request.getClass()); + Preconditions.checkNotNull(actionType, "Could not find action for request type: " + request.getClass().getName()); + + Constructor<A> constructor; + try { + constructor = actionType.getConstructor(request.getClass()); + } catch (NoSuchMethodException e) { + throw new TopiaException(e); + } + try { + return constructor.newInstance(request); + } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { + throw new TopiaException(e); + } + + } + + @Override + public void execute(CreateSchemaRequest request) { + executeOneRequest(request); + } + + @Override + public void execute(DropSchemaRequest request) { + executeOneRequest(request); + } + + @Override + public void execute(ReplicateTablesRequest request) { + executeOneRequest(request); + } + + @Override + public void execute(UpdateTablesRequest request) { + executeOneRequest(request); + } + + @Override + public void execute(DeleteTablesRequest request) { + executeOneRequest(request); + } + + protected void executeOneRequest(AbstractSqlRequest request) { + SqlRequests sqlRequests = SqlRequests.of(request); + execute(sqlRequests); + } +} -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/3860_introduce_topiasqlbatchsupport in repository topia. See http://git.nuiton.org/topia.git commit 3be1a247a86035d6edd9c469e7304b14eb7fb1b4 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 5 20:10:16 2016 +0100 Add a configuration object for Topia Sql batch service and use it --- .../topia/service/sql/batch/SqlRequests.java | 2 +- .../service/sql/batch/TopiaSqlBatchService.java | 2 + .../batch/TopiaSqlBatchServiceConfiguration.java | 34 +++++++++++++++++ .../sql/batch/TopiaSqlBatchServiceImpl.java | 43 ++++++++++++++++++++-- .../sql/batch/actions/AbstractTablesAction.java | 2 +- .../sql/batch/actions/AbstractTablesRequest.java | 35 +++++++++++++----- .../sql/batch/actions/DeleteTablesAction.java | 4 +- .../sql/batch/actions/ReplicateTablesAction.java | 4 +- .../sql/batch/actions/UpdateTablesAction.java | 4 +- 9 files changed, 109 insertions(+), 21 deletions(-) diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/SqlRequests.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/SqlRequests.java index f6f3286..b67afe4 100644 --- a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/SqlRequests.java +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/SqlRequests.java @@ -386,7 +386,7 @@ public class SqlRequests implements Iterable<AbstractSqlRequest> { } public B setFetchSize(int fetchSize) { - delegate.setFetchSize(fetchSize); + delegate.setReadFetchSize(fetchSize); return returnThis(); } diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchService.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchService.java index 3f895ab..3e97c14 100644 --- a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchService.java +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchService.java @@ -37,6 +37,8 @@ import org.nuiton.topia.service.sql.batch.actions.UpdateTablesRequest; */ public interface TopiaSqlBatchService extends TopiaService { + TopiaSqlBatchServiceConfiguration getConfiguration(); + SqlRequests.Builder requestBuilder(); CreateSchemaRequest.Builder createSchemaRequestBuilder(); diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchServiceConfiguration.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchServiceConfiguration.java new file mode 100644 index 0000000..1a1f7fa --- /dev/null +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchServiceConfiguration.java @@ -0,0 +1,34 @@ +package org.nuiton.topia.service.sql.batch; + +/** + * Created on 05/01/16. + * + * @author Tony Chemit - chemit@codelutin.com + */ +public class TopiaSqlBatchServiceConfiguration { + + public static final String PROPERTY_READ_FETCH_SIZE = "readFetchSize"; + public static final String PROPERTY_WRITE_BATCH_SIZE = "writeBatchSize"; + public static final int DEFAULT_READ_FETCH_SIZE = 1000; + public static final int DEFAULT_WRITE_BATCH_SIZE = 1000; + + protected int readFetchSize = DEFAULT_READ_FETCH_SIZE; + + protected int writeBatchSize = DEFAULT_WRITE_BATCH_SIZE; + + public int getReadFetchSize() { + return readFetchSize; + } + + public int getWriteBatchSize() { + return writeBatchSize; + } + + protected void setReadFetchSize(int readFetchSize) { + this.readFetchSize = readFetchSize; + } + + protected void setWriteBatchSize(int writeBatchSize) { + this.writeBatchSize = writeBatchSize; + } +} diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchServiceImpl.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchServiceImpl.java index 1ea5fd2..5bf651a 100644 --- a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchServiceImpl.java +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchServiceImpl.java @@ -60,11 +60,29 @@ public class TopiaSqlBatchServiceImpl implements TopiaSqlBatchService { .put(UpdateTablesRequest.class, UpdateTablesAction.class) .put(DeleteTablesRequest.class, DeleteTablesAction.class) .build(); - private TopiaApplicationContext topiaApplicationContext; + + protected TopiaApplicationContext topiaApplicationContext; + + protected TopiaSqlBatchServiceConfiguration configuration; @Override public void initTopiaService(TopiaApplicationContext topiaApplicationContext, Map<String, String> serviceConfiguration) { + this.topiaApplicationContext = topiaApplicationContext; + this.configuration = new TopiaSqlBatchServiceConfiguration(); + + String readFetchSizeStr = serviceConfiguration.get(TopiaSqlBatchServiceConfiguration.PROPERTY_READ_FETCH_SIZE); + int readFetchSize = readFetchSizeStr != null + ? Integer.valueOf(readFetchSizeStr) + : TopiaSqlBatchServiceConfiguration.DEFAULT_READ_FETCH_SIZE; + configuration.setReadFetchSize(readFetchSize); + + String writeBatchSizeStr = serviceConfiguration.get(TopiaSqlBatchServiceConfiguration.PROPERTY_WRITE_BATCH_SIZE); + int writeBatchSize = writeBatchSizeStr == null + ? TopiaSqlBatchServiceConfiguration.DEFAULT_WRITE_BATCH_SIZE + : Integer.valueOf(writeBatchSizeStr); + configuration.setWriteBatchSize(writeBatchSize); + } @Override @@ -73,6 +91,11 @@ public class TopiaSqlBatchServiceImpl implements TopiaSqlBatchService { } @Override + public TopiaSqlBatchServiceConfiguration getConfiguration() { + return configuration; + } + + @Override public SqlRequests.Builder requestBuilder() { return SqlRequests.builder().from(topiaApplicationContext); } @@ -89,17 +112,29 @@ public class TopiaSqlBatchServiceImpl implements TopiaSqlBatchService { @Override public ReplicateTablesRequest.Builder replicateTablesRequestBuilder() { - return ReplicateTablesRequest.builder().from(topiaApplicationContext); + return ReplicateTablesRequest + .builder() + .from(topiaApplicationContext) + .setReadFetchSize(configuration.getReadFetchSize()) + .setWriteBatchSize(configuration.getWriteBatchSize()); } @Override public UpdateTablesRequest.Builder updateTablesRequestBuilder() { - return UpdateTablesRequest.builder().from(topiaApplicationContext); + return UpdateTablesRequest + .builder() + .from(topiaApplicationContext) + .setReadFetchSize(configuration.getReadFetchSize()) + .setWriteBatchSize(configuration.getWriteBatchSize()); } @Override public DeleteTablesRequest.Builder deleteTablesRequestBuilder() { - return DeleteTablesRequest.builder().from(topiaApplicationContext); + return DeleteTablesRequest + .builder() + .from(topiaApplicationContext) + .setReadFetchSize(configuration.getReadFetchSize()) + .setWriteBatchSize(configuration.getWriteBatchSize()); } @Override diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractTablesAction.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractTablesAction.java index 02ece9e..471f026 100644 --- a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractTablesAction.java +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractTablesAction.java @@ -204,7 +204,7 @@ public abstract class AbstractTablesAction<R extends AbstractTablesRequest> exte statement.setString(index++, id); } } - statement.setFetchSize(request.getFetchSize()); + statement.setFetchSize(request.getReadFetchSize()); return statement; } diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractTablesRequest.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractTablesRequest.java index 9edad80..82cadac 100644 --- a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractTablesRequest.java +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/AbstractTablesRequest.java @@ -24,6 +24,7 @@ package org.nuiton.topia.service.sql.batch.actions; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.nuiton.topia.service.sql.batch.TopiaSqlBatchServiceConfiguration; import org.nuiton.topia.service.sql.batch.tables.TopiaSqlTables; /** @@ -36,23 +37,33 @@ import org.nuiton.topia.service.sql.batch.tables.TopiaSqlTables; */ public abstract class AbstractTablesRequest extends AbstractSqlRequest { - public static final int DEFAULT_FETCH_SIZE = 100; /** * Logger. */ private static final Log log = LogFactory.getLog(AbstractTablesRequest.class); - protected int fetchSize; + + protected int readFetchSize; + + protected int writeBatchSize; protected TopiaSqlTableSelectArgument selectArgument; protected TopiaSqlTables tables; - public int getFetchSize() { - return fetchSize; + public int getReadFetchSize() { + return readFetchSize; } - public void setFetchSize(int fetchSize) { - this.fetchSize = fetchSize; + public void setReadFetchSize(int readFetchSize) { + this.readFetchSize = readFetchSize; + } + + public int getWriteBatchSize() { + return writeBatchSize; + } + + public void setWriteBatchSize(int writeBatchSize) { + this.writeBatchSize = writeBatchSize; } public TopiaSqlTableSelectArgument getSelectArgument() { @@ -83,7 +94,8 @@ public abstract class AbstractTablesRequest extends AbstractSqlRequest { protected AbstractTablesRequestBuilder(R sqlActionRequest) { super(sqlActionRequest); - setFetchSize(DEFAULT_FETCH_SIZE); + setReadFetchSize(TopiaSqlBatchServiceConfiguration.DEFAULT_READ_FETCH_SIZE); + setWriteBatchSize(TopiaSqlBatchServiceConfiguration.DEFAULT_WRITE_BATCH_SIZE); } public B setTables(TopiaSqlTables tables) { @@ -91,8 +103,13 @@ public abstract class AbstractTablesRequest extends AbstractSqlRequest { return returnThis(); } - public B setFetchSize(int fetchSize) { - request.setFetchSize(fetchSize); + public B setReadFetchSize(int readFetchSize) { + request.setReadFetchSize(readFetchSize); + return returnThis(); + } + + public B setWriteBatchSize(int writeBatchSize) { + request.setWriteBatchSize(writeBatchSize); return returnThis(); } diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/DeleteTablesAction.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/DeleteTablesAction.java index f703ec8..20e2ddb 100644 --- a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/DeleteTablesAction.java +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/DeleteTablesAction.java @@ -80,7 +80,7 @@ public class DeleteTablesAction extends AbstractTablesAction<DeleteTablesRequest } - int fetchSize = request.getFetchSize(); + int writeBatchSize = request.getWriteBatchSize(); String tableName = table.getFullyTableName(); long index = 0; @@ -113,7 +113,7 @@ public class DeleteTablesAction extends AbstractTablesAction<DeleteTablesRequest } - if ((++index % fetchSize) == 0) { + if ((++index % writeBatchSize) == 0) { flush(writeStatement, writer, tableName, index); } diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/ReplicateTablesAction.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/ReplicateTablesAction.java index 537b3c5..4f1c911 100644 --- a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/ReplicateTablesAction.java +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/ReplicateTablesAction.java @@ -76,7 +76,7 @@ public class ReplicateTablesAction extends AbstractTablesAction<ReplicateTablesR } - int fetchSize = request.getFetchSize(); + int writeBatchSize = request.getWriteBatchSize(); String tableName = table.getFullyTableName(); long index = 0; @@ -111,7 +111,7 @@ public class ReplicateTablesAction extends AbstractTablesAction<ReplicateTablesR } - if ((++index % fetchSize) == 0) { + if ((++index % writeBatchSize) == 0) { flush(writeStatement, writer, tableName, index); } diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/UpdateTablesAction.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/UpdateTablesAction.java index edf4bf0..4da342c 100644 --- a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/UpdateTablesAction.java +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/UpdateTablesAction.java @@ -86,7 +86,7 @@ public class UpdateTablesAction extends AbstractTablesAction<UpdateTablesRequest } - int fetchSize = request.getFetchSize(); + int writeBatchSize = request.getWriteBatchSize(); String tableName = table.getFullyTableName(); long index = 0; @@ -125,7 +125,7 @@ public class UpdateTablesAction extends AbstractTablesAction<UpdateTablesRequest } - if ((++index % fetchSize) == 0) { + if ((++index % writeBatchSize) == 0) { flush(writeStatement, writer, tableName, index); } -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/3860_introduce_topiasqlbatchsupport in repository topia. See http://git.nuiton.org/topia.git commit 29ed7349275e772fadba2f024423b11d78595b71 Author: Tony CHEMIT <chemit@codelutin.com> Date: Tue Jan 5 22:12:29 2016 +0100 Add missing license headers --- .../support/TopiaMetadataModelSupportImpl.java | 23 ++++++++++++++++++++++ .../persistence/metadata/TopiaMetadataEntity.java | 23 ++++++++++++++++++++++ .../persistence/metadata/TopiaMetadataModel.java | 22 +++++++++++++++++++++ .../metadata/TopiaMetadataModelVisitor.java | 23 ++++++++++++++++++++++ .../support/TopiaMetadataModelSupport.java | 23 ++++++++++++++++++++++ .../batch/TopiaSqlBatchServiceConfiguration.java | 23 ++++++++++++++++++++++ .../templates/TopiaMetadataModelGenerator.java | 23 ++++++++++++++++++++++ 7 files changed, 160 insertions(+) diff --git a/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/TopiaMetadataModelSupportImpl.java b/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/TopiaMetadataModelSupportImpl.java index 3b0ccca..ec34d54 100644 --- a/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/TopiaMetadataModelSupportImpl.java +++ b/topia-persistence/src/main/java/org/nuiton/topia/persistence/internal/support/TopiaMetadataModelSupportImpl.java @@ -1,5 +1,27 @@ package org.nuiton.topia.persistence.internal.support; +/* + * #%L + * ToPIA :: Persistence + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + import org.nuiton.topia.persistence.TopiaException; import org.nuiton.topia.persistence.TopiaPersistenceContext; import org.nuiton.topia.persistence.metadata.TopiaMetadataModel; @@ -11,6 +33,7 @@ import java.io.IOException; * Created on 04/01/16. * * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 */ public class TopiaMetadataModelSupportImpl implements TopiaMetadataModelSupport { diff --git a/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataEntity.java b/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataEntity.java index c409592..789063a 100644 --- a/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataEntity.java +++ b/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataEntity.java @@ -1,5 +1,27 @@ package org.nuiton.topia.persistence.metadata; +/* + * #%L + * ToPIA :: Persistence + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + import com.google.common.base.MoreObjects; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -12,6 +34,7 @@ import java.util.Objects; * Created on 03/01/16. * * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 */ public class TopiaMetadataEntity { diff --git a/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataModel.java b/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataModel.java index 70cc470..19812fe 100644 --- a/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataModel.java +++ b/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataModel.java @@ -1,5 +1,27 @@ package org.nuiton.topia.persistence.metadata; +/* + * #%L + * ToPIA :: Persistence + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + import com.google.common.base.Optional; import com.google.common.base.Preconditions; import com.google.gson.Gson; diff --git a/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataModelVisitor.java b/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataModelVisitor.java index b3c55c5..2aefd8f 100644 --- a/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataModelVisitor.java +++ b/topia-persistence/src/main/java/org/nuiton/topia/persistence/metadata/TopiaMetadataModelVisitor.java @@ -1,5 +1,27 @@ package org.nuiton.topia.persistence.metadata; +/* + * #%L + * ToPIA :: Persistence + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -10,6 +32,7 @@ import java.util.Set; * Created on 04/01/16. * * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 */ public interface TopiaMetadataModelVisitor { diff --git a/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaMetadataModelSupport.java b/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaMetadataModelSupport.java index bc148ed..b6cb9a7 100644 --- a/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaMetadataModelSupport.java +++ b/topia-persistence/src/main/java/org/nuiton/topia/persistence/support/TopiaMetadataModelSupport.java @@ -1,11 +1,34 @@ package org.nuiton.topia.persistence.support; +/* + * #%L + * ToPIA :: Persistence + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + import org.nuiton.topia.persistence.metadata.TopiaMetadataModel; /** * Created on 02/01/16. * * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 */ public interface TopiaMetadataModelSupport { diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchServiceConfiguration.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchServiceConfiguration.java index 1a1f7fa..b889c8b 100644 --- a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchServiceConfiguration.java +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchServiceConfiguration.java @@ -1,9 +1,32 @@ package org.nuiton.topia.service.sql.batch; +/* + * #%L + * ToPIA :: Service Sql batch + * %% + * Copyright (C) 2004 - 2016 CodeLutin, Tony Chemit + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + /** * Created on 05/01/16. * * @author Tony Chemit - chemit@codelutin.com + * @since 3.0.1 */ public class TopiaSqlBatchServiceConfiguration { diff --git a/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaMetadataModelGenerator.java b/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaMetadataModelGenerator.java index 6e6e27b..c9a40a0 100644 --- a/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaMetadataModelGenerator.java +++ b/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaMetadataModelGenerator.java @@ -1,5 +1,27 @@ package org.nuiton.topia.templates; +/* + * #%L + * ToPIA :: Templates + * %% + * Copyright (C) 2004 - 2016 CodeLutin + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * #L% + */ + import com.google.common.base.Optional; import com.google.gson.Gson; import com.google.gson.GsonBuilder; @@ -27,6 +49,7 @@ import java.util.List; * * @author Tony Chemit - chemit@codelutin.com * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.templates.TopiaMetadataModelGenerator" + * @since 3.0.1 */ public class TopiaMetadataModelGenerator extends ObjectModelGenerator { -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/3860_introduce_topiasqlbatchsupport in repository topia. See http://git.nuiton.org/topia.git commit 7d394c1abbd7a34a45b3b2d9677c663795de74a7 Author: Tony CHEMIT <chemit@codelutin.com> Date: Fri Jan 8 13:42:26 2016 +0100 Add javadoc --- .../topia/service/sql/batch/SqlRequests.java | 2 + .../service/sql/batch/TopiaSqlBatchService.java | 52 ++++++++++++++++++++++ .../batch/TopiaSqlBatchServiceConfiguration.java | 8 ++++ .../service/sql/batch/tables/TopiaSqlTable.java | 2 + .../service/sql/batch/tables/TopiaSqlTables.java | 2 + .../sql/batch/tables/TopiaSqlTablesFactory.java | 2 + 6 files changed, 68 insertions(+) diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/SqlRequests.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/SqlRequests.java index b67afe4..07d0894 100644 --- a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/SqlRequests.java +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/SqlRequests.java @@ -41,6 +41,8 @@ import java.nio.file.Path; import java.util.Iterator; /** + * A {@link SqlRequests} is a container of requests. + * * Created on 04/01/16. * * @author Tony Chemit - chemit@codelutin.com diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchService.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchService.java index 3e97c14..aa312c8 100644 --- a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchService.java +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchService.java @@ -37,30 +37,82 @@ import org.nuiton.topia.service.sql.batch.actions.UpdateTablesRequest; */ public interface TopiaSqlBatchService extends TopiaService { + /** + * @return the service configuration. + */ TopiaSqlBatchServiceConfiguration getConfiguration(); + /** + * @return Starts a new {@link SqlRequests} builder. + */ SqlRequests.Builder requestBuilder(); + /** + * @return Starts a new {@link CreateSchemaRequest} builder. + */ CreateSchemaRequest.Builder createSchemaRequestBuilder(); + /** + * @return Starts a new {@link DropSchemaRequest} builder. + */ DropSchemaRequest.Builder dropSchemaRequestBuilder(); + /** + * @return Starts a new {@link ReplicateTablesRequest} builder. + */ ReplicateTablesRequest.Builder replicateTablesRequestBuilder(); + /** + * @return Starts a new {@link UpdateTablesRequest} builder. + */ UpdateTablesRequest.Builder updateTablesRequestBuilder(); + + /** + * @return Starts a new {@link DeleteTablesRequest} builder. + */ DeleteTablesRequest.Builder deleteTablesRequestBuilder(); + /** + * Execute a {@link SqlRequests}. + * + * @param requests the request to execute + */ void execute(SqlRequests requests); + /** + * Execute a {@link CreateSchemaRequest}. + * + * @param request the request to execute + */ void execute(CreateSchemaRequest request); + /** + * Execute a {@link DropSchemaRequest}. + * + * @param request the request to execute + */ void execute(DropSchemaRequest request); + /** + * Execute a {@link ReplicateTablesRequest}. + * + * @param request the request to execute + */ void execute(ReplicateTablesRequest request); + /** + * Execute a {@link UpdateTablesRequest}. + * + * @param request the request to execute + */ void execute(UpdateTablesRequest request); + /** + * Execute a {@link DeleteTablesRequest}. + * + * @param request the request to execute + */ void execute(DeleteTablesRequest request); } diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchServiceConfiguration.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchServiceConfiguration.java index b889c8b..e7770a2 100644 --- a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchServiceConfiguration.java +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchServiceConfiguration.java @@ -23,6 +23,8 @@ package org.nuiton.topia.service.sql.batch; */ /** + * Configuration of the {@link TopiaSqlBatchService}. + * <p> * Created on 05/01/16. * * @author Tony Chemit - chemit@codelutin.com @@ -35,8 +37,14 @@ public class TopiaSqlBatchServiceConfiguration { public static final int DEFAULT_READ_FETCH_SIZE = 1000; public static final int DEFAULT_WRITE_BATCH_SIZE = 1000; + /** + * The fetch size used by read statements. + */ protected int readFetchSize = DEFAULT_READ_FETCH_SIZE; + /** + * The batch size used by write statements. + */ protected int writeBatchSize = DEFAULT_WRITE_BATCH_SIZE; public int getReadFetchSize() { diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTable.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTable.java index fd04e9e..e493e15 100644 --- a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTable.java +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTable.java @@ -28,6 +28,8 @@ import com.google.common.collect.ImmutableSet; import java.util.Objects; /** + * This object represents a sql table. + * * Created on 30/12/15. * * @author Tony Chemit - chemit@codelutin.com diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTables.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTables.java index 5498284..c99f63e 100644 --- a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTables.java +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTables.java @@ -37,6 +37,8 @@ import java.util.Objects; import java.util.TreeMap; /** + * A container of {@link TopiaSqlTable}. + * * Created on 01/01/16. * * @author Tony Chemit - chemit@codelutin.com diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTablesFactory.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTablesFactory.java index 9c4e489..0ee5d12 100644 --- a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTablesFactory.java +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/tables/TopiaSqlTablesFactory.java @@ -34,6 +34,8 @@ import java.util.LinkedHashSet; import java.util.Set; /** + * A factory of {@link TopiaSqlTables}. + * * Created on 04/01/16. * * @author Tony Chemit - chemit@codelutin.com -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
This is an automated email from the git hooks/post-receive script. New commit to branch feature/3860_introduce_topiasqlbatchsupport in repository topia. See http://git.nuiton.org/topia.git commit 1f6318e6be01b6bc9a6fef5773cd048cc9346588 Author: Tony CHEMIT <chemit@codelutin.com> Date: Sat Jan 9 17:23:16 2016 +0100 Do not create drop schema in CreateSchemaAction --- .../org/nuiton/topia/service/sql/batch/actions/CreateSchemaAction.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/CreateSchemaAction.java b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/CreateSchemaAction.java index ec3b881..f9db372 100644 --- a/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/CreateSchemaAction.java +++ b/topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/actions/CreateSchemaAction.java @@ -28,6 +28,7 @@ import org.hibernate.cfg.Configuration; import org.hibernate.cfg.Environment; import org.hibernate.dialect.Dialect; import org.hibernate.tool.hbm2ddl.SchemaExport; +import org.hibernate.tool.hbm2ddl.Target; import org.nuiton.topia.persistence.TopiaException; import java.io.IOException; @@ -64,7 +65,7 @@ public class CreateSchemaAction extends AbstractSchemaAction<CreateSchemaRequest new SchemaExport(hibernateConfiguration, properties) .setOutputFile(sqlScriptFile.toFile().getAbsolutePath()) .setDelimiter(";") - .create(false, false); + .execute(Target.NONE, SchemaExport.Type.CREATE); String sqlStatements = ""; if (request.isAddSchema()) { -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.
participants (1)
-
nuiton.org scm