You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@empire-db.apache.org by de...@apache.org on 2016/11/09 10:59:08 UTC
[01/14] empire-db git commit: Fixed wrong placeholder for logging
[Forced Update!]
Repository: empire-db
Updated Branches:
refs/heads/EMPIREDB-247 3158c077c -> 04cc588fb (forced update)
Fixed wrong placeholder for logging
Project: http://git-wip-us.apache.org/repos/asf/empire-db/repo
Commit: http://git-wip-us.apache.org/repos/asf/empire-db/commit/386368c9
Tree: http://git-wip-us.apache.org/repos/asf/empire-db/tree/386368c9
Diff: http://git-wip-us.apache.org/repos/asf/empire-db/diff/386368c9
Branch: refs/heads/EMPIREDB-247
Commit: 386368c916d6258ccb94b8e7e3ab0df51deec5d1
Parents: e769f0f
Author: Jan Glaubitz <ja...@glaubitz.org>
Authored: Fri Aug 19 09:13:17 2016 +0200
Committer: Jan Glaubitz <ja...@glaubitz.org>
Committed: Fri Aug 19 09:13:17 2016 +0200
----------------------------------------------------------------------
.../src/main/java/org/apache/empire/jsf2/app/WebApplication.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/empire-db/blob/386368c9/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/WebApplication.java
----------------------------------------------------------------------
diff --git a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/WebApplication.java b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/WebApplication.java
index 0766b50..4bbbb1e 100644
--- a/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/WebApplication.java
+++ b/empire-db-jsf2/src/main/java/org/apache/empire/jsf2/app/WebApplication.java
@@ -81,7 +81,7 @@ public abstract class WebApplication
protected WebApplication()
{ // subscribe
- log.info("WebApplication {0} created", getClass().getName());
+ log.info("WebApplication {} created", getClass().getName());
// Must be a singleton
if (appInstance!=null) {
throw new RuntimeException("An attempt was made to create second instance of WebApplication. WebApplication must be a singleton!");
[06/14] empire-db git commit: Remove unused class EmpireDriverFactory
Posted by de...@apache.org.
Remove unused class EmpireDriverFactory
Project: http://git-wip-us.apache.org/repos/asf/empire-db/repo
Commit: http://git-wip-us.apache.org/repos/asf/empire-db/commit/f6c979e6
Tree: http://git-wip-us.apache.org/repos/asf/empire-db/tree/f6c979e6
Diff: http://git-wip-us.apache.org/repos/asf/empire-db/diff/f6c979e6
Branch: refs/heads/EMPIREDB-247
Commit: f6c979e654e4dff051ed3e4c0dfd3fb3093cd5ad
Parents: cc86a1f
Author: inemeth <in...@apache.org>
Authored: Wed Nov 2 10:56:00 2016 +0100
Committer: inemeth <in...@apache.org>
Committed: Wed Nov 2 10:56:00 2016 +0100
----------------------------------------------------------------------
.../empire/spring/EmpireDriverFactory.java | 101 -------------------
1 file changed, 101 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/empire-db/blob/f6c979e6/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireDriverFactory.java
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireDriverFactory.java b/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireDriverFactory.java
deleted file mode 100644
index 4548482..0000000
--- a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireDriverFactory.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.empire.spring;
-
-import java.sql.Connection;
-
-import org.apache.empire.db.DBDatabaseDriver;
-import org.apache.empire.db.derby.DBDatabaseDriverDerby;
-import org.apache.empire.db.h2.DBDatabaseDriverH2;
-import org.apache.empire.db.hsql.DBDatabaseDriverHSql;
-import org.apache.empire.db.mysql.DBDatabaseDriverMySQL;
-import org.apache.empire.db.oracle.DBDatabaseDriverOracle;
-import org.apache.empire.db.postgresql.DBDatabaseDriverPostgreSQL;
-import org.apache.empire.db.sqlserver.DBDatabaseDriverMSSQL;
-import org.springframework.jdbc.core.support.JdbcDaoSupport;
-
-/**
- * Creates the Empire-DB Drivers. Extends JdbcDaoSupport because it needs a Connection
- */
-public class EmpireDriverFactory extends JdbcDaoSupport {
-
- // copy&paste from the SampleApp
-
- public DBDatabaseDriver createDriver(String driverclass, String schema) {
- if (isClass(DBDatabaseDriverMySQL.class, driverclass))
- {
- DBDatabaseDriverMySQL driver = new DBDatabaseDriverMySQL();
- // Set Driver specific properties (if any)
- driver.setDatabaseName(schema);
- return driver;
- }
- else if (isClass(DBDatabaseDriverOracle.class, driverclass))
- {
- DBDatabaseDriverOracle driver = new DBDatabaseDriverOracle();
- // Set Driver specific properties (if any)
- return driver;
- }
- else if (isClass(DBDatabaseDriverMSSQL.class, driverclass))
- {
- DBDatabaseDriverMSSQL driver = new DBDatabaseDriverMSSQL();
- // Set Driver specific properties (if any)
- driver.setDatabaseName(schema);
- return driver;
- }
- else if (isClass(DBDatabaseDriverHSql.class, driverclass))
- {
- DBDatabaseDriverHSql driver = new DBDatabaseDriverHSql();
- // Set Driver specific properties (if any)
- return driver;
- }
- else if (isClass(DBDatabaseDriverPostgreSQL.class, driverclass))
- {
- DBDatabaseDriverPostgreSQL driver = new DBDatabaseDriverPostgreSQL();
- // Set Driver specific properties (if any)
- driver.setDatabaseName(schema);
- // Create the reverse function that is needed by this sample
- Connection conn = getConnection();
- driver.createReverseFunction(conn);
- releaseConnection(conn);
- return driver;
- }
- else if (isClass(DBDatabaseDriverH2.class, driverclass))
- {
- DBDatabaseDriverH2 driver = new DBDatabaseDriverH2();
- // Set Driver specific properties (if any)
- driver.setDatabaseName(schema);
- return driver;
- }
- else if (isClass(DBDatabaseDriverDerby.class, driverclass))
- {
- DBDatabaseDriverDerby driver = new DBDatabaseDriverDerby();
- // Set Driver specific properties (if any)
- driver.setDatabaseName(schema);
- return driver;
- }
- else
- { // Unknown Provider
- throw new RuntimeException("Unknown Database Driver " + driverclass);
- }
- }
-
- private boolean isClass(Class<? extends DBDatabaseDriver> clazz, String name) {
- return name.equals(clazz.getName());
- }
-}
[14/14] empire-db git commit: EMPIREDB-247
Posted by de...@apache.org.
EMPIREDB-247
- better naming of API
- clarify usage in docs
Project: http://git-wip-us.apache.org/repos/asf/empire-db/repo
Commit: http://git-wip-us.apache.org/repos/asf/empire-db/commit/74313783
Tree: http://git-wip-us.apache.org/repos/asf/empire-db/tree/74313783
Diff: http://git-wip-us.apache.org/repos/asf/empire-db/diff/74313783
Branch: refs/heads/EMPIREDB-247
Commit: 74313783814a95d859a2107de78618ccc06383e1
Parents: 890fa48
Author: Jan Glaubitz <ja...@glaubitz.org>
Authored: Fri Aug 12 12:31:25 2016 +0200
Committer: Jan Glaubitz <ja...@glaubitz.org>
Committed: Wed Nov 9 11:56:53 2016 +0100
----------------------------------------------------------------------
.../src/main/java/org/apache/empire/db/DBCommand.java | 8 ++++----
.../src/main/java/org/apache/empire/db/DBDatabase.java | 10 +++++-----
.../org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java | 2 +-
3 files changed, 10 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/empire-db/blob/74313783/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBCommand.java b/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
index 6941cc8..786fdbe 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
@@ -1132,16 +1132,16 @@ public abstract class DBCommand extends DBCommandExpr
}
/**
- * Creates the Insert or Update ("UPSERT") SQL-Command.
+ * Creates the INSERT or UPDATE ("UPSERT") SQL-Command.
*
- * This depends on your Database (driver) and might not be supported.
+ * This depends on your Database(driver) and might not be supported.
* Check DBDatabaseDriver.isSupported(PERFORM_UPSERT)
*
* @return the SQL-Command
*/
- public synchronized String getInsertOrUpdate()
+ public synchronized String getUpdateOrInsert()
{
- throw new NotSupportedException(this, "getInsertOrUpdate");
+ throw new NotSupportedException(this, "getUpdateOrInsert");
}
/**
http://git-wip-us.apache.org/repos/asf/empire-db/blob/74313783/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java b/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
index 5d84c30..a0d24e8 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
@@ -1387,10 +1387,11 @@ public abstract class DBDatabase extends DBObject
}
/**
- * Executes an Insert or Update Statement from a command object
+ * Executes an UPDATE or INSERT Statement from a command object
*
- * This depends on your Database (driver) and might not be supported.
- * Check DBDatabaseDriver.isSupported(PERFORM_UPSERT)
+ * Depending on your database(driver) this might be supported
+ * in one single statement (Check DBDatabaseDriver.isSupported(PERFORM_UPSERT)),
+ * or as fallback with an UPDATE, followed by an INSERT if nothing was updated.
*
* @param cmd the command object containing the update command
* @param conn a valid connection to the database.
@@ -1400,11 +1401,10 @@ public abstract class DBDatabase extends DBObject
{
if (getDriver().isSupported(DBDriverFeature.PERFORM_UPSERT))
{
- return executeSQL(cmd.getInsertOrUpdate(), cmd.getParamValues(), conn);
+ return executeSQL(cmd.getUpdateOrInsert(), cmd.getParamValues(), conn);
}
else
{
- log.warn("{} is not supported by your Database(driver). Falling back to two statements");
int count = executeUpdate(cmd, conn);
if (count < 1) {
// nothing updated -> INSERT
http://git-wip-us.apache.org/repos/asf/empire-db/blob/74313783/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java b/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
index 2429660..a02f7d8 100644
--- a/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
+++ b/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
@@ -123,7 +123,7 @@ public class DBDatabaseDriverMySQL extends DBDatabaseDriver
}
@Override
- public synchronized String getInsertOrUpdate()
+ public synchronized String getUpdateOrInsert()
{
StringBuilder buf = new StringBuilder(getInsert());
buf.append(" ON DUPLICATE KEY UPDATE ");
[09/14] empire-db git commit: [maven-release-plugin] prepare for next
development iteration
Posted by de...@apache.org.
[maven-release-plugin] prepare for next development iteration
Project: http://git-wip-us.apache.org/repos/asf/empire-db/repo
Commit: http://git-wip-us.apache.org/repos/asf/empire-db/commit/d54dcaf7
Tree: http://git-wip-us.apache.org/repos/asf/empire-db/tree/d54dcaf7
Diff: http://git-wip-us.apache.org/repos/asf/empire-db/diff/d54dcaf7
Branch: refs/heads/EMPIREDB-247
Commit: d54dcaf79ab3540c88315bc089628c41ae5dcad1
Parents: 2ab03fe
Author: Rainer D�bele <do...@apache.org>
Authored: Wed Nov 9 11:08:31 2016 +0100
Committer: Rainer D�bele <do...@apache.org>
Committed: Wed Nov 9 11:08:31 2016 +0100
----------------------------------------------------------------------
empire-db-codegen/pom.xml | 2 +-
empire-db-dist/pom.xml | 2 +-
empire-db-examples/empire-db-example-advanced/pom.xml | 2 +-
empire-db-examples/empire-db-example-basic/pom.xml | 2 +-
empire-db-examples/empire-db-example-cxf/pom.xml | 2 +-
empire-db-examples/empire-db-example-jsf2/pom.xml | 2 +-
empire-db-examples/empire-db-example-spring/pom.xml | 4 ++--
empire-db-examples/empire-db-example-struts2-cxf/pom.xml | 2 +-
empire-db-examples/empire-db-example-struts2/pom.xml | 2 +-
empire-db-examples/pom.xml | 2 +-
empire-db-jsf2/pom.xml | 2 +-
empire-db-maven-plugin/pom.xml | 2 +-
empire-db-spring/pom.xml | 2 +-
empire-db-struts2/pom.xml | 2 +-
empire-db/pom.xml | 2 +-
pom.xml | 4 ++--
16 files changed, 18 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/empire-db/blob/d54dcaf7/empire-db-codegen/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-codegen/pom.xml b/empire-db-codegen/pom.xml
index 31b8f33..2e4bca2 100644
--- a/empire-db-codegen/pom.xml
+++ b/empire-db-codegen/pom.xml
@@ -20,7 +20,7 @@
<parent>
<artifactId>empire-db-parent</artifactId>
<groupId>org.apache.empire-db</groupId>
- <version>2.4.5</version>
+ <version>2.4.6-SNAPSHOT</version>
</parent>
<artifactId>empire-db-codegen</artifactId>
<packaging>jar</packaging>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/d54dcaf7/empire-db-dist/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-dist/pom.xml b/empire-db-dist/pom.xml
index 4f1bd23..95c663a 100644
--- a/empire-db-dist/pom.xml
+++ b/empire-db-dist/pom.xml
@@ -19,7 +19,7 @@
<parent>
<artifactId>empire-db-parent</artifactId>
<groupId>org.apache.empire-db</groupId>
- <version>2.4.5</version>
+ <version>2.4.6-SNAPSHOT</version>
</parent>
<artifactId>empire-db-dist</artifactId>
<name>Apache Empire-db Distribtion</name>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/d54dcaf7/empire-db-examples/empire-db-example-advanced/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-advanced/pom.xml b/empire-db-examples/empire-db-example-advanced/pom.xml
index 01760c4..ec50482 100644
--- a/empire-db-examples/empire-db-example-advanced/pom.xml
+++ b/empire-db-examples/empire-db-example-advanced/pom.xml
@@ -19,7 +19,7 @@
<parent>
<groupId>org.apache.empire-db</groupId>
<artifactId>empire-db-examples</artifactId>
- <version>2.4.5</version>
+ <version>2.4.6-SNAPSHOT</version>
</parent>
<artifactId>empire-db-example-advanced</artifactId>
<name>Apache Empire-db Advanced Example</name>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/d54dcaf7/empire-db-examples/empire-db-example-basic/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-basic/pom.xml b/empire-db-examples/empire-db-example-basic/pom.xml
index 1498dc5..b5a9b83 100644
--- a/empire-db-examples/empire-db-example-basic/pom.xml
+++ b/empire-db-examples/empire-db-example-basic/pom.xml
@@ -19,7 +19,7 @@
<parent>
<groupId>org.apache.empire-db</groupId>
<artifactId>empire-db-examples</artifactId>
- <version>2.4.5</version>
+ <version>2.4.6-SNAPSHOT</version>
</parent>
<artifactId>empire-db-example-basic</artifactId>
<name>Apache Empire-db Basic Example</name>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/d54dcaf7/empire-db-examples/empire-db-example-cxf/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-cxf/pom.xml b/empire-db-examples/empire-db-example-cxf/pom.xml
index 86a44f5..2b37ea9 100644
--- a/empire-db-examples/empire-db-example-cxf/pom.xml
+++ b/empire-db-examples/empire-db-example-cxf/pom.xml
@@ -18,7 +18,7 @@
<parent>
<artifactId>empire-db-examples</artifactId>
<groupId>org.apache.empire-db</groupId>
- <version>2.4.5</version>
+ <version>2.4.6-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>empire-db-example-cxf</artifactId>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/d54dcaf7/empire-db-examples/empire-db-example-jsf2/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-jsf2/pom.xml b/empire-db-examples/empire-db-example-jsf2/pom.xml
index 4e54deb..eb985b4 100644
--- a/empire-db-examples/empire-db-example-jsf2/pom.xml
+++ b/empire-db-examples/empire-db-example-jsf2/pom.xml
@@ -19,7 +19,7 @@
<parent>
<artifactId>empire-db-examples</artifactId>
<groupId>org.apache.empire-db</groupId>
- <version>2.4.5</version>
+ <version>2.4.6-SNAPSHOT</version>
</parent>
<artifactId>empire-db-example-jsf2</artifactId>
<name>Apache Empire-db JSF2 Example</name>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/d54dcaf7/empire-db-examples/empire-db-example-spring/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-spring/pom.xml b/empire-db-examples/empire-db-example-spring/pom.xml
index 3d7eb6f..b120430 100644
--- a/empire-db-examples/empire-db-example-spring/pom.xml
+++ b/empire-db-examples/empire-db-example-spring/pom.xml
@@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.empire-db</groupId>
<artifactId>empire-db-examples</artifactId>
- <version>2.4.5</version>
+ <version>2.4.6-SNAPSHOT</version>
</parent>
<artifactId>empire-db-example-spring</artifactId>
<name>Apache Empire-db Spring Example</name>
@@ -111,7 +111,7 @@
<dependency>
<groupId>org.apache.empire-db</groupId>
<artifactId>empire-db-spring</artifactId>
- <version>2.4.5</version>
+ <version>2.4.6-SNAPSHOT</version>
</dependency>
</dependencies>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/d54dcaf7/empire-db-examples/empire-db-example-struts2-cxf/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-struts2-cxf/pom.xml b/empire-db-examples/empire-db-example-struts2-cxf/pom.xml
index 569a5f8..d89fb46 100644
--- a/empire-db-examples/empire-db-example-struts2-cxf/pom.xml
+++ b/empire-db-examples/empire-db-example-struts2-cxf/pom.xml
@@ -21,7 +21,7 @@
<parent>
<artifactId>empire-db-examples</artifactId>
<groupId>org.apache.empire-db</groupId>
- <version>2.4.5</version>
+ <version>2.4.6-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>empire-db-example-struts2-cxf</artifactId>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/d54dcaf7/empire-db-examples/empire-db-example-struts2/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-struts2/pom.xml b/empire-db-examples/empire-db-example-struts2/pom.xml
index a69618d..8b0c455 100644
--- a/empire-db-examples/empire-db-example-struts2/pom.xml
+++ b/empire-db-examples/empire-db-example-struts2/pom.xml
@@ -19,7 +19,7 @@
<parent>
<groupId>org.apache.empire-db</groupId>
<artifactId>empire-db-examples</artifactId>
- <version>2.4.5</version>
+ <version>2.4.6-SNAPSHOT</version>
</parent>
<artifactId>empire-db-example-struts2</artifactId>
<packaging>war</packaging>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/d54dcaf7/empire-db-examples/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-examples/pom.xml b/empire-db-examples/pom.xml
index 69bf1ae..836c6fb 100644
--- a/empire-db-examples/pom.xml
+++ b/empire-db-examples/pom.xml
@@ -19,7 +19,7 @@
<parent>
<groupId>org.apache.empire-db</groupId>
<artifactId>empire-db-parent</artifactId>
- <version>2.4.5</version>
+ <version>2.4.6-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>empire-db-examples</artifactId>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/d54dcaf7/empire-db-jsf2/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-jsf2/pom.xml b/empire-db-jsf2/pom.xml
index 4a78953..beebdb1 100644
--- a/empire-db-jsf2/pom.xml
+++ b/empire-db-jsf2/pom.xml
@@ -20,7 +20,7 @@
<parent>
<artifactId>empire-db-parent</artifactId>
<groupId>org.apache.empire-db</groupId>
- <version>2.4.5</version>
+ <version>2.4.6-SNAPSHOT</version>
</parent>
<artifactId>empire-db-jsf2</artifactId>
<packaging>jar</packaging>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/d54dcaf7/empire-db-maven-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-maven-plugin/pom.xml b/empire-db-maven-plugin/pom.xml
index da05311..b01317b 100644
--- a/empire-db-maven-plugin/pom.xml
+++ b/empire-db-maven-plugin/pom.xml
@@ -20,7 +20,7 @@
<parent>
<artifactId>empire-db-parent</artifactId>
<groupId>org.apache.empire-db</groupId>
- <version>2.4.5</version>
+ <version>2.4.6-SNAPSHOT</version>
</parent>
<artifactId>empire-db-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/d54dcaf7/empire-db-spring/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-spring/pom.xml b/empire-db-spring/pom.xml
index 51b5a77..4179724 100644
--- a/empire-db-spring/pom.xml
+++ b/empire-db-spring/pom.xml
@@ -20,7 +20,7 @@
<parent>
<artifactId>empire-db-parent</artifactId>
<groupId>org.apache.empire-db</groupId>
- <version>2.4.5</version>
+ <version>2.4.6-SNAPSHOT</version>
</parent>
<artifactId>empire-db-spring</artifactId>
<name>Apache Empire-db Spring JDBC Template</name>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/d54dcaf7/empire-db-struts2/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-struts2/pom.xml b/empire-db-struts2/pom.xml
index 0a8ca87..ac97c92 100644
--- a/empire-db-struts2/pom.xml
+++ b/empire-db-struts2/pom.xml
@@ -20,7 +20,7 @@
<parent>
<artifactId>empire-db-parent</artifactId>
<groupId>org.apache.empire-db</groupId>
- <version>2.4.5</version>
+ <version>2.4.6-SNAPSHOT</version>
</parent>
<artifactId>empire-db-struts2</artifactId>
<packaging>jar</packaging>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/d54dcaf7/empire-db/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db/pom.xml b/empire-db/pom.xml
index df291cc..16d8f0a 100644
--- a/empire-db/pom.xml
+++ b/empire-db/pom.xml
@@ -20,7 +20,7 @@
<parent>
<artifactId>empire-db-parent</artifactId>
<groupId>org.apache.empire-db</groupId>
- <version>2.4.5</version>
+ <version>2.4.6-SNAPSHOT</version>
</parent>
<artifactId>empire-db</artifactId>
<packaging>jar</packaging>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/d54dcaf7/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index dba427d..00b46c2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,7 @@
<groupId>org.apache.empire-db</groupId>
<artifactId>empire-db-parent</artifactId>
<packaging>pom</packaging>
- <version>2.4.5</version>
+ <version>2.4.6-SNAPSHOT</version>
<name>Apache Empire-db</name>
<description>Apache Empire-db is an Open Source relational data persistence component which allows database vendor independent dynamic query definition as well as safe and simple data retrieval and updating. Compared to most other solutions like e.g. Hibernate, TopLink, iBATIS or JPA implementations, Empire-db takes a considerably different approach, with a special focus on compile-time safety, reduced redundancies and improved developer productivity.</description>
<inceptionYear>2008</inceptionYear>
@@ -177,7 +177,7 @@
<connection>scm:git:http://git-wip-us.apache.org/repos/asf/empire-db.git</connection>
<developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/empire-db.git</developerConnection>
<url>http://git-wip-us.apache.org/repos/asf/wicket/repo?p=empire-db.git</url>
- <tag>apache-empire-db-2.4.5-rc1</tag>
+ <tag>HEAD</tag>
</scm>
<mailingLists>
[02/14] empire-db git commit: EMPIREDB-248 Submitted fix provided by
Alberto Osvaldo Gonzalez
Posted by de...@apache.org.
EMPIREDB-248
Submitted fix provided by Alberto Osvaldo Gonzalez
Project: http://git-wip-us.apache.org/repos/asf/empire-db/repo
Commit: http://git-wip-us.apache.org/repos/asf/empire-db/commit/325e4223
Tree: http://git-wip-us.apache.org/repos/asf/empire-db/tree/325e4223
Diff: http://git-wip-us.apache.org/repos/asf/empire-db/diff/325e4223
Branch: refs/heads/EMPIREDB-247
Commit: 325e4223c0539e5e607109a078ef9004522a031d
Parents: 386368c
Author: Rainer D�bele <do...@esteam.de>
Authored: Sat Oct 29 13:27:12 2016 +0200
Committer: Rainer D�bele <do...@esteam.de>
Committed: Sat Oct 29 13:27:12 2016 +0200
----------------------------------------------------------------------
.../empire/db/postgresql/DBDatabaseDriverPostgreSQL.java | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/empire-db/blob/325e4223/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java b/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java
index 5965dc7..21024e8 100644
--- a/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java
+++ b/empire-db/src/main/java/org/apache/empire/db/postgresql/DBDatabaseDriverPostgreSQL.java
@@ -361,9 +361,9 @@ public class DBDatabaseDriverPostgreSQL extends DBDatabaseDriver
case SQL_FUNC_FLOOR: return "floor(?)";
case SQL_FUNC_MODULO: return "mod(?,{0})";
// Date
- case SQL_FUNC_DAY: return "day(?)";
- case SQL_FUNC_MONTH: return "month(?)";
- case SQL_FUNC_YEAR: return "year(?)";
+ case SQL_FUNC_DAY: return "extract(day from ?)";
+ case SQL_FUNC_MONTH: return "extract(month from ?)";
+ case SQL_FUNC_YEAR: return "extract(year from ?)";
// Aggregation
case SQL_FUNC_SUM: return "sum(?)";
case SQL_FUNC_MAX: return "max(?)";
[05/14] empire-db git commit: Spring Examples moved to examples
project
Posted by de...@apache.org.
Spring Examples moved to examples project
Project: http://git-wip-us.apache.org/repos/asf/empire-db/repo
Commit: http://git-wip-us.apache.org/repos/asf/empire-db/commit/cc86a1fd
Tree: http://git-wip-us.apache.org/repos/asf/empire-db/tree/cc86a1fd
Diff: http://git-wip-us.apache.org/repos/asf/empire-db/diff/cc86a1fd
Branch: refs/heads/EMPIREDB-247
Commit: cc86a1fd7d80ffd5a81910e68a5fd07901a4786d
Parents: f951502
Author: inemeth <in...@apache.org>
Authored: Mon Oct 31 09:21:30 2016 +0100
Committer: inemeth <in...@apache.org>
Committed: Mon Oct 31 09:21:30 2016 +0100
----------------------------------------------------------------------
.../empire-db-example-spring/pom.xml | 7 +-
.../empire/spring/example1/EmpireApp.java | 47 +++
.../empire/spring/example1/EmpireAppImpl.java | 336 +++++++++++++++++++
.../empire/spring/example1/SampleBean.java | 126 +++++++
.../apache/empire/spring/example1/SampleDB.java | 148 ++++++++
.../empire/spring/example1/SampleSpringApp.java | 86 +++++
.../empire/spring/example2/Department.java | 99 ++++++
.../apache/empire/spring/example2/Employee.java | 140 ++++++++
.../empire/spring/example2/EmployeeDao.java | 47 +++
.../empire/spring/example2/EmployeeDaoImpl.java | 231 +++++++++++++
.../spring/example2/EmployeeSpringApp.java | 227 +++++++++++++
.../resources/example1/applicationContext.xml | 92 +++++
.../example2/applicationContext-employee.xml | 85 +++++
.../src/main/resources/settings.properties | 2 +-
empire-db-spring/pom.xml | 10 -
.../empire/spring/example1/EmpireApp.java | 47 ---
.../empire/spring/example1/EmpireAppImpl.java | 336 -------------------
.../empire/spring/example1/SampleBean.java | 126 -------
.../apache/empire/spring/example1/SampleDB.java | 148 --------
.../empire/spring/example1/SampleSpringApp.java | 86 -----
.../empire/spring/example2/Department.java | 99 ------
.../apache/empire/spring/example2/Employee.java | 140 --------
.../empire/spring/example2/EmployeeDao.java | 47 ---
.../empire/spring/example2/EmployeeDaoImpl.java | 231 -------------
.../spring/example2/EmployeeSpringApp.java | 227 -------------
.../resources/example1/applicationContext.xml | 92 -----
.../example2/applicationContext-employee.xml | 85 -----
.../src/main/resources/log4j.properties | 21 --
.../src/main/resources/settings.properties | 44 ---
29 files changed, 1671 insertions(+), 1741 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-examples/empire-db-example-spring/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-spring/pom.xml b/empire-db-examples/empire-db-example-spring/pom.xml
index 0eba0e9..101cb25 100644
--- a/empire-db-examples/empire-db-example-spring/pom.xml
+++ b/empire-db-examples/empire-db-example-spring/pom.xml
@@ -107,7 +107,12 @@
<version>1.0</version>
</dependency>
-->
-
+
+ <dependency>
+ <groupId>org.apache.empire-db</groupId>
+ <artifactId>empire-db-spring</artifactId>
+ <version>2.4.5-SNAPSHOT</version>
+ </dependency>
</dependencies>
<!-- better would be to add this repository in your settings.xml -->
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example1/EmpireApp.java
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example1/EmpireApp.java b/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example1/EmpireApp.java
new file mode 100644
index 0000000..ddf809f
--- /dev/null
+++ b/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example1/EmpireApp.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.spring.example1;
+
+
+/**
+ * This is the interface to the application. It is usually some high level interface; for this basic
+ * example this is the dao object.
+ *
+ */
+public interface EmpireApp {
+
+ void clearDatabase();
+
+ void setupDatabase();
+
+ Integer insertDepartment(String departmentName, String businessUnit);
+
+ Integer insertEmployee(String firstName, String lastName, String gender, int departmentId);
+
+ void updateEmployee(int idPers, String phoneNumber);
+
+ void doQuery(QueryType type);
+
+ public enum QueryType
+ {
+ Reader,
+ BeanList,
+ XmlDocument
+ }
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example1/EmpireAppImpl.java
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example1/EmpireAppImpl.java b/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example1/EmpireAppImpl.java
new file mode 100644
index 0000000..ba5bd45
--- /dev/null
+++ b/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example1/EmpireAppImpl.java
@@ -0,0 +1,336 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.spring.example1;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.empire.db.DBColumn;
+import org.apache.empire.db.DBColumnExpr;
+import org.apache.empire.db.DBCommand;
+import org.apache.empire.db.DBDatabase;
+import org.apache.empire.db.DBDatabaseDriver;
+import org.apache.empire.db.DBReader;
+import org.apache.empire.db.DBRecord;
+import org.apache.empire.db.DBRecordData;
+import org.apache.empire.db.DBSQLScript;
+import org.apache.empire.db.DBTable;
+import org.apache.empire.db.derby.DBDatabaseDriverDerby;
+import org.apache.empire.db.h2.DBDatabaseDriverH2;
+import org.apache.empire.db.hsql.DBDatabaseDriverHSql;
+import org.apache.empire.db.postgresql.DBDatabaseDriverPostgreSQL;
+import org.apache.empire.spring.DBReaderExtractor;
+import org.apache.empire.spring.DBRecordCallbackHandler;
+import org.apache.empire.spring.DBRecordMapper;
+import org.apache.empire.spring.EmpireDaoSupport;
+import org.apache.empire.xml.XMLWriter;
+import org.springframework.dao.DataAccessException;
+import org.springframework.jdbc.core.ConnectionCallback;
+import org.springframework.transaction.annotation.Transactional;
+import org.w3c.dom.Document;
+
+/**
+ *
+ */
+public class EmpireAppImpl extends EmpireDaoSupport implements EmpireApp {
+
+ @Transactional
+ public void clearDatabase() {
+ SampleDB db = getDatabase();
+
+ DBCommand cmd = db.createCommand();
+ // Delete all Employees (no constraints)
+ getEmpireTemplate().executeDelete(db.EMPLOYEES, cmd);
+ // Delete all Departments (no constraints)
+ getEmpireTemplate().executeDelete(db.DEPARTMENTS, cmd);
+ }
+
+
+ @Transactional
+ public Integer insertDepartment(String departmentName, String businessUnit) {
+ SampleDB db = getDatabase();
+
+ DBRecord rec = new DBRecord();
+ rec.create(db.DEPARTMENTS);
+ rec.setValue(db.DEPARTMENTS.NAME, departmentName);
+ rec.setValue(db.DEPARTMENTS.BUSINESS_UNIT, businessUnit);
+
+ getEmpireTemplate().updateRecord(rec);
+ // Return Department ID
+ return rec.getInt(db.DEPARTMENTS.DEPARTMENT_ID);
+ }
+
+ @Transactional
+ public Integer insertEmployee(String firstName, String lastName,
+ String gender, int departmentId) {
+ SampleDB db = getDatabase();
+
+ DBRecord rec = new DBRecord();
+ rec.create(db.EMPLOYEES);
+ rec.setValue(db.EMPLOYEES.FIRSTNAME, firstName);
+ rec.setValue(db.EMPLOYEES.LASTNAME, lastName);
+ rec.setValue(db.EMPLOYEES.GENDER, gender);
+ rec.setValue(db.EMPLOYEES.DEPARTMENT_ID, departmentId);
+ getEmpireTemplate().updateRecord(rec);
+ // Return Employee ID
+ return rec.getInt(db.EMPLOYEES.EMPLOYEE_ID);
+ }
+
+ @Transactional
+ public void updateEmployee(int idPers, String phoneNumber) {
+ if (getEmployee(idPers) == null) {
+ // if you like more verbose exceptions for the app
+ throw new IllegalArgumentException(
+ "The specified employee does not exist.");
+ }
+
+ SampleDB db = getDatabase();
+
+ DBRecord rec = getEmpireTemplate().openRecord(db.EMPLOYEES, idPers);
+ // Set
+ rec.setValue(db.EMPLOYEES.PHONE_NUMBER, phoneNumber);
+ getEmpireTemplate().updateRecord(rec);
+ }
+
+ @Transactional(readOnly = true)
+ public void doQuery(QueryType type) {
+ SampleDB db = getDatabase();
+
+ // Define the query
+ DBCommand cmd = db.createCommand();
+ // Define shortcuts for tables used - not necessary but convenient
+ final SampleDB.Employees EMP = db.EMPLOYEES;
+ final SampleDB.Departments DEP = db.DEPARTMENTS;
+
+ // The following expression concats lastname + ', ' + firstname
+ final DBColumnExpr EMPLOYEE_FULLNAME = EMP.LASTNAME.append(", ")
+ .append(EMP.FIRSTNAME).as("FULL_NAME");
+
+ // The following expression extracts the extension number from the phone
+ // field
+ // e.g. substr(PHONE_NUMBER,
+ // length(PHONE_NUMBER)-instr(reverse(PHONE_NUMBER), '-')+2) AS
+ // PHONE_EXTENSION
+ // Hint: Since the reverse() function is not supported by HSQLDB there
+ // is special treatment for HSQL
+ final DBColumnExpr PHONE_LAST_DASH;
+ if (db.getDriver() instanceof DBDatabaseDriverHSql
+ || db.getDriver() instanceof DBDatabaseDriverDerby
+ || db.getDriver() instanceof DBDatabaseDriverH2)
+ PHONE_LAST_DASH = EMP.PHONE_NUMBER.indexOf("-",
+ EMP.PHONE_NUMBER.indexOf("-").plus(1)).plus(1); // HSQLDB
+ // only
+ else
+ PHONE_LAST_DASH = EMP.PHONE_NUMBER.length()
+ .minus(EMP.PHONE_NUMBER.reverse().indexOf("-")).plus(2);
+ final DBColumnExpr PHONE_EXT_NUMBER = EMP.PHONE_NUMBER.substring(
+ PHONE_LAST_DASH).as("PHONE_EXTENSION");
+
+ // DBColumnExpr genderExpr =
+ // cmd.select(EMP.GENDER.decode(EMP.GENDER.getOptions()).as(EMP.GENDER.getName()));
+ // Select required columns
+ cmd.select(EMP.EMPLOYEE_ID, EMPLOYEE_FULLNAME);
+ if (db.getDriver() instanceof DBDatabaseDriverPostgreSQL) {
+ // postgres does not support the substring expression
+ cmd.select(EMP.GENDER, EMP.PHONE_NUMBER);
+ } else {
+ cmd.select(EMP.GENDER, EMP.PHONE_NUMBER, PHONE_EXT_NUMBER);
+
+ }
+ cmd.select(DEP.NAME.as("DEPARTMENT"));
+ cmd.select(DEP.BUSINESS_UNIT);
+ cmd.join(EMP.DEPARTMENT_ID, DEP.DEPARTMENT_ID);
+ // Set constraints and order
+ cmd.where(EMP.LASTNAME.length().isGreaterThan(0));
+ cmd.orderBy(EMP.LASTNAME, EMP.FIRSTNAME);
+
+ // Query Records and print output
+ try {
+ // Open Reader
+ System.out.println("Running Query:");
+ System.out.println(cmd.getSelect());
+ // Print output
+ System.out.println("---------------------------------");
+ switch (type) {
+ case BeanList:
+ // Text-Output by iterating through all records.
+ DBRecordCallbackHandler readerImpl = new DBRecordCallbackHandler() {
+
+ public void processRecord(DBRecordData reader) {
+ System.out.println(reader.getString(EMP.EMPLOYEE_ID)
+ + "\t"
+ + reader.getString(EMPLOYEE_FULLNAME)
+ + "\t"
+ + EMP.GENDER.getOptions().get(
+ reader.getString(EMP.GENDER)) + "\t"
+ + reader.getString(PHONE_EXT_NUMBER) + "\t"
+ + reader.getString(DEP.NAME));
+
+ }
+ };
+ getEmpireTemplate().query(cmd, readerImpl);
+ break;
+ case Reader:
+ // Text-Output using a list of Java Beans supplied by the
+ // DBReader
+ DBReaderExtractor<List<SampleBean>> beanListImpl = new DBReaderExtractor<List<SampleBean>>() {
+
+ public List<SampleBean> process(DBReader reader) {
+ return reader.getBeanList(SampleBean.class);
+ }
+ };
+ List<SampleBean> beanList = getEmpireTemplate().query(cmd,
+ beanListImpl);
+ System.out.println(String.valueOf(beanList.size())
+ + " SampleBeans returned from Query.");
+ for (SampleBean b : beanList) {
+ System.out.println(b.toString());
+ }
+ break;
+ case XmlDocument:
+ // XML Output
+ XmlDocumentExtractor xmlImpl = new XmlDocumentExtractor();
+ Document doc = getEmpireTemplate().query(cmd, xmlImpl);
+ // Print XML Document to System.out
+ XMLWriter.debug(doc);
+ break;
+ }
+
+ } finally {
+
+ // always close Reader
+
+ // reader is closed in EmpireTemplate's methods
+
+ // reader.close();
+ }
+ }
+
+ public Map<Object, Object> getDepartment(int id) {
+ SampleDB db = getDatabase();
+ return get(db.DEPARTMENTS, id);
+ }
+
+ public Map<Object, Object> getEmployee(int id) {
+ SampleDB db = getDatabase();
+ return get(db.EMPLOYEES, id);
+ }
+
+ private Map<Object, Object> get(DBTable table, int pk) {
+
+ SampleDB db = getDatabase();
+
+ DBCommand cmd = db.createCommand();
+ cmd.select(table.getColumns());
+ cmd.where(table.getPrimaryKey().getColumns()[0].is(pk)); // i know there
+ // is just
+ // one
+ // pk-column
+ // ;-)
+ Map<Object, Object> dep = getEmpireTemplate().queryForObject(cmd,
+ new RowToObjectMapDataMapper(table));
+
+ return dep;
+ }
+
+ public static class XmlDocumentExtractor implements
+ DBReaderExtractor<Document> {
+
+ public Document process(DBReader reader) {
+ return reader.getXmlDocument();
+ }
+
+ }
+
+ public static class RowToObjectMapDataMapper implements
+ DBRecordMapper<Map<Object, Object>> {
+
+ DBTable table;
+
+ public RowToObjectMapDataMapper(DBTable table) {
+ super();
+ this.table = table;
+ }
+
+ public Map<Object, Object> mapRecord(DBRecordData record, int rowNum) {
+ Map<Object, Object> dep = new HashMap<Object, Object>();
+ for (DBColumn col : table.getColumns()) {
+ dep.put(col.getName(), record.getValue(col));
+ }
+ return dep;
+ }
+
+ }
+
+ public boolean databaseExists() {
+ Connection conn = getConnection();
+ try {
+ DBDatabase db = getDatabase();
+ if (db.getTables() == null || db.getTables().isEmpty()) {
+ throw new AssertionError(
+ "There are no tables in this database!");
+ }
+ DBCommand cmd = db.createCommand();
+ if (cmd == null) {
+ throw new AssertionError("The DBCommand object is null.");
+ }
+ DBTable t = db.getTables().get(0);
+ cmd.select(t.count());
+ return (db.querySingleInt(cmd, -1, conn) >= 0);
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+ public void initializeDatabase() {
+ if (!databaseExists()) {
+ createDatabase();
+ }
+ }
+
+ @Transactional
+ public void setupDatabase() {
+ initializeDatabase();
+ }
+
+ public void createDatabase() {
+
+ // create DLL for Database Definition
+ final DBSQLScript script = new DBSQLScript();
+ final DBDatabaseDriver driver = getDatabase().getDriver();
+ getDatabase().getCreateDDLScript(driver, script);
+
+ // Show DLL Statement
+ System.out.println(script.toString());
+ // Execute Script
+ getEmpireTemplate().execute(new ConnectionCallback<Object>() {
+
+ public Object doInConnection(Connection con) throws SQLException,
+ DataAccessException {
+ script.executeAll(driver, con, false);
+ return null;
+ }
+ });
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example1/SampleBean.java
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example1/SampleBean.java b/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example1/SampleBean.java
new file mode 100644
index 0000000..efe89b1
--- /dev/null
+++ b/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example1/SampleBean.java
@@ -0,0 +1,126 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.spring.example1;
+
+
+/**
+ * The SampleBean class is used to demonstrate JavaBean support for SQL-Queries.
+ * The SampleBean is used in the SampleApp's queryRecords function.
+ */
+public class SampleBean
+{
+ private int employeeId;
+ private String fullName;
+ private String gender;
+ private String phoneNumber;
+ private String department;
+ private String businessUnit;
+
+ /*
+ * Uncomment this if you want to use constructor instead of setters
+ * However, number of arguments and data types must match query!
+ *
+ public SampleBean(int employeeId, String fullName, String gender, String phoneNumber, String department, String businessUnit)
+ {
+ this.employeeId = employeeId;
+ this.fullName = fullName;
+ this.gender = gender;
+ this.phoneNumber = phoneNumber;
+ this.department = department;
+ this.businessUnit = businessUnit;
+ }
+ */
+
+ public int getEmployeeId()
+ {
+ return employeeId;
+ }
+
+ public void setEmployeeId(int employeeId)
+ {
+ this.employeeId = employeeId;
+ }
+
+ public String getFullName()
+ {
+ return fullName;
+ }
+
+ public void setFullName(String fullName)
+ {
+ this.fullName = fullName;
+ }
+
+ public String getGender()
+ {
+ return gender;
+ }
+
+ public void setGender(String gender)
+ {
+ this.gender = gender;
+ }
+
+ public String getPhoneNumber()
+ {
+ return phoneNumber;
+ }
+
+ public void setPhoneNumber(String phoneNumber)
+ {
+ this.phoneNumber = phoneNumber;
+ }
+
+ public String getDepartment()
+ {
+ return department;
+ }
+
+ public void setDepartment(String department)
+ {
+ this.department = department;
+ }
+
+ public String getBusinessUnit()
+ {
+ return businessUnit;
+ }
+
+ public void setBusinessUnit(String businessUnit)
+ {
+ this.businessUnit = businessUnit;
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuffer buf = new StringBuffer();
+ buf.append(employeeId);
+ buf.append("\t");
+ buf.append(fullName);
+ buf.append("\t");
+ buf.append(gender);
+ buf.append("\t");
+ buf.append(department);
+ buf.append("\t");
+ buf.append(businessUnit);
+ return buf.toString();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example1/SampleDB.java
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example1/SampleDB.java b/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example1/SampleDB.java
new file mode 100644
index 0000000..c8f3284
--- /dev/null
+++ b/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example1/SampleDB.java
@@ -0,0 +1,148 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.spring.example1;
+
+import org.apache.empire.commons.Options;
+import org.apache.empire.data.DataType;
+import org.apache.empire.data.DataMode;
+import org.apache.empire.db.DBColumn;
+import org.apache.empire.db.DBDatabase;
+import org.apache.empire.db.DBTable;
+import org.apache.empire.db.DBTableColumn;
+
+/**
+ * <PRE>
+ * This file contains the definition of the data model in Java.
+ * The SampleDB data model consists of two tables and a foreign key relation.
+ * The tables are defined as nested classes here, but you may put the in separate files if you want.
+ *
+ * PLEASE NOTE THE NAMING CONVENTION:
+ * Since all tables, views and columns are declared as "final" constants they are all in upper case.
+ * We recommend using a prefix of T_ for tables and C_ for columns in order to keep them together
+ * when listed in your IDE's code completion.
+ * There is no need to stick to this convention but it makes life just another little bit easier.
+ *
+ * You may declare other database tables or views in the same way.
+ * </PRE>
+ */
+public class SampleDB extends DBDatabase
+{
+ private final static long serialVersionUID = 1L;
+
+ /**
+ * This class represents the definition of the Departments table.
+ */
+ public static class Departments extends DBTable
+ {
+
+ private final static long serialVersionUID = 1L;
+
+ public final DBTableColumn DEPARTMENT_ID;
+ public final DBTableColumn NAME;
+ public final DBTableColumn HEAD;
+ public final DBTableColumn BUSINESS_UNIT;
+ public final DBTableColumn UPDATE_TIMESTAMP;
+
+ public Departments(DBDatabase db)
+ {
+ super("DEPARTMENTS", db);
+ // ID
+ DEPARTMENT_ID = addColumn("DEPARTMENT_ID", DataType.AUTOINC, 0, true, "DEP_ID_SEQUENCE");
+ NAME = addColumn("NAME", DataType.TEXT, 80, true);
+ HEAD = addColumn("HEAD", DataType.TEXT, 80, false);
+ BUSINESS_UNIT = addColumn("BUSINESS_UNIT", DataType.TEXT, 4, true, "ITTK");
+ UPDATE_TIMESTAMP= addColumn("UPDATE_TIMESTAMP", DataType.DATETIME, 0, true);
+
+ // Primary Key
+ setPrimaryKey(DEPARTMENT_ID);
+ // Set other Indexes
+ addIndex("DEARTMENT_NAME_IDX", true, new DBColumn[] { NAME });
+ // Set timestamp column for save updates
+ setTimestampColumn(UPDATE_TIMESTAMP);
+ }
+ }
+
+ /**
+ * This class represents the definition of the Employees table.
+ */
+ public static class Employees extends DBTable
+ {
+ private final static long serialVersionUID = 1L;
+
+ public final DBTableColumn EMPLOYEE_ID;
+ public final DBTableColumn SALUTATION;
+ public final DBTableColumn FIRSTNAME;
+ public final DBTableColumn LASTNAME;
+ public final DBTableColumn DATE_OF_BIRTH;
+ public final DBTableColumn DEPARTMENT_ID;
+ public final DBTableColumn GENDER;
+ public final DBTableColumn PHONE_NUMBER;
+ public final DBTableColumn EMAIL;
+ public final DBTableColumn SALARY;
+ public final DBTableColumn RETIRED;
+ public final DBTableColumn UPDATE_TIMESTAMP;
+
+ public Employees(DBDatabase db)
+ {
+ super("EMPLOYEES", db);
+ // ID
+ EMPLOYEE_ID = addColumn("EMPLOYEE_ID", DataType.AUTOINC, 0, true, "EMPLOYEE_ID_SEQUENCE");
+ SALUTATION = addColumn("SALUTATION", DataType.TEXT, 20, false);
+ FIRSTNAME = addColumn("FIRST_NAME", DataType.TEXT, 40, true);
+ LASTNAME = addColumn("LAST_NAME", DataType.TEXT, 40, true);
+ DATE_OF_BIRTH = addColumn("DATE_OF_BIRTH", DataType.DATE, 0, false);
+ DEPARTMENT_ID = addColumn("DEPARTMENT_ID", DataType.INTEGER, 0, true);
+ GENDER = addColumn("GENDER", DataType.TEXT, 1, false);
+ PHONE_NUMBER = addColumn("PHONE_NUMBER", DataType.TEXT, 40, false);
+ EMAIL = addColumn("EMAIL", DataType.TEXT, 80, false);
+ SALARY = addColumn("SALARY", DataType.DECIMAL, 10.2, false);
+ RETIRED = addColumn("RETIRED", DataType.BOOL, 0, true, false);
+ UPDATE_TIMESTAMP= addColumn("UPDATE_TIMESTAMP", DataType.DATETIME, 0, true);
+
+ // Primary Key
+ setPrimaryKey(EMPLOYEE_ID);
+ // Set other Indexes
+ addIndex("EMPLOYEE_NAME_IDX", true, new DBColumn[] { FIRSTNAME, LASTNAME, DATE_OF_BIRTH });
+ // Set timestamp column for save updates
+ setTimestampColumn(UPDATE_TIMESTAMP);
+
+ // Create Options for GENDER column
+ Options genders = new Options();
+ genders.set("M", "Male");
+ genders.set("F", "Female");
+ GENDER.setOptions(genders);
+ }
+ }
+
+ // Declare all Tables and Views here
+ public final Departments DEPARTMENTS = new Departments(this);
+ public final Employees EMPLOYEES = new Employees(this);
+
+ /**
+ * Constructor of the SampleDB data model description
+ *
+ * Put all foreign key relations here.
+ */
+ public SampleDB()
+ {
+ // Define Foreign-Key Relations
+ addRelation( EMPLOYEES.DEPARTMENT_ID.referenceOn( DEPARTMENTS.DEPARTMENT_ID ));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example1/SampleSpringApp.java
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example1/SampleSpringApp.java b/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example1/SampleSpringApp.java
new file mode 100644
index 0000000..3ff0230
--- /dev/null
+++ b/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example1/SampleSpringApp.java
@@ -0,0 +1,86 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.spring.example1;
+
+import java.util.logging.Logger;
+
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.GenericApplicationContext;
+import org.springframework.core.io.ClassPathResource;
+
+/**
+ *
+ */
+public class SampleSpringApp {
+ private static final Logger log = Logger.getLogger(SampleSpringApp.class.getName());
+
+ //creates the application context
+ //this is usually in some bootstrapping code; so your application will
+ //just have one at runtime.
+ static ApplicationContext ctx = getContext();
+
+ //get the service that is the entry point into the application
+ //normally this is injected by spring into classes that need it
+ static EmpireApp appBean = ctx.getBean("empireApp", EmpireApp.class);
+
+ public static void main(String[] args) throws Exception {
+
+ System.out.println("Running Spring Example...");
+
+ appBean.setupDatabase();
+ appBean.clearDatabase();
+
+ System.out.println("*** Step 6: insertDepartment() & insertEmployee() ***");
+ int idDevDep = appBean.insertDepartment("Development", "ITTK");
+ int idSalDep = appBean.insertDepartment("Sales", "ITTK");
+
+ int idPers1 = appBean.insertEmployee("Peter", "Sharp", "M", idDevDep);
+ int idPers2 = appBean.insertEmployee("Fred", "Bloggs", "M", idDevDep);
+ int idPers3 = appBean.insertEmployee("Emma", "White", "F", idSalDep);
+
+ System.out.println("*** Step 7: updateEmployee() ***");
+ appBean.updateEmployee(idPers1, "+49-7531-457160");
+ appBean.updateEmployee(idPers2, "+49-5555-505050");
+ appBean.updateEmployee(idPers3, "+49-040-125486");
+
+ System.out.println("*** Step 8 Option 1: queryRecords() / Tab-Output ***");
+ appBean.doQuery(EmpireApp.QueryType.Reader);
+
+ System.out.println("*** Step 8 Option 2: queryRecords() / Bean-List-Output ***");
+ appBean.doQuery(EmpireApp.QueryType.BeanList);
+
+ System.out.println("*** Step 8 Option 3: queryRecords() / XML-Output ***");
+ appBean.doQuery(EmpireApp.QueryType.XmlDocument);
+
+
+ }
+
+
+
+ static GenericApplicationContext getContext() {
+ log.info("Creating Spring Application Context ...");
+ GenericApplicationContext ctx = new GenericApplicationContext();
+ XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx);
+ reader.loadBeanDefinitions(new ClassPathResource("/example1/applicationContext.xml"));
+
+ ctx.refresh();
+ return ctx;
+ }
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example2/Department.java
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example2/Department.java b/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example2/Department.java
new file mode 100644
index 0000000..08d8943
--- /dev/null
+++ b/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example2/Department.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.spring.example2;
+
+public class Department {
+
+ private Integer departmentId;
+ private String name;
+ private String businessUnit;
+ private String head;
+
+ public Integer getDepartmentId() {
+ return departmentId;
+ }
+
+ public void setDepartmentId(Integer departmentId) {
+ this.departmentId = departmentId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getBusinessUnit() {
+ return businessUnit;
+ }
+
+ public void setBusinessUnit(String businessUnit) {
+ this.businessUnit = businessUnit;
+ }
+
+ public String getHead() {
+ return head;
+ }
+
+ public void setHead(String head) {
+ this.head = head;
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer buf = new StringBuffer();
+ buf.append(departmentId);
+ buf.append("\t");
+ buf.append(name);
+ buf.append(" ");
+ buf.append(businessUnit);
+ buf.append("\t");
+ buf.append(head);
+ return buf.toString();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+
+ if (obj.getClass().equals(this.getClass())) {
+ Department other = (Department) obj;
+ if (other.departmentId == null || this.departmentId == null) {
+ return false;
+ }
+ return this.departmentId.equals(other.departmentId);
+ }
+
+ return super.equals(obj);
+ }
+
+ @Override
+ public int hashCode() {
+ return 1;
+ }
+
+
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example2/Employee.java
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example2/Employee.java b/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example2/Employee.java
new file mode 100644
index 0000000..5a07ce9
--- /dev/null
+++ b/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example2/Employee.java
@@ -0,0 +1,140 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.spring.example2;
+
+public class Employee {
+
+ public static enum Gender {
+
+ M("Male"), F("Female");
+
+ private String label;
+
+ private Gender(String label) {
+ this.label = label;
+ }
+
+ @Override
+ public String toString() {
+ return this.label;
+ }
+ }
+
+ private Integer employeeId;
+ private String firstName;
+ private String lastName;
+ private Gender gender;
+ private String phoneNumber;
+
+ private Department department;
+
+ public Integer getEmployeeId() {
+ return employeeId;
+ }
+
+ public void setEmployeeId(Integer employeeId) {
+ this.employeeId = employeeId;
+ }
+
+ public String getFirstName() {
+ return firstName;
+ }
+
+ public void setFirstName(String firstName) {
+ this.firstName = firstName;
+ }
+
+ public String getLastName() {
+ return lastName;
+ }
+
+ public void setLastName(String lastName) {
+ this.lastName = lastName;
+ }
+
+ public Gender getGender() {
+ return gender;
+ }
+
+ public void setGender(Gender gender) {
+ this.gender = gender;
+ }
+
+ public String getPhoneNumber() {
+ return phoneNumber;
+ }
+
+ public void setPhoneNumber(String phoneNumber) {
+ this.phoneNumber = phoneNumber;
+ }
+
+ public Department getDepartment() {
+ return department;
+ }
+
+ public void setDepartment(Department department) {
+ this.department = department;
+ }
+
+ @Override
+ public String toString() {
+ StringBuffer buf = new StringBuffer();
+ buf.append(employeeId);
+ buf.append("\t");
+ buf.append(firstName);
+ buf.append(" ");
+ buf.append(lastName);
+ buf.append("\t");
+ buf.append(gender);
+
+ if (department != null){
+ buf.append("\t");
+ buf.append(department.getName());
+ buf.append("\t");
+ buf.append(department.getBusinessUnit());
+ }
+ return buf.toString();
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+
+ if (obj.getClass().equals(this.getClass())) {
+ Employee other = (Employee) obj;
+ if (other.employeeId == null || this.employeeId == null) {
+ return false;
+ }
+ return this.employeeId.equals(other.employeeId);
+ }
+
+ return super.equals(obj);
+ }
+
+ @Override
+ public int hashCode() {
+ return 1;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDao.java
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDao.java b/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDao.java
new file mode 100644
index 0000000..b2dd39f
--- /dev/null
+++ b/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDao.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.spring.example2;
+
+import java.util.List;
+
+public interface EmployeeDao {
+
+ public List<Employee> getEmployees();
+
+ public List<Department> getDepartments();
+
+ public Integer createEmployee(Employee employee);
+
+ public void updateEmployee(Employee employee);
+
+ public Employee openEmployee(Integer id);
+
+ public Employee findEmployee(String firstName, String lastName);
+
+ public Department openDepartment(Integer id);
+
+ public Department findDepartment(String name);
+
+ public Integer createDepartment(Department department);
+
+ public void updateDepartment(Department department);
+
+ public void renameDepartment(Integer id, String name);
+
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDaoImpl.java
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDaoImpl.java b/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDaoImpl.java
new file mode 100644
index 0000000..37eb07b
--- /dev/null
+++ b/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDaoImpl.java
@@ -0,0 +1,231 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.spring.example2;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.empire.db.DBCommand;
+import org.apache.empire.db.DBJoinType;
+import org.apache.empire.db.DBRecord;
+import org.apache.empire.db.DBRecordData;
+import org.apache.empire.spring.DBRecordMapper;
+import org.apache.empire.spring.DBRecordWriter;
+import org.apache.empire.spring.EmpireDaoSupport;
+import org.apache.empire.spring.example1.SampleDB;
+import org.apache.empire.spring.example1.SampleDB.Departments;
+import org.apache.empire.spring.example1.SampleDB.Employees;
+import org.springframework.transaction.annotation.Transactional;
+
+public class EmployeeDaoImpl extends EmpireDaoSupport implements EmployeeDao {
+
+ private Employees EMPLOYEES;
+ private Departments DEPARTMENTS;
+
+ @Override
+ protected void initEmpireDao() {
+ SampleDB db = getDatabase();
+ this.EMPLOYEES = db.EMPLOYEES;
+ this.DEPARTMENTS = db.DEPARTMENTS;
+ }
+
+ private DBCommand createEmployeeSelectCommand() {
+ DBCommand cmd = getDatabase().createCommand();
+ cmd.select(EMPLOYEES.getColumns());
+ cmd.select(DEPARTMENTS.getColumns());
+
+ cmd.join(EMPLOYEES.DEPARTMENT_ID, DEPARTMENTS.DEPARTMENT_ID, DBJoinType.INNER);
+ return cmd;
+ }
+
+ private DBCommand createDepartmentSelectCommand() {
+ DBCommand cmd = getDatabase().createCommand();
+ cmd.select(DEPARTMENTS.getColumns());
+ return cmd;
+ }
+
+ @Transactional(readOnly = true)
+ public Employee openEmployee(Integer id) {
+ DBCommand cmd = createEmployeeSelectCommand();
+ cmd.where(EMPLOYEES.EMPLOYEE_ID.is(id));
+ return getEmpireTemplate().queryForObject(cmd, new EmployeeMapper());
+ }
+
+ @Transactional(readOnly = true)
+ public Employee findEmployee(String firstName, String lastName) {
+ DBCommand cmd = createEmployeeSelectCommand();
+ cmd.where(EMPLOYEES.FIRSTNAME.is(firstName));
+ cmd.where(EMPLOYEES.LASTNAME.is(lastName));
+ return getEmpireTemplate().queryForObject(cmd, new EmployeeMapper());
+ }
+
+ @Transactional(readOnly = true)
+ public Department openDepartment(Integer id) {
+ DBCommand cmd = createDepartmentSelectCommand();
+ cmd.where(DEPARTMENTS.DEPARTMENT_ID.is(id));
+ return getEmpireTemplate().queryForBean(cmd, Department.class);
+ }
+
+ @Transactional(readOnly = true)
+ public Department findDepartment(String name) {
+ DBCommand cmd = createDepartmentSelectCommand();
+ cmd.where(DEPARTMENTS.NAME.is(name));
+ return getEmpireTemplate().queryForBean(cmd, Department.class);
+ }
+
+ @Transactional(readOnly = true)
+ public List<Department> getDepartments() {
+ DBCommand cmd = createDepartmentSelectCommand();
+ return getEmpireTemplate().queryForBeanList(cmd, Department.class);
+ }
+
+
+ @Transactional
+ public void renameDepartment(Integer id, String name) {
+ DBCommand cmd = getDatabase().createCommand();
+ cmd.where(DEPARTMENTS.DEPARTMENT_ID.is(id));
+ cmd.set(DEPARTMENTS.NAME.to(name));
+ getEmpireTemplate().executeUpdate(cmd);
+ }
+
+ @Transactional(readOnly = true)
+ public List<Employee> getEmployees() {
+ DBCommand cmd = createEmployeeSelectCommand();
+ return getEmpireTemplate().query(cmd, new EmployeeMapper());
+ }
+
+ @Transactional
+ public Integer createEmployee(Employee employee) {
+ DBRecord record = new DBRecord();
+ record.create(EMPLOYEES);
+ new EmployeeWriter().write(record, employee);
+ getEmpireTemplate().updateRecord(record);
+ return record.getInt(EMPLOYEES.EMPLOYEE_ID);
+ }
+
+ @Transactional
+ public void updateEmployee(Employee employee) {
+ DBRecord record = getEmpireTemplate().openRecord(EMPLOYEES, employee.getEmployeeId());
+ new EmployeeWriter().write(record, employee);
+ getEmpireTemplate().updateRecord(record);
+ }
+
+ @Transactional
+ public Integer createDepartment(Department department) {
+ DBRecord record = new DBRecord();
+ record.create(DEPARTMENTS);
+ new DepartmentWriter().write(record, department);
+ getEmpireTemplate().updateRecord(record);
+ return record.getInt(DEPARTMENTS.DEPARTMENT_ID);
+ }
+
+ @Transactional
+ public void updateDepartment(Department department) {
+ DBRecord record = getEmpireTemplate().openRecord(DEPARTMENTS, department.getDepartmentId());
+ new DepartmentWriter().write(record, department);
+ getEmpireTemplate().updateRecord(record);
+ }
+
+ private class EmployeeMapper implements DBRecordMapper<Employee> {
+
+ DepartmentMapper departmentMapper = new DepartmentMapper();
+
+ @Override
+ public Employee mapRecord(DBRecordData record, int rowNum) {
+ Employee result = new Employee();
+ // Auto-copy all properties
+ //record.setBeanProperties(result);
+
+ result.setEmployeeId(record.getInt(EMPLOYEES.EMPLOYEE_ID));
+ result.setFirstName(record.getString(EMPLOYEES.FIRSTNAME));
+ result.setLastName(record.getString(EMPLOYEES.LASTNAME));
+ result.setGender(Employee.Gender.valueOf(record.getString(EMPLOYEES.GENDER)));
+ result.setPhoneNumber(record.getString(EMPLOYEES.PHONE_NUMBER));
+
+ result.setDepartment(departmentMapper.mapRecord(record, rowNum));
+ return result;
+ }
+
+ }
+
+ private class EmployeeWriter implements DBRecordWriter<Employee> {
+
+ @Override
+ public void write(DBRecord record, Employee entity) {
+ // Auto-copy all properties
+ //record.setRecordValues(entity);
+
+ record.setValue(EMPLOYEES.EMPLOYEE_ID, entity.getEmployeeId());
+ record.setValue(EMPLOYEES.FIRSTNAME, entity.getFirstName());
+ record.setValue(EMPLOYEES.LASTNAME, entity.getLastName());
+ record.setValue(EMPLOYEES.GENDER, entity.getGender().name());
+ record.setValue(EMPLOYEES.PHONE_NUMBER, entity.getPhoneNumber());
+
+ record.setValue(EMPLOYEES.DEPARTMENT_ID, entity.getDepartment().getDepartmentId());
+ }
+
+ }
+
+ private class DepartmentMapper implements DBRecordMapper<Department> {
+
+ // reader cache, in case of joined resultset the same object is returned
+
+ Map<Integer, Department> cache = new HashMap<Integer, Department>();
+
+ @Override
+ public Department mapRecord(DBRecordData record, int rowNum) {
+
+ Integer id = record.getInt(DEPARTMENTS.DEPARTMENT_ID);
+
+ Department department = cache.get(id);
+ if (department == null) {
+ department = new Department();
+ // Auto-copy all properties
+ //record.setBeanProperties(department);
+
+ department.setDepartmentId(id);
+ department.setName(record.getString(DEPARTMENTS.NAME));
+ department.setHead(record.getString(DEPARTMENTS.HEAD));
+ department.setBusinessUnit(record.getString(DEPARTMENTS.BUSINESS_UNIT));
+
+ cache.put(id, department);
+ }
+ return department;
+ }
+
+ }
+
+ private class DepartmentWriter implements DBRecordWriter<Department> {
+
+ @Override
+ public void write(DBRecord record, Department entity) {
+ // Auto-copy all properties
+ //record.setRecordValues(entity);
+
+ record.setValue(DEPARTMENTS.DEPARTMENT_ID, entity.getDepartmentId());
+ record.setValue(DEPARTMENTS.NAME, entity.getName());
+ record.setValue(DEPARTMENTS.HEAD, entity.getHead());
+ record.setValue(DEPARTMENTS.BUSINESS_UNIT, entity.getBusinessUnit());
+
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example2/EmployeeSpringApp.java
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example2/EmployeeSpringApp.java b/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example2/EmployeeSpringApp.java
new file mode 100644
index 0000000..3b641a7
--- /dev/null
+++ b/empire-db-examples/empire-db-example-spring/src/main/java/org/apache/empire/spring/example2/EmployeeSpringApp.java
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.spring.example2;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.apache.empire.db.DBColumnExpr;
+import org.apache.empire.db.DBCommand;
+import org.apache.empire.db.DBDatabase;
+import org.apache.empire.db.DBDatabaseDriver;
+import org.apache.empire.db.DBSQLScript;
+import org.apache.empire.db.DBTable;
+import org.apache.empire.spring.EmpireTemplate;
+import org.apache.empire.spring.example1.SampleDB;
+import org.apache.empire.spring.example2.Employee.Gender;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.GenericApplicationContext;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.dao.DataAccessException;
+import org.springframework.jdbc.core.ConnectionCallback;
+
+/**
+ *
+ */
+public class EmployeeSpringApp {
+ private static final Logger log = Logger.getLogger(EmployeeSpringApp.class.getName());
+
+ //creates the application context
+ //this is usually in some bootstrapping code; so your application will
+ //just have one at runtime.
+ static ApplicationContext ctx = getContext();
+
+ //get the service that is the entry point into the application
+ //normally this is injected by spring into classes that need it
+ static EmployeeDao employeeDao = ctx.getBean("employeeDao", EmployeeDao.class);
+ static SampleDB sampleDb = ctx.getBean("sampleDb", SampleDB.class);
+
+ public static void main(String[] args) throws Exception {
+
+ System.out.println("Running Spring Example...");
+
+ setupDatabase();
+ clearDatabase();
+
+ Department depDevelopment, depSales;
+
+ System.out.println("*** Create Departments ***");
+
+ {
+ depDevelopment = new Department();
+ depDevelopment.setName("Development");
+ depDevelopment.setBusinessUnit("ITTK");
+ Integer id = employeeDao.createDepartment(depDevelopment);
+ depDevelopment = employeeDao.openDepartment(id);
+ }
+ {
+ depSales = new Department();
+ depSales.setName("Sales");
+ depSales.setBusinessUnit("ITTK");
+ Integer id = employeeDao.createDepartment(depSales);
+ depSales = employeeDao.openDepartment(id);
+ }
+
+ System.out.println("*** Create Employees ***");
+
+ Employee peter = new Employee();
+ peter.setFirstName("Peter");
+ peter.setLastName("Sharp");
+ peter.setGender(Gender.M);
+ peter.setDepartment(depDevelopment);
+
+ Integer peterId = employeeDao.createEmployee(peter);
+ peter = employeeDao.openEmployee(peterId);
+
+
+
+ Employee fred = new Employee();
+ fred.setFirstName("Fred");
+ fred.setLastName("Bloggs");
+ fred.setGender(Gender.M);
+ fred.setDepartment(depDevelopment);
+
+ Integer fredId = employeeDao.createEmployee(fred);
+ fred = employeeDao.openEmployee(fredId);
+
+
+ Employee emma = new Employee();
+ emma.setFirstName("Emma");
+ emma.setLastName("White");
+ emma.setGender(Gender.F);
+ emma.setDepartment(depSales);
+
+ Integer emmaId = employeeDao.createEmployee(emma);
+ emma = employeeDao.openEmployee(emmaId);
+
+
+ System.out.println("*** updateEmployees ***");
+
+ peter.setPhoneNumber("+49-7531-457160");
+ employeeDao.updateEmployee(peter);
+
+ fred.setPhoneNumber("+49-5555-505050");
+ employeeDao.updateEmployee(fred);
+
+ emma.setPhoneNumber("+49-040-125486");
+ employeeDao.updateEmployee(emma);
+
+ System.out.println("*** List employees ***");
+
+ List<Employee> employees = employeeDao.getEmployees();
+ for (Iterator<Employee> iterator = employees.iterator(); iterator.hasNext();) {
+ Employee employee = iterator.next();
+ System.out.println(employee);
+ }
+
+ System.out.println("*** List departments ***");
+
+ List<Department> departments = employeeDao.getDepartments();
+ for (Iterator<Department> iterator = departments.iterator(); iterator.hasNext();) {
+ Department department = iterator.next();
+ System.out.println(department);
+ }
+
+ }
+
+ private static void clearDatabase() {
+ // Delete all Employees (no constraints)
+
+ EmpireTemplate empireTemplate = ctx.getBean("empireTemplate", EmpireTemplate.class);
+ empireTemplate.executeDelete(sampleDb.EMPLOYEES, sampleDb.createCommand());
+ empireTemplate.executeDelete(sampleDb.DEPARTMENTS, sampleDb.createCommand());
+
+ }
+
+
+
+
+ public static void setupDatabase() {
+ if (!databaseExists()) {
+ createDatabase();
+ }
+ }
+
+
+ public static boolean databaseExists() {
+ try {
+ DBDatabase db = sampleDb;
+ if (db.getTables() == null || db.getTables().isEmpty()) {
+ throw new AssertionError(
+ "There are no tables in this database!");
+ }
+ DBCommand cmd = db.createCommand();
+ if (cmd == null) {
+ throw new AssertionError("The DBCommand object is null.");
+ }
+ DBTable t = db.getTables().get(0);
+ DBColumnExpr COUNT = t.count();
+
+ cmd.select(COUNT);
+
+ EmpireTemplate empireTemplate = ctx.getBean("empireTemplate", EmpireTemplate.class);
+ return (empireTemplate.queryForInteger(cmd, COUNT, -1) >= 0);
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
+
+ private static void createDatabase() {
+
+ // create DLL for Database Definition
+ final DBSQLScript script = new DBSQLScript();
+ final DBDatabaseDriver driver = sampleDb.getDriver();
+ sampleDb.getCreateDDLScript(driver, script);
+
+ // Show DLL Statement
+ System.out.println(script.toString());
+ // Execute Script
+ EmpireTemplate empireTemplate = ctx.getBean("empireTemplate", EmpireTemplate.class);
+ empireTemplate.execute(new ConnectionCallback<Object>() {
+
+ @Override
+ public Object doInConnection(Connection con) throws SQLException,
+ DataAccessException {
+ script.executeAll(driver, con, false);
+ return null;
+ }
+ });
+
+ }
+
+
+
+ static GenericApplicationContext getContext() {
+ log.info("Creating Spring Application Context ...");
+ GenericApplicationContext ctx = new GenericApplicationContext();
+ XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx);
+ reader.loadBeanDefinitions(new ClassPathResource("/example2/applicationContext-employee.xml"));
+
+ ctx.refresh();
+ return ctx;
+ }
+
+
+
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-examples/empire-db-example-spring/src/main/resources/example1/applicationContext.xml
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-spring/src/main/resources/example1/applicationContext.xml b/empire-db-examples/empire-db-example-spring/src/main/resources/example1/applicationContext.xml
new file mode 100644
index 0000000..7987d5a
--- /dev/null
+++ b/empire-db-examples/empire-db-example-spring/src/main/resources/example1/applicationContext.xml
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xmlns:aop="http://www.springframework.org/schema/aop"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
+
+
+ <!-- one option is to use a class from spring that will read the properties file
+ and replaces the ${...} placeholders with the appropriate values -->
+ <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
+ <property name="locations">
+ <value>classpath:/settings.properties</value>
+ </property>
+ </bean>
+
+ <!-- Data Source / DB Settings -->
+ <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
+ <property name="driverClassName" value="${jdbc.driverClass}"/>
+ <property name="url" value="${jdbc.url}"/>
+ <property name="username" value="${jdbc.username}"/>
+ <property name="password" value="${jdbc.password}"/>
+ </bean>
+
+ <!-- Transaction manager for a single JDBC DataSource (alternative to JTA) -->
+ <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
+ <constructor-arg ref="dataSource"/>
+ </bean>
+ <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
+ <property name="transactionManager" ref="transactionManager"/>
+ </bean>
+
+ <!-- @Transactional -->
+ <tx:annotation-driven transaction-manager="transactionManager"/>
+
+ <!-- Empire-DB classes -->
+
+ <!-- application dao/services -->
+ <bean id="empireApp" class="org.apache.empire.spring.example1.EmpireAppImpl" parent="empireDao"/>
+
+
+ <bean id="empireDb" class="org.apache.empire.spring.DBDatabaseFactoryBean">
+ <property name="driverClass" value="${empire.driver}"/>
+ <property name="schema" value="${empire.schemaname}"/>
+ <property name="databaseClass" value="org.apache.empire.spring.example1.SampleDB"/>
+ </bean>
+
+ <bean id="empireDao" abstract="true">
+ <property name="database" ref="empireDb"/>
+ <property name="empireTemplate" ref="empireTemplate"/>
+ </bean>
+
+
+ <bean id="empireTemplate" class="org.apache.empire.spring.EmpireTemplate">
+ <property name="dataSource" ref="dataSource"/>
+ </bean>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+</beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-examples/empire-db-example-spring/src/main/resources/example2/applicationContext-employee.xml
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-spring/src/main/resources/example2/applicationContext-employee.xml b/empire-db-examples/empire-db-example-spring/src/main/resources/example2/applicationContext-employee.xml
new file mode 100644
index 0000000..08ce097
--- /dev/null
+++ b/empire-db-examples/empire-db-example-spring/src/main/resources/example2/applicationContext-employee.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:tx="http://www.springframework.org/schema/tx"
+ xmlns:aop="http://www.springframework.org/schema/aop"
+ xsi:schemaLocation="
+ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+ http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
+ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
+
+
+ <!-- one option is to use a class from spring that will read the properties file
+ and replaces the ${...} placeholders with the appropriate values -->
+ <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
+ <property name="locations">
+ <value>classpath:/settings.properties</value>
+ </property>
+ </bean>
+
+ <!-- Data Source / DB Settings -->
+ <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
+ <property name="driverClassName" value="${jdbc.driverClass}"/>
+ <property name="url" value="${jdbc.url}"/>
+ <property name="username" value="${jdbc.username}"/>
+ <property name="password" value="${jdbc.password}"/>
+ </bean>
+
+ <!-- Transaction manager for a single JDBC DataSource (alternative to JTA) -->
+ <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
+ <constructor-arg ref="dataSource"/>
+ </bean>
+ <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
+ <property name="transactionManager" ref="transactionManager"/>
+ </bean>
+
+ <!-- @Transactional -->
+ <tx:annotation-driven transaction-manager="transactionManager"/>
+
+ <!-- Empire-DB classes -->
+
+ <!-- application dao/services -->
+ <bean id="employeeDao" class="org.apache.empire.spring.example2.EmployeeDaoImpl" parent="empireDao"/>
+
+
+ <bean id="sampleDb" class="org.apache.empire.spring.DBDatabaseFactoryBean">
+ <property name="driverClass" value="${empire.driver}"/>
+ <property name="schema" value="${empire.schemaname}"/>
+ <property name="databaseClass" value="org.apache.empire.spring.example1.SampleDB"/>
+ </bean>
+
+ <bean id="empireDao" abstract="true">
+ <property name="database" ref="sampleDb"/>
+ <property name="empireTemplate" ref="empireTemplate"/>
+ </bean>
+
+
+ <bean id="empireTemplate" class="org.apache.empire.spring.EmpireTemplate">
+ <property name="dataSource" ref="dataSource"/>
+ </bean>
+
+
+
+
+
+
+
+</beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-examples/empire-db-example-spring/src/main/resources/settings.properties
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-spring/src/main/resources/settings.properties b/empire-db-examples/empire-db-example-spring/src/main/resources/settings.properties
index 6c36099..e5ba794 100644
--- a/empire-db-examples/empire-db-example-spring/src/main/resources/settings.properties
+++ b/empire-db-examples/empire-db-example-spring/src/main/resources/settings.properties
@@ -22,7 +22,7 @@ jdbc.username=sa
jdbc.password=
empire.driver= org.apache.empire.db.hsql.DBDatabaseDriverHSql
-empire.schemaname=DBSAMPLE1
+empire.schemaname=
## Derby settings (tested)
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-spring/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-spring/pom.xml b/empire-db-spring/pom.xml
index 0cdbad1..3579299 100644
--- a/empire-db-spring/pom.xml
+++ b/empire-db-spring/pom.xml
@@ -38,11 +38,6 @@
<artifactId>empire-db</artifactId>
</dependency>
<dependency>
- <groupId>hsqldb</groupId>
- <artifactId>hsqldb</artifactId>
- </dependency>
-
- <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
@@ -54,11 +49,6 @@
<version>${spring.version}</version>
</dependency>
- <dependency>
- <groupId>commons-dbcp</groupId>
- <artifactId>commons-dbcp</artifactId>
- <version>1.2.2</version>
- </dependency>
</dependencies>
</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-spring/src/main/java/org/apache/empire/spring/example1/EmpireApp.java
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/java/org/apache/empire/spring/example1/EmpireApp.java b/empire-db-spring/src/main/java/org/apache/empire/spring/example1/EmpireApp.java
deleted file mode 100644
index ddf809f..0000000
--- a/empire-db-spring/src/main/java/org/apache/empire/spring/example1/EmpireApp.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.empire.spring.example1;
-
-
-/**
- * This is the interface to the application. It is usually some high level interface; for this basic
- * example this is the dao object.
- *
- */
-public interface EmpireApp {
-
- void clearDatabase();
-
- void setupDatabase();
-
- Integer insertDepartment(String departmentName, String businessUnit);
-
- Integer insertEmployee(String firstName, String lastName, String gender, int departmentId);
-
- void updateEmployee(int idPers, String phoneNumber);
-
- void doQuery(QueryType type);
-
- public enum QueryType
- {
- Reader,
- BeanList,
- XmlDocument
- }
-}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-spring/src/main/java/org/apache/empire/spring/example1/EmpireAppImpl.java
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/java/org/apache/empire/spring/example1/EmpireAppImpl.java b/empire-db-spring/src/main/java/org/apache/empire/spring/example1/EmpireAppImpl.java
deleted file mode 100644
index ba5bd45..0000000
--- a/empire-db-spring/src/main/java/org/apache/empire/spring/example1/EmpireAppImpl.java
+++ /dev/null
@@ -1,336 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.empire.spring.example1;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.empire.db.DBColumn;
-import org.apache.empire.db.DBColumnExpr;
-import org.apache.empire.db.DBCommand;
-import org.apache.empire.db.DBDatabase;
-import org.apache.empire.db.DBDatabaseDriver;
-import org.apache.empire.db.DBReader;
-import org.apache.empire.db.DBRecord;
-import org.apache.empire.db.DBRecordData;
-import org.apache.empire.db.DBSQLScript;
-import org.apache.empire.db.DBTable;
-import org.apache.empire.db.derby.DBDatabaseDriverDerby;
-import org.apache.empire.db.h2.DBDatabaseDriverH2;
-import org.apache.empire.db.hsql.DBDatabaseDriverHSql;
-import org.apache.empire.db.postgresql.DBDatabaseDriverPostgreSQL;
-import org.apache.empire.spring.DBReaderExtractor;
-import org.apache.empire.spring.DBRecordCallbackHandler;
-import org.apache.empire.spring.DBRecordMapper;
-import org.apache.empire.spring.EmpireDaoSupport;
-import org.apache.empire.xml.XMLWriter;
-import org.springframework.dao.DataAccessException;
-import org.springframework.jdbc.core.ConnectionCallback;
-import org.springframework.transaction.annotation.Transactional;
-import org.w3c.dom.Document;
-
-/**
- *
- */
-public class EmpireAppImpl extends EmpireDaoSupport implements EmpireApp {
-
- @Transactional
- public void clearDatabase() {
- SampleDB db = getDatabase();
-
- DBCommand cmd = db.createCommand();
- // Delete all Employees (no constraints)
- getEmpireTemplate().executeDelete(db.EMPLOYEES, cmd);
- // Delete all Departments (no constraints)
- getEmpireTemplate().executeDelete(db.DEPARTMENTS, cmd);
- }
-
-
- @Transactional
- public Integer insertDepartment(String departmentName, String businessUnit) {
- SampleDB db = getDatabase();
-
- DBRecord rec = new DBRecord();
- rec.create(db.DEPARTMENTS);
- rec.setValue(db.DEPARTMENTS.NAME, departmentName);
- rec.setValue(db.DEPARTMENTS.BUSINESS_UNIT, businessUnit);
-
- getEmpireTemplate().updateRecord(rec);
- // Return Department ID
- return rec.getInt(db.DEPARTMENTS.DEPARTMENT_ID);
- }
-
- @Transactional
- public Integer insertEmployee(String firstName, String lastName,
- String gender, int departmentId) {
- SampleDB db = getDatabase();
-
- DBRecord rec = new DBRecord();
- rec.create(db.EMPLOYEES);
- rec.setValue(db.EMPLOYEES.FIRSTNAME, firstName);
- rec.setValue(db.EMPLOYEES.LASTNAME, lastName);
- rec.setValue(db.EMPLOYEES.GENDER, gender);
- rec.setValue(db.EMPLOYEES.DEPARTMENT_ID, departmentId);
- getEmpireTemplate().updateRecord(rec);
- // Return Employee ID
- return rec.getInt(db.EMPLOYEES.EMPLOYEE_ID);
- }
-
- @Transactional
- public void updateEmployee(int idPers, String phoneNumber) {
- if (getEmployee(idPers) == null) {
- // if you like more verbose exceptions for the app
- throw new IllegalArgumentException(
- "The specified employee does not exist.");
- }
-
- SampleDB db = getDatabase();
-
- DBRecord rec = getEmpireTemplate().openRecord(db.EMPLOYEES, idPers);
- // Set
- rec.setValue(db.EMPLOYEES.PHONE_NUMBER, phoneNumber);
- getEmpireTemplate().updateRecord(rec);
- }
-
- @Transactional(readOnly = true)
- public void doQuery(QueryType type) {
- SampleDB db = getDatabase();
-
- // Define the query
- DBCommand cmd = db.createCommand();
- // Define shortcuts for tables used - not necessary but convenient
- final SampleDB.Employees EMP = db.EMPLOYEES;
- final SampleDB.Departments DEP = db.DEPARTMENTS;
-
- // The following expression concats lastname + ', ' + firstname
- final DBColumnExpr EMPLOYEE_FULLNAME = EMP.LASTNAME.append(", ")
- .append(EMP.FIRSTNAME).as("FULL_NAME");
-
- // The following expression extracts the extension number from the phone
- // field
- // e.g. substr(PHONE_NUMBER,
- // length(PHONE_NUMBER)-instr(reverse(PHONE_NUMBER), '-')+2) AS
- // PHONE_EXTENSION
- // Hint: Since the reverse() function is not supported by HSQLDB there
- // is special treatment for HSQL
- final DBColumnExpr PHONE_LAST_DASH;
- if (db.getDriver() instanceof DBDatabaseDriverHSql
- || db.getDriver() instanceof DBDatabaseDriverDerby
- || db.getDriver() instanceof DBDatabaseDriverH2)
- PHONE_LAST_DASH = EMP.PHONE_NUMBER.indexOf("-",
- EMP.PHONE_NUMBER.indexOf("-").plus(1)).plus(1); // HSQLDB
- // only
- else
- PHONE_LAST_DASH = EMP.PHONE_NUMBER.length()
- .minus(EMP.PHONE_NUMBER.reverse().indexOf("-")).plus(2);
- final DBColumnExpr PHONE_EXT_NUMBER = EMP.PHONE_NUMBER.substring(
- PHONE_LAST_DASH).as("PHONE_EXTENSION");
-
- // DBColumnExpr genderExpr =
- // cmd.select(EMP.GENDER.decode(EMP.GENDER.getOptions()).as(EMP.GENDER.getName()));
- // Select required columns
- cmd.select(EMP.EMPLOYEE_ID, EMPLOYEE_FULLNAME);
- if (db.getDriver() instanceof DBDatabaseDriverPostgreSQL) {
- // postgres does not support the substring expression
- cmd.select(EMP.GENDER, EMP.PHONE_NUMBER);
- } else {
- cmd.select(EMP.GENDER, EMP.PHONE_NUMBER, PHONE_EXT_NUMBER);
-
- }
- cmd.select(DEP.NAME.as("DEPARTMENT"));
- cmd.select(DEP.BUSINESS_UNIT);
- cmd.join(EMP.DEPARTMENT_ID, DEP.DEPARTMENT_ID);
- // Set constraints and order
- cmd.where(EMP.LASTNAME.length().isGreaterThan(0));
- cmd.orderBy(EMP.LASTNAME, EMP.FIRSTNAME);
-
- // Query Records and print output
- try {
- // Open Reader
- System.out.println("Running Query:");
- System.out.println(cmd.getSelect());
- // Print output
- System.out.println("---------------------------------");
- switch (type) {
- case BeanList:
- // Text-Output by iterating through all records.
- DBRecordCallbackHandler readerImpl = new DBRecordCallbackHandler() {
-
- public void processRecord(DBRecordData reader) {
- System.out.println(reader.getString(EMP.EMPLOYEE_ID)
- + "\t"
- + reader.getString(EMPLOYEE_FULLNAME)
- + "\t"
- + EMP.GENDER.getOptions().get(
- reader.getString(EMP.GENDER)) + "\t"
- + reader.getString(PHONE_EXT_NUMBER) + "\t"
- + reader.getString(DEP.NAME));
-
- }
- };
- getEmpireTemplate().query(cmd, readerImpl);
- break;
- case Reader:
- // Text-Output using a list of Java Beans supplied by the
- // DBReader
- DBReaderExtractor<List<SampleBean>> beanListImpl = new DBReaderExtractor<List<SampleBean>>() {
-
- public List<SampleBean> process(DBReader reader) {
- return reader.getBeanList(SampleBean.class);
- }
- };
- List<SampleBean> beanList = getEmpireTemplate().query(cmd,
- beanListImpl);
- System.out.println(String.valueOf(beanList.size())
- + " SampleBeans returned from Query.");
- for (SampleBean b : beanList) {
- System.out.println(b.toString());
- }
- break;
- case XmlDocument:
- // XML Output
- XmlDocumentExtractor xmlImpl = new XmlDocumentExtractor();
- Document doc = getEmpireTemplate().query(cmd, xmlImpl);
- // Print XML Document to System.out
- XMLWriter.debug(doc);
- break;
- }
-
- } finally {
-
- // always close Reader
-
- // reader is closed in EmpireTemplate's methods
-
- // reader.close();
- }
- }
-
- public Map<Object, Object> getDepartment(int id) {
- SampleDB db = getDatabase();
- return get(db.DEPARTMENTS, id);
- }
-
- public Map<Object, Object> getEmployee(int id) {
- SampleDB db = getDatabase();
- return get(db.EMPLOYEES, id);
- }
-
- private Map<Object, Object> get(DBTable table, int pk) {
-
- SampleDB db = getDatabase();
-
- DBCommand cmd = db.createCommand();
- cmd.select(table.getColumns());
- cmd.where(table.getPrimaryKey().getColumns()[0].is(pk)); // i know there
- // is just
- // one
- // pk-column
- // ;-)
- Map<Object, Object> dep = getEmpireTemplate().queryForObject(cmd,
- new RowToObjectMapDataMapper(table));
-
- return dep;
- }
-
- public static class XmlDocumentExtractor implements
- DBReaderExtractor<Document> {
-
- public Document process(DBReader reader) {
- return reader.getXmlDocument();
- }
-
- }
-
- public static class RowToObjectMapDataMapper implements
- DBRecordMapper<Map<Object, Object>> {
-
- DBTable table;
-
- public RowToObjectMapDataMapper(DBTable table) {
- super();
- this.table = table;
- }
-
- public Map<Object, Object> mapRecord(DBRecordData record, int rowNum) {
- Map<Object, Object> dep = new HashMap<Object, Object>();
- for (DBColumn col : table.getColumns()) {
- dep.put(col.getName(), record.getValue(col));
- }
- return dep;
- }
-
- }
-
- public boolean databaseExists() {
- Connection conn = getConnection();
- try {
- DBDatabase db = getDatabase();
- if (db.getTables() == null || db.getTables().isEmpty()) {
- throw new AssertionError(
- "There are no tables in this database!");
- }
- DBCommand cmd = db.createCommand();
- if (cmd == null) {
- throw new AssertionError("The DBCommand object is null.");
- }
- DBTable t = db.getTables().get(0);
- cmd.select(t.count());
- return (db.querySingleInt(cmd, -1, conn) >= 0);
- } catch (Exception e) {
- return false;
- }
- }
-
- public void initializeDatabase() {
- if (!databaseExists()) {
- createDatabase();
- }
- }
-
- @Transactional
- public void setupDatabase() {
- initializeDatabase();
- }
-
- public void createDatabase() {
-
- // create DLL for Database Definition
- final DBSQLScript script = new DBSQLScript();
- final DBDatabaseDriver driver = getDatabase().getDriver();
- getDatabase().getCreateDDLScript(driver, script);
-
- // Show DLL Statement
- System.out.println(script.toString());
- // Execute Script
- getEmpireTemplate().execute(new ConnectionCallback<Object>() {
-
- public Object doInConnection(Connection con) throws SQLException,
- DataAccessException {
- script.executeAll(driver, con, false);
- return null;
- }
- });
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-spring/src/main/java/org/apache/empire/spring/example1/SampleBean.java
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/java/org/apache/empire/spring/example1/SampleBean.java b/empire-db-spring/src/main/java/org/apache/empire/spring/example1/SampleBean.java
deleted file mode 100644
index efe89b1..0000000
--- a/empire-db-spring/src/main/java/org/apache/empire/spring/example1/SampleBean.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.empire.spring.example1;
-
-
-/**
- * The SampleBean class is used to demonstrate JavaBean support for SQL-Queries.
- * The SampleBean is used in the SampleApp's queryRecords function.
- */
-public class SampleBean
-{
- private int employeeId;
- private String fullName;
- private String gender;
- private String phoneNumber;
- private String department;
- private String businessUnit;
-
- /*
- * Uncomment this if you want to use constructor instead of setters
- * However, number of arguments and data types must match query!
- *
- public SampleBean(int employeeId, String fullName, String gender, String phoneNumber, String department, String businessUnit)
- {
- this.employeeId = employeeId;
- this.fullName = fullName;
- this.gender = gender;
- this.phoneNumber = phoneNumber;
- this.department = department;
- this.businessUnit = businessUnit;
- }
- */
-
- public int getEmployeeId()
- {
- return employeeId;
- }
-
- public void setEmployeeId(int employeeId)
- {
- this.employeeId = employeeId;
- }
-
- public String getFullName()
- {
- return fullName;
- }
-
- public void setFullName(String fullName)
- {
- this.fullName = fullName;
- }
-
- public String getGender()
- {
- return gender;
- }
-
- public void setGender(String gender)
- {
- this.gender = gender;
- }
-
- public String getPhoneNumber()
- {
- return phoneNumber;
- }
-
- public void setPhoneNumber(String phoneNumber)
- {
- this.phoneNumber = phoneNumber;
- }
-
- public String getDepartment()
- {
- return department;
- }
-
- public void setDepartment(String department)
- {
- this.department = department;
- }
-
- public String getBusinessUnit()
- {
- return businessUnit;
- }
-
- public void setBusinessUnit(String businessUnit)
- {
- this.businessUnit = businessUnit;
- }
-
- @Override
- public String toString()
- {
- StringBuffer buf = new StringBuffer();
- buf.append(employeeId);
- buf.append("\t");
- buf.append(fullName);
- buf.append("\t");
- buf.append(gender);
- buf.append("\t");
- buf.append(department);
- buf.append("\t");
- buf.append(businessUnit);
- return buf.toString();
- }
-
-}
[11/14] empire-db git commit: EMPIREDB-247
Posted by de...@apache.org.
EMPIREDB-247
- automatically add WHERE PKs to cmd
Project: http://git-wip-us.apache.org/repos/asf/empire-db/repo
Commit: http://git-wip-us.apache.org/repos/asf/empire-db/commit/04cc588f
Tree: http://git-wip-us.apache.org/repos/asf/empire-db/tree/04cc588f
Diff: http://git-wip-us.apache.org/repos/asf/empire-db/diff/04cc588f
Branch: refs/heads/EMPIREDB-247
Commit: 04cc588fb171d079e057aecd65096de2860153ab
Parents: 16c3111
Author: Jan Glaubitz <ja...@glaubitz.org>
Authored: Fri Aug 19 13:58:28 2016 +0200
Committer: Jan Glaubitz <ja...@glaubitz.org>
Committed: Wed Nov 9 11:56:53 2016 +0100
----------------------------------------------------------------------
.../src/main/java/org/apache/empire/db/DBDatabase.java | 11 +++++++++++
1 file changed, 11 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/empire-db/blob/04cc588f/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java b/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
index 5757b96..b9b7817 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
@@ -40,6 +40,7 @@ import org.apache.empire.db.exceptions.QueryFailedException;
import org.apache.empire.db.exceptions.QueryNoResultException;
import org.apache.empire.db.exceptions.StatementFailedException;
import org.apache.empire.db.expr.column.DBValueExpr;
+import org.apache.empire.db.expr.set.DBSetExpr;
import org.apache.empire.exceptions.InternalException;
import org.apache.empire.exceptions.InvalidArgumentException;
import org.apache.empire.exceptions.ItemExistsException;
@@ -1405,6 +1406,16 @@ public abstract class DBDatabase extends DBObject
}
else
{
+ // Add WHERE (<all pks> to UPDATE
+ DBTable table = (DBTable) cmd.set.get(0).getTable();
+ for (DBSetExpr se : cmd.set)
+ {
+ DBColumn column = se.column;
+ if (table.getPrimaryKey().contains(column))
+ {
+ cmd.where(column.is(se.value));
+ }
+ }
int count = executeUpdate(cmd, conn);
if (count < 1) {
// nothing updated -> INSERT
[04/14] empire-db git commit: Spring Examples moved to examples
project
Posted by de...@apache.org.
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-spring/src/main/java/org/apache/empire/spring/example1/SampleDB.java
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/java/org/apache/empire/spring/example1/SampleDB.java b/empire-db-spring/src/main/java/org/apache/empire/spring/example1/SampleDB.java
deleted file mode 100644
index c8f3284..0000000
--- a/empire-db-spring/src/main/java/org/apache/empire/spring/example1/SampleDB.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.empire.spring.example1;
-
-import org.apache.empire.commons.Options;
-import org.apache.empire.data.DataType;
-import org.apache.empire.data.DataMode;
-import org.apache.empire.db.DBColumn;
-import org.apache.empire.db.DBDatabase;
-import org.apache.empire.db.DBTable;
-import org.apache.empire.db.DBTableColumn;
-
-/**
- * <PRE>
- * This file contains the definition of the data model in Java.
- * The SampleDB data model consists of two tables and a foreign key relation.
- * The tables are defined as nested classes here, but you may put the in separate files if you want.
- *
- * PLEASE NOTE THE NAMING CONVENTION:
- * Since all tables, views and columns are declared as "final" constants they are all in upper case.
- * We recommend using a prefix of T_ for tables and C_ for columns in order to keep them together
- * when listed in your IDE's code completion.
- * There is no need to stick to this convention but it makes life just another little bit easier.
- *
- * You may declare other database tables or views in the same way.
- * </PRE>
- */
-public class SampleDB extends DBDatabase
-{
- private final static long serialVersionUID = 1L;
-
- /**
- * This class represents the definition of the Departments table.
- */
- public static class Departments extends DBTable
- {
-
- private final static long serialVersionUID = 1L;
-
- public final DBTableColumn DEPARTMENT_ID;
- public final DBTableColumn NAME;
- public final DBTableColumn HEAD;
- public final DBTableColumn BUSINESS_UNIT;
- public final DBTableColumn UPDATE_TIMESTAMP;
-
- public Departments(DBDatabase db)
- {
- super("DEPARTMENTS", db);
- // ID
- DEPARTMENT_ID = addColumn("DEPARTMENT_ID", DataType.AUTOINC, 0, true, "DEP_ID_SEQUENCE");
- NAME = addColumn("NAME", DataType.TEXT, 80, true);
- HEAD = addColumn("HEAD", DataType.TEXT, 80, false);
- BUSINESS_UNIT = addColumn("BUSINESS_UNIT", DataType.TEXT, 4, true, "ITTK");
- UPDATE_TIMESTAMP= addColumn("UPDATE_TIMESTAMP", DataType.DATETIME, 0, true);
-
- // Primary Key
- setPrimaryKey(DEPARTMENT_ID);
- // Set other Indexes
- addIndex("DEARTMENT_NAME_IDX", true, new DBColumn[] { NAME });
- // Set timestamp column for save updates
- setTimestampColumn(UPDATE_TIMESTAMP);
- }
- }
-
- /**
- * This class represents the definition of the Employees table.
- */
- public static class Employees extends DBTable
- {
- private final static long serialVersionUID = 1L;
-
- public final DBTableColumn EMPLOYEE_ID;
- public final DBTableColumn SALUTATION;
- public final DBTableColumn FIRSTNAME;
- public final DBTableColumn LASTNAME;
- public final DBTableColumn DATE_OF_BIRTH;
- public final DBTableColumn DEPARTMENT_ID;
- public final DBTableColumn GENDER;
- public final DBTableColumn PHONE_NUMBER;
- public final DBTableColumn EMAIL;
- public final DBTableColumn SALARY;
- public final DBTableColumn RETIRED;
- public final DBTableColumn UPDATE_TIMESTAMP;
-
- public Employees(DBDatabase db)
- {
- super("EMPLOYEES", db);
- // ID
- EMPLOYEE_ID = addColumn("EMPLOYEE_ID", DataType.AUTOINC, 0, true, "EMPLOYEE_ID_SEQUENCE");
- SALUTATION = addColumn("SALUTATION", DataType.TEXT, 20, false);
- FIRSTNAME = addColumn("FIRST_NAME", DataType.TEXT, 40, true);
- LASTNAME = addColumn("LAST_NAME", DataType.TEXT, 40, true);
- DATE_OF_BIRTH = addColumn("DATE_OF_BIRTH", DataType.DATE, 0, false);
- DEPARTMENT_ID = addColumn("DEPARTMENT_ID", DataType.INTEGER, 0, true);
- GENDER = addColumn("GENDER", DataType.TEXT, 1, false);
- PHONE_NUMBER = addColumn("PHONE_NUMBER", DataType.TEXT, 40, false);
- EMAIL = addColumn("EMAIL", DataType.TEXT, 80, false);
- SALARY = addColumn("SALARY", DataType.DECIMAL, 10.2, false);
- RETIRED = addColumn("RETIRED", DataType.BOOL, 0, true, false);
- UPDATE_TIMESTAMP= addColumn("UPDATE_TIMESTAMP", DataType.DATETIME, 0, true);
-
- // Primary Key
- setPrimaryKey(EMPLOYEE_ID);
- // Set other Indexes
- addIndex("EMPLOYEE_NAME_IDX", true, new DBColumn[] { FIRSTNAME, LASTNAME, DATE_OF_BIRTH });
- // Set timestamp column for save updates
- setTimestampColumn(UPDATE_TIMESTAMP);
-
- // Create Options for GENDER column
- Options genders = new Options();
- genders.set("M", "Male");
- genders.set("F", "Female");
- GENDER.setOptions(genders);
- }
- }
-
- // Declare all Tables and Views here
- public final Departments DEPARTMENTS = new Departments(this);
- public final Employees EMPLOYEES = new Employees(this);
-
- /**
- * Constructor of the SampleDB data model description
- *
- * Put all foreign key relations here.
- */
- public SampleDB()
- {
- // Define Foreign-Key Relations
- addRelation( EMPLOYEES.DEPARTMENT_ID.referenceOn( DEPARTMENTS.DEPARTMENT_ID ));
- }
-
-}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-spring/src/main/java/org/apache/empire/spring/example1/SampleSpringApp.java
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/java/org/apache/empire/spring/example1/SampleSpringApp.java b/empire-db-spring/src/main/java/org/apache/empire/spring/example1/SampleSpringApp.java
deleted file mode 100644
index 3ff0230..0000000
--- a/empire-db-spring/src/main/java/org/apache/empire/spring/example1/SampleSpringApp.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.empire.spring.example1;
-
-import java.util.logging.Logger;
-
-import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.support.GenericApplicationContext;
-import org.springframework.core.io.ClassPathResource;
-
-/**
- *
- */
-public class SampleSpringApp {
- private static final Logger log = Logger.getLogger(SampleSpringApp.class.getName());
-
- //creates the application context
- //this is usually in some bootstrapping code; so your application will
- //just have one at runtime.
- static ApplicationContext ctx = getContext();
-
- //get the service that is the entry point into the application
- //normally this is injected by spring into classes that need it
- static EmpireApp appBean = ctx.getBean("empireApp", EmpireApp.class);
-
- public static void main(String[] args) throws Exception {
-
- System.out.println("Running Spring Example...");
-
- appBean.setupDatabase();
- appBean.clearDatabase();
-
- System.out.println("*** Step 6: insertDepartment() & insertEmployee() ***");
- int idDevDep = appBean.insertDepartment("Development", "ITTK");
- int idSalDep = appBean.insertDepartment("Sales", "ITTK");
-
- int idPers1 = appBean.insertEmployee("Peter", "Sharp", "M", idDevDep);
- int idPers2 = appBean.insertEmployee("Fred", "Bloggs", "M", idDevDep);
- int idPers3 = appBean.insertEmployee("Emma", "White", "F", idSalDep);
-
- System.out.println("*** Step 7: updateEmployee() ***");
- appBean.updateEmployee(idPers1, "+49-7531-457160");
- appBean.updateEmployee(idPers2, "+49-5555-505050");
- appBean.updateEmployee(idPers3, "+49-040-125486");
-
- System.out.println("*** Step 8 Option 1: queryRecords() / Tab-Output ***");
- appBean.doQuery(EmpireApp.QueryType.Reader);
-
- System.out.println("*** Step 8 Option 2: queryRecords() / Bean-List-Output ***");
- appBean.doQuery(EmpireApp.QueryType.BeanList);
-
- System.out.println("*** Step 8 Option 3: queryRecords() / XML-Output ***");
- appBean.doQuery(EmpireApp.QueryType.XmlDocument);
-
-
- }
-
-
-
- static GenericApplicationContext getContext() {
- log.info("Creating Spring Application Context ...");
- GenericApplicationContext ctx = new GenericApplicationContext();
- XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx);
- reader.loadBeanDefinitions(new ClassPathResource("/example1/applicationContext.xml"));
-
- ctx.refresh();
- return ctx;
- }
-}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-spring/src/main/java/org/apache/empire/spring/example2/Department.java
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/java/org/apache/empire/spring/example2/Department.java b/empire-db-spring/src/main/java/org/apache/empire/spring/example2/Department.java
deleted file mode 100644
index 08d8943..0000000
--- a/empire-db-spring/src/main/java/org/apache/empire/spring/example2/Department.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.empire.spring.example2;
-
-public class Department {
-
- private Integer departmentId;
- private String name;
- private String businessUnit;
- private String head;
-
- public Integer getDepartmentId() {
- return departmentId;
- }
-
- public void setDepartmentId(Integer departmentId) {
- this.departmentId = departmentId;
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getBusinessUnit() {
- return businessUnit;
- }
-
- public void setBusinessUnit(String businessUnit) {
- this.businessUnit = businessUnit;
- }
-
- public String getHead() {
- return head;
- }
-
- public void setHead(String head) {
- this.head = head;
- }
-
- @Override
- public String toString() {
- StringBuffer buf = new StringBuffer();
- buf.append(departmentId);
- buf.append("\t");
- buf.append(name);
- buf.append(" ");
- buf.append(businessUnit);
- buf.append("\t");
- buf.append(head);
- return buf.toString();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
-
- if (obj.getClass().equals(this.getClass())) {
- Department other = (Department) obj;
- if (other.departmentId == null || this.departmentId == null) {
- return false;
- }
- return this.departmentId.equals(other.departmentId);
- }
-
- return super.equals(obj);
- }
-
- @Override
- public int hashCode() {
- return 1;
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-spring/src/main/java/org/apache/empire/spring/example2/Employee.java
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/java/org/apache/empire/spring/example2/Employee.java b/empire-db-spring/src/main/java/org/apache/empire/spring/example2/Employee.java
deleted file mode 100644
index 5a07ce9..0000000
--- a/empire-db-spring/src/main/java/org/apache/empire/spring/example2/Employee.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.empire.spring.example2;
-
-public class Employee {
-
- public static enum Gender {
-
- M("Male"), F("Female");
-
- private String label;
-
- private Gender(String label) {
- this.label = label;
- }
-
- @Override
- public String toString() {
- return this.label;
- }
- }
-
- private Integer employeeId;
- private String firstName;
- private String lastName;
- private Gender gender;
- private String phoneNumber;
-
- private Department department;
-
- public Integer getEmployeeId() {
- return employeeId;
- }
-
- public void setEmployeeId(Integer employeeId) {
- this.employeeId = employeeId;
- }
-
- public String getFirstName() {
- return firstName;
- }
-
- public void setFirstName(String firstName) {
- this.firstName = firstName;
- }
-
- public String getLastName() {
- return lastName;
- }
-
- public void setLastName(String lastName) {
- this.lastName = lastName;
- }
-
- public Gender getGender() {
- return gender;
- }
-
- public void setGender(Gender gender) {
- this.gender = gender;
- }
-
- public String getPhoneNumber() {
- return phoneNumber;
- }
-
- public void setPhoneNumber(String phoneNumber) {
- this.phoneNumber = phoneNumber;
- }
-
- public Department getDepartment() {
- return department;
- }
-
- public void setDepartment(Department department) {
- this.department = department;
- }
-
- @Override
- public String toString() {
- StringBuffer buf = new StringBuffer();
- buf.append(employeeId);
- buf.append("\t");
- buf.append(firstName);
- buf.append(" ");
- buf.append(lastName);
- buf.append("\t");
- buf.append(gender);
-
- if (department != null){
- buf.append("\t");
- buf.append(department.getName());
- buf.append("\t");
- buf.append(department.getBusinessUnit());
- }
- return buf.toString();
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
-
- if (obj.getClass().equals(this.getClass())) {
- Employee other = (Employee) obj;
- if (other.employeeId == null || this.employeeId == null) {
- return false;
- }
- return this.employeeId.equals(other.employeeId);
- }
-
- return super.equals(obj);
- }
-
- @Override
- public int hashCode() {
- return 1;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDao.java
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDao.java b/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDao.java
deleted file mode 100644
index b2dd39f..0000000
--- a/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDao.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.empire.spring.example2;
-
-import java.util.List;
-
-public interface EmployeeDao {
-
- public List<Employee> getEmployees();
-
- public List<Department> getDepartments();
-
- public Integer createEmployee(Employee employee);
-
- public void updateEmployee(Employee employee);
-
- public Employee openEmployee(Integer id);
-
- public Employee findEmployee(String firstName, String lastName);
-
- public Department openDepartment(Integer id);
-
- public Department findDepartment(String name);
-
- public Integer createDepartment(Department department);
-
- public void updateDepartment(Department department);
-
- public void renameDepartment(Integer id, String name);
-
-}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDaoImpl.java
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDaoImpl.java b/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDaoImpl.java
deleted file mode 100644
index 37eb07b..0000000
--- a/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDaoImpl.java
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.empire.spring.example2;
-
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.empire.db.DBCommand;
-import org.apache.empire.db.DBJoinType;
-import org.apache.empire.db.DBRecord;
-import org.apache.empire.db.DBRecordData;
-import org.apache.empire.spring.DBRecordMapper;
-import org.apache.empire.spring.DBRecordWriter;
-import org.apache.empire.spring.EmpireDaoSupport;
-import org.apache.empire.spring.example1.SampleDB;
-import org.apache.empire.spring.example1.SampleDB.Departments;
-import org.apache.empire.spring.example1.SampleDB.Employees;
-import org.springframework.transaction.annotation.Transactional;
-
-public class EmployeeDaoImpl extends EmpireDaoSupport implements EmployeeDao {
-
- private Employees EMPLOYEES;
- private Departments DEPARTMENTS;
-
- @Override
- protected void initEmpireDao() {
- SampleDB db = getDatabase();
- this.EMPLOYEES = db.EMPLOYEES;
- this.DEPARTMENTS = db.DEPARTMENTS;
- }
-
- private DBCommand createEmployeeSelectCommand() {
- DBCommand cmd = getDatabase().createCommand();
- cmd.select(EMPLOYEES.getColumns());
- cmd.select(DEPARTMENTS.getColumns());
-
- cmd.join(EMPLOYEES.DEPARTMENT_ID, DEPARTMENTS.DEPARTMENT_ID, DBJoinType.INNER);
- return cmd;
- }
-
- private DBCommand createDepartmentSelectCommand() {
- DBCommand cmd = getDatabase().createCommand();
- cmd.select(DEPARTMENTS.getColumns());
- return cmd;
- }
-
- @Transactional(readOnly = true)
- public Employee openEmployee(Integer id) {
- DBCommand cmd = createEmployeeSelectCommand();
- cmd.where(EMPLOYEES.EMPLOYEE_ID.is(id));
- return getEmpireTemplate().queryForObject(cmd, new EmployeeMapper());
- }
-
- @Transactional(readOnly = true)
- public Employee findEmployee(String firstName, String lastName) {
- DBCommand cmd = createEmployeeSelectCommand();
- cmd.where(EMPLOYEES.FIRSTNAME.is(firstName));
- cmd.where(EMPLOYEES.LASTNAME.is(lastName));
- return getEmpireTemplate().queryForObject(cmd, new EmployeeMapper());
- }
-
- @Transactional(readOnly = true)
- public Department openDepartment(Integer id) {
- DBCommand cmd = createDepartmentSelectCommand();
- cmd.where(DEPARTMENTS.DEPARTMENT_ID.is(id));
- return getEmpireTemplate().queryForBean(cmd, Department.class);
- }
-
- @Transactional(readOnly = true)
- public Department findDepartment(String name) {
- DBCommand cmd = createDepartmentSelectCommand();
- cmd.where(DEPARTMENTS.NAME.is(name));
- return getEmpireTemplate().queryForBean(cmd, Department.class);
- }
-
- @Transactional(readOnly = true)
- public List<Department> getDepartments() {
- DBCommand cmd = createDepartmentSelectCommand();
- return getEmpireTemplate().queryForBeanList(cmd, Department.class);
- }
-
-
- @Transactional
- public void renameDepartment(Integer id, String name) {
- DBCommand cmd = getDatabase().createCommand();
- cmd.where(DEPARTMENTS.DEPARTMENT_ID.is(id));
- cmd.set(DEPARTMENTS.NAME.to(name));
- getEmpireTemplate().executeUpdate(cmd);
- }
-
- @Transactional(readOnly = true)
- public List<Employee> getEmployees() {
- DBCommand cmd = createEmployeeSelectCommand();
- return getEmpireTemplate().query(cmd, new EmployeeMapper());
- }
-
- @Transactional
- public Integer createEmployee(Employee employee) {
- DBRecord record = new DBRecord();
- record.create(EMPLOYEES);
- new EmployeeWriter().write(record, employee);
- getEmpireTemplate().updateRecord(record);
- return record.getInt(EMPLOYEES.EMPLOYEE_ID);
- }
-
- @Transactional
- public void updateEmployee(Employee employee) {
- DBRecord record = getEmpireTemplate().openRecord(EMPLOYEES, employee.getEmployeeId());
- new EmployeeWriter().write(record, employee);
- getEmpireTemplate().updateRecord(record);
- }
-
- @Transactional
- public Integer createDepartment(Department department) {
- DBRecord record = new DBRecord();
- record.create(DEPARTMENTS);
- new DepartmentWriter().write(record, department);
- getEmpireTemplate().updateRecord(record);
- return record.getInt(DEPARTMENTS.DEPARTMENT_ID);
- }
-
- @Transactional
- public void updateDepartment(Department department) {
- DBRecord record = getEmpireTemplate().openRecord(DEPARTMENTS, department.getDepartmentId());
- new DepartmentWriter().write(record, department);
- getEmpireTemplate().updateRecord(record);
- }
-
- private class EmployeeMapper implements DBRecordMapper<Employee> {
-
- DepartmentMapper departmentMapper = new DepartmentMapper();
-
- @Override
- public Employee mapRecord(DBRecordData record, int rowNum) {
- Employee result = new Employee();
- // Auto-copy all properties
- //record.setBeanProperties(result);
-
- result.setEmployeeId(record.getInt(EMPLOYEES.EMPLOYEE_ID));
- result.setFirstName(record.getString(EMPLOYEES.FIRSTNAME));
- result.setLastName(record.getString(EMPLOYEES.LASTNAME));
- result.setGender(Employee.Gender.valueOf(record.getString(EMPLOYEES.GENDER)));
- result.setPhoneNumber(record.getString(EMPLOYEES.PHONE_NUMBER));
-
- result.setDepartment(departmentMapper.mapRecord(record, rowNum));
- return result;
- }
-
- }
-
- private class EmployeeWriter implements DBRecordWriter<Employee> {
-
- @Override
- public void write(DBRecord record, Employee entity) {
- // Auto-copy all properties
- //record.setRecordValues(entity);
-
- record.setValue(EMPLOYEES.EMPLOYEE_ID, entity.getEmployeeId());
- record.setValue(EMPLOYEES.FIRSTNAME, entity.getFirstName());
- record.setValue(EMPLOYEES.LASTNAME, entity.getLastName());
- record.setValue(EMPLOYEES.GENDER, entity.getGender().name());
- record.setValue(EMPLOYEES.PHONE_NUMBER, entity.getPhoneNumber());
-
- record.setValue(EMPLOYEES.DEPARTMENT_ID, entity.getDepartment().getDepartmentId());
- }
-
- }
-
- private class DepartmentMapper implements DBRecordMapper<Department> {
-
- // reader cache, in case of joined resultset the same object is returned
-
- Map<Integer, Department> cache = new HashMap<Integer, Department>();
-
- @Override
- public Department mapRecord(DBRecordData record, int rowNum) {
-
- Integer id = record.getInt(DEPARTMENTS.DEPARTMENT_ID);
-
- Department department = cache.get(id);
- if (department == null) {
- department = new Department();
- // Auto-copy all properties
- //record.setBeanProperties(department);
-
- department.setDepartmentId(id);
- department.setName(record.getString(DEPARTMENTS.NAME));
- department.setHead(record.getString(DEPARTMENTS.HEAD));
- department.setBusinessUnit(record.getString(DEPARTMENTS.BUSINESS_UNIT));
-
- cache.put(id, department);
- }
- return department;
- }
-
- }
-
- private class DepartmentWriter implements DBRecordWriter<Department> {
-
- @Override
- public void write(DBRecord record, Department entity) {
- // Auto-copy all properties
- //record.setRecordValues(entity);
-
- record.setValue(DEPARTMENTS.DEPARTMENT_ID, entity.getDepartmentId());
- record.setValue(DEPARTMENTS.NAME, entity.getName());
- record.setValue(DEPARTMENTS.HEAD, entity.getHead());
- record.setValue(DEPARTMENTS.BUSINESS_UNIT, entity.getBusinessUnit());
-
- }
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeSpringApp.java
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeSpringApp.java b/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeSpringApp.java
deleted file mode 100644
index 3b641a7..0000000
--- a/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeSpringApp.java
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.empire.spring.example2;
-
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.Iterator;
-import java.util.List;
-import java.util.logging.Logger;
-
-import org.apache.empire.db.DBColumnExpr;
-import org.apache.empire.db.DBCommand;
-import org.apache.empire.db.DBDatabase;
-import org.apache.empire.db.DBDatabaseDriver;
-import org.apache.empire.db.DBSQLScript;
-import org.apache.empire.db.DBTable;
-import org.apache.empire.spring.EmpireTemplate;
-import org.apache.empire.spring.example1.SampleDB;
-import org.apache.empire.spring.example2.Employee.Gender;
-import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
-import org.springframework.context.ApplicationContext;
-import org.springframework.context.support.GenericApplicationContext;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.dao.DataAccessException;
-import org.springframework.jdbc.core.ConnectionCallback;
-
-/**
- *
- */
-public class EmployeeSpringApp {
- private static final Logger log = Logger.getLogger(EmployeeSpringApp.class.getName());
-
- //creates the application context
- //this is usually in some bootstrapping code; so your application will
- //just have one at runtime.
- static ApplicationContext ctx = getContext();
-
- //get the service that is the entry point into the application
- //normally this is injected by spring into classes that need it
- static EmployeeDao employeeDao = ctx.getBean("employeeDao", EmployeeDao.class);
- static SampleDB sampleDb = ctx.getBean("sampleDb", SampleDB.class);
-
- public static void main(String[] args) throws Exception {
-
- System.out.println("Running Spring Example...");
-
- setupDatabase();
- clearDatabase();
-
- Department depDevelopment, depSales;
-
- System.out.println("*** Create Departments ***");
-
- {
- depDevelopment = new Department();
- depDevelopment.setName("Development");
- depDevelopment.setBusinessUnit("ITTK");
- Integer id = employeeDao.createDepartment(depDevelopment);
- depDevelopment = employeeDao.openDepartment(id);
- }
- {
- depSales = new Department();
- depSales.setName("Sales");
- depSales.setBusinessUnit("ITTK");
- Integer id = employeeDao.createDepartment(depSales);
- depSales = employeeDao.openDepartment(id);
- }
-
- System.out.println("*** Create Employees ***");
-
- Employee peter = new Employee();
- peter.setFirstName("Peter");
- peter.setLastName("Sharp");
- peter.setGender(Gender.M);
- peter.setDepartment(depDevelopment);
-
- Integer peterId = employeeDao.createEmployee(peter);
- peter = employeeDao.openEmployee(peterId);
-
-
-
- Employee fred = new Employee();
- fred.setFirstName("Fred");
- fred.setLastName("Bloggs");
- fred.setGender(Gender.M);
- fred.setDepartment(depDevelopment);
-
- Integer fredId = employeeDao.createEmployee(fred);
- fred = employeeDao.openEmployee(fredId);
-
-
- Employee emma = new Employee();
- emma.setFirstName("Emma");
- emma.setLastName("White");
- emma.setGender(Gender.F);
- emma.setDepartment(depSales);
-
- Integer emmaId = employeeDao.createEmployee(emma);
- emma = employeeDao.openEmployee(emmaId);
-
-
- System.out.println("*** updateEmployees ***");
-
- peter.setPhoneNumber("+49-7531-457160");
- employeeDao.updateEmployee(peter);
-
- fred.setPhoneNumber("+49-5555-505050");
- employeeDao.updateEmployee(fred);
-
- emma.setPhoneNumber("+49-040-125486");
- employeeDao.updateEmployee(emma);
-
- System.out.println("*** List employees ***");
-
- List<Employee> employees = employeeDao.getEmployees();
- for (Iterator<Employee> iterator = employees.iterator(); iterator.hasNext();) {
- Employee employee = iterator.next();
- System.out.println(employee);
- }
-
- System.out.println("*** List departments ***");
-
- List<Department> departments = employeeDao.getDepartments();
- for (Iterator<Department> iterator = departments.iterator(); iterator.hasNext();) {
- Department department = iterator.next();
- System.out.println(department);
- }
-
- }
-
- private static void clearDatabase() {
- // Delete all Employees (no constraints)
-
- EmpireTemplate empireTemplate = ctx.getBean("empireTemplate", EmpireTemplate.class);
- empireTemplate.executeDelete(sampleDb.EMPLOYEES, sampleDb.createCommand());
- empireTemplate.executeDelete(sampleDb.DEPARTMENTS, sampleDb.createCommand());
-
- }
-
-
-
-
- public static void setupDatabase() {
- if (!databaseExists()) {
- createDatabase();
- }
- }
-
-
- public static boolean databaseExists() {
- try {
- DBDatabase db = sampleDb;
- if (db.getTables() == null || db.getTables().isEmpty()) {
- throw new AssertionError(
- "There are no tables in this database!");
- }
- DBCommand cmd = db.createCommand();
- if (cmd == null) {
- throw new AssertionError("The DBCommand object is null.");
- }
- DBTable t = db.getTables().get(0);
- DBColumnExpr COUNT = t.count();
-
- cmd.select(COUNT);
-
- EmpireTemplate empireTemplate = ctx.getBean("empireTemplate", EmpireTemplate.class);
- return (empireTemplate.queryForInteger(cmd, COUNT, -1) >= 0);
- } catch (Exception e) {
- return false;
- }
- }
-
-
- private static void createDatabase() {
-
- // create DLL for Database Definition
- final DBSQLScript script = new DBSQLScript();
- final DBDatabaseDriver driver = sampleDb.getDriver();
- sampleDb.getCreateDDLScript(driver, script);
-
- // Show DLL Statement
- System.out.println(script.toString());
- // Execute Script
- EmpireTemplate empireTemplate = ctx.getBean("empireTemplate", EmpireTemplate.class);
- empireTemplate.execute(new ConnectionCallback<Object>() {
-
- @Override
- public Object doInConnection(Connection con) throws SQLException,
- DataAccessException {
- script.executeAll(driver, con, false);
- return null;
- }
- });
-
- }
-
-
-
- static GenericApplicationContext getContext() {
- log.info("Creating Spring Application Context ...");
- GenericApplicationContext ctx = new GenericApplicationContext();
- XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx);
- reader.loadBeanDefinitions(new ClassPathResource("/example2/applicationContext-employee.xml"));
-
- ctx.refresh();
- return ctx;
- }
-
-
-
-}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-spring/src/main/resources/example1/applicationContext.xml
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/resources/example1/applicationContext.xml b/empire-db-spring/src/main/resources/example1/applicationContext.xml
deleted file mode 100644
index 7987d5a..0000000
--- a/empire-db-spring/src/main/resources/example1/applicationContext.xml
+++ /dev/null
@@ -1,92 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
--->
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
-
-
- <!-- one option is to use a class from spring that will read the properties file
- and replaces the ${...} placeholders with the appropriate values -->
- <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property name="locations">
- <value>classpath:/settings.properties</value>
- </property>
- </bean>
-
- <!-- Data Source / DB Settings -->
- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
- <property name="driverClassName" value="${jdbc.driverClass}"/>
- <property name="url" value="${jdbc.url}"/>
- <property name="username" value="${jdbc.username}"/>
- <property name="password" value="${jdbc.password}"/>
- </bean>
-
- <!-- Transaction manager for a single JDBC DataSource (alternative to JTA) -->
- <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <constructor-arg ref="dataSource"/>
- </bean>
- <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
- <property name="transactionManager" ref="transactionManager"/>
- </bean>
-
- <!-- @Transactional -->
- <tx:annotation-driven transaction-manager="transactionManager"/>
-
- <!-- Empire-DB classes -->
-
- <!-- application dao/services -->
- <bean id="empireApp" class="org.apache.empire.spring.example1.EmpireAppImpl" parent="empireDao"/>
-
-
- <bean id="empireDb" class="org.apache.empire.spring.DBDatabaseFactoryBean">
- <property name="driverClass" value="${empire.driver}"/>
- <property name="schema" value="${empire.schemaname}"/>
- <property name="databaseClass" value="org.apache.empire.spring.example1.SampleDB"/>
- </bean>
-
- <bean id="empireDao" abstract="true">
- <property name="database" ref="empireDb"/>
- <property name="empireTemplate" ref="empireTemplate"/>
- </bean>
-
-
- <bean id="empireTemplate" class="org.apache.empire.spring.EmpireTemplate">
- <property name="dataSource" ref="dataSource"/>
- </bean>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-</beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-spring/src/main/resources/example2/applicationContext-employee.xml
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/resources/example2/applicationContext-employee.xml b/empire-db-spring/src/main/resources/example2/applicationContext-employee.xml
deleted file mode 100644
index 08ce097..0000000
--- a/empire-db-spring/src/main/resources/example2/applicationContext-employee.xml
+++ /dev/null
@@ -1,85 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
--->
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:tx="http://www.springframework.org/schema/tx"
- xmlns:aop="http://www.springframework.org/schema/aop"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
- http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
- http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
-
-
- <!-- one option is to use a class from spring that will read the properties file
- and replaces the ${...} placeholders with the appropriate values -->
- <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property name="locations">
- <value>classpath:/settings.properties</value>
- </property>
- </bean>
-
- <!-- Data Source / DB Settings -->
- <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
- <property name="driverClassName" value="${jdbc.driverClass}"/>
- <property name="url" value="${jdbc.url}"/>
- <property name="username" value="${jdbc.username}"/>
- <property name="password" value="${jdbc.password}"/>
- </bean>
-
- <!-- Transaction manager for a single JDBC DataSource (alternative to JTA) -->
- <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
- <constructor-arg ref="dataSource"/>
- </bean>
- <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
- <property name="transactionManager" ref="transactionManager"/>
- </bean>
-
- <!-- @Transactional -->
- <tx:annotation-driven transaction-manager="transactionManager"/>
-
- <!-- Empire-DB classes -->
-
- <!-- application dao/services -->
- <bean id="employeeDao" class="org.apache.empire.spring.example2.EmployeeDaoImpl" parent="empireDao"/>
-
-
- <bean id="sampleDb" class="org.apache.empire.spring.DBDatabaseFactoryBean">
- <property name="driverClass" value="${empire.driver}"/>
- <property name="schema" value="${empire.schemaname}"/>
- <property name="databaseClass" value="org.apache.empire.spring.example1.SampleDB"/>
- </bean>
-
- <bean id="empireDao" abstract="true">
- <property name="database" ref="sampleDb"/>
- <property name="empireTemplate" ref="empireTemplate"/>
- </bean>
-
-
- <bean id="empireTemplate" class="org.apache.empire.spring.EmpireTemplate">
- <property name="dataSource" ref="dataSource"/>
- </bean>
-
-
-
-
-
-
-
-</beans>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-spring/src/main/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/resources/log4j.properties b/empire-db-spring/src/main/resources/log4j.properties
deleted file mode 100644
index 031ae65..0000000
--- a/empire-db-spring/src/main/resources/log4j.properties
+++ /dev/null
@@ -1,21 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-log4j.rootCategory=FATAL, console
-log4j.appender.console=org.apache.log4j.ConsoleAppender
-log4j.appender.console.layout=org.apache.log4j.PatternLayout
-log4j.appender.console.layout.conversionPattern = %d{ISO8601} %-5p [%c] - %m%n
http://git-wip-us.apache.org/repos/asf/empire-db/blob/cc86a1fd/empire-db-spring/src/main/resources/settings.properties
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/resources/settings.properties b/empire-db-spring/src/main/resources/settings.properties
deleted file mode 100644
index e5ba794..0000000
--- a/empire-db-spring/src/main/resources/settings.properties
+++ /dev/null
@@ -1,44 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements. See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership. The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License. You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied. See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-## HSQLDB settings (tested)
-jdbc.url=jdbc:hsqldb:file:target/hsqldb/sample;shutdown=true
-jdbc.driverClass=org.hsqldb.jdbcDriver
-jdbc.username=sa
-jdbc.password=
-
-empire.driver= org.apache.empire.db.hsql.DBDatabaseDriverHSql
-empire.schemaname=
-
-
-## Derby settings (tested)
-#jdbc.url=jdbc:derby:target/dbsample1;create=true
-#jdbc.driverClass=org.apache.derby.jdbc.EmbeddedDriver
-#jdbc.username=
-#jdbc.password=
-#
-#empire.driver=org.apache.empire.db.derby.DBDatabaseDriverDerby
-#empire.schemaname=DBSAMPLE1
-
-## MySQL settings (tested)
-#jdbc.url=jdbc:mysql://localhost
-#jdbc.driverClass=com.mysql.jdbc.Driver
-#jdbc.username=test
-#jdbc.password=test
-#
-#empire.driver=org.apache.empire.db.mysql.DBDatabaseDriverMySQL
-#empire.schemaname=dbsample1
[08/14] empire-db git commit: [maven-release-plugin] prepare release
apache-empire-db-2.4.5-rc1
Posted by de...@apache.org.
[maven-release-plugin] prepare release apache-empire-db-2.4.5-rc1
Project: http://git-wip-us.apache.org/repos/asf/empire-db/repo
Commit: http://git-wip-us.apache.org/repos/asf/empire-db/commit/2ab03fe5
Tree: http://git-wip-us.apache.org/repos/asf/empire-db/tree/2ab03fe5
Diff: http://git-wip-us.apache.org/repos/asf/empire-db/diff/2ab03fe5
Branch: refs/heads/EMPIREDB-247
Commit: 2ab03fe54973b8318d040a326b374250296b6f6c
Parents: 54edaff
Author: Rainer D�bele <do...@apache.org>
Authored: Wed Nov 9 11:07:51 2016 +0100
Committer: Rainer D�bele <do...@apache.org>
Committed: Wed Nov 9 11:07:51 2016 +0100
----------------------------------------------------------------------
empire-db-codegen/pom.xml | 2 +-
empire-db-dist/pom.xml | 2 +-
empire-db-examples/empire-db-example-advanced/pom.xml | 2 +-
empire-db-examples/empire-db-example-basic/pom.xml | 2 +-
empire-db-examples/empire-db-example-cxf/pom.xml | 2 +-
empire-db-examples/empire-db-example-jsf2/pom.xml | 2 +-
empire-db-examples/empire-db-example-spring/pom.xml | 4 ++--
empire-db-examples/empire-db-example-struts2-cxf/pom.xml | 2 +-
empire-db-examples/empire-db-example-struts2/pom.xml | 2 +-
empire-db-examples/pom.xml | 2 +-
empire-db-jsf2/pom.xml | 2 +-
empire-db-maven-plugin/pom.xml | 2 +-
empire-db-spring/pom.xml | 5 ++---
empire-db-struts2/pom.xml | 2 +-
empire-db/pom.xml | 2 +-
pom.xml | 4 ++--
16 files changed, 19 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/empire-db/blob/2ab03fe5/empire-db-codegen/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-codegen/pom.xml b/empire-db-codegen/pom.xml
index ca00034..31b8f33 100644
--- a/empire-db-codegen/pom.xml
+++ b/empire-db-codegen/pom.xml
@@ -20,7 +20,7 @@
<parent>
<artifactId>empire-db-parent</artifactId>
<groupId>org.apache.empire-db</groupId>
- <version>2.4.5-SNAPSHOT</version>
+ <version>2.4.5</version>
</parent>
<artifactId>empire-db-codegen</artifactId>
<packaging>jar</packaging>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/2ab03fe5/empire-db-dist/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-dist/pom.xml b/empire-db-dist/pom.xml
index 9f4244c..4f1bd23 100644
--- a/empire-db-dist/pom.xml
+++ b/empire-db-dist/pom.xml
@@ -19,7 +19,7 @@
<parent>
<artifactId>empire-db-parent</artifactId>
<groupId>org.apache.empire-db</groupId>
- <version>2.4.5-SNAPSHOT</version>
+ <version>2.4.5</version>
</parent>
<artifactId>empire-db-dist</artifactId>
<name>Apache Empire-db Distribtion</name>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/2ab03fe5/empire-db-examples/empire-db-example-advanced/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-advanced/pom.xml b/empire-db-examples/empire-db-example-advanced/pom.xml
index 1e81f42..01760c4 100644
--- a/empire-db-examples/empire-db-example-advanced/pom.xml
+++ b/empire-db-examples/empire-db-example-advanced/pom.xml
@@ -19,7 +19,7 @@
<parent>
<groupId>org.apache.empire-db</groupId>
<artifactId>empire-db-examples</artifactId>
- <version>2.4.5-SNAPSHOT</version>
+ <version>2.4.5</version>
</parent>
<artifactId>empire-db-example-advanced</artifactId>
<name>Apache Empire-db Advanced Example</name>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/2ab03fe5/empire-db-examples/empire-db-example-basic/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-basic/pom.xml b/empire-db-examples/empire-db-example-basic/pom.xml
index 801b402..1498dc5 100644
--- a/empire-db-examples/empire-db-example-basic/pom.xml
+++ b/empire-db-examples/empire-db-example-basic/pom.xml
@@ -19,7 +19,7 @@
<parent>
<groupId>org.apache.empire-db</groupId>
<artifactId>empire-db-examples</artifactId>
- <version>2.4.5-SNAPSHOT</version>
+ <version>2.4.5</version>
</parent>
<artifactId>empire-db-example-basic</artifactId>
<name>Apache Empire-db Basic Example</name>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/2ab03fe5/empire-db-examples/empire-db-example-cxf/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-cxf/pom.xml b/empire-db-examples/empire-db-example-cxf/pom.xml
index 0be98ed..86a44f5 100644
--- a/empire-db-examples/empire-db-example-cxf/pom.xml
+++ b/empire-db-examples/empire-db-example-cxf/pom.xml
@@ -18,7 +18,7 @@
<parent>
<artifactId>empire-db-examples</artifactId>
<groupId>org.apache.empire-db</groupId>
- <version>2.4.5-SNAPSHOT</version>
+ <version>2.4.5</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>empire-db-example-cxf</artifactId>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/2ab03fe5/empire-db-examples/empire-db-example-jsf2/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-jsf2/pom.xml b/empire-db-examples/empire-db-example-jsf2/pom.xml
index fbf3328..4e54deb 100644
--- a/empire-db-examples/empire-db-example-jsf2/pom.xml
+++ b/empire-db-examples/empire-db-example-jsf2/pom.xml
@@ -19,7 +19,7 @@
<parent>
<artifactId>empire-db-examples</artifactId>
<groupId>org.apache.empire-db</groupId>
- <version>2.4.5-SNAPSHOT</version>
+ <version>2.4.5</version>
</parent>
<artifactId>empire-db-example-jsf2</artifactId>
<name>Apache Empire-db JSF2 Example</name>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/2ab03fe5/empire-db-examples/empire-db-example-spring/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-spring/pom.xml b/empire-db-examples/empire-db-example-spring/pom.xml
index 101cb25..3d7eb6f 100644
--- a/empire-db-examples/empire-db-example-spring/pom.xml
+++ b/empire-db-examples/empire-db-example-spring/pom.xml
@@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.empire-db</groupId>
<artifactId>empire-db-examples</artifactId>
- <version>2.4.5-SNAPSHOT</version>
+ <version>2.4.5</version>
</parent>
<artifactId>empire-db-example-spring</artifactId>
<name>Apache Empire-db Spring Example</name>
@@ -111,7 +111,7 @@
<dependency>
<groupId>org.apache.empire-db</groupId>
<artifactId>empire-db-spring</artifactId>
- <version>2.4.5-SNAPSHOT</version>
+ <version>2.4.5</version>
</dependency>
</dependencies>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/2ab03fe5/empire-db-examples/empire-db-example-struts2-cxf/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-struts2-cxf/pom.xml b/empire-db-examples/empire-db-example-struts2-cxf/pom.xml
index c57a731..569a5f8 100644
--- a/empire-db-examples/empire-db-example-struts2-cxf/pom.xml
+++ b/empire-db-examples/empire-db-example-struts2-cxf/pom.xml
@@ -21,7 +21,7 @@
<parent>
<artifactId>empire-db-examples</artifactId>
<groupId>org.apache.empire-db</groupId>
- <version>2.4.5-SNAPSHOT</version>
+ <version>2.4.5</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>empire-db-example-struts2-cxf</artifactId>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/2ab03fe5/empire-db-examples/empire-db-example-struts2/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-struts2/pom.xml b/empire-db-examples/empire-db-example-struts2/pom.xml
index b8034a4..a69618d 100644
--- a/empire-db-examples/empire-db-example-struts2/pom.xml
+++ b/empire-db-examples/empire-db-example-struts2/pom.xml
@@ -19,7 +19,7 @@
<parent>
<groupId>org.apache.empire-db</groupId>
<artifactId>empire-db-examples</artifactId>
- <version>2.4.5-SNAPSHOT</version>
+ <version>2.4.5</version>
</parent>
<artifactId>empire-db-example-struts2</artifactId>
<packaging>war</packaging>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/2ab03fe5/empire-db-examples/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-examples/pom.xml b/empire-db-examples/pom.xml
index d640701..69bf1ae 100644
--- a/empire-db-examples/pom.xml
+++ b/empire-db-examples/pom.xml
@@ -19,7 +19,7 @@
<parent>
<groupId>org.apache.empire-db</groupId>
<artifactId>empire-db-parent</artifactId>
- <version>2.4.5-SNAPSHOT</version>
+ <version>2.4.5</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>empire-db-examples</artifactId>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/2ab03fe5/empire-db-jsf2/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-jsf2/pom.xml b/empire-db-jsf2/pom.xml
index d0119e5..4a78953 100644
--- a/empire-db-jsf2/pom.xml
+++ b/empire-db-jsf2/pom.xml
@@ -20,7 +20,7 @@
<parent>
<artifactId>empire-db-parent</artifactId>
<groupId>org.apache.empire-db</groupId>
- <version>2.4.5-SNAPSHOT</version>
+ <version>2.4.5</version>
</parent>
<artifactId>empire-db-jsf2</artifactId>
<packaging>jar</packaging>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/2ab03fe5/empire-db-maven-plugin/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-maven-plugin/pom.xml b/empire-db-maven-plugin/pom.xml
index 613fc11..da05311 100644
--- a/empire-db-maven-plugin/pom.xml
+++ b/empire-db-maven-plugin/pom.xml
@@ -20,7 +20,7 @@
<parent>
<artifactId>empire-db-parent</artifactId>
<groupId>org.apache.empire-db</groupId>
- <version>2.4.5-SNAPSHOT</version>
+ <version>2.4.5</version>
</parent>
<artifactId>empire-db-maven-plugin</artifactId>
<packaging>maven-plugin</packaging>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/2ab03fe5/empire-db-spring/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-spring/pom.xml b/empire-db-spring/pom.xml
index 3579299..51b5a77 100644
--- a/empire-db-spring/pom.xml
+++ b/empire-db-spring/pom.xml
@@ -15,13 +15,12 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-<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">
+<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>
<artifactId>empire-db-parent</artifactId>
<groupId>org.apache.empire-db</groupId>
- <version>2.4.5-SNAPSHOT</version>
+ <version>2.4.5</version>
</parent>
<artifactId>empire-db-spring</artifactId>
<name>Apache Empire-db Spring JDBC Template</name>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/2ab03fe5/empire-db-struts2/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-struts2/pom.xml b/empire-db-struts2/pom.xml
index 6c881af..0a8ca87 100644
--- a/empire-db-struts2/pom.xml
+++ b/empire-db-struts2/pom.xml
@@ -20,7 +20,7 @@
<parent>
<artifactId>empire-db-parent</artifactId>
<groupId>org.apache.empire-db</groupId>
- <version>2.4.5-SNAPSHOT</version>
+ <version>2.4.5</version>
</parent>
<artifactId>empire-db-struts2</artifactId>
<packaging>jar</packaging>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/2ab03fe5/empire-db/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db/pom.xml b/empire-db/pom.xml
index d7d5df9..df291cc 100644
--- a/empire-db/pom.xml
+++ b/empire-db/pom.xml
@@ -20,7 +20,7 @@
<parent>
<artifactId>empire-db-parent</artifactId>
<groupId>org.apache.empire-db</groupId>
- <version>2.4.5-SNAPSHOT</version>
+ <version>2.4.5</version>
</parent>
<artifactId>empire-db</artifactId>
<packaging>jar</packaging>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/2ab03fe5/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 8b205ba..dba427d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -27,7 +27,7 @@
<groupId>org.apache.empire-db</groupId>
<artifactId>empire-db-parent</artifactId>
<packaging>pom</packaging>
- <version>2.4.5-SNAPSHOT</version>
+ <version>2.4.5</version>
<name>Apache Empire-db</name>
<description>Apache Empire-db is an Open Source relational data persistence component which allows database vendor independent dynamic query definition as well as safe and simple data retrieval and updating. Compared to most other solutions like e.g. Hibernate, TopLink, iBATIS or JPA implementations, Empire-db takes a considerably different approach, with a special focus on compile-time safety, reduced redundancies and improved developer productivity.</description>
<inceptionYear>2008</inceptionYear>
@@ -177,7 +177,7 @@
<connection>scm:git:http://git-wip-us.apache.org/repos/asf/empire-db.git</connection>
<developerConnection>scm:git:https://git-wip-us.apache.org/repos/asf/empire-db.git</developerConnection>
<url>http://git-wip-us.apache.org/repos/asf/wicket/repo?p=empire-db.git</url>
- <tag>HEAD</tag>
+ <tag>apache-empire-db-2.4.5-rc1</tag>
</scm>
<mailingLists>
[10/14] empire-db git commit: EMPIREDB-247
Posted by de...@apache.org.
EMPIREDB-247
- better naming of API
Project: http://git-wip-us.apache.org/repos/asf/empire-db/repo
Commit: http://git-wip-us.apache.org/repos/asf/empire-db/commit/3e27a77d
Tree: http://git-wip-us.apache.org/repos/asf/empire-db/tree/3e27a77d
Diff: http://git-wip-us.apache.org/repos/asf/empire-db/diff/3e27a77d
Branch: refs/heads/EMPIREDB-247
Commit: 3e27a77d8e9a106bd2db6f09bef751aec284607f
Parents: 7431378
Author: Jan Glaubitz <ja...@glaubitz.org>
Authored: Fri Aug 12 12:43:30 2016 +0200
Committer: Jan Glaubitz <ja...@glaubitz.org>
Committed: Wed Nov 9 11:56:53 2016 +0100
----------------------------------------------------------------------
empire-db/src/main/java/org/apache/empire/db/DBDatabase.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/empire-db/blob/3e27a77d/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java b/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
index a0d24e8..5757b96 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
@@ -1397,7 +1397,7 @@ public abstract class DBDatabase extends DBObject
* @param conn a valid connection to the database.
* @return the number of records that have been updated or inserted with the supplied statement
*/
- public final int executeInsertOrUpdate(DBCommand cmd, Connection conn)
+ public final int executeUpdateOrInsert(DBCommand cmd, Connection conn)
{
if (getDriver().isSupported(DBDriverFeature.PERFORM_UPSERT))
{
[07/14] empire-db git commit: Release 2.4.5
Posted by de...@apache.org.
Release 2.4.5
Project: http://git-wip-us.apache.org/repos/asf/empire-db/repo
Commit: http://git-wip-us.apache.org/repos/asf/empire-db/commit/54edaff4
Tree: http://git-wip-us.apache.org/repos/asf/empire-db/tree/54edaff4
Diff: http://git-wip-us.apache.org/repos/asf/empire-db/diff/54edaff4
Branch: refs/heads/EMPIREDB-247
Commit: 54edaff48b6c83a837dcc26d6827df76a5d9d98a
Parents: f6c979e
Author: Rainer D�bele <do...@apache.org>
Authored: Wed Nov 9 09:21:59 2016 +0100
Committer: Rainer D�bele <do...@apache.org>
Committed: Wed Nov 9 09:21:59 2016 +0100
----------------------------------------------------------------------
CHANGELOG.txt | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/empire-db/blob/54edaff4/CHANGELOG.txt
----------------------------------------------------------------------
diff --git a/CHANGELOG.txt b/CHANGELOG.txt
index 30d1980..e2f52a1 100644
--- a/CHANGELOG.txt
+++ b/CHANGELOG.txt
@@ -5,6 +5,34 @@ For more Information about a particular issue please visit
https://issues.apache.org/jira/browse/EMPIREDB
--------------
+Release 2.4.5:
+--------------
+
+** Improvement
+ EMPIREDB-245 Add Supprt for DELETE with JOIN for MySQL
+ EMPIREDB-243 Add Eclipse m2e plugin lifecycle mapping
+ EMPIREDB-242 Explicitly declare cross joins
+ EMPIREDB-238 Miscellaneous small improvements
+ EMPIREDB-237 Add support for the modulo function in SQL generation
+ EMPIREDB-235 Improve Empire-JSF-Extensions for JSF 2.2
+ EMPIREDB-233 Remove MSSQL DateFormat dependency
+ EMPIREDB-232 Support InputControls to work correctly in MyFaces and inside UIData components
+ EMPIREDB-231 Improve CheckboxInputControl
+ EMPIREDB-229 Code cleanup and adjustment of maven project settings
+ EMPIREDB-228 Allow access to TagEncodingHelper in derived classes
+ EMPIREDB-227 Spring Integration
+
+** Bugfix
+ EMPIREDB-248 date functions not properly handled in PostgreSQL
+ EMPIREDB-246 Label Required Mark check inconsistent
+ EMPIREDB-241 Error in lower() implementation for PostgreSQL
+ EMPIREDB-240 Update Spring dependencies in examples
+ EMPIREDB-239 Enum-handling: take name or ordinal as field value
+ EMPIREDB-236 Subquery join with DBQuery produces invalid join
+ EMPIREDB-230 MSSQL DDL generates incorrect data type for BLOB with nonzero length
+ EMPIREDB-226 Empire generates incorrect SQL when DBCommand's where list is empty
+
+--------------
Release 2.4.4:
--------------
** Improvement
[12/14] empire-db git commit: EMPIREDB-247
Posted by de...@apache.org.
EMPIREDB-247
- added Support for DBCmdParam
Project: http://git-wip-us.apache.org/repos/asf/empire-db/repo
Commit: http://git-wip-us.apache.org/repos/asf/empire-db/commit/16c3111c
Tree: http://git-wip-us.apache.org/repos/asf/empire-db/tree/16c3111c
Diff: http://git-wip-us.apache.org/repos/asf/empire-db/diff/16c3111c
Branch: refs/heads/EMPIREDB-247
Commit: 16c3111cab83b9eccc0ce300acc23b57bc7309c1
Parents: 3e27a77
Author: Jan Glaubitz <ja...@glaubitz.org>
Authored: Fri Aug 19 13:18:36 2016 +0200
Committer: Jan Glaubitz <ja...@glaubitz.org>
Committed: Wed Nov 9 11:56:53 2016 +0100
----------------------------------------------------------------------
.../empire/db/mysql/DBDatabaseDriverMySQL.java | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/empire-db/blob/16c3111c/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java b/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
index a02f7d8..dfc7aba 100644
--- a/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
+++ b/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
@@ -125,10 +125,21 @@ public class DBDatabaseDriverMySQL extends DBDatabaseDriver
@Override
public synchronized String getUpdateOrInsert()
{
+ // Start with SELECT
StringBuilder buf = new StringBuilder(getInsert());
+ // Add
buf.append(" ON DUPLICATE KEY UPDATE ");
- long context = CTX_NAME | CTX_VALUE;
- addListExpr(buf, set, context, ", ");
+ for (int i = 0; i < this.set.size(); i++)
+ {
+ if (i > 0)
+ {
+ buf.append(", ");
+ }
+ buf.append(this.set.get(i).getColumn().getName());
+ buf.append("=VALUES(");
+ buf.append(this.set.get(i).getColumn().getName());
+ buf.append(")");
+ }
return buf.toString();
}
[13/14] empire-db git commit: EMPIREDB-247
Posted by de...@apache.org.
EMPIREDB-247
Project: http://git-wip-us.apache.org/repos/asf/empire-db/repo
Commit: http://git-wip-us.apache.org/repos/asf/empire-db/commit/890fa480
Tree: http://git-wip-us.apache.org/repos/asf/empire-db/tree/890fa480
Diff: http://git-wip-us.apache.org/repos/asf/empire-db/diff/890fa480
Branch: refs/heads/EMPIREDB-247
Commit: 890fa480f564cec82195b026566029d204bfd79c
Parents: d54dcaf
Author: Jan Glaubitz <ja...@glaubitz.org>
Authored: Tue Aug 9 07:55:00 2016 +0200
Committer: Jan Glaubitz <ja...@glaubitz.org>
Committed: Wed Nov 9 11:56:53 2016 +0100
----------------------------------------------------------------------
.../java/org/apache/empire/db/DBCommand.java | 14 ++++++++++
.../java/org/apache/empire/db/DBDatabase.java | 28 ++++++++++++++++++++
.../org/apache/empire/db/DBDriverFeature.java | 3 ++-
.../empire/db/mysql/DBDatabaseDriverMySQL.java | 12 +++++++++
4 files changed, 56 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/empire-db/blob/890fa480/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBCommand.java b/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
index f3eff01..6941cc8 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBCommand.java
@@ -42,6 +42,7 @@ import org.apache.empire.db.expr.set.DBSetExpr;
import org.apache.empire.exceptions.InternalException;
import org.apache.empire.exceptions.MiscellaneousErrorException;
import org.apache.empire.exceptions.ObjectNotValidException;
+import org.apache.empire.exceptions.NotSupportedException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -1131,6 +1132,19 @@ public abstract class DBCommand extends DBCommandExpr
}
/**
+ * Creates the Insert or Update ("UPSERT") SQL-Command.
+ *
+ * This depends on your Database (driver) and might not be supported.
+ * Check DBDatabaseDriver.isSupported(PERFORM_UPSERT)
+ *
+ * @return the SQL-Command
+ */
+ public synchronized String getInsertOrUpdate()
+ {
+ throw new NotSupportedException(this, "getInsertOrUpdate");
+ }
+
+ /**
* Creates the delete SQL-Command.
*
* @param table the table object
http://git-wip-us.apache.org/repos/asf/empire-db/blob/890fa480/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java b/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
index bd4a754..5d84c30 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBDatabase.java
@@ -1387,6 +1387,34 @@ public abstract class DBDatabase extends DBObject
}
/**
+ * Executes an Insert or Update Statement from a command object
+ *
+ * This depends on your Database (driver) and might not be supported.
+ * Check DBDatabaseDriver.isSupported(PERFORM_UPSERT)
+ *
+ * @param cmd the command object containing the update command
+ * @param conn a valid connection to the database.
+ * @return the number of records that have been updated or inserted with the supplied statement
+ */
+ public final int executeInsertOrUpdate(DBCommand cmd, Connection conn)
+ {
+ if (getDriver().isSupported(DBDriverFeature.PERFORM_UPSERT))
+ {
+ return executeSQL(cmd.getInsertOrUpdate(), cmd.getParamValues(), conn);
+ }
+ else
+ {
+ log.warn("{} is not supported by your Database(driver). Falling back to two statements");
+ int count = executeUpdate(cmd, conn);
+ if (count < 1) {
+ // nothing updated -> INSERT
+ count += executeInsert(cmd, conn);
+ }
+ return count;
+ }
+ }
+
+ /**
* Executes a Delete statement from a command object
* @param from the database table from which to delete records
* @param cmd the command object containing the delete constraints
http://git-wip-us.apache.org/repos/asf/empire-db/blob/890fa480/empire-db/src/main/java/org/apache/empire/db/DBDriverFeature.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/DBDriverFeature.java b/empire-db/src/main/java/org/apache/empire/db/DBDriverFeature.java
index c0004e4..7cb7758 100644
--- a/empire-db/src/main/java/org/apache/empire/db/DBDriverFeature.java
+++ b/empire-db/src/main/java/org/apache/empire/db/DBDriverFeature.java
@@ -28,5 +28,6 @@ public enum DBDriverFeature {
CREATE_SCHEMA,
SEQUENCES,
QUERY_LIMIT_ROWS,
- QUERY_SKIP_ROWS
+ QUERY_SKIP_ROWS,
+ PERFORM_UPSERT
}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/890fa480/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
----------------------------------------------------------------------
diff --git a/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java b/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
index b758b74..2429660 100644
--- a/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
+++ b/empire-db/src/main/java/org/apache/empire/db/mysql/DBDatabaseDriverMySQL.java
@@ -121,6 +121,17 @@ public class DBDatabaseDriverMySQL extends DBDatabaseDriver
addWhere(buf);
return buf.toString();
}
+
+ @Override
+ public synchronized String getInsertOrUpdate()
+ {
+ StringBuilder buf = new StringBuilder(getInsert());
+ buf.append(" ON DUPLICATE KEY UPDATE ");
+ long context = CTX_NAME | CTX_VALUE;
+ addListExpr(buf, set, context, ", ");
+ return buf.toString();
+ }
+
}
// Properties
@@ -571,6 +582,7 @@ public class DBDatabaseDriverMySQL extends DBDatabaseDriver
case SEQUENCES: return useSequenceTable;
case QUERY_LIMIT_ROWS: return true;
case QUERY_SKIP_ROWS: return true;
+ case PERFORM_UPSERT: return true;
default:
// All other features are not supported by default
return false;
[03/14] empire-db git commit: Removed obsolete classes + examples
updated
Posted by de...@apache.org.
Removed obsolete classes + examples updated
EmpireRecord, EmpireReader deleted, enums are handled in core classes
Project: http://git-wip-us.apache.org/repos/asf/empire-db/repo
Commit: http://git-wip-us.apache.org/repos/asf/empire-db/commit/f9515027
Tree: http://git-wip-us.apache.org/repos/asf/empire-db/tree/f9515027
Diff: http://git-wip-us.apache.org/repos/asf/empire-db/diff/f9515027
Branch: refs/heads/EMPIREDB-247
Commit: f95150273651ca8ae74c0f1f04b121ee3f2f3538
Parents: 325e422
Author: inemeth <in...@apache.org>
Authored: Mon Oct 31 08:17:57 2016 +0100
Committer: inemeth <in...@apache.org>
Committed: Mon Oct 31 08:17:57 2016 +0100
----------------------------------------------------------------------
.../org/apache/empire/spring/EmpireReader.java | 105 -------------------
.../org/apache/empire/spring/EmpireRecord.java | 68 ------------
.../apache/empire/spring/EmpireTemplate.java | 4 +-
.../empire/spring/example1/EmpireAppImpl.java | 5 +-
.../empire/spring/example2/EmployeeDaoImpl.java | 31 +++---
.../resources/example1/applicationContext.xml | 4 +-
.../example2/applicationContext-employee.xml | 2 -
7 files changed, 20 insertions(+), 199 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/empire-db/blob/f9515027/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireReader.java
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireReader.java b/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireReader.java
deleted file mode 100644
index 8cc2f54..0000000
--- a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireReader.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.empire.spring;
-
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.InvocationTargetException;
-
-import org.apache.commons.beanutils.BeanUtils;
-import org.apache.commons.beanutils.BeanUtilsBean;
-import org.apache.commons.beanutils.PropertyUtils;
-import org.apache.empire.commons.ObjectUtils;
-import org.apache.empire.commons.StringUtils;
-import org.apache.empire.data.ColumnExpr;
-import org.apache.empire.db.DBReader;
-import org.apache.empire.exceptions.BeanPropertySetException;
-import org.apache.empire.exceptions.InvalidArgumentException;
-import org.apache.empire.exceptions.ItemNotFoundException;
-
-public class EmpireReader extends DBReader
-{
- private static final long serialVersionUID = 1L;
-
- @Override
- protected void setBeanProperty(ColumnExpr column, Object bean, String property, Object value)
- {
- try
- {
- if (bean == null)
- throw new InvalidArgumentException("bean", bean);
- if (StringUtils.isEmpty(property))
- throw new InvalidArgumentException("property", property);
-
- // Get descriptor
- PropertyDescriptor descriptor = BeanUtilsBean.getInstance().getPropertyUtils().getPropertyDescriptor(bean, property);
- if (descriptor == null)
- {
- return; // Skip this property setter
- }
- // Check enum
- Class<?> type = descriptor.getPropertyType();
- if (type.isEnum())
- {
- // Enum<?> ev = Enum.valueOf(type, value);
- boolean found = false;
- Enum<?>[] items = (Enum[]) type.getEnumConstants();
- for (int i = 0; i < items.length; i++)
- {
- Enum<?> item = items[i];
- if (ObjectUtils.compareEqual(item.name(), value))
- {
- value = item;
- found = true;
- break;
- }
- }
- // Enumeration value not found
- if (!found)
- throw new ItemNotFoundException(value);
- }
-
- // Set Property Value
- if (value != null)
- { // Bean utils will convert if necessary
- BeanUtils.setProperty(bean, property, value);
- }
- else
- { // Don't convert, just set
- PropertyUtils.setProperty(bean, property, null);
- }
- }
- catch (IllegalAccessException e)
- { log.error(bean.getClass().getName() + ": unable to set property '" + property + "'");
- throw new BeanPropertySetException(bean, property, e);
- }
- catch (InvocationTargetException e)
- { log.error(bean.getClass().getName() + ": unable to set property '" + property + "'");
- throw new BeanPropertySetException(bean, property, e);
- }
- catch (NoSuchMethodException e)
- { log.error(bean.getClass().getName() + ": unable to set property '" + property + "'");
- throw new BeanPropertySetException(bean, property, e);
- }
- catch (NullPointerException e)
- { log.error(bean.getClass().getName() + ": unable to set property '" + property + "'");
- throw new BeanPropertySetException(bean, property, e);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/f9515027/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireRecord.java
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireRecord.java b/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireRecord.java
deleted file mode 100644
index aef674c..0000000
--- a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireRecord.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.empire.spring;
-
-import java.beans.PropertyDescriptor;
-import java.lang.reflect.InvocationTargetException;
-
-import org.apache.commons.beanutils.BeanUtilsBean;
-import org.apache.commons.beanutils.PropertyUtilsBean;
-import org.apache.empire.data.Column;
-import org.apache.empire.db.DBRecord;
-import org.apache.empire.exceptions.BeanPropertyGetException;
-
-public class EmpireRecord extends DBRecord
-{
- private static final long serialVersionUID = 1L;
-
- @Override
- protected void setRecordValue(Column column, Object bean, String property)
- {
- try
- {
- // Get descriptor
- Object value;
- PropertyUtilsBean pub = BeanUtilsBean.getInstance().getPropertyUtils();
- PropertyDescriptor descriptor = pub.getPropertyDescriptor(bean, property);
- if (descriptor == null) {
- return; // Skip this property setter
- }
-
- // Get Property Value
- value = pub.getSimpleProperty(bean, property);
-
- // Check enum
- if (value instanceof Enum<?>)
- value = ((Enum<?>)value).name();
-
- // Set the record value
- setValue( column, value );
-
- } catch (IllegalAccessException e)
- { log.error(bean.getClass().getName() + ": unable to get property '" + property + "'");
- throw new BeanPropertyGetException(bean, property, e);
- } catch (NoSuchMethodException e)
- { log.error(bean.getClass().getName() + ": unable to get property '" + property + "'");
- throw new BeanPropertyGetException(bean, property, e);
- } catch (InvocationTargetException e)
- { log.error(bean.getClass().getName() + ": unable to get property '" + property + "'");
- throw new BeanPropertyGetException(bean, property, e);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/f9515027/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireTemplate.java
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireTemplate.java b/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireTemplate.java
index ddf3301..b7b5cd7 100644
--- a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireTemplate.java
+++ b/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireTemplate.java
@@ -609,7 +609,7 @@ public class EmpireTemplate implements InitializingBean {
class ReadRecordCallback implements ConnectionCallback<DBRecord> {
public DBRecord doInConnection(Connection connection)
throws SQLException, DataAccessException {
- DBRecord record = new EmpireRecord();
+ DBRecord record = EmpireTemplate.this.recordFactory.getObject();
record.read(table, keys, connection);
return record;
}
@@ -650,7 +650,7 @@ public class EmpireTemplate implements InitializingBean {
class ReadRecordCallback implements ConnectionCallback<DBRecord> {
public DBRecord doInConnection(Connection connection)
throws SQLException, DataAccessException {
- DBRecord record = new EmpireRecord();
+ DBRecord record = EmpireTemplate.this.recordFactory.getObject();
try {
record.read(table, keys, connection);
} catch (RecordNotFoundException e) {
http://git-wip-us.apache.org/repos/asf/empire-db/blob/f9515027/empire-db-spring/src/main/java/org/apache/empire/spring/example1/EmpireAppImpl.java
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/java/org/apache/empire/spring/example1/EmpireAppImpl.java b/empire-db-spring/src/main/java/org/apache/empire/spring/example1/EmpireAppImpl.java
index f35ed89..ba5bd45 100644
--- a/empire-db-spring/src/main/java/org/apache/empire/spring/example1/EmpireAppImpl.java
+++ b/empire-db-spring/src/main/java/org/apache/empire/spring/example1/EmpireAppImpl.java
@@ -42,7 +42,6 @@ import org.apache.empire.spring.DBReaderExtractor;
import org.apache.empire.spring.DBRecordCallbackHandler;
import org.apache.empire.spring.DBRecordMapper;
import org.apache.empire.spring.EmpireDaoSupport;
-import org.apache.empire.spring.EmpireRecord;
import org.apache.empire.xml.XMLWriter;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.ConnectionCallback;
@@ -70,7 +69,7 @@ public class EmpireAppImpl extends EmpireDaoSupport implements EmpireApp {
public Integer insertDepartment(String departmentName, String businessUnit) {
SampleDB db = getDatabase();
- DBRecord rec = new EmpireRecord();
+ DBRecord rec = new DBRecord();
rec.create(db.DEPARTMENTS);
rec.setValue(db.DEPARTMENTS.NAME, departmentName);
rec.setValue(db.DEPARTMENTS.BUSINESS_UNIT, businessUnit);
@@ -85,7 +84,7 @@ public class EmpireAppImpl extends EmpireDaoSupport implements EmpireApp {
String gender, int departmentId) {
SampleDB db = getDatabase();
- DBRecord rec = new EmpireRecord();
+ DBRecord rec = new DBRecord();
rec.create(db.EMPLOYEES);
rec.setValue(db.EMPLOYEES.FIRSTNAME, firstName);
rec.setValue(db.EMPLOYEES.LASTNAME, lastName);
http://git-wip-us.apache.org/repos/asf/empire-db/blob/f9515027/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDaoImpl.java
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDaoImpl.java b/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDaoImpl.java
index d605feb..37eb07b 100644
--- a/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDaoImpl.java
+++ b/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDaoImpl.java
@@ -29,7 +29,6 @@ import org.apache.empire.db.DBRecordData;
import org.apache.empire.spring.DBRecordMapper;
import org.apache.empire.spring.DBRecordWriter;
import org.apache.empire.spring.EmpireDaoSupport;
-import org.apache.empire.spring.EmpireRecord;
import org.apache.empire.spring.example1.SampleDB;
import org.apache.empire.spring.example1.SampleDB.Departments;
import org.apache.empire.spring.example1.SampleDB.Employees;
@@ -93,7 +92,7 @@ public class EmployeeDaoImpl extends EmpireDaoSupport implements EmployeeDao {
@Transactional(readOnly = true)
public List<Department> getDepartments() {
- DBCommand cmd = createEmployeeSelectCommand();
+ DBCommand cmd = createDepartmentSelectCommand();
return getEmpireTemplate().queryForBeanList(cmd, Department.class);
}
@@ -114,7 +113,7 @@ public class EmployeeDaoImpl extends EmpireDaoSupport implements EmployeeDao {
@Transactional
public Integer createEmployee(Employee employee) {
- DBRecord record = new EmpireRecord();
+ DBRecord record = new DBRecord();
record.create(EMPLOYEES);
new EmployeeWriter().write(record, employee);
getEmpireTemplate().updateRecord(record);
@@ -130,7 +129,7 @@ public class EmployeeDaoImpl extends EmpireDaoSupport implements EmployeeDao {
@Transactional
public Integer createDepartment(Department department) {
- DBRecord record = new EmpireRecord();
+ DBRecord record = new DBRecord();
record.create(DEPARTMENTS);
new DepartmentWriter().write(record, department);
getEmpireTemplate().updateRecord(record);
@@ -152,14 +151,14 @@ public class EmployeeDaoImpl extends EmpireDaoSupport implements EmployeeDao {
public Employee mapRecord(DBRecordData record, int rowNum) {
Employee result = new Employee();
// Auto-copy all properties
- record.setBeanProperties(result);
- /*
+ //record.setBeanProperties(result);
+
result.setEmployeeId(record.getInt(EMPLOYEES.EMPLOYEE_ID));
result.setFirstName(record.getString(EMPLOYEES.FIRSTNAME));
result.setLastName(record.getString(EMPLOYEES.LASTNAME));
result.setGender(Employee.Gender.valueOf(record.getString(EMPLOYEES.GENDER)));
result.setPhoneNumber(record.getString(EMPLOYEES.PHONE_NUMBER));
- */
+
result.setDepartment(departmentMapper.mapRecord(record, rowNum));
return result;
}
@@ -171,14 +170,14 @@ public class EmployeeDaoImpl extends EmpireDaoSupport implements EmployeeDao {
@Override
public void write(DBRecord record, Employee entity) {
// Auto-copy all properties
- record.setRecordValues(entity);
- /*
+ //record.setRecordValues(entity);
+
record.setValue(EMPLOYEES.EMPLOYEE_ID, entity.getEmployeeId());
record.setValue(EMPLOYEES.FIRSTNAME, entity.getFirstName());
record.setValue(EMPLOYEES.LASTNAME, entity.getLastName());
record.setValue(EMPLOYEES.GENDER, entity.getGender().name());
record.setValue(EMPLOYEES.PHONE_NUMBER, entity.getPhoneNumber());
- */
+
record.setValue(EMPLOYEES.DEPARTMENT_ID, entity.getDepartment().getDepartmentId());
}
@@ -199,13 +198,13 @@ public class EmployeeDaoImpl extends EmpireDaoSupport implements EmployeeDao {
if (department == null) {
department = new Department();
// Auto-copy all properties
- record.setBeanProperties(department);
- /*
+ //record.setBeanProperties(department);
+
department.setDepartmentId(id);
department.setName(record.getString(DEPARTMENTS.NAME));
department.setHead(record.getString(DEPARTMENTS.HEAD));
department.setBusinessUnit(record.getString(DEPARTMENTS.BUSINESS_UNIT));
- */
+
cache.put(id, department);
}
return department;
@@ -218,13 +217,13 @@ public class EmployeeDaoImpl extends EmpireDaoSupport implements EmployeeDao {
@Override
public void write(DBRecord record, Department entity) {
// Auto-copy all properties
- record.setRecordValues(entity);
- /*
+ //record.setRecordValues(entity);
+
record.setValue(DEPARTMENTS.DEPARTMENT_ID, entity.getDepartmentId());
record.setValue(DEPARTMENTS.NAME, entity.getName());
record.setValue(DEPARTMENTS.HEAD, entity.getHead());
record.setValue(DEPARTMENTS.BUSINESS_UNIT, entity.getBusinessUnit());
- */
+
}
}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/f9515027/empire-db-spring/src/main/resources/example1/applicationContext.xml
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/resources/example1/applicationContext.xml b/empire-db-spring/src/main/resources/example1/applicationContext.xml
index 648b4b2..7987d5a 100644
--- a/empire-db-spring/src/main/resources/example1/applicationContext.xml
+++ b/empire-db-spring/src/main/resources/example1/applicationContext.xml
@@ -67,15 +67,13 @@
</bean>
<bean id="empireDao" abstract="true">
- <property name="database" ref="sampleDb"/>
+ <property name="database" ref="empireDb"/>
<property name="empireTemplate" ref="empireTemplate"/>
</bean>
<bean id="empireTemplate" class="org.apache.empire.spring.EmpireTemplate">
<property name="dataSource" ref="dataSource"/>
- <property name="dBRecordClass" value="org.apache.empire.spring.EmpireRecord"/>
- <property name="dBReaderClass" value="org.apache.empire.spring.EmpireReader"/>
</bean>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/f9515027/empire-db-spring/src/main/resources/example2/applicationContext-employee.xml
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/resources/example2/applicationContext-employee.xml b/empire-db-spring/src/main/resources/example2/applicationContext-employee.xml
index 79799a7..08ce097 100644
--- a/empire-db-spring/src/main/resources/example2/applicationContext-employee.xml
+++ b/empire-db-spring/src/main/resources/example2/applicationContext-employee.xml
@@ -74,8 +74,6 @@
<bean id="empireTemplate" class="org.apache.empire.spring.EmpireTemplate">
<property name="dataSource" ref="dataSource"/>
- <property name="dBRecordClass" value="org.apache.empire.spring.EmpireRecord"/>
- <property name="dBReaderClass" value="org.apache.empire.spring.EmpireReader"/>
</bean>