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 2018/01/16 09:13:26 UTC
[1/2] empire-db git commit: EMPIREDB-271 Moved example to the
examples folder and renamed it to empire-db-example-vue
Repository: empire-db
Updated Branches:
refs/heads/master 8dbffdbc5 -> caaec0de9
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-vue-example/src/main/java/org/apache/empire/rest/service/listener/AppListener.java
----------------------------------------------------------------------
diff --git a/empire-db-vue-example/src/main/java/org/apache/empire/rest/service/listener/AppListener.java b/empire-db-vue-example/src/main/java/org/apache/empire/rest/service/listener/AppListener.java
deleted file mode 100644
index 8cee6ed..0000000
--- a/empire-db-vue-example/src/main/java/org/apache/empire/rest/service/listener/AppListener.java
+++ /dev/null
@@ -1,248 +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.rest.service.listener;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-
-import javax.servlet.ServletContext;
-import javax.servlet.ServletContextEvent;
-import javax.servlet.ServletContextListener;
-
-import org.apache.empire.commons.StringUtils;
-import org.apache.empire.db.DBCommand;
-import org.apache.empire.db.DBDatabase;
-import org.apache.empire.db.DBDatabaseDriver;
-import org.apache.empire.db.DBRecord;
-import org.apache.empire.db.DBSQLScript;
-import org.apache.empire.db.exceptions.QueryFailedException;
-import org.apache.empire.db.hsql.DBDatabaseDriverHSql;
-import org.apache.empire.db.mysql.DBDatabaseDriverMySQL;
-import org.apache.empire.vuesample.model.EmpireServiceConsts;
-import org.apache.empire.vuesample.model.db.SampleDB;
-import org.apache.log4j.ConsoleAppender;
-import org.apache.log4j.Level;
-import org.apache.log4j.PatternLayout;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class AppListener implements ServletContextListener {
-
- private static final Logger log = LoggerFactory.getLogger(AppListener.class);
-
- @Override
- public void contextInitialized(ServletContextEvent sce) {
-
- log.debug("contextInitialized");
-
- // Logging
- initLogging();
-
- //
- Connection conn = getJDBCConnection(sce.getServletContext());
-
- // DB
- SampleDB db = initDatabase(sce.getServletContext());
- DBDatabaseDriver driver = new DBDatabaseDriverMySQL();
- db.open(driver, conn);
-
- // Add to context
- sce.getServletContext().setAttribute(EmpireServiceConsts.ATTRIBUTE_DB, db);
- // sce.getServletContext().setAttribute(MobileImportServiceConsts.ATTRIBUTE_DATASOURCE, ds);
- // sce.getServletContext().setAttribute(MobileImportServiceConsts.ATTRIBUTE_CONFIG, config);
-
- log.debug("contextInitialized done");
-
- }
-
- @Override
- public void contextDestroyed(ServletContextEvent sce) {
- log.debug("contextDestroyed");
- log.debug("contextDestroyed done");
- }
-
- private SampleDB initDatabase(ServletContext ctx) {
- SampleDB db = new SampleDB();
-
- // Open Database (and create if not existing)
- DBDatabaseDriver driver = new DBDatabaseDriverHSql();
- log.info("Opening database '{}' using driver '{}'", db.getClass().getSimpleName(), driver.getClass().getSimpleName());
- Connection conn = null;
- try {
- conn = getJDBCConnection(ctx);
- db.open(driver, conn);
- if (!databaseExists(db, conn)) {
- // STEP 4: Create Database
- log.info("Creating database {}", db.getClass().getSimpleName());
- createSampleDatabase(db, driver, conn);
- }
- } finally {
- releaseConnection(db, conn, true);
- }
-
- return db;
- }
-
- private static boolean databaseExists(SampleDB db, Connection conn) {
- // Check wether DB exists
- DBCommand cmd = db.createCommand();
- cmd.select(db.T_DEPARTMENTS.count());
- try {
- return (db.querySingleInt(cmd, -1, conn) >= 0);
- } catch (QueryFailedException e) {
- return false;
- }
- }
-
- private static void createSampleDatabase(SampleDB db, DBDatabaseDriver driver, Connection conn) {
- // create DLL for Database Definition
- DBSQLScript script = new DBSQLScript();
- db.getCreateDDLScript(driver, script);
- // Show DLL Statements
- System.out.println(script.toString());
- // Execute Script
- script.executeAll(driver, conn, false);
- db.commit(conn);
- // Open again
- if (!db.isOpen()) {
- db.open(driver, conn);
- }
- // Insert Sample Departments
- insertDepartmentSampleRecord(db, conn, "Procurement", "ITTK");
- int idDevDep = insertDepartmentSampleRecord(db, conn, "Development", "ITTK");
- int idSalDep = insertDepartmentSampleRecord(db, conn, "Sales", "ITTK");
- // Insert Sample Employees
- insertEmployeeSampleRecord(db, conn, "Mr.", "Eugen", "Miller", "M", idDevDep);
- insertEmployeeSampleRecord(db, conn, "Mr.", "Max", "Mc. Callahan", "M", idDevDep);
- insertEmployeeSampleRecord(db, conn, "Mrs.", "Anna", "Smith", "F", idSalDep);
- // Commit
- db.commit(conn);
- }
-
- private static int insertDepartmentSampleRecord(SampleDB db, Connection conn, String department_name, String businessUnit) {
- // Insert a Department
- DBRecord rec = new DBRecord();
- rec.create(db.T_DEPARTMENTS);
- rec.setValue(db.T_DEPARTMENTS.NAME, department_name);
- rec.setValue(db.T_DEPARTMENTS.BUSINESS_UNIT, businessUnit);
- try {
- rec.update(conn);
- } catch (Exception e) {
- log.error(e.getLocalizedMessage());
- return 0;
- }
- // Return Department ID
- return rec.getInt(db.T_DEPARTMENTS.DEPARTMENT_ID);
- }
-
- /*
- * Insert a person
- */
- private static int insertEmployeeSampleRecord(SampleDB db, Connection conn, String salutation, String firstName, String lastName, String gender, int depID) {
- // Insert an Employee
- DBRecord rec = new DBRecord();
- rec.create(db.T_EMPLOYEES);
- rec.setValue(db.T_EMPLOYEES.SALUTATION, salutation);
- rec.setValue(db.T_EMPLOYEES.FIRST_NAME, firstName);
- rec.setValue(db.T_EMPLOYEES.LAST_NAME, lastName);
- rec.setValue(db.T_EMPLOYEES.GENDER, gender);
- rec.setValue(db.T_EMPLOYEES.DEPARTMENT_ID, depID);
- try {
- rec.update(conn);
- } catch (Exception e) {
- log.error(e.getLocalizedMessage());
- return 0;
- }
- // Return Employee ID
- return rec.getInt(db.T_EMPLOYEES.EMPLOYEE_ID);
- }
-
- public static Connection getJDBCConnection(ServletContext appContext) {
- // Establish a new database connection
- Connection conn = null;
-
- String jdbcURL = "jdbc:hsqldb:file:hsqldb/sample;shutdown=true";
- String jdbcUser = "sa";
- String jdbcPwd = "";
-
- if (jdbcURL.indexOf("file:") > 0) {
- jdbcURL = StringUtils.replace(jdbcURL, "file:", "file:" + appContext.getRealPath("/"));
- }
- // Connect
- log.info("Connecting to Database'" + jdbcURL + "' / User=" + jdbcUser);
- try { // Connect to the databse
- Class.forName("org.hsqldb.jdbcDriver").newInstance();
- conn = DriverManager.getConnection(jdbcURL, jdbcUser, jdbcPwd);
- log.info("Connected successfully");
- // set the AutoCommit to false this session. You must commit
- // explicitly now
- conn.setAutoCommit(false);
- log.info("AutoCommit is " + conn.getAutoCommit());
-
- } catch (Exception e) {
- log.error("Failed to connect directly to '" + jdbcURL + "' / User=" + jdbcUser);
- log.error(e.toString());
- throw new RuntimeException(e);
- }
- return conn;
- }
-
- protected void releaseConnection(DBDatabase db, Connection conn, boolean commit) {
- // release connection
- if (conn == null) {
- return;
- }
- // Commit or rollback connection depending on the exit code
- if (commit) { // success: commit all changes
- db.commit(conn);
- log.debug("REQUEST {}: commited.");
- } else { // failure: rollback all changes
- db.rollback(conn);
- log.debug("REQUEST {}: rolled back.");
- }
- }
-
- private void initLogging() {
-
- // Init Logging
- ConsoleAppender consoleAppender = new ConsoleAppender();
- String pattern = "%-5p [%d{yyyy/MM/dd HH:mm}]: %m at %l %n";
- consoleAppender.setLayout(new PatternLayout(pattern));
- consoleAppender.activateOptions();
-
- org.apache.log4j.Logger.getRootLogger().addAppender(consoleAppender);
- org.apache.log4j.Logger.getRootLogger().setLevel(Level.ALL);
-
- Level loglevel = Level.DEBUG;
- log.info("Setting LogLevel to {}", loglevel);
-
- // RootLogger
- org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO);
-
- // Empire-db Logs
- org.apache.log4j.Logger empireLog = org.apache.log4j.Logger.getLogger("org.apache.empire.db.DBDatabase");
- empireLog.setLevel(loglevel);
-
- // Vue.js Sample
- org.apache.log4j.Logger miLog = org.apache.log4j.Logger.getLogger("org.apache.empire.rest");
- miLog.setLevel(loglevel);
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-vue-example/src/main/java/org/apache/empire/vuesample/model/EmpireServiceConsts.java
----------------------------------------------------------------------
diff --git a/empire-db-vue-example/src/main/java/org/apache/empire/vuesample/model/EmpireServiceConsts.java b/empire-db-vue-example/src/main/java/org/apache/empire/vuesample/model/EmpireServiceConsts.java
deleted file mode 100644
index f95dc4c..0000000
--- a/empire-db-vue-example/src/main/java/org/apache/empire/vuesample/model/EmpireServiceConsts.java
+++ /dev/null
@@ -1,31 +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.vuesample.model;
-
-public class EmpireServiceConsts {
-
- public static final String ATTRIBUTE_DB = "db";
-
- public static final String ATTRIBUTE_CONNECTION = "connection";
-
- public static final String ATTRIBUTE_DATASOURCE = "ds";
-
- public static final String ATTRIBUTE_CONFIG = "config";
-
-}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-vue-example/src/main/java/org/apache/empire/vuesample/model/db/EmployeeBean.java
----------------------------------------------------------------------
diff --git a/empire-db-vue-example/src/main/java/org/apache/empire/vuesample/model/db/EmployeeBean.java b/empire-db-vue-example/src/main/java/org/apache/empire/vuesample/model/db/EmployeeBean.java
deleted file mode 100644
index 048c793..0000000
--- a/empire-db-vue-example/src/main/java/org/apache/empire/vuesample/model/db/EmployeeBean.java
+++ /dev/null
@@ -1,65 +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.vuesample.model.db;
-
-import org.apache.empire.rest.EmpireColumn;
-
-public class EmployeeBean {
-
- private EmpireColumn employeeId;
-
- private EmpireColumn firstName;
-
- private EmpireColumn lastName;
-
- private EmpireColumn dateOfBirth;
-
- public EmpireColumn getEmployeeId() {
- return this.employeeId;
- }
-
- public void setEmployeeId(EmpireColumn employeeId) {
- this.employeeId = employeeId;
- }
-
- public EmpireColumn getFirstName() {
- return this.firstName;
- }
-
- public void setFirstName(EmpireColumn firstName) {
- this.firstName = firstName;
- }
-
- public EmpireColumn getLastName() {
- return this.lastName;
- }
-
- public void setLastName(EmpireColumn lastName) {
- this.lastName = lastName;
- }
-
- public EmpireColumn getDateOfBirth() {
- return this.dateOfBirth;
- }
-
- public void setDateOfBirth(EmpireColumn dateOfBirth) {
- this.dateOfBirth = dateOfBirth;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-vue-example/src/main/java/org/apache/empire/vuesample/model/db/SampleDB.java
----------------------------------------------------------------------
diff --git a/empire-db-vue-example/src/main/java/org/apache/empire/vuesample/model/db/SampleDB.java b/empire-db-vue-example/src/main/java/org/apache/empire/vuesample/model/db/SampleDB.java
deleted file mode 100644
index 735d323..0000000
--- a/empire-db-vue-example/src/main/java/org/apache/empire/vuesample/model/db/SampleDB.java
+++ /dev/null
@@ -1,156 +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.vuesample.model.db;
-
-import org.apache.empire.commons.Options;
-import org.apache.empire.data.DataMode;
-import org.apache.empire.data.DataType;
-import org.apache.empire.db.DBColumn;
-import org.apache.empire.db.DBDatabase;
-import org.apache.empire.db.DBTableColumn;
-
-public class SampleDB extends DBDatabase
-{
- private final static long serialVersionUID = 1L;
-
- // Declare all Tables
- public final TDepartments T_DEPARTMENTS = new TDepartments(this);
- public final TEmployees T_EMPLOYEES = new TEmployees(this);
-
- /**
- * Constructor SampleDB
- */
- public SampleDB()
- {
- // Define Foreign-Key Relations
- addRelation(T_EMPLOYEES.DEPARTMENT_ID.referenceOn(T_DEPARTMENTS.DEPARTMENT_ID));
- }
-
- // Needed for the DBELResolver
- @Override
- protected void register(String id)
- {
- super.register("db");
- }
-
- /**
- * This class represents the definition of the Departments table.
- */
- public static class TDepartments extends SampleTable
- {
- private static final 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 TDepartments(DBDatabase db)
- {
- super("DEPARTMENTS", db);
- // ID
- DEPARTMENT_ID = addColumn("DEPARTMENT_ID", DataType.AUTOINC, 0, DataMode.NotNull, "DEP_ID_SEQUENCE");
- NAME = addColumn("NAME", DataType.TEXT, 80, DataMode.NotNull);
- HEAD = addColumn("HEAD", DataType.TEXT, 80, DataMode.Nullable);
- BUSINESS_UNIT = addColumn("BUSINESS_UNIT", DataType.TEXT, 4, DataMode.NotNull, "ITTK");
- UPDATE_TIMESTAMP= addColumn("UPDATE_TIMESTAMP", DataType.DATETIME, 0, DataMode.NotNull);
-
- // 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 TEmployees extends SampleTable
- {
- private static final long serialVersionUID = 1L;
-
- public final DBTableColumn EMPLOYEE_ID;
- public final DBTableColumn SALUTATION;
-// public final DBTableColumn PICTURE;
- public final DBTableColumn FIRST_NAME;
- public final DBTableColumn LAST_NAME;
- 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 RETIRED;
- public final DBTableColumn UPDATE_TIMESTAMP;
- public TEmployees(DBDatabase db)
- {
- super("EMPLOYEES", db);
- // ID
- EMPLOYEE_ID = addColumn("EMPLOYEE_ID", DataType.AUTOINC, 0, DataMode.NotNull, "EMPLOYEE_ID_SEQUENCE");
- SALUTATION = addColumn("SALUTATION", DataType.TEXT, 5, DataMode.Nullable);
- FIRST_NAME = addColumn("FIRST_NAME", DataType.TEXT, 40, DataMode.NotNull);
- LAST_NAME = addColumn("LAST_NAME", DataType.TEXT, 40, DataMode.NotNull);
- DATE_OF_BIRTH = addColumn("DATE_OF_BIRTH", DataType.DATE, 0, DataMode.Nullable);
- DEPARTMENT_ID = addColumn("DEPARTMENT_ID", DataType.INTEGER, 0, DataMode.NotNull);
- GENDER = addColumn("GENDER", DataType.TEXT, 1, DataMode.Nullable);
- PHONE_NUMBER = addColumn("PHONE_NUMBER", DataType.TEXT, 40, DataMode.Nullable);
- EMAIL = addColumn("EMAIL", DataType.TEXT, 80, DataMode.Nullable);
- RETIRED = addColumn("RETIRED", DataType.BOOL, 0, DataMode.NotNull, false);
- // PICTURE = addColumn("PICTURE", DataType.BLOB, 0, DataMode.Nullable);
- UPDATE_TIMESTAMP= addColumn("UPDATE_TIMESTAMP", DataType.DATETIME, 0, DataMode.NotNull);
-
- // Primary Key
- setPrimaryKey(EMPLOYEE_ID);
- // Set other Indexes
- addIndex("PERSON_NAME_IDX", true, new DBColumn[] { FIRST_NAME, LAST_NAME, DATE_OF_BIRTH });
-
- // Set timestamp column for save updates
- setTimestampColumn(UPDATE_TIMESTAMP);
-
- // Create Options for GENDER column
- Options genders = new Options();
- genders.set("M", "!option.employee.gender.male");
- genders.set("F", "!option.employee.gender.female");
- GENDER.setOptions(genders);
- GENDER.setControlType("select");
-
- Options retired = new Options();
- retired.set(false, "!option.employee.active");
- retired.set(true, "!option.employee.retired");
- RETIRED.setOptions(retired);
- RETIRED.setControlType("checkbox");
-
- // Set special control types
- DEPARTMENT_ID.setControlType("select");
- PHONE_NUMBER .setControlType("phone");
-
- // Set optional formatting attributes
- DATE_OF_BIRTH.setAttribute("format:date", "yyyy-MM-dd");
-
- // PICTURE.setControlType("blob");
-
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-vue-example/src/main/java/org/apache/empire/vuesample/model/db/SampleTable.java
----------------------------------------------------------------------
diff --git a/empire-db-vue-example/src/main/java/org/apache/empire/vuesample/model/db/SampleTable.java b/empire-db-vue-example/src/main/java/org/apache/empire/vuesample/model/db/SampleTable.java
deleted file mode 100644
index 353bf75..0000000
--- a/empire-db-vue-example/src/main/java/org/apache/empire/vuesample/model/db/SampleTable.java
+++ /dev/null
@@ -1,81 +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.vuesample.model.db;
-
-import java.util.Locale;
-
-import org.apache.empire.data.DataType;
-import org.apache.empire.db.DBDatabase;
-import org.apache.empire.db.DBTable;
-import org.apache.empire.db.DBTableColumn;
-
-/**
- * Base class definition for all database tables Automatically generates a message-key for the field title e.g. for the column
- * EMPLOYEES.DATE_OF_BIRTH it generates the key "!field.title.employees.dateOfBirth";
- */
-public class SampleTable extends DBTable
-{
- private final static long serialVersionUID = 1L;
- public final String MESSAGE_KEY_PREFIX = "!field.title.";
-
- public SampleTable(String name, DBDatabase db)
- {
- super(name, db);
- }
-
- @Override
- protected void addColumn(DBTableColumn column)
- {
- // Set Translation Title
- String col = column.getBeanPropertyName();
- String tbl = getName().toLowerCase();
- String key = MESSAGE_KEY_PREFIX + tbl + "." + col;
- column.setTitle(key);
-
- // Set Default Control Type
- DataType type = column.getDataType();
- column.setControlType((type == DataType.BOOL) ? "checkbox" : "text");
-
- // Add Column
- super.addColumn(column);
- }
-
- public enum LanguageIndex {
- DE(Locale.GERMAN),
-
- EN(Locale.ENGLISH);
-
- private final Locale locale;
-
- private LanguageIndex(Locale locale)
- {
- this.locale = locale;
- }
-
- public Locale getLocale()
- {
- return this.locale;
- }
-
- public String getDBLangKey()
- {
- return this.name().toUpperCase();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-vue-example/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/empire-db-vue-example/src/main/webapp/WEB-INF/web.xml b/empire-db-vue-example/src/main/webapp/WEB-INF/web.xml
deleted file mode 100644
index 123c05a..0000000
--- a/empire-db-vue-example/src/main/webapp/WEB-INF/web.xml
+++ /dev/null
@@ -1,41 +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. -->
-<web-app id="vue-example" version="3.0"
- xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
-
- <servlet>
- <servlet-name>Jersey Web Application</servlet-name>
- <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
- <init-param>
- <param-name>jersey.config.server.provider.packages</param-name>
- <param-value>org.apache.empire.rest.service</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
-
- <servlet-mapping>
- <servlet-name>Jersey Web Application</servlet-name>
- <url-pattern>/ws/*</url-pattern>
- </servlet-mapping>
-
- <welcome-file-list>
- <welcome-file>index.html</welcome-file>
- </welcome-file-list>
-
- <listener>
- <listener-class>org.apache.empire.rest.service.listener.AppListener</listener-class>
- </listener>
-
-</web-app>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-vue-example/src/main/webapp/components/einput/einput.js
----------------------------------------------------------------------
diff --git a/empire-db-vue-example/src/main/webapp/components/einput/einput.js b/empire-db-vue-example/src/main/webapp/components/einput/einput.js
deleted file mode 100644
index e84c400..0000000
--- a/empire-db-vue-example/src/main/webapp/components/einput/einput.js
+++ /dev/null
@@ -1,25 +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.
- */
-Vue.component('einput', {
-
- props: ['col'],
-
- template: '<input v-bind:value="col.value" v-bind:type="col.meta.type" v-bind:required="col.meta.required" v-bind:readonly="col.meta.readonly" v-bind:maxlength="col.meta.size"></input>'
-
-});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-vue-example/src/main/webapp/index.html
----------------------------------------------------------------------
diff --git a/empire-db-vue-example/src/main/webapp/index.html b/empire-db-vue-example/src/main/webapp/index.html
deleted file mode 100644
index 6f332ee..0000000
--- a/empire-db-vue-example/src/main/webapp/index.html
+++ /dev/null
@@ -1,57 +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.
- -->
-<!DOCTYPE html>
-<html>
-<head>
- <title></title>
- <!-- <script src="js/jquery-3.2.1.min.js"></script> -->
- <!-- <script src="https://unpkg.com/vue"></script> -->
- <script src="components/einput/einput.js"></script>
-</head>
-<body>
-
- <div id="app">
-
- <table>
-
- <tr>
- <td>ID</td>
- <td><einput v-bind:col="employee.employeeId"></einput></td>
- </tr>
- <tr>
- <td>Last Name</td>
- <td><einput v-bind:col="employee.lastName"></einput></td>
- </tr>
- <tr>
- <td>First name</td>
- <td><einput v-bind:col="employee.firstName"></einput></td>
- </tr>
- <tr>
- <td>Date of Birth</td>
- <td><einput v-bind:col="employee.dateOfBirth"></einput></td>
- </tr>
-
- </table>
-
- </div>
-
- <script src="js/app.js"></script>
-
-</body>
-</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-vue-example/src/main/webapp/js/app.js
----------------------------------------------------------------------
diff --git a/empire-db-vue-example/src/main/webapp/js/app.js b/empire-db-vue-example/src/main/webapp/js/app.js
deleted file mode 100644
index eeed1c5..0000000
--- a/empire-db-vue-example/src/main/webapp/js/app.js
+++ /dev/null
@@ -1,42 +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.
- */
-var vm = new Vue({
-
- el: '#app',
-
- created: function () {
- this.loadEmployee(1);
- },
-
- data: {
- employee: {}
- },
-
- methods: {
-
- loadEmployee: function (id) {
- var self = this;
- $.getJSON("ws/employee/" + id, function(data) {
- self.employee = data;
- });
- }
-
- }
-
-});
\ No newline at end of file
[2/2] empire-db git commit: EMPIREDB-271 Moved example to the
examples folder and renamed it to empire-db-example-vue
Posted by do...@apache.org.
EMPIREDB-271
Moved example to the examples folder and renamed it to empire-db-example-vue
Project: http://git-wip-us.apache.org/repos/asf/empire-db/repo
Commit: http://git-wip-us.apache.org/repos/asf/empire-db/commit/caaec0de
Tree: http://git-wip-us.apache.org/repos/asf/empire-db/tree/caaec0de
Diff: http://git-wip-us.apache.org/repos/asf/empire-db/diff/caaec0de
Branch: refs/heads/master
Commit: caaec0de9a3bedcb41b32713884b07ba88fa10bd
Parents: 8dbffdb
Author: Rainer Döbele <do...@apache.org>
Authored: Tue Jan 16 10:13:21 2018 +0100
Committer: Rainer Döbele <do...@apache.org>
Committed: Tue Jan 16 10:13:21 2018 +0100
----------------------------------------------------------------------
.../empire-db-example-vue/.gitignore | 7 +
.../empire-db-example-vue/pom.xml | 142 +++++++++++
.../org/apache/empire/rest/EmpireColumn.java | 45 ++++
.../apache/empire/rest/EmpireColumnMeta.java | 63 +++++
.../empire/rest/service/EmployeeService.java | 179 +++++++++++++
.../org/apache/empire/rest/service/Service.java | 62 +++++
.../empire/rest/service/filter/CORSFilter.java | 40 +++
.../service/filter/ServiceRequestFilter.java | 59 +++++
.../service/filter/ServiceResponseFilter.java | 78 ++++++
.../rest/service/listener/AppListener.java | 248 +++++++++++++++++++
.../vuesample/model/EmpireServiceConsts.java | 31 +++
.../empire/vuesample/model/db/EmployeeBean.java | 65 +++++
.../empire/vuesample/model/db/SampleDB.java | 156 ++++++++++++
.../empire/vuesample/model/db/SampleTable.java | 81 ++++++
.../src/main/webapp/WEB-INF/web.xml | 41 +++
.../src/main/webapp/components/einput/einput.js | 25 ++
.../src/main/webapp/index.html | 57 +++++
.../src/main/webapp/js/app.js | 42 ++++
empire-db-examples/pom.xml | 1 +
empire-db-vue-example/.gitignore | 7 -
empire-db-vue-example/pom.xml | 144 -----------
.../org/apache/empire/rest/EmpireColumn.java | 45 ----
.../apache/empire/rest/EmpireColumnMeta.java | 63 -----
.../empire/rest/service/EmployeeService.java | 179 -------------
.../org/apache/empire/rest/service/Service.java | 62 -----
.../empire/rest/service/filter/CORSFilter.java | 40 ---
.../service/filter/ServiceRequestFilter.java | 59 -----
.../service/filter/ServiceResponseFilter.java | 78 ------
.../rest/service/listener/AppListener.java | 248 -------------------
.../vuesample/model/EmpireServiceConsts.java | 31 ---
.../empire/vuesample/model/db/EmployeeBean.java | 65 -----
.../empire/vuesample/model/db/SampleDB.java | 156 ------------
.../empire/vuesample/model/db/SampleTable.java | 81 ------
.../src/main/webapp/WEB-INF/web.xml | 41 ---
.../src/main/webapp/components/einput/einput.js | 25 --
.../src/main/webapp/index.html | 57 -----
empire-db-vue-example/src/main/webapp/js/app.js | 42 ----
37 files changed, 1422 insertions(+), 1423 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-examples/empire-db-example-vue/.gitignore
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-vue/.gitignore b/empire-db-examples/empire-db-example-vue/.gitignore
new file mode 100644
index 0000000..a76eba0
--- /dev/null
+++ b/empire-db-examples/empire-db-example-vue/.gitignore
@@ -0,0 +1,7 @@
+target/
+.settings/
+.metadata/
+.classpath
+.project
+.tern-project
+*.log
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-examples/empire-db-example-vue/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-vue/pom.xml b/empire-db-examples/empire-db-example-vue/pom.xml
new file mode 100644
index 0000000..a78c8f3
--- /dev/null
+++ b/empire-db-examples/empire-db-example-vue/pom.xml
@@ -0,0 +1,142 @@
+<?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. -->
+
+<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>2.4.7-SNAPSHOT</version>
+ </parent>
+ <artifactId>empire-db-example-vue</artifactId>
+ <packaging>war</packaging>
+ <name>Empire-db Vue.js Example</name>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+ <maven.compile.source>1.7</maven.compile.source>
+ <maven.compile.target>1.7</maven.compile.target>
+ </properties>
+
+ <dependencies>
+
+ <!-- Servlet API -->
+ <dependency>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- hsql -->
+ <dependency>
+ <groupId>hsqldb</groupId>
+ <artifactId>hsqldb</artifactId>
+ </dependency>
+
+ <!-- Tomcat JDBC Connection Pool -->
+ <dependency>
+ <groupId>org.apache.tomcat</groupId>
+ <artifactId>tomcat-dbcp</artifactId>
+ <version>8.0.39</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- Empire-db -->
+ <dependency>
+ <groupId>org.apache.empire-db</groupId>
+ <artifactId>empire-db</artifactId>
+ </dependency>
+
+ <!-- RS API -->
+ <dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>javax.ws.rs-api</artifactId>
+ <version>2.0</version>
+ </dependency>
+
+ <!-- Jersey -->
+ <dependency>
+ <groupId>org.glassfish.jersey.containers</groupId>
+ <artifactId>jersey-container-servlet-core</artifactId>
+ <version>2.25.1</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.glassfish.jersey.media</groupId>
+ <artifactId>jersey-media-json-jackson</artifactId>
+ <version>2.25.1</version>
+ </dependency>
+
+ <!-- common io -->
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <version>2.5</version>
+ </dependency>
+
+ <!-- Logging -->
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ </dependency>
+
+ <!-- Test <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId>
+ <version>4.12</version> </dependency> -->
+
+ </dependencies>
+
+ <build>
+
+ <finalName>evue</finalName>
+
+ <plugins>
+ <!-- Eclipse Web Tools Platform -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-eclipse-plugin</artifactId>
+ <configuration>
+ <m2eclipse>true</m2eclipse>
+ <downloadSources>true</downloadSources>
+ <wtpversion>1.5</wtpversion>
+ </configuration>
+ </plugin>
+
+ <!-- Maven Compiler Plugin -->
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>${maven.compile.source}</source>
+ <target>${maven.compile.target}</target>
+ </configuration>
+ </plugin>
+
+ <!-- Maven WAR Plugin -->
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <configuration>
+ <webResources>
+ <resource>
+ <directory>src/main/webapp</directory>
+ <filtering>true</filtering>
+ </resource>
+ </webResources>
+ </configuration>
+ </plugin>
+
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/EmpireColumn.java
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/EmpireColumn.java b/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/EmpireColumn.java
new file mode 100644
index 0000000..5c62f80
--- /dev/null
+++ b/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/EmpireColumn.java
@@ -0,0 +1,45 @@
+/*
+ * 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.rest;
+
+import org.apache.empire.rest.EmpireColumnMeta;
+
+public class EmpireColumn {
+
+ private Object value;
+
+ private EmpireColumnMeta meta;
+
+ public Object getValue() {
+ return this.value;
+ }
+
+ public void setValue(Object value) {
+ this.value = value;
+ }
+
+ public EmpireColumnMeta getMeta() {
+ return this.meta;
+ }
+
+ public void setMeta(EmpireColumnMeta meta) {
+ this.meta = meta;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/EmpireColumnMeta.java
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/EmpireColumnMeta.java b/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/EmpireColumnMeta.java
new file mode 100644
index 0000000..cd8f425
--- /dev/null
+++ b/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/EmpireColumnMeta.java
@@ -0,0 +1,63 @@
+/*
+ * 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.rest;
+
+public class EmpireColumnMeta {
+
+ private Double size;
+
+ private String type;
+
+ private boolean required;
+
+ private boolean readonly;
+
+ public Double getSize() {
+ return this.size;
+ }
+
+ public void setSize(Double size) {
+ this.size = size;
+ }
+
+ public String getType() {
+ return this.type;
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+ public boolean isRequired() {
+ return this.required;
+ }
+
+ public void setRequired(boolean required) {
+ this.required = required;
+ }
+
+ public boolean isReadonly() {
+ return this.readonly;
+ }
+
+ public void setReadonly(boolean readonly) {
+ this.readonly = readonly;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/service/EmployeeService.java
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/service/EmployeeService.java b/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/service/EmployeeService.java
new file mode 100644
index 0000000..8efcbe0
--- /dev/null
+++ b/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/service/EmployeeService.java
@@ -0,0 +1,179 @@
+/*
+ * 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.rest.service;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response.Status;
+
+import org.apache.empire.db.DBColumn;
+import org.apache.empire.db.DBCommand;
+import org.apache.empire.db.DBReader;
+import org.apache.empire.rest.EmpireColumn;
+import org.apache.empire.rest.EmpireColumnMeta;
+import org.apache.empire.vuesample.model.db.EmployeeBean;
+import org.apache.empire.vuesample.model.db.SampleDB;
+import org.apache.empire.vuesample.model.db.SampleDB.TEmployees;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Path("/employee")
+public class EmployeeService extends Service {
+
+ private static final Logger log = LoggerFactory.getLogger(EmployeeService.class);
+
+ @POST
+ @Path("/{employeeId}")
+ @Consumes(MediaType.APPLICATION_JSON)
+ public Response updateEmployee(@PathParam("employeeId") int employeeId, EmployeeBean employee) {
+
+ SampleDB db = getDatabase();
+ TEmployees TE = db.T_EMPLOYEES;
+
+ DBCommand cmd = db.createCommand();
+
+ // First name
+ cmd.set(TE.FIRST_NAME.to(TE.FIRST_NAME.validate(getValue(employee.getFirstName()))));
+
+ // Last name
+ cmd.set(TE.LAST_NAME.to(TE.LAST_NAME.validate(getValue(employee.getLastName()))));
+
+ // Date of Birth
+ cmd.set(TE.DATE_OF_BIRTH.to(TE.DATE_OF_BIRTH.validate(getValue(employee.getDateOfBirth()))));
+
+ cmd.where(TE.EMPLOYEE_ID.is(employeeId));
+
+ int executeUpdate = db.executeUpdate(cmd, getConnection());
+
+ if (executeUpdate == 0) {
+ return Response.status(Status.NOT_FOUND).build();
+ } else {
+ return Response.ok().build();
+ }
+
+ }
+
+ @GET
+ @Path("/{employeeId}")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getEmployee(@PathParam("employeeId") int employeeId) {
+
+ SampleDB db = getDatabase();
+
+ TEmployees TE = db.T_EMPLOYEES;
+
+ DBCommand cmd = db.createCommand();
+ cmd.select(TE.EMPLOYEE_ID, TE.LAST_NAME, TE.FIRST_NAME, TE.DATE_OF_BIRTH);
+ cmd.where(TE.EMPLOYEE_ID.is(employeeId));
+
+ DBReader reader = new DBReader();
+ EmployeeBean eb = new EmployeeBean();
+
+ try {
+ reader.open(cmd, getConnection());
+
+ if (!reader.moveNext()) {
+ // Employee not found
+ return Response.status(Status.NOT_FOUND).build();
+ }
+
+ eb = createEmployee(reader);
+
+ } finally {
+ reader.close();
+ }
+
+ return Response.ok(eb).build();
+ }
+
+ @GET
+ @Path("/list/")
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getEmployeeList() {
+
+ SampleDB db = getDatabase();
+
+ TEmployees TE = db.T_EMPLOYEES;
+
+ DBCommand cmd = db.createCommand();
+ cmd.select(TE.EMPLOYEE_ID, TE.LAST_NAME, TE.FIRST_NAME, TE.DATE_OF_BIRTH);
+
+ DBReader reader = new DBReader();
+ List<EmployeeBean> list = new ArrayList<>();
+
+ try {
+ reader.open(cmd, getConnection());
+ while (reader.moveNext()) {
+ list.add(createEmployee(reader));
+ }
+
+ } finally {
+ reader.close();
+ }
+
+ return Response.ok(list).build();
+
+ }
+
+ private EmployeeBean createEmployee(DBReader reader) {
+
+ TEmployees TE = getDatabase().T_EMPLOYEES;
+
+ EmployeeBean eb = new EmployeeBean();
+ eb.setEmployeeId(createEmpireColumn(reader, TE.EMPLOYEE_ID));
+ eb.setLastName(createEmpireColumn(reader, TE.LAST_NAME));
+ eb.setFirstName(createEmpireColumn(reader, TE.FIRST_NAME));
+ eb.setDateOfBirth(createEmpireColumn(reader, TE.DATE_OF_BIRTH));
+
+ return eb;
+ }
+
+ private EmpireColumn createEmpireColumn(DBReader reader, DBColumn col) {
+
+ EmpireColumn ec = new EmpireColumn();
+ // Value
+ ec.setValue(reader.getValue(col));
+ // Meta
+ EmpireColumnMeta meta = new EmpireColumnMeta();
+ meta.setSize(col.getSize());
+ meta.setType(col.getDataType().name());
+ meta.setRequired(col.isRequired());
+ meta.setReadonly(col.isReadOnly());
+ ec.setMeta(meta);
+
+ return ec;
+ }
+
+ private Object getValue(EmpireColumn ec) {
+ if (ec == null) {
+ return null;
+ }
+ return ec.getValue();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/service/Service.java
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/service/Service.java b/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/service/Service.java
new file mode 100644
index 0000000..f1a449d
--- /dev/null
+++ b/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/service/Service.java
@@ -0,0 +1,62 @@
+/*
+ * 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.rest.service;
+
+import java.sql.Connection;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.core.Context;
+
+import org.apache.empire.vuesample.model.EmpireServiceConsts;
+import org.apache.empire.vuesample.model.db.SampleDB;
+import org.glassfish.jersey.server.ContainerRequest;
+
+public abstract class Service {
+
+ @Context
+ private ServletContext context;
+
+ @Context
+ private ContainerRequestContext containerRequestContext;
+
+ @Context
+ private HttpServletRequest req;
+
+ public SampleDB getDatabase() {
+ return (SampleDB) this.context.getAttribute(EmpireServiceConsts.ATTRIBUTE_DB);
+ }
+
+ public Connection getConnection() {
+ ContainerRequest containerRequest = (ContainerRequest) this.containerRequestContext;
+ return (Connection) containerRequest.getProperty(EmpireServiceConsts.ATTRIBUTE_CONNECTION);
+ }
+
+ public ServletRequest getServletRequest() {
+ return this.req;
+ }
+
+ public String getRemoteAddr() {
+ // TODO check X-Real-IP / X-Forwarded-For
+ return this.req.getRemoteAddr();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/service/filter/CORSFilter.java
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/service/filter/CORSFilter.java b/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/service/filter/CORSFilter.java
new file mode 100644
index 0000000..b36fe6a
--- /dev/null
+++ b/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/service/filter/CORSFilter.java
@@ -0,0 +1,40 @@
+/*
+ * 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.rest.service.filter;
+
+import java.io.IOException;
+
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.ext.Provider;
+
+@Provider
+public class CORSFilter implements ContainerResponseFilter {
+
+ @Override
+ public void filter(final ContainerRequestContext requestContext, final ContainerResponseContext cres) throws IOException {
+ // cres.getHeaders().add("Access-Control-Allow-Origin", "*");
+ // cres.getHeaders().add("Access-Control-Allow-Headers", "origin, content-type, accept, authorization");
+ // cres.getHeaders().add("Access-Control-Allow-Credentials", "true");
+ // cres.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD");
+ // cres.getHeaders().add("Access-Control-Max-Age", "1209600");
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/service/filter/ServiceRequestFilter.java
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/service/filter/ServiceRequestFilter.java b/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/service/filter/ServiceRequestFilter.java
new file mode 100644
index 0000000..183595c
--- /dev/null
+++ b/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/service/filter/ServiceRequestFilter.java
@@ -0,0 +1,59 @@
+/*
+ * 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.rest.service.filter;
+
+import java.io.IOException;
+import java.sql.Connection;
+
+import javax.annotation.Priority;
+import javax.servlet.ServletContext;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerRequestFilter;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.empire.rest.service.listener.AppListener;
+import org.apache.empire.vuesample.model.EmpireServiceConsts;
+import org.glassfish.jersey.server.ContainerRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Provider
+@Priority(0)
+public class ServiceRequestFilter implements ContainerRequestFilter {
+
+ private static final Logger log = LoggerFactory.getLogger(ServiceRequestFilter.class);
+
+ @Context
+ private ServletContext servletContext;
+
+ @Override
+ public void filter(ContainerRequestContext requestContext) throws IOException {
+
+ ContainerRequest containerRequest = (ContainerRequest) requestContext;
+
+ // get Connection from pool
+ Connection conn = AppListener.getJDBCConnection(this.servletContext);
+
+ // Add to context
+ containerRequest.setProperty(EmpireServiceConsts.ATTRIBUTE_CONNECTION, conn);
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/service/filter/ServiceResponseFilter.java
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/service/filter/ServiceResponseFilter.java b/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/service/filter/ServiceResponseFilter.java
new file mode 100644
index 0000000..b2dedb0
--- /dev/null
+++ b/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/service/filter/ServiceResponseFilter.java
@@ -0,0 +1,78 @@
+/*
+ * 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.rest.service.filter;
+
+import java.io.IOException;
+import java.sql.Connection;
+import java.sql.SQLException;
+
+import javax.annotation.Priority;
+import javax.ws.rs.container.ContainerRequestContext;
+import javax.ws.rs.container.ContainerResponseContext;
+import javax.ws.rs.container.ContainerResponseFilter;
+import javax.ws.rs.core.Response.Status.Family;
+import javax.ws.rs.ext.Provider;
+
+import org.apache.empire.vuesample.model.EmpireServiceConsts;
+import org.glassfish.jersey.server.ContainerRequest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Provider
+@Priority(99999)
+public class ServiceResponseFilter implements ContainerResponseFilter {
+
+ private static final Logger log = LoggerFactory.getLogger(ServiceResponseFilter.class);
+
+ @Override
+ public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
+
+ // responseContext.getHeaders().putSingle(key, value);
+
+ ContainerRequest containerRequest = (ContainerRequest) requestContext;
+ Connection conn = (Connection) containerRequest.getProperty(EmpireServiceConsts.ATTRIBUTE_CONNECTION);
+
+ boolean success = responseContext.getStatusInfo().getFamily() == Family.SUCCESSFUL;
+
+ try {
+
+ if (conn == null || conn.isClosed()) {
+ // Connection not found or already closed
+ return;
+ }
+
+ if (success) {
+ // commit
+ conn.commit();
+ } else {
+ // rollback
+ conn.rollback();
+ }
+
+ // close connection / return to pool
+ conn.close();
+
+ } catch (SQLException e) {
+ log.error("Error releasing connection", e);
+ responseContext.setStatus(500);
+ }
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/service/listener/AppListener.java
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/service/listener/AppListener.java b/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/service/listener/AppListener.java
new file mode 100644
index 0000000..a3c1249
--- /dev/null
+++ b/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/rest/service/listener/AppListener.java
@@ -0,0 +1,248 @@
+/*
+ * 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.rest.service.listener;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+
+import org.apache.empire.commons.StringUtils;
+import org.apache.empire.db.DBCommand;
+import org.apache.empire.db.DBDatabase;
+import org.apache.empire.db.DBDatabaseDriver;
+import org.apache.empire.db.DBRecord;
+import org.apache.empire.db.DBSQLScript;
+import org.apache.empire.db.exceptions.QueryFailedException;
+import org.apache.empire.db.hsql.DBDatabaseDriverHSql;
+import org.apache.empire.db.mysql.DBDatabaseDriverMySQL;
+import org.apache.empire.vuesample.model.EmpireServiceConsts;
+import org.apache.empire.vuesample.model.db.SampleDB;
+import org.apache.log4j.ConsoleAppender;
+import org.apache.log4j.Level;
+import org.apache.log4j.PatternLayout;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class AppListener implements ServletContextListener {
+
+ private static final Logger log = LoggerFactory.getLogger(AppListener.class);
+
+ @Override
+ public void contextInitialized(ServletContextEvent sce) {
+
+ log.debug("contextInitialized");
+
+ // Logging
+ initLogging();
+
+ //
+ Connection conn = getJDBCConnection(sce.getServletContext());
+
+ // DB
+ SampleDB db = initDatabase(sce.getServletContext());
+ DBDatabaseDriver driver = new DBDatabaseDriverMySQL();
+ db.open(driver, conn);
+
+ // Add to context
+ sce.getServletContext().setAttribute(EmpireServiceConsts.ATTRIBUTE_DB, db);
+ // sce.getServletContext().setAttribute(MobileImportServiceConsts.ATTRIBUTE_DATASOURCE, ds);
+ // sce.getServletContext().setAttribute(MobileImportServiceConsts.ATTRIBUTE_CONFIG, config);
+
+ log.debug("contextInitialized done");
+
+ }
+
+ @Override
+ public void contextDestroyed(ServletContextEvent sce) {
+ log.debug("contextDestroyed");
+ log.debug("contextDestroyed done");
+ }
+
+ private SampleDB initDatabase(ServletContext ctx) {
+ SampleDB db = new SampleDB();
+
+ // Open Database (and create if not existing)
+ DBDatabaseDriver driver = new DBDatabaseDriverHSql();
+ log.info("Opening database '{}' using driver '{}'", db.getClass().getSimpleName(), driver.getClass().getSimpleName());
+ Connection conn = null;
+ try {
+ conn = getJDBCConnection(ctx);
+ db.open(driver, conn);
+ if (!databaseExists(db, conn)) {
+ // STEP 4: Create Database
+ log.info("Creating database {}", db.getClass().getSimpleName());
+ createSampleDatabase(db, driver, conn);
+ }
+ } finally {
+ releaseConnection(db, conn, true);
+ }
+
+ return db;
+ }
+
+ private static boolean databaseExists(SampleDB db, Connection conn) {
+ // Check wether DB exists
+ DBCommand cmd = db.createCommand();
+ cmd.select(db.T_DEPARTMENTS.count());
+ try {
+ return (db.querySingleInt(cmd, -1, conn) >= 0);
+ } catch (QueryFailedException e) {
+ return false;
+ }
+ }
+
+ private static void createSampleDatabase(SampleDB db, DBDatabaseDriver driver, Connection conn) {
+ // create DLL for Database Definition
+ DBSQLScript script = new DBSQLScript();
+ db.getCreateDDLScript(driver, script);
+ // Show DLL Statements
+ System.out.println(script.toString());
+ // Execute Script
+ script.executeAll(driver, conn, false);
+ db.commit(conn);
+ // Open again
+ if (!db.isOpen()) {
+ db.open(driver, conn);
+ }
+ // Insert Sample Departments
+ insertDepartmentSampleRecord(db, conn, "Procurement", "ITTK");
+ int idDevDep = insertDepartmentSampleRecord(db, conn, "Development", "ITTK");
+ int idSalDep = insertDepartmentSampleRecord(db, conn, "Sales", "ITTK");
+ // Insert Sample Employees
+ insertEmployeeSampleRecord(db, conn, "Mr.", "Eugen", "Miller", "M", idDevDep);
+ insertEmployeeSampleRecord(db, conn, "Mr.", "Max", "Mc. Callahan", "M", idDevDep);
+ insertEmployeeSampleRecord(db, conn, "Mrs.", "Anna", "Smith", "F", idSalDep);
+ // Commit
+ db.commit(conn);
+ }
+
+ private static int insertDepartmentSampleRecord(SampleDB db, Connection conn, String department_name, String businessUnit) {
+ // Insert a Department
+ DBRecord rec = new DBRecord();
+ rec.create(db.T_DEPARTMENTS);
+ rec.setValue(db.T_DEPARTMENTS.NAME, department_name);
+ rec.setValue(db.T_DEPARTMENTS.BUSINESS_UNIT, businessUnit);
+ try {
+ rec.update(conn);
+ } catch (Exception e) {
+ log.error(e.getLocalizedMessage());
+ return 0;
+ }
+ // Return Department ID
+ return rec.getInt(db.T_DEPARTMENTS.DEPARTMENT_ID);
+ }
+
+ /*
+ * Insert a person
+ */
+ private static int insertEmployeeSampleRecord(SampleDB db, Connection conn, String salutation, String firstName, String lastName, String gender, int depID) {
+ // Insert an Employee
+ DBRecord rec = new DBRecord();
+ rec.create(db.T_EMPLOYEES);
+ rec.setValue(db.T_EMPLOYEES.SALUTATION, salutation);
+ rec.setValue(db.T_EMPLOYEES.FIRST_NAME, firstName);
+ rec.setValue(db.T_EMPLOYEES.LAST_NAME, lastName);
+ rec.setValue(db.T_EMPLOYEES.GENDER, gender);
+ rec.setValue(db.T_EMPLOYEES.DEPARTMENT_ID, depID);
+ try {
+ rec.update(conn);
+ } catch (Exception e) {
+ log.error(e.getLocalizedMessage());
+ return 0;
+ }
+ // Return Employee ID
+ return rec.getInt(db.T_EMPLOYEES.EMPLOYEE_ID);
+ }
+
+ public static Connection getJDBCConnection(ServletContext appContext) {
+ // Establish a new database connection
+ Connection conn = null;
+
+ String jdbcURL = "jdbc:hsqldb:file:hsqldb/sample;shutdown=true";
+ String jdbcUser = "sa";
+ String jdbcPwd = "";
+
+ if (jdbcURL.indexOf("file:") > 0) {
+ jdbcURL = StringUtils.replace(jdbcURL, "file:", "file:" + appContext.getRealPath("/"));
+ }
+ // Connect
+ log.info("Connecting to Database'" + jdbcURL + "' / User=" + jdbcUser);
+ try { // Connect to the databse
+ Class.forName("org.hsqldb.jdbcDriver").newInstance();
+ conn = DriverManager.getConnection(jdbcURL, jdbcUser, jdbcPwd);
+ log.info("Connected successfully");
+ // set the AutoCommit to false this session. You must commit
+ // explicitly now
+ conn.setAutoCommit(false);
+ log.info("AutoCommit is " + conn.getAutoCommit());
+
+ } catch (Exception e) {
+ log.error("Failed to connect directly to '" + jdbcURL + "' / User=" + jdbcUser);
+ log.error(e.toString());
+ throw new RuntimeException(e);
+ }
+ return conn;
+ }
+
+ protected void releaseConnection(DBDatabase db, Connection conn, boolean commit) {
+ // release connection
+ if (conn == null) {
+ return;
+ }
+ // Commit or rollback connection depending on the exit code
+ if (commit) { // success: commit all changes
+ db.commit(conn);
+ log.debug("REQUEST {}: commited.");
+ } else { // failure: rollback all changes
+ db.rollback(conn);
+ log.debug("REQUEST {}: rolled back.");
+ }
+ }
+
+ private void initLogging() {
+
+ // Init Logging
+ ConsoleAppender consoleAppender = new ConsoleAppender();
+ String pattern = "%-5p [%d{yyyy/MM/dd HH:mm}]: %m at %l %n";
+ consoleAppender.setLayout(new PatternLayout(pattern));
+ consoleAppender.activateOptions();
+
+ org.apache.log4j.Logger.getRootLogger().addAppender(consoleAppender);
+ org.apache.log4j.Logger.getRootLogger().setLevel(Level.ALL);
+
+ Level loglevel = Level.DEBUG;
+ log.info("Setting LogLevel to {}", loglevel);
+
+ // RootLogger
+ org.apache.log4j.Logger.getRootLogger().setLevel(Level.INFO);
+
+ // Empire-db Logs
+ org.apache.log4j.Logger empireLog = org.apache.log4j.Logger.getLogger("org.apache.empire.db.DBDatabase");
+ empireLog.setLevel(loglevel);
+
+ // Vue.js Sample
+ org.apache.log4j.Logger miLog = org.apache.log4j.Logger.getLogger("org.apache.empire.rest");
+ miLog.setLevel(loglevel);
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/vuesample/model/EmpireServiceConsts.java
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/vuesample/model/EmpireServiceConsts.java b/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/vuesample/model/EmpireServiceConsts.java
new file mode 100644
index 0000000..833e968
--- /dev/null
+++ b/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/vuesample/model/EmpireServiceConsts.java
@@ -0,0 +1,31 @@
+/*
+ * 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.vuesample.model;
+
+public class EmpireServiceConsts {
+
+ public static final String ATTRIBUTE_DB = "db";
+
+ public static final String ATTRIBUTE_CONNECTION = "connection";
+
+ public static final String ATTRIBUTE_DATASOURCE = "ds";
+
+ public static final String ATTRIBUTE_CONFIG = "config";
+
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/vuesample/model/db/EmployeeBean.java
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/vuesample/model/db/EmployeeBean.java b/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/vuesample/model/db/EmployeeBean.java
new file mode 100644
index 0000000..622c02b
--- /dev/null
+++ b/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/vuesample/model/db/EmployeeBean.java
@@ -0,0 +1,65 @@
+/*
+ * 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.vuesample.model.db;
+
+import org.apache.empire.rest.EmpireColumn;
+
+public class EmployeeBean {
+
+ private EmpireColumn employeeId;
+
+ private EmpireColumn firstName;
+
+ private EmpireColumn lastName;
+
+ private EmpireColumn dateOfBirth;
+
+ public EmpireColumn getEmployeeId() {
+ return this.employeeId;
+ }
+
+ public void setEmployeeId(EmpireColumn employeeId) {
+ this.employeeId = employeeId;
+ }
+
+ public EmpireColumn getFirstName() {
+ return this.firstName;
+ }
+
+ public void setFirstName(EmpireColumn firstName) {
+ this.firstName = firstName;
+ }
+
+ public EmpireColumn getLastName() {
+ return this.lastName;
+ }
+
+ public void setLastName(EmpireColumn lastName) {
+ this.lastName = lastName;
+ }
+
+ public EmpireColumn getDateOfBirth() {
+ return this.dateOfBirth;
+ }
+
+ public void setDateOfBirth(EmpireColumn dateOfBirth) {
+ this.dateOfBirth = dateOfBirth;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/vuesample/model/db/SampleDB.java
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/vuesample/model/db/SampleDB.java b/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/vuesample/model/db/SampleDB.java
new file mode 100644
index 0000000..735d323
--- /dev/null
+++ b/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/vuesample/model/db/SampleDB.java
@@ -0,0 +1,156 @@
+/*
+ * 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.vuesample.model.db;
+
+import org.apache.empire.commons.Options;
+import org.apache.empire.data.DataMode;
+import org.apache.empire.data.DataType;
+import org.apache.empire.db.DBColumn;
+import org.apache.empire.db.DBDatabase;
+import org.apache.empire.db.DBTableColumn;
+
+public class SampleDB extends DBDatabase
+{
+ private final static long serialVersionUID = 1L;
+
+ // Declare all Tables
+ public final TDepartments T_DEPARTMENTS = new TDepartments(this);
+ public final TEmployees T_EMPLOYEES = new TEmployees(this);
+
+ /**
+ * Constructor SampleDB
+ */
+ public SampleDB()
+ {
+ // Define Foreign-Key Relations
+ addRelation(T_EMPLOYEES.DEPARTMENT_ID.referenceOn(T_DEPARTMENTS.DEPARTMENT_ID));
+ }
+
+ // Needed for the DBELResolver
+ @Override
+ protected void register(String id)
+ {
+ super.register("db");
+ }
+
+ /**
+ * This class represents the definition of the Departments table.
+ */
+ public static class TDepartments extends SampleTable
+ {
+ private static final 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 TDepartments(DBDatabase db)
+ {
+ super("DEPARTMENTS", db);
+ // ID
+ DEPARTMENT_ID = addColumn("DEPARTMENT_ID", DataType.AUTOINC, 0, DataMode.NotNull, "DEP_ID_SEQUENCE");
+ NAME = addColumn("NAME", DataType.TEXT, 80, DataMode.NotNull);
+ HEAD = addColumn("HEAD", DataType.TEXT, 80, DataMode.Nullable);
+ BUSINESS_UNIT = addColumn("BUSINESS_UNIT", DataType.TEXT, 4, DataMode.NotNull, "ITTK");
+ UPDATE_TIMESTAMP= addColumn("UPDATE_TIMESTAMP", DataType.DATETIME, 0, DataMode.NotNull);
+
+ // 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 TEmployees extends SampleTable
+ {
+ private static final long serialVersionUID = 1L;
+
+ public final DBTableColumn EMPLOYEE_ID;
+ public final DBTableColumn SALUTATION;
+// public final DBTableColumn PICTURE;
+ public final DBTableColumn FIRST_NAME;
+ public final DBTableColumn LAST_NAME;
+ 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 RETIRED;
+ public final DBTableColumn UPDATE_TIMESTAMP;
+ public TEmployees(DBDatabase db)
+ {
+ super("EMPLOYEES", db);
+ // ID
+ EMPLOYEE_ID = addColumn("EMPLOYEE_ID", DataType.AUTOINC, 0, DataMode.NotNull, "EMPLOYEE_ID_SEQUENCE");
+ SALUTATION = addColumn("SALUTATION", DataType.TEXT, 5, DataMode.Nullable);
+ FIRST_NAME = addColumn("FIRST_NAME", DataType.TEXT, 40, DataMode.NotNull);
+ LAST_NAME = addColumn("LAST_NAME", DataType.TEXT, 40, DataMode.NotNull);
+ DATE_OF_BIRTH = addColumn("DATE_OF_BIRTH", DataType.DATE, 0, DataMode.Nullable);
+ DEPARTMENT_ID = addColumn("DEPARTMENT_ID", DataType.INTEGER, 0, DataMode.NotNull);
+ GENDER = addColumn("GENDER", DataType.TEXT, 1, DataMode.Nullable);
+ PHONE_NUMBER = addColumn("PHONE_NUMBER", DataType.TEXT, 40, DataMode.Nullable);
+ EMAIL = addColumn("EMAIL", DataType.TEXT, 80, DataMode.Nullable);
+ RETIRED = addColumn("RETIRED", DataType.BOOL, 0, DataMode.NotNull, false);
+ // PICTURE = addColumn("PICTURE", DataType.BLOB, 0, DataMode.Nullable);
+ UPDATE_TIMESTAMP= addColumn("UPDATE_TIMESTAMP", DataType.DATETIME, 0, DataMode.NotNull);
+
+ // Primary Key
+ setPrimaryKey(EMPLOYEE_ID);
+ // Set other Indexes
+ addIndex("PERSON_NAME_IDX", true, new DBColumn[] { FIRST_NAME, LAST_NAME, DATE_OF_BIRTH });
+
+ // Set timestamp column for save updates
+ setTimestampColumn(UPDATE_TIMESTAMP);
+
+ // Create Options for GENDER column
+ Options genders = new Options();
+ genders.set("M", "!option.employee.gender.male");
+ genders.set("F", "!option.employee.gender.female");
+ GENDER.setOptions(genders);
+ GENDER.setControlType("select");
+
+ Options retired = new Options();
+ retired.set(false, "!option.employee.active");
+ retired.set(true, "!option.employee.retired");
+ RETIRED.setOptions(retired);
+ RETIRED.setControlType("checkbox");
+
+ // Set special control types
+ DEPARTMENT_ID.setControlType("select");
+ PHONE_NUMBER .setControlType("phone");
+
+ // Set optional formatting attributes
+ DATE_OF_BIRTH.setAttribute("format:date", "yyyy-MM-dd");
+
+ // PICTURE.setControlType("blob");
+
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/vuesample/model/db/SampleTable.java
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/vuesample/model/db/SampleTable.java b/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/vuesample/model/db/SampleTable.java
new file mode 100644
index 0000000..353bf75
--- /dev/null
+++ b/empire-db-examples/empire-db-example-vue/src/main/java/org/apache/empire/vuesample/model/db/SampleTable.java
@@ -0,0 +1,81 @@
+/*
+ * 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.vuesample.model.db;
+
+import java.util.Locale;
+
+import org.apache.empire.data.DataType;
+import org.apache.empire.db.DBDatabase;
+import org.apache.empire.db.DBTable;
+import org.apache.empire.db.DBTableColumn;
+
+/**
+ * Base class definition for all database tables Automatically generates a message-key for the field title e.g. for the column
+ * EMPLOYEES.DATE_OF_BIRTH it generates the key "!field.title.employees.dateOfBirth";
+ */
+public class SampleTable extends DBTable
+{
+ private final static long serialVersionUID = 1L;
+ public final String MESSAGE_KEY_PREFIX = "!field.title.";
+
+ public SampleTable(String name, DBDatabase db)
+ {
+ super(name, db);
+ }
+
+ @Override
+ protected void addColumn(DBTableColumn column)
+ {
+ // Set Translation Title
+ String col = column.getBeanPropertyName();
+ String tbl = getName().toLowerCase();
+ String key = MESSAGE_KEY_PREFIX + tbl + "." + col;
+ column.setTitle(key);
+
+ // Set Default Control Type
+ DataType type = column.getDataType();
+ column.setControlType((type == DataType.BOOL) ? "checkbox" : "text");
+
+ // Add Column
+ super.addColumn(column);
+ }
+
+ public enum LanguageIndex {
+ DE(Locale.GERMAN),
+
+ EN(Locale.ENGLISH);
+
+ private final Locale locale;
+
+ private LanguageIndex(Locale locale)
+ {
+ this.locale = locale;
+ }
+
+ public Locale getLocale()
+ {
+ return this.locale;
+ }
+
+ public String getDBLangKey()
+ {
+ return this.name().toUpperCase();
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-examples/empire-db-example-vue/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-vue/src/main/webapp/WEB-INF/web.xml b/empire-db-examples/empire-db-example-vue/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..cfb49fe
--- /dev/null
+++ b/empire-db-examples/empire-db-example-vue/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,41 @@
+<?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. -->
+<web-app id="vue-example" version="3.0"
+ xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
+
+ <servlet>
+ <servlet-name>Jersey Web Application</servlet-name>
+ <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>jersey.config.server.provider.packages</param-name>
+ <param-value>org.apache.empire.rest.service</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>Jersey Web Application</servlet-name>
+ <url-pattern>/ws/*</url-pattern>
+ </servlet-mapping>
+
+ <welcome-file-list>
+ <welcome-file>index.html</welcome-file>
+ </welcome-file-list>
+
+ <listener>
+ <listener-class>org.apache.empire.rest.service.listener.AppListener</listener-class>
+ </listener>
+
+</web-app>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-examples/empire-db-example-vue/src/main/webapp/components/einput/einput.js
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-vue/src/main/webapp/components/einput/einput.js b/empire-db-examples/empire-db-example-vue/src/main/webapp/components/einput/einput.js
new file mode 100644
index 0000000..85ca24d
--- /dev/null
+++ b/empire-db-examples/empire-db-example-vue/src/main/webapp/components/einput/einput.js
@@ -0,0 +1,25 @@
+/*
+ * 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.
+ */
+Vue.component('einput', {
+
+ props: ['col'],
+
+ template: '<input v-bind:value="col.value" v-bind:type="col.meta.type" v-bind:required="col.meta.required" v-bind:readonly="col.meta.readonly" v-bind:maxlength="col.meta.size"></input>'
+
+});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-examples/empire-db-example-vue/src/main/webapp/index.html
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-vue/src/main/webapp/index.html b/empire-db-examples/empire-db-example-vue/src/main/webapp/index.html
new file mode 100644
index 0000000..ee9eb10
--- /dev/null
+++ b/empire-db-examples/empire-db-example-vue/src/main/webapp/index.html
@@ -0,0 +1,57 @@
+<!--
+ 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.
+ -->
+<!DOCTYPE html>
+<html>
+<head>
+ <title></title>
+ <!-- <script src="js/jquery-3.2.1.min.js"></script> -->
+ <!-- <script src="https://unpkg.com/vue"></script> -->
+ <script src="components/einput/einput.js"></script>
+</head>
+<body>
+
+ <div id="app">
+
+ <table>
+
+ <tr>
+ <td>ID</td>
+ <td><einput v-bind:col="employee.employeeId"></einput></td>
+ </tr>
+ <tr>
+ <td>Last Name</td>
+ <td><einput v-bind:col="employee.lastName"></einput></td>
+ </tr>
+ <tr>
+ <td>First name</td>
+ <td><einput v-bind:col="employee.firstName"></einput></td>
+ </tr>
+ <tr>
+ <td>Date of Birth</td>
+ <td><einput v-bind:col="employee.dateOfBirth"></einput></td>
+ </tr>
+
+ </table>
+
+ </div>
+
+ <script src="js/app.js"></script>
+
+</body>
+</html>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-examples/empire-db-example-vue/src/main/webapp/js/app.js
----------------------------------------------------------------------
diff --git a/empire-db-examples/empire-db-example-vue/src/main/webapp/js/app.js b/empire-db-examples/empire-db-example-vue/src/main/webapp/js/app.js
new file mode 100644
index 0000000..c516657
--- /dev/null
+++ b/empire-db-examples/empire-db-example-vue/src/main/webapp/js/app.js
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+var vm = new Vue({
+
+ el: '#app',
+
+ created: function () {
+ this.loadEmployee(1);
+ },
+
+ data: {
+ employee: {}
+ },
+
+ methods: {
+
+ loadEmployee: function (id) {
+ var self = this;
+ $.getJSON("ws/employee/" + id, function(data) {
+ self.employee = data;
+ });
+ }
+
+ }
+
+});
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-examples/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-examples/pom.xml b/empire-db-examples/pom.xml
index b826144..a2cca98 100644
--- a/empire-db-examples/pom.xml
+++ b/empire-db-examples/pom.xml
@@ -39,6 +39,7 @@
<module>empire-db-example-struts2</module>
<module>empire-db-example-struts2-cxf</module>
<module>empire-db-example-jsf2</module>
+ <module>empire-db-example-vue</module>
<!-- <module>empire-db-example-codegen</module> -->
</modules>
<build>
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-vue-example/.gitignore
----------------------------------------------------------------------
diff --git a/empire-db-vue-example/.gitignore b/empire-db-vue-example/.gitignore
deleted file mode 100644
index a76eba0..0000000
--- a/empire-db-vue-example/.gitignore
+++ /dev/null
@@ -1,7 +0,0 @@
-target/
-.settings/
-.metadata/
-.classpath
-.project
-.tern-project
-*.log
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-vue-example/pom.xml
----------------------------------------------------------------------
diff --git a/empire-db-vue-example/pom.xml b/empire-db-vue-example/pom.xml
deleted file mode 100644
index 7afcfa2..0000000
--- a/empire-db-vue-example/pom.xml
+++ /dev/null
@@ -1,144 +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. -->
-
-<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-parent</artifactId>
- <groupId>org.apache.empire-db</groupId>
- <version>2.4.7-SNAPSHOT</version>
- </parent>
-
- <artifactId>empire-db-vue-example</artifactId>
- <packaging>war</packaging>
- <name>Empire-db Vue.js Example</name>
-
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
- <maven.compile.source>1.6</maven.compile.source>
- <maven.compile.target>1.6</maven.compile.target>
- </properties>
-
- <dependencies>
-
- <!-- Servlet API -->
- <dependency>
- <groupId>javax.servlet</groupId>
- <artifactId>servlet-api</artifactId>
- <scope>provided</scope>
- </dependency>
-
- <!-- hsql -->
- <dependency>
- <groupId>hsqldb</groupId>
- <artifactId>hsqldb</artifactId>
- </dependency>
-
- <!-- Tomcat JDBC Connection Pool -->
- <dependency>
- <groupId>org.apache.tomcat</groupId>
- <artifactId>tomcat-dbcp</artifactId>
- <version>8.0.39</version>
- <scope>provided</scope>
- </dependency>
-
- <!-- Empire-db -->
- <dependency>
- <groupId>org.apache.empire-db</groupId>
- <artifactId>empire-db</artifactId>
- </dependency>
-
- <!-- RS API -->
- <dependency>
- <groupId>javax.ws.rs</groupId>
- <artifactId>javax.ws.rs-api</artifactId>
- <version>2.0</version>
- </dependency>
-
- <!-- Jersey -->
- <dependency>
- <groupId>org.glassfish.jersey.containers</groupId>
- <artifactId>jersey-container-servlet-core</artifactId>
- <version>2.25.1</version>
- </dependency>
-
- <dependency>
- <groupId>org.glassfish.jersey.media</groupId>
- <artifactId>jersey-media-json-jackson</artifactId>
- <version>2.25.1</version>
- </dependency>
-
- <!-- common io -->
- <dependency>
- <groupId>commons-io</groupId>
- <artifactId>commons-io</artifactId>
- <version>2.5</version>
- </dependency>
-
- <!-- Logging -->
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- </dependency>
-
- <!-- Test <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId>
- <version>4.12</version> </dependency> -->
-
- </dependencies>
-
- <build>
-
- <finalName>evue</finalName>
-
- <plugins>
- <!-- Eclipse Web Tools Platform -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-eclipse-plugin</artifactId>
- <configuration>
- <m2eclipse>true</m2eclipse>
- <downloadSources>true</downloadSources>
- <wtpversion>1.5</wtpversion>
- </configuration>
- </plugin>
-
- <!-- Maven Compiler Plugin -->
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.8</source>
- <target>1.8</target>
- </configuration>
- </plugin>
-
- <!-- Maven WAR Plugin -->
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-war-plugin</artifactId>
- <configuration>
- <webResources>
- <resource>
- <directory>src/main/webapp</directory>
- <filtering>true</filtering>
- </resource>
- </webResources>
- </configuration>
- </plugin>
-
- </plugins>
- </build>
-
-</project>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-vue-example/src/main/java/org/apache/empire/rest/EmpireColumn.java
----------------------------------------------------------------------
diff --git a/empire-db-vue-example/src/main/java/org/apache/empire/rest/EmpireColumn.java b/empire-db-vue-example/src/main/java/org/apache/empire/rest/EmpireColumn.java
deleted file mode 100644
index 3b0c9a6..0000000
--- a/empire-db-vue-example/src/main/java/org/apache/empire/rest/EmpireColumn.java
+++ /dev/null
@@ -1,45 +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.rest;
-
-import org.apache.empire.rest.EmpireColumnMeta;
-
-public class EmpireColumn {
-
- private Object value;
-
- private EmpireColumnMeta meta;
-
- public Object getValue() {
- return this.value;
- }
-
- public void setValue(Object value) {
- this.value = value;
- }
-
- public EmpireColumnMeta getMeta() {
- return this.meta;
- }
-
- public void setMeta(EmpireColumnMeta meta) {
- this.meta = meta;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-vue-example/src/main/java/org/apache/empire/rest/EmpireColumnMeta.java
----------------------------------------------------------------------
diff --git a/empire-db-vue-example/src/main/java/org/apache/empire/rest/EmpireColumnMeta.java b/empire-db-vue-example/src/main/java/org/apache/empire/rest/EmpireColumnMeta.java
deleted file mode 100644
index 3a30390..0000000
--- a/empire-db-vue-example/src/main/java/org/apache/empire/rest/EmpireColumnMeta.java
+++ /dev/null
@@ -1,63 +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.rest;
-
-public class EmpireColumnMeta {
-
- private Double size;
-
- private String type;
-
- private boolean required;
-
- private boolean readonly;
-
- public Double getSize() {
- return this.size;
- }
-
- public void setSize(Double size) {
- this.size = size;
- }
-
- public String getType() {
- return this.type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public boolean isRequired() {
- return this.required;
- }
-
- public void setRequired(boolean required) {
- this.required = required;
- }
-
- public boolean isReadonly() {
- return this.readonly;
- }
-
- public void setReadonly(boolean readonly) {
- this.readonly = readonly;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-vue-example/src/main/java/org/apache/empire/rest/service/EmployeeService.java
----------------------------------------------------------------------
diff --git a/empire-db-vue-example/src/main/java/org/apache/empire/rest/service/EmployeeService.java b/empire-db-vue-example/src/main/java/org/apache/empire/rest/service/EmployeeService.java
deleted file mode 100644
index dcc72b4..0000000
--- a/empire-db-vue-example/src/main/java/org/apache/empire/rest/service/EmployeeService.java
+++ /dev/null
@@ -1,179 +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.rest.service;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
-
-import org.apache.empire.db.DBColumn;
-import org.apache.empire.db.DBCommand;
-import org.apache.empire.db.DBReader;
-import org.apache.empire.rest.EmpireColumn;
-import org.apache.empire.rest.EmpireColumnMeta;
-import org.apache.empire.vuesample.model.db.EmployeeBean;
-import org.apache.empire.vuesample.model.db.SampleDB;
-import org.apache.empire.vuesample.model.db.SampleDB.TEmployees;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Path("/employee")
-public class EmployeeService extends Service {
-
- private static final Logger log = LoggerFactory.getLogger(EmployeeService.class);
-
- @POST
- @Path("/{employeeId}")
- @Consumes(MediaType.APPLICATION_JSON)
- public Response updateEmployee(@PathParam("employeeId") int employeeId, EmployeeBean employee) {
-
- SampleDB db = getDatabase();
- TEmployees TE = db.T_EMPLOYEES;
-
- DBCommand cmd = db.createCommand();
-
- // First name
- cmd.set(TE.FIRST_NAME.to(TE.FIRST_NAME.validate(getValue(employee.getFirstName()))));
-
- // Last name
- cmd.set(TE.LAST_NAME.to(TE.LAST_NAME.validate(getValue(employee.getLastName()))));
-
- // Date of Birth
- cmd.set(TE.DATE_OF_BIRTH.to(TE.DATE_OF_BIRTH.validate(getValue(employee.getDateOfBirth()))));
-
- cmd.where(TE.EMPLOYEE_ID.is(employeeId));
-
- int executeUpdate = db.executeUpdate(cmd, getConnection());
-
- if (executeUpdate == 0) {
- return Response.status(Status.NOT_FOUND).build();
- } else {
- return Response.ok().build();
- }
-
- }
-
- @GET
- @Path("/{employeeId}")
- @Produces(MediaType.APPLICATION_JSON)
- public Response getEmployee(@PathParam("employeeId") int employeeId) {
-
- SampleDB db = getDatabase();
-
- TEmployees TE = db.T_EMPLOYEES;
-
- DBCommand cmd = db.createCommand();
- cmd.select(TE.EMPLOYEE_ID, TE.LAST_NAME, TE.FIRST_NAME, TE.DATE_OF_BIRTH);
- cmd.where(TE.EMPLOYEE_ID.is(employeeId));
-
- DBReader reader = new DBReader();
- EmployeeBean eb = new EmployeeBean();
-
- try {
- reader.open(cmd, getConnection());
-
- if (!reader.moveNext()) {
- // Employee not found
- return Response.status(Status.NOT_FOUND).build();
- }
-
- eb = createEmployee(reader);
-
- } finally {
- reader.close();
- }
-
- return Response.ok(eb).build();
- }
-
- @GET
- @Path("/list/")
- @Produces(MediaType.APPLICATION_JSON)
- public Response getEmployeeList() {
-
- SampleDB db = getDatabase();
-
- TEmployees TE = db.T_EMPLOYEES;
-
- DBCommand cmd = db.createCommand();
- cmd.select(TE.EMPLOYEE_ID, TE.LAST_NAME, TE.FIRST_NAME, TE.DATE_OF_BIRTH);
-
- DBReader reader = new DBReader();
- List<EmployeeBean> list = new ArrayList<>();
-
- try {
- reader.open(cmd, getConnection());
- while (reader.moveNext()) {
- list.add(createEmployee(reader));
- }
-
- } finally {
- reader.close();
- }
-
- return Response.ok(list).build();
-
- }
-
- private EmployeeBean createEmployee(DBReader reader) {
-
- TEmployees TE = getDatabase().T_EMPLOYEES;
-
- EmployeeBean eb = new EmployeeBean();
- eb.setEmployeeId(createEmpireColumn(reader, TE.EMPLOYEE_ID));
- eb.setLastName(createEmpireColumn(reader, TE.LAST_NAME));
- eb.setFirstName(createEmpireColumn(reader, TE.FIRST_NAME));
- eb.setDateOfBirth(createEmpireColumn(reader, TE.DATE_OF_BIRTH));
-
- return eb;
- }
-
- private EmpireColumn createEmpireColumn(DBReader reader, DBColumn col) {
-
- EmpireColumn ec = new EmpireColumn();
- // Value
- ec.setValue(reader.getValue(col));
- // Meta
- EmpireColumnMeta meta = new EmpireColumnMeta();
- meta.setSize(col.getSize());
- meta.setType(col.getDataType().name());
- meta.setRequired(col.isRequired());
- meta.setReadonly(col.isReadOnly());
- ec.setMeta(meta);
-
- return ec;
- }
-
- private Object getValue(EmpireColumn ec) {
- if (ec == null) {
- return null;
- }
- return ec.getValue();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-vue-example/src/main/java/org/apache/empire/rest/service/Service.java
----------------------------------------------------------------------
diff --git a/empire-db-vue-example/src/main/java/org/apache/empire/rest/service/Service.java b/empire-db-vue-example/src/main/java/org/apache/empire/rest/service/Service.java
deleted file mode 100644
index e3dc177..0000000
--- a/empire-db-vue-example/src/main/java/org/apache/empire/rest/service/Service.java
+++ /dev/null
@@ -1,62 +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.rest.service;
-
-import java.sql.Connection;
-
-import javax.servlet.ServletContext;
-import javax.servlet.ServletRequest;
-import javax.servlet.http.HttpServletRequest;
-import javax.ws.rs.container.ContainerRequestContext;
-import javax.ws.rs.core.Context;
-
-import org.apache.empire.vuesample.model.EmpireServiceConsts;
-import org.apache.empire.vuesample.model.db.SampleDB;
-import org.glassfish.jersey.server.ContainerRequest;
-
-public abstract class Service {
-
- @Context
- private ServletContext context;
-
- @Context
- private ContainerRequestContext containerRequestContext;
-
- @Context
- private HttpServletRequest req;
-
- public SampleDB getDatabase() {
- return (SampleDB) this.context.getAttribute(EmpireServiceConsts.ATTRIBUTE_DB);
- }
-
- public Connection getConnection() {
- ContainerRequest containerRequest = (ContainerRequest) this.containerRequestContext;
- return (Connection) containerRequest.getProperty(EmpireServiceConsts.ATTRIBUTE_CONNECTION);
- }
-
- public ServletRequest getServletRequest() {
- return this.req;
- }
-
- public String getRemoteAddr() {
- // TODO check X-Real-IP / X-Forwarded-For
- return this.req.getRemoteAddr();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-vue-example/src/main/java/org/apache/empire/rest/service/filter/CORSFilter.java
----------------------------------------------------------------------
diff --git a/empire-db-vue-example/src/main/java/org/apache/empire/rest/service/filter/CORSFilter.java b/empire-db-vue-example/src/main/java/org/apache/empire/rest/service/filter/CORSFilter.java
deleted file mode 100644
index df1ca36..0000000
--- a/empire-db-vue-example/src/main/java/org/apache/empire/rest/service/filter/CORSFilter.java
+++ /dev/null
@@ -1,40 +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.rest.service.filter;
-
-import java.io.IOException;
-
-import javax.ws.rs.container.ContainerRequestContext;
-import javax.ws.rs.container.ContainerResponseContext;
-import javax.ws.rs.container.ContainerResponseFilter;
-import javax.ws.rs.ext.Provider;
-
-@Provider
-public class CORSFilter implements ContainerResponseFilter {
-
- @Override
- public void filter(final ContainerRequestContext requestContext, final ContainerResponseContext cres) throws IOException {
- // cres.getHeaders().add("Access-Control-Allow-Origin", "*");
- // cres.getHeaders().add("Access-Control-Allow-Headers", "origin, content-type, accept, authorization");
- // cres.getHeaders().add("Access-Control-Allow-Credentials", "true");
- // cres.getHeaders().add("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS, HEAD");
- // cres.getHeaders().add("Access-Control-Max-Age", "1209600");
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-vue-example/src/main/java/org/apache/empire/rest/service/filter/ServiceRequestFilter.java
----------------------------------------------------------------------
diff --git a/empire-db-vue-example/src/main/java/org/apache/empire/rest/service/filter/ServiceRequestFilter.java b/empire-db-vue-example/src/main/java/org/apache/empire/rest/service/filter/ServiceRequestFilter.java
deleted file mode 100644
index 5a18d83..0000000
--- a/empire-db-vue-example/src/main/java/org/apache/empire/rest/service/filter/ServiceRequestFilter.java
+++ /dev/null
@@ -1,59 +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.rest.service.filter;
-
-import java.io.IOException;
-import java.sql.Connection;
-
-import javax.annotation.Priority;
-import javax.servlet.ServletContext;
-import javax.ws.rs.container.ContainerRequestContext;
-import javax.ws.rs.container.ContainerRequestFilter;
-import javax.ws.rs.core.Context;
-import javax.ws.rs.ext.Provider;
-
-import org.apache.empire.rest.service.listener.AppListener;
-import org.apache.empire.vuesample.model.EmpireServiceConsts;
-import org.glassfish.jersey.server.ContainerRequest;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Provider
-@Priority(0)
-public class ServiceRequestFilter implements ContainerRequestFilter {
-
- private static final Logger log = LoggerFactory.getLogger(ServiceRequestFilter.class);
-
- @Context
- private ServletContext servletContext;
-
- @Override
- public void filter(ContainerRequestContext requestContext) throws IOException {
-
- ContainerRequest containerRequest = (ContainerRequest) requestContext;
-
- // get Connection from pool
- Connection conn = AppListener.getJDBCConnection(this.servletContext);
-
- // Add to context
- containerRequest.setProperty(EmpireServiceConsts.ATTRIBUTE_CONNECTION, conn);
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/empire-db/blob/caaec0de/empire-db-vue-example/src/main/java/org/apache/empire/rest/service/filter/ServiceResponseFilter.java
----------------------------------------------------------------------
diff --git a/empire-db-vue-example/src/main/java/org/apache/empire/rest/service/filter/ServiceResponseFilter.java b/empire-db-vue-example/src/main/java/org/apache/empire/rest/service/filter/ServiceResponseFilter.java
deleted file mode 100644
index 42bf9c3..0000000
--- a/empire-db-vue-example/src/main/java/org/apache/empire/rest/service/filter/ServiceResponseFilter.java
+++ /dev/null
@@ -1,78 +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.rest.service.filter;
-
-import java.io.IOException;
-import java.sql.Connection;
-import java.sql.SQLException;
-
-import javax.annotation.Priority;
-import javax.ws.rs.container.ContainerRequestContext;
-import javax.ws.rs.container.ContainerResponseContext;
-import javax.ws.rs.container.ContainerResponseFilter;
-import javax.ws.rs.core.Response.Status.Family;
-import javax.ws.rs.ext.Provider;
-
-import org.apache.empire.vuesample.model.EmpireServiceConsts;
-import org.glassfish.jersey.server.ContainerRequest;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@Provider
-@Priority(99999)
-public class ServiceResponseFilter implements ContainerResponseFilter {
-
- private static final Logger log = LoggerFactory.getLogger(ServiceResponseFilter.class);
-
- @Override
- public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
-
- // responseContext.getHeaders().putSingle(key, value);
-
- ContainerRequest containerRequest = (ContainerRequest) requestContext;
- Connection conn = (Connection) containerRequest.getProperty(EmpireServiceConsts.ATTRIBUTE_CONNECTION);
-
- boolean success = responseContext.getStatusInfo().getFamily() == Family.SUCCESSFUL;
-
- try {
-
- if (conn == null || conn.isClosed()) {
- // Connection not found or already closed
- return;
- }
-
- if (success) {
- // commit
- conn.commit();
- } else {
- // rollback
- conn.rollback();
- }
-
- // close connection / return to pool
- conn.close();
-
- } catch (SQLException e) {
- log.error("Error releasing connection", e);
- responseContext.setStatus(500);
- }
-
- }
-
-}