empire-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From doeb...@apache.org
Subject [1/2] empire-db git commit: EMPIREDB-227 Spring JDBC Template contributed by Ivan Nemeth
Date Fri, 25 Sep 2015 10:25:38 GMT
Repository: empire-db
Updated Branches:
  refs/heads/master cedc9788e -> 20ecbae8b


http://git-wip-us.apache.org/repos/asf/empire-db/blob/20ecbae8/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDaoImpl.java
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDaoImpl.java
b/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDaoImpl.java
new file mode 100644
index 0000000..7a384f9
--- /dev/null
+++ b/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDaoImpl.java
@@ -0,0 +1,225 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.spring.example2;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.empire.db.DBCommand;
+import org.apache.empire.db.DBJoinType;
+import org.apache.empire.db.DBRecord;
+import org.apache.empire.db.DBRecordData;
+import org.apache.empire.spring.EmpireDaoSupport;
+import org.apache.empire.spring.EmpireDataReader;
+import org.apache.empire.spring.EmpireRecord;
+import org.apache.empire.spring.EmpireRecordWriter;
+import org.apache.empire.spring.example1.SampleDB;
+import org.apache.empire.spring.example1.SampleDB.Departments;
+import org.apache.empire.spring.example1.SampleDB.Employees;
+import org.springframework.transaction.annotation.Transactional;
+
+public class EmployeeDaoImpl extends EmpireDaoSupport implements EmployeeDao {
+
+	private Employees EMPLOYEES;
+	private Departments DEPARTMENTS;
+
+	@Override
+	protected void initEmpireDao() {
+		SampleDB db = getDatabase();
+		this.EMPLOYEES = db.EMPLOYEES;
+		this.DEPARTMENTS = db.DEPARTMENTS;
+	}
+
+	private DBCommand createEmployeeSelectCommand() {
+		DBCommand cmd = getDatabase().createCommand();
+		cmd.select(EMPLOYEES.getColumns());
+		cmd.select(DEPARTMENTS.getColumns());
+
+		cmd.join(EMPLOYEES.DEPARTMENT_ID, DEPARTMENTS.DEPARTMENT_ID, DBJoinType.INNER);
+		return cmd;
+	}
+
+	private DBCommand createDepartmentSelectCommand() {
+		DBCommand cmd = getDatabase().createCommand();
+		cmd.select(DEPARTMENTS.getColumns());
+		return cmd;
+	}
+
+	@Transactional(readOnly = true)
+	public Employee openEmployee(Integer id) {
+		DBCommand cmd = createEmployeeSelectCommand();
+		cmd.where(EMPLOYEES.EMPLOYEE_ID.is(id));
+		return getEmpireTemplate().queryForObject(cmd, new EmployeeMapper());
+	}
+
+	@Transactional(readOnly = true)
+	public Employee findEmployee(String firstName, String lastName) {
+		DBCommand cmd = createEmployeeSelectCommand();
+		cmd.where(EMPLOYEES.FIRSTNAME.is(firstName));
+		cmd.where(EMPLOYEES.LASTNAME.is(lastName));
+		return getEmpireTemplate().queryForObject(cmd, new EmployeeMapper());
+	}
+	
+	@Transactional(readOnly = true)
+	public Department openDepartment(Integer id) {
+		DBCommand cmd = createDepartmentSelectCommand();
+		cmd.where(DEPARTMENTS.DEPARTMENT_ID.is(id));
+		return getEmpireTemplate().queryForObject(cmd, new DepartmentMapper());
+	}
+
+	@Transactional(readOnly = true)
+	public Department findDepartment(String name) {
+		DBCommand cmd = createDepartmentSelectCommand();
+		cmd.where(DEPARTMENTS.NAME.is(name));
+		return getEmpireTemplate().queryForObject(cmd, new DepartmentMapper());
+	}
+
+	@Transactional
+	public void renameDepartment(Integer id, String name) {
+		DBCommand cmd = getDatabase().createCommand();
+		cmd.where(DEPARTMENTS.DEPARTMENT_ID.is(id));
+		cmd.set(DEPARTMENTS.NAME.to(name));
+		getEmpireTemplate().executeUpdate(cmd);
+	}
+
+	@Transactional(readOnly = true)
+	public List<Employee> getEmployees() {
+		DBCommand cmd = createEmployeeSelectCommand();
+		return getEmpireTemplate().query(cmd, new EmployeeMapper());
+	}
+
+	@Transactional
+	public Integer createEmployee(Employee employee) {
+		DBRecord record = new EmpireRecord();
+		record.create(EMPLOYEES);
+		new EmployeeWriter().write(record, employee);
+		getEmpireTemplate().updateRecord(record);
+		return record.getInt(EMPLOYEES.EMPLOYEE_ID);
+	}
+
+	@Transactional
+	public void updateEmployee(Employee employee) {
+		DBRecord record = getEmpireTemplate().openRecord(EMPLOYEES, employee.getEmployeeId());
+		new EmployeeWriter().write(record, employee);
+		getEmpireTemplate().updateRecord(record);
+	}
+
+	@Transactional
+	public Integer createDepartment(Department department) {
+		DBRecord record = new EmpireRecord();
+		record.create(DEPARTMENTS);
+		new DepartmentWriter().write(record, department);
+		getEmpireTemplate().updateRecord(record);
+		return record.getInt(DEPARTMENTS.DEPARTMENT_ID);
+	}
+
+	@Transactional
+	public void updateDepartment(Department department) {
+		DBRecord record = getEmpireTemplate().openRecord(DEPARTMENTS, department.getDepartmentId());
+		new DepartmentWriter().write(record, department);
+		getEmpireTemplate().updateRecord(record);
+	}
+
+	private class EmployeeMapper implements EmpireDataReader<Employee> {
+
+		DepartmentMapper departmentMapper = new DepartmentMapper();
+
+        @Override
+		public Employee read(DBRecordData record) {
+			Employee result = new Employee();
+            // Auto-copy all properties
+			record.getBeanProperties(result);
+			/*
+			result.setEmployeeId(record.getInt(EMPLOYEES.EMPLOYEE_ID));
+			result.setFirstName(record.getString(EMPLOYEES.FIRSTNAME));
+			result.setLastName(record.getString(EMPLOYEES.LASTNAME));
+			result.setGender(Employee.Gender.valueOf(record.getString(EMPLOYEES.GENDER)));
+			result.setPhoneNumber(record.getString(EMPLOYEES.PHONE_NUMBER));
+			*/
+			result.setDepartment(departmentMapper.read(record));
+			return result;
+		}
+
+	}
+
+	private class EmployeeWriter implements EmpireRecordWriter<Employee> {
+
+        @Override
+		public void write(DBRecord record, Employee entity) {
+			// Auto-copy all properties
+		    record.setBeanValues(entity);
+			/*
+		    record.setValue(EMPLOYEES.EMPLOYEE_ID, entity.getEmployeeId());
+			record.setValue(EMPLOYEES.FIRSTNAME, entity.getFirstName());
+			record.setValue(EMPLOYEES.LASTNAME, entity.getLastName());
+			record.setValue(EMPLOYEES.GENDER, entity.getGender().name());
+			record.setValue(EMPLOYEES.PHONE_NUMBER, entity.getPhoneNumber());
+			*/
+			record.setValue(EMPLOYEES.DEPARTMENT_ID, entity.getDepartment().getDepartmentId());
+		}
+
+	}
+
+	private class DepartmentMapper implements EmpireDataReader<Department> {
+
+		// reader cache, in case of joined resultset the same object is returned
+
+		Map<Integer, Department> cache = new HashMap<Integer, Department>();
+
+        @Override
+		public Department read(DBRecordData record) {
+
+			Integer id = record.getInt(DEPARTMENTS.DEPARTMENT_ID);
+
+			Department department = cache.get(id);
+			if (department == null) {
+				department = new Department();
+                // Auto-copy all properties
+				record.getBeanProperties(department);
+				/*
+				department.setDepartmentId(id);
+				department.setName(record.getString(DEPARTMENTS.NAME));
+				department.setHead(record.getString(DEPARTMENTS.HEAD));
+				department.setBusinessUnit(record.getString(DEPARTMENTS.BUSINESS_UNIT));
+				*/		
+				cache.put(id, department);
+			}
+			return department;
+		}
+
+	}
+
+	private class DepartmentWriter implements EmpireRecordWriter<Department> {
+
+		@Override
+        public void write(DBRecord record, Department entity) {
+            // Auto-copy all properties
+		    record.setBeanValues(entity);
+		    /*
+			record.setValue(DEPARTMENTS.DEPARTMENT_ID, entity.getDepartmentId());
+			record.setValue(DEPARTMENTS.NAME, entity.getName());
+			record.setValue(DEPARTMENTS.HEAD, entity.getHead());
+			record.setValue(DEPARTMENTS.BUSINESS_UNIT, entity.getBusinessUnit());
+			*/
+		}
+
+	}
+
+}

http://git-wip-us.apache.org/repos/asf/empire-db/blob/20ecbae8/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeSpringApp.java
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeSpringApp.java
b/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeSpringApp.java
new file mode 100644
index 0000000..90d964a
--- /dev/null
+++ b/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeSpringApp.java
@@ -0,0 +1,220 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.empire.spring.example2;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.logging.Logger;
+
+import org.apache.empire.db.DBColumnExpr;
+import org.apache.empire.db.DBCommand;
+import org.apache.empire.db.DBDatabase;
+import org.apache.empire.db.DBDatabaseDriver;
+import org.apache.empire.db.DBSQLScript;
+import org.apache.empire.db.DBTable;
+import org.apache.empire.spring.EmpireTemplate;
+import org.apache.empire.spring.example1.SampleDB;
+import org.apache.empire.spring.example2.Employee.Gender;
+import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.support.GenericApplicationContext;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.dao.DataAccessException;
+import org.springframework.jdbc.core.ConnectionCallback;
+
+/**
+ * 
+ */
+public class EmployeeSpringApp {
+    private static final Logger log = Logger.getLogger(EmployeeSpringApp.class.getName());
+
+    //creates the application context
+    //this is usually in some bootstrapping code; so your application will
+    //just have one at runtime.
+    static ApplicationContext ctx = getContext();
+
+    //get the service that is the entry point into the application
+    //normally this is injected by spring into classes that need it
+    static EmployeeDao employeeDao = ctx.getBean("employeeDao", EmployeeDao.class);
+    static SampleDB sampleDb = ctx.getBean("sampleDb", SampleDB.class);
+
+    public static void main(String[] args) throws Exception {
+
+        System.out.println("Running Spring Example...");
+
+        setupDatabase();
+        clearDatabase();
+        
+        Department depDevelopment, depSales;
+        
+        System.out.println("*** Create Departments ***");
+        
+        {
+        	depDevelopment = new Department();
+        	depDevelopment.setName("Development");
+        	depDevelopment.setBusinessUnit("ITTK");
+        	Integer id = employeeDao.createDepartment(depDevelopment);
+        	depDevelopment = employeeDao.openDepartment(id);
+        }
+        {
+        	depSales = new Department();
+        	depSales.setName("Sales");
+        	depSales.setBusinessUnit("ITTK");
+        	Integer id = employeeDao.createDepartment(depSales);
+        	depSales = employeeDao.openDepartment(id);
+        }
+        
+        System.out.println("*** Create Employees ***");
+
+        Employee peter = new Employee();
+        peter.setFirstName("Peter");
+        peter.setLastName("Sharp");
+        peter.setGender(Gender.M);
+        peter.setDepartment(depDevelopment);
+        
+        Integer peterId = employeeDao.createEmployee(peter);
+        peter = employeeDao.openEmployee(peterId);
+        
+        
+        
+        Employee fred = new Employee();
+        fred.setFirstName("Fred");
+        fred.setLastName("Bloggs");
+        fred.setGender(Gender.M);
+        fred.setDepartment(depDevelopment);
+
+        Integer fredId = employeeDao.createEmployee(fred);
+        fred = employeeDao.openEmployee(fredId);
+
+        
+        Employee emma = new Employee();
+        emma.setFirstName("Emma");
+        emma.setLastName("White");
+        emma.setGender(Gender.F);
+        emma.setDepartment(depSales);
+        
+        Integer emmaId = employeeDao.createEmployee(emma);
+        emma = employeeDao.openEmployee(emmaId);
+        
+
+        System.out.println("*** updateEmployees ***");
+        
+        peter.setPhoneNumber("+49-7531-457160");
+        employeeDao.updateEmployee(peter);
+        
+        fred.setPhoneNumber("+49-5555-505050");
+        employeeDao.updateEmployee(fred);
+        
+        emma.setPhoneNumber("+49-040-125486");
+        employeeDao.updateEmployee(emma);
+
+        System.out.println("*** List employees ***");
+        
+        List<Employee> employees = employeeDao.getEmployees();
+        for (Iterator<Employee> iterator = employees.iterator(); iterator.hasNext();)
{
+			Employee employee = iterator.next();
+			System.out.println(employee);
+		}
+        
+        
+    }
+
+    private static void clearDatabase() {
+        // Delete all Employees (no constraints)
+        
+        EmpireTemplate empireTemplate = ctx.getBean("empireTemplate", EmpireTemplate.class);
+        empireTemplate.executeDelete(sampleDb.EMPLOYEES, sampleDb.createCommand());
+        empireTemplate.executeDelete(sampleDb.DEPARTMENTS, sampleDb.createCommand());
+		
+	}
+
+
+
+
+	public static void setupDatabase() {
+		if (!databaseExists()) {
+			createDatabase();
+		}
+	}
+	
+
+	public static boolean databaseExists() {
+		try {
+			DBDatabase db = sampleDb;
+			if (db.getTables() == null || db.getTables().isEmpty()) {
+				throw new AssertionError(
+						"There are no tables in this database!");
+			}
+			DBCommand cmd = db.createCommand();
+			if (cmd == null) {
+				throw new AssertionError("The DBCommand object is null.");
+			}
+			DBTable t = db.getTables().get(0);
+			DBColumnExpr COUNT = t.count();
+			
+			cmd.select(COUNT);
+			
+			EmpireTemplate empireTemplate = ctx.getBean("empireTemplate", EmpireTemplate.class);
+			return (empireTemplate.queryForInteger(cmd, COUNT, -1) >= 0);
+		} catch (Exception e) {
+			return false;
+		}
+	}
+
+
+	private static void createDatabase() {
+
+		// create DLL for Database Definition
+		final DBSQLScript script = new DBSQLScript();
+		final DBDatabaseDriver driver = sampleDb.getDriver();
+		sampleDb.getCreateDDLScript(driver, script);
+
+		// Show DLL Statement
+		System.out.println(script.toString());
+		// Execute Script
+		EmpireTemplate empireTemplate = ctx.getBean("empireTemplate", EmpireTemplate.class);
+		empireTemplate.execute(new ConnectionCallback<Object>() {
+
+			@Override
+            public Object doInConnection(Connection con) throws SQLException,
+					DataAccessException {
+        				script.executeAll(driver, con, false);
+        				return null;
+        			}
+		});
+
+	}
+
+
+
+	static GenericApplicationContext getContext() {
+        log.info("Creating Spring Application Context ...");
+        GenericApplicationContext ctx = new GenericApplicationContext();
+        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(ctx);
+        reader.loadBeanDefinitions(new ClassPathResource("/example2/applicationContext-employee.xml"));
+
+        ctx.refresh();
+        return ctx;
+    }
+    
+    
+    
+}

http://git-wip-us.apache.org/repos/asf/empire-db/blob/20ecbae8/empire-db-spring/src/main/resources/example1/applicationContext.xml
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/resources/example1/applicationContext.xml b/empire-db-spring/src/main/resources/example1/applicationContext.xml
new file mode 100644
index 0000000..56b0699
--- /dev/null
+++ b/empire-db-spring/src/main/resources/example1/applicationContext.xml
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+  
+   http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:tx="http://www.springframework.org/schema/tx"
+       xmlns:aop="http://www.springframework.org/schema/aop"
+       xsi:schemaLocation="
+       	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+       	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
+		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
+
+
+    <!-- one option is to use a class from spring that will read the properties file
+         and replaces the ${...} placeholders with the appropriate values -->
+    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
+        <property name="locations">
+            <value>classpath:/settings.properties</value>
+        </property>
+    </bean>
+
+    <!-- Data Source / DB Settings -->
+    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
+        <property name="driverClassName" value="${jdbc.driverClass}"/>
+        <property name="url" value="${jdbc.url}"/>
+        <property name="username" value="${jdbc.username}"/>
+        <property name="password" value="${jdbc.password}"/>
+    </bean>
+
+    <!-- Transaction manager for a single JDBC DataSource (alternative to JTA) -->
+    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
+        <constructor-arg ref="dataSource"/>
+    </bean>
+    <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
+        <property name="transactionManager" ref="transactionManager"/>
+    </bean>
+
+    <!-- @Transactional -->
+    <tx:annotation-driven transaction-manager="transactionManager"/>
+
+    <!-- Empire-DB classes -->
+    
+    <!-- application dao/services -->
+    <bean id="empireApp" class="org.apache.empire.spring.example1.EmpireAppImpl" parent="empireDao"/>
+
+    
+    <bean id="empireDb" class="org.apache.empire.spring.DbDatabaseFactoryBean">
+    	<property name="driverClass" value="${empire.driver}"/>
+    	<property name="schema" value="${empire.schemaname}"/>
+    	<property name="databaseClass" value="org.apache.empire.spring.example1.SampleDB"/>
+    </bean>
+    
+    <bean id="empireDao" abstract="true">
+    	<property name="database" ref="empireDb"/>
+    	<property name="dataSource" ref="dataSource"/>
+    </bean>
+    
+    
+    
+    
+    
+    
+    
+    
+    
+    
+</beans>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/empire-db/blob/20ecbae8/empire-db-spring/src/main/resources/example2/applicationContext-employee.xml
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/resources/example2/applicationContext-employee.xml
b/empire-db-spring/src/main/resources/example2/applicationContext-employee.xml
new file mode 100644
index 0000000..349122d
--- /dev/null
+++ b/empire-db-spring/src/main/resources/example2/applicationContext-employee.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+  
+   http://www.apache.org/licenses/LICENSE-2.0
+  
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:tx="http://www.springframework.org/schema/tx"
+       xmlns:aop="http://www.springframework.org/schema/aop"
+       xsi:schemaLocation="
+       	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
+       	http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
+		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
+
+
+    <!-- one option is to use a class from spring that will read the properties file
+         and replaces the ${...} placeholders with the appropriate values -->
+    <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
+        <property name="locations">
+            <value>classpath:/settings.properties</value>
+        </property>
+    </bean>
+
+    <!-- Data Source / DB Settings -->
+    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
+        <property name="driverClassName" value="${jdbc.driverClass}"/>
+        <property name="url" value="${jdbc.url}"/>
+        <property name="username" value="${jdbc.username}"/>
+        <property name="password" value="${jdbc.password}"/>
+    </bean>
+
+    <!-- Transaction manager for a single JDBC DataSource (alternative to JTA) -->
+    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
+        <constructor-arg ref="dataSource"/>
+    </bean>
+    <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate">
+        <property name="transactionManager" ref="transactionManager"/>
+    </bean>
+
+    <!-- @Transactional -->
+    <tx:annotation-driven transaction-manager="transactionManager"/>
+
+    <!-- Empire-DB classes -->
+    
+    <!-- application dao/services -->
+    <bean id="employeeDao" class="org.apache.empire.spring.example2.EmployeeDaoImpl" parent="empireDao"/>
+
+    
+    <bean id="sampleDb" class="org.apache.empire.spring.DbDatabaseFactoryBean">
+    	<property name="driverClass" value="${empire.driver}"/>
+    	<property name="schema" value="${empire.schemaname}"/>
+    	<property name="databaseClass" value="org.apache.empire.spring.example1.SampleDB"/>
+    </bean>
+    
+    <bean id="empireDao" abstract="true">
+    	<property name="database" ref="sampleDb"/>
+    	<property name="dataSource" ref="dataSource"/>
+    </bean>
+    
+    
+    <bean id="empireTemplate" class="org.apache.empire.spring.EmpireTemplate">
+    	<property name="dataSource" ref="dataSource"/>
+    </bean>
+    
+    
+    
+    
+    
+    
+    
+</beans>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/empire-db/blob/20ecbae8/empire-db-spring/src/main/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/resources/log4j.properties b/empire-db-spring/src/main/resources/log4j.properties
new file mode 100644
index 0000000..031ae65
--- /dev/null
+++ b/empire-db-spring/src/main/resources/log4j.properties
@@ -0,0 +1,21 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+log4j.rootCategory=FATAL, console
+log4j.appender.console=org.apache.log4j.ConsoleAppender
+log4j.appender.console.layout=org.apache.log4j.PatternLayout
+log4j.appender.console.layout.conversionPattern = %d{ISO8601} %-5p [%c] - %m%n

http://git-wip-us.apache.org/repos/asf/empire-db/blob/20ecbae8/empire-db-spring/src/main/resources/settings.properties
----------------------------------------------------------------------
diff --git a/empire-db-spring/src/main/resources/settings.properties b/empire-db-spring/src/main/resources/settings.properties
new file mode 100644
index 0000000..e5ba794
--- /dev/null
+++ b/empire-db-spring/src/main/resources/settings.properties
@@ -0,0 +1,44 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#  http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+## HSQLDB settings (tested)
+jdbc.url=jdbc:hsqldb:file:target/hsqldb/sample;shutdown=true
+jdbc.driverClass=org.hsqldb.jdbcDriver
+jdbc.username=sa
+jdbc.password=
+
+empire.driver= org.apache.empire.db.hsql.DBDatabaseDriverHSql
+empire.schemaname=
+
+
+## Derby settings (tested)
+#jdbc.url=jdbc:derby:target/dbsample1;create=true
+#jdbc.driverClass=org.apache.derby.jdbc.EmbeddedDriver
+#jdbc.username=
+#jdbc.password=
+#
+#empire.driver=org.apache.empire.db.derby.DBDatabaseDriverDerby
+#empire.schemaname=DBSAMPLE1
+
+## MySQL settings (tested)
+#jdbc.url=jdbc:mysql://localhost
+#jdbc.driverClass=com.mysql.jdbc.Driver
+#jdbc.username=test
+#jdbc.password=test
+#
+#empire.driver=org.apache.empire.db.mysql.DBDatabaseDriverMySQL
+#empire.schemaname=dbsample1

http://git-wip-us.apache.org/repos/asf/empire-db/blob/20ecbae8/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 672948d..997fb6a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -38,6 +38,7 @@
 		<module>empire-db-jsf2</module>
 		<module>empire-db-codegen</module>
 		<module>empire-db-maven-plugin</module>
+		<module>empire-db-spring</module>
 		<module>empire-db-examples</module>
 	</modules>
 	


Mime
View raw message