Topia-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
January 2016
- 1 participants
- 24 discussions
branch feature/3860_introduce_topiasqlbatchsupport updated (e57b090 -> a70e884)
by nuiton.org scm 05 Jan '16
by nuiton.org scm 05 Jan '16
05 Jan '16
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
from e57b090 Add TopiaSqlBatchService and his default implementation
new a70e884 Add a configuration object for Topia Sql batch service and use it
The 1 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 a70e884dc8e2947e968f38040ffefc140b01586f
Author: Tony CHEMIT <chemit(a)codelutin.com>
Date: Tue Jan 5 20:10:16 2016 +0100
Add a configuration object for Topia Sql batch service and use it
Summary of changes:
.../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(-)
create mode 100644 topia-service-sql-batch/src/main/java/org/nuiton/topia/service/sql/batch/TopiaSqlBatchServiceConfiguration.java
--
To stop receiving notification emails like this one, please contact
nuiton.org SCM administrator <admin+scm(a)nuiton.org>.
1
1
branch feature/3860_introduce_topiasqlbatchsupport created (now e57b090)
by nuiton.org scm 05 Jan '16
by nuiton.org scm 05 Jan '16
05 Jan '16
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
at e57b090 Add TopiaSqlBatchService and his default implementation
This branch includes the following new commits:
new 7a4fee1 Introduce TopiaMetadataModel
new e2c019a Use gson to load and store TopiaMetadataModel
new 4c7bf77 Introduce TopiaMetadataModelSupport and add this new support to TopiaApplicationContext
new b8ff4e8 Introduce TopiaMetadataModelGenerator and include it into default Topia templates
new da2bcfd Add also getEntityEnum by name in TopiaEntityEnumProvider
new a36406f Generate metadata model location path
new 12d177e Add withShell method on metadata entity
new b866192 Add new topia-sql-batch module
new 4f594a9 Add TopiaSqlTable API
new d254cc8 Add Sql action abstract classes
new 3bd7535 Add create schema actions
new 8da3fb2 Add drop schem action
new e6ff976 Add replicate tables action
new 716a078 Add update tables action
new a36739d Add delete tables action
new e57b090 Add TopiaSqlBatchService and his default implementation
The 16 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 8da3fb281570e66562bea9f73e86bfff9a4d6761
Author: Tony CHEMIT <chemit(a)codelutin.com>
Date: Tue Jan 5 08:26:53 2016 +0100
Add drop schem action
commit e6ff976ddb0739ffe8e8db25289916769f0852e0
Author: Tony CHEMIT <chemit(a)codelutin.com>
Date: Tue Jan 5 08:27:10 2016 +0100
Add replicate tables action
commit 716a0786731f1f138717e53d9c1ba71e6b97224f
Author: Tony CHEMIT <chemit(a)codelutin.com>
Date: Tue Jan 5 08:27:25 2016 +0100
Add update tables action
commit a36739d0fefc9fb5beb2fc40a2d7ec475ec82dae
Author: Tony CHEMIT <chemit(a)codelutin.com>
Date: Tue Jan 5 08:27:40 2016 +0100
Add delete tables action
commit e57b090066962ecdf5b5ddbc660531cef20bbc94
Author: Tony CHEMIT <chemit(a)codelutin.com>
Date: Tue Jan 5 08:29:01 2016 +0100
Add TopiaSqlBatchService and his default implementation
commit 3bd75359b81a81fed510b666b6c77d7b5093f77d
Author: Tony CHEMIT <chemit(a)codelutin.com>
Date: Tue Jan 5 08:26:39 2016 +0100
Add create schema actions
commit d254cc8250b234e9447a32942f30961f2c756c98
Author: Tony CHEMIT <chemit(a)codelutin.com>
Date: Tue Jan 5 08:26:11 2016 +0100
Add Sql action abstract classes
commit 4f594a9bb3f2c11c89da84f228e6d9481adbc570
Author: Tony CHEMIT <chemit(a)codelutin.com>
Date: Tue Jan 5 08:25:22 2016 +0100
Add TopiaSqlTable API
commit b8661923b3920a2fa6d7c83f57b178102b4734b1
Author: Tony CHEMIT <chemit(a)codelutin.com>
Date: Tue Jan 5 08:24:59 2016 +0100
Add new topia-sql-batch module
commit 12d177efab307d8188934d9dbdbed340376d8689
Author: Tony CHEMIT <chemit(a)codelutin.com>
Date: Mon Jan 4 20:45:41 2016 +0100
Add withShell method on metadata entity
commit a36406fa0ec05512680c02d4e3b990e3659c52a6
Author: Tony CHEMIT <chemit(a)codelutin.com>
Date: Mon Jan 4 20:44:35 2016 +0100
Generate metadata model location path
commit da2bcfd4396b8f4ec049079a5d8bfabeebd75a99
Author: Tony CHEMIT <chemit(a)codelutin.com>
Date: Mon Jan 4 17:26:50 2016 +0100
Add also getEntityEnum by name in TopiaEntityEnumProvider
commit b8ff4e829a893687069952964de30ff00481dc3b
Author: Tony CHEMIT <chemit(a)codelutin.com>
Date: Mon Jan 4 13:39:07 2016 +0100
Introduce TopiaMetadataModelGenerator and include it into default Topia templates
commit 4c7bf7758c4c683188098085904b0fd12a20b84a
Author: Tony CHEMIT <chemit(a)codelutin.com>
Date: Mon Jan 4 13:36:34 2016 +0100
Introduce TopiaMetadataModelSupport and add this new support to TopiaApplicationContext
commit e2c019ac5963fa3c3aa89572a78f47cfea4589b8
Author: Tony CHEMIT <chemit(a)codelutin.com>
Date: Mon Jan 4 13:35:18 2016 +0100
Use gson to load and store TopiaMetadataModel
commit 7a4fee1fb91979649397f9994d648b6df317ca13
Author: Tony CHEMIT <chemit(a)codelutin.com>
Date: Mon Jan 4 13:33:37 2016 +0100
Introduce TopiaMetadataModel
--
To stop receiving notification emails like this one, please contact
nuiton.org SCM administrator <admin+scm(a)nuiton.org>.
1
5
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 8da3fb281570e66562bea9f73e86bfff9a4d6761
Author: Tony CHEMIT <chemit(a)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(a)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(a)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(a)nuiton.org>.
1
0
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 d254cc8250b234e9447a32942f30961f2c756c98
Author: Tony CHEMIT <chemit(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)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(a)nuiton.org>.
1
0
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 4f594a9bb3f2c11c89da84f228e6d9481adbc570
Author: Tony CHEMIT <chemit(a)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(a)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(a)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(a)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(a)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(a)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(a)nuiton.org>.
1
0
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 b8661923b3920a2fa6d7c83f57b178102b4734b1
Author: Tony CHEMIT <chemit(a)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(a)nuiton.org>.
1
0
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 12d177efab307d8188934d9dbdbed340376d8689
Author: Tony CHEMIT <chemit(a)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(a)nuiton.org>.
1
0
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 a36406fa0ec05512680c02d4e3b990e3659c52a6
Author: Tony CHEMIT <chemit(a)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(a)nuiton.org>.
1
0
05 Jan '16
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 da2bcfd4396b8f4ec049079a5d8bfabeebd75a99
Author: Tony CHEMIT <chemit(a)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(a)nuiton.org>.
1
0
04/16: Introduce TopiaMetadataModelGenerator and include it into default Topia templates
by nuiton.org scm 05 Jan '16
by nuiton.org scm 05 Jan '16
05 Jan '16
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 b8ff4e829a893687069952964de30ff00481dc3b
Author: Tony CHEMIT <chemit(a)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(a)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(a)nuiton.org>.
1
0