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 do...@apache.org on 2022/03/04 15:48:44 UTC
[empire-db] branch master updated: EMPIREDB-380 Spring-boot-example donated by Ralf Eichinger
This is an automated email from the ASF dual-hosted git repository.
doebele pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/empire-db.git
The following commit(s) were added to refs/heads/master by this push:
new 0d9706c EMPIREDB-380 Spring-boot-example donated by Ralf Eichinger
0d9706c is described below
commit 0d9706cdb5fbad5452905dfedcdce085803e9252
Author: Rainer Döbele <do...@apache.org>
AuthorDate: Fri Mar 4 16:48:42 2022 +0100
EMPIREDB-380 Spring-boot-example donated by Ralf Eichinger
---
.../org/apache/empire/samples/db/SampleApp.java | 40 +++----
.../empire-db-example-codegen/generate-example.xml | 12 +--
.../empire-db-example-spring-boot/.gitignore | 4 +
.../empire-db-example-spring-boot/pom.xml | 116 ++++++++++-----------
.../empire/samples/springboot/SampleApp.java | 39 ++++---
empire-db-examples/pom.xml | 2 +-
6 files changed, 113 insertions(+), 100 deletions(-)
diff --git a/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java b/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java
index b7009cc..583cecc 100644
--- a/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java
+++ b/empire-db-examples/empire-db-example-basic/src/main/java/org/apache/empire/samples/db/SampleApp.java
@@ -249,8 +249,8 @@ public class SampleApp
// SECTION 6: Modify some data
log.info("Step 6: updateEmployee()");
- updateEmployee(idEmp1, "+49-7531-457160");
- updateEmployee(idEmp2, "+49-5555-505050");
+ updateEmployee(idEmp1, "+49-7531-457160", true);
+ updateEmployee(idEmp2, "+49-5555-505050", false);
// Partial Record
updatePartialRecord(idEmp3, "+49-040-125486");
// Update Joined Records (Make Fred Bloggs head of department and set salary)
@@ -351,23 +351,27 @@ public class SampleApp
* Updates an employee record by setting the phone number.
* </PRE>
*/
- private void updateEmployee(long idEmp, String phoneNumber)
+ private void updateEmployee(long idEmp, String phoneNumber, boolean useRecord)
{
- /*
- // Update an Employee
- DBRecord rec = new DBRecord(context, db.EMPLOYEES);
- rec.read(idEmp);
- // Set
- rec.set(db.EMPLOYEES.PHONE_NUMBER, phoneNumber);
- rec.update();
- */
-
- DBRecordBean rec = new DBRecordBean();
- rec.read(context, db.EMPLOYEES, idEmp);
- // Set
- rec.set(db.EMPLOYEES.PHONE_NUMBER, phoneNumber);
- rec.update(context);
-
+ // Update an Employee
+ if (useRecord)
+ {
+ // Use a DBRecord (recommended)
+ DBRecord rec = new DBRecord(context, db.EMPLOYEES);
+ rec.read(idEmp);
+ // Set
+ rec.set(db.EMPLOYEES.PHONE_NUMBER, phoneNumber);
+ rec.update();
+
+ }
+ else
+ { // Or use a DBRecordBean:
+ DBRecordBean rec = new DBRecordBean();
+ rec.read(context, db.EMPLOYEES, idEmp);
+ // Set
+ rec.set(db.EMPLOYEES.PHONE_NUMBER, phoneNumber);
+ rec.update(context);
+ }
}
/**
diff --git a/empire-db-examples/empire-db-example-codegen/generate-example.xml b/empire-db-examples/empire-db-example-codegen/generate-example.xml
index 3f03783..d766b76 100644
--- a/empire-db-examples/empire-db-example-codegen/generate-example.xml
+++ b/empire-db-examples/empire-db-example-codegen/generate-example.xml
@@ -21,16 +21,16 @@
<properties>
<!-- JDBC-Connection to connect to server -->
- <jdbcClass>org.hsqldb.jdbc.JDBCDriver</jdbcClass>
- <jdbcURL>jdbc:hsqldb:file:src/test/resources/hsqldb/sample;shutdown=true</jdbcURL>
- <jdbcUser>sa</jdbcUser>
- <jdbcPwd></jdbcPwd>
+ <jdbcClass>com.microsoft.sqlserver.jdbc.SQLServerDriver</jdbcClass>
+ <jdbcURL>jdbc:sqlserver://esteams12\sql17</jdbcURL>
+ <jdbcUser>jdbcUser</jdbcUser>
+ <jdbcPwd>jdbcPwd</jdbcPwd>
<!-- Empire-db DBMS Handler class -->
- <dbmsHandlerClass>org.apache.empire.dbms.hsql.DBMSHandlerHSql</dbmsHandlerClass>
+ <dbmsHandlerClass>org.apache.empire.dbms.sqlserver.DBMSHandlerMSSQL</dbmsHandlerClass>
<!-- Schema options -->
- <dbCatalog></dbCatalog>
+ <dbCatalog>DBSAMPLEADV</dbCatalog>
<dbSchema></dbSchema>
<dbTablePattern></dbTablePattern>
diff --git a/empire-db-examples/empire-db-example-spring-boot/.gitignore b/empire-db-examples/empire-db-example-spring-boot/.gitignore
new file mode 100644
index 0000000..915e909
--- /dev/null
+++ b/empire-db-examples/empire-db-example-spring-boot/.gitignore
@@ -0,0 +1,4 @@
+/.settings/
+/hsqldb/
+/.classpath
+/.project
diff --git a/empire-db-examples/empire-db-example-spring-boot/pom.xml b/empire-db-examples/empire-db-example-spring-boot/pom.xml
index 59b1132..4737144 100644
--- a/empire-db-examples/empire-db-example-spring-boot/pom.xml
+++ b/empire-db-examples/empire-db-example-spring-boot/pom.xml
@@ -1,69 +1,67 @@
<?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.
+ 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.
-->
-<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>
+<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/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <artifactId>empire-db-examples</artifactId>
+ <groupId>org.apache.empire-db</groupId>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+ <name>Apache Empire-db Spring Boot Example</name>
+ <artifactId>empire-db-example-spring-boot</artifactId>
+ <packaging>jar</packaging>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.6.3</version>
- <relativePath/> <!-- lookup parent from repository -->
- </parent>
-
- <name>Apache Empire-db Spring Boot Example</name>
- <groupId>org.apache.empire-db</groupId>
- <artifactId>empire-db-example-spring-boot</artifactId>
- <version>3.0.0-SNAPSHOT</version>
- <packaging>jar</packaging>
+ <properties>
+ <spring-boot.version>2.6.4</spring-boot.version>
+ </properties>
- <dependencies>
- <dependency>
- <groupId>org.apache.empire-db</groupId>
- <artifactId>empire-db</artifactId>
- <version>3.0.0-SNAPSHOT</version>
- </dependency>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.empire-db</groupId>
+ <artifactId>empire-db</artifactId>
+ </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter</artifactId>
- </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter</artifactId>
+ <version>${spring-boot.version}</version>
+ </dependency>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-jdbc</artifactId>
- </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-jdbc</artifactId>
+ <version>${spring-boot.version}</version>
+ </dependency>
- <dependency>
- <groupId>org.hsqldb</groupId>
- <artifactId>hsqldb</artifactId>
- <scope>runtime</scope>
- </dependency>
- </dependencies>
+ <dependency>
+ <groupId>org.hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ <scope>runtime</scope>
+ </dependency>
+ </dependencies>
- <build>
- <plugins>
- <!-- Package as an executable jar -->
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
+ <build>
+ <plugins>
+ <!-- Package as an executable jar -->
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/empire-db-examples/empire-db-example-spring-boot/src/main/java/org/apache/empire/samples/springboot/SampleApp.java b/empire-db-examples/empire-db-example-spring-boot/src/main/java/org/apache/empire/samples/springboot/SampleApp.java
index 92075d0..24981ae 100644
--- a/empire-db-examples/empire-db-example-spring-boot/src/main/java/org/apache/empire/samples/springboot/SampleApp.java
+++ b/empire-db-examples/empire-db-example-spring-boot/src/main/java/org/apache/empire/samples/springboot/SampleApp.java
@@ -240,6 +240,7 @@ public class SampleApp implements ApplicationRunner {
}
}
+ @SuppressWarnings("unused")
private void populateAndModify() {
clearDatabase();
@@ -258,8 +259,8 @@ public class SampleApp implements ApplicationRunner {
// SECTION 6: Modify some data
LOGGER.info("Step 6: updateEmployee()");
- updateEmployee(idEmp1, "+49-7531-457160");
- updateEmployee(idEmp2, "+49-5555-505050");
+ updateEmployee(idEmp1, "+49-7531-457160", true);
+ updateEmployee(idEmp2, "+49-5555-505050", false);
// Partial Record
updatePartialRecord(idEmp3, "+49-040-125486");
// Update Joined Records (Make Fred Bloggs head of department and set salary)
@@ -641,21 +642,27 @@ public class SampleApp implements ApplicationRunner {
* Updates an employee record by setting the phone number.
* </PRE>
*/
- private void updateEmployee(long idEmp, String phoneNumber) {
- /*
+ private void updateEmployee(long idEmp, String phoneNumber, boolean useRecord)
+ {
// Update an Employee
- DBRecord rec = new DBRecord(context, db.EMPLOYEES);
- rec.read(idEmp);
- // Set
- rec.set(db.EMPLOYEES.PHONE_NUMBER, phoneNumber);
- rec.update();
- */
-
- DBRecordBean rec = new DBRecordBean();
- rec.read(context, db.EMPLOYEES, idEmp);
- // Set
- rec.set(db.EMPLOYEES.PHONE_NUMBER, phoneNumber);
- rec.update(context);
+ if (useRecord)
+ {
+ // Use a DBRecord (recommended)
+ DBRecord rec = new DBRecord(context, db.EMPLOYEES);
+ rec.read(idEmp);
+ // Set
+ rec.set(db.EMPLOYEES.PHONE_NUMBER, phoneNumber);
+ rec.update();
+
+ }
+ else
+ { // Or use a DBRecordBean:
+ DBRecordBean rec = new DBRecordBean();
+ rec.read(context, db.EMPLOYEES, idEmp);
+ // Set
+ rec.set(db.EMPLOYEES.PHONE_NUMBER, phoneNumber);
+ rec.update(context);
+ }
}
/**
diff --git a/empire-db-examples/pom.xml b/empire-db-examples/pom.xml
index 54fd620..f4e1baa 100644
--- a/empire-db-examples/pom.xml
+++ b/empire-db-examples/pom.xml
@@ -37,7 +37,7 @@
<module>empire-db-example-codegen</module>
<module>empire-db-example-jsf2</module>
<module>empire-db-example-vue</module>
- <!-- <module>empire-db-example-codegen</module> -->
+ <module>empire-db-example-spring-boot</module>
</modules>
<build>
<pluginManagement>