Removed obsolete classes + examples updated EmpireRecord, EmpireReader deleted, enums are handled in core classes
Project: http://git-wip-us.apache.org/repos/asf/empire-db/repo Commit: http://git-wip-us.apache.org/repos/asf/empire-db/commit/f9515027 Tree: http://git-wip-us.apache.org/repos/asf/empire-db/tree/f9515027 Diff: http://git-wip-us.apache.org/repos/asf/empire-db/diff/f9515027 Branch: refs/heads/EMPIREDB-247 Commit: f95150273651ca8ae74c0f1f04b121ee3f2f3538 Parents: 325e422 Author: inemeth <[email protected]> Authored: Mon Oct 31 08:17:57 2016 +0100 Committer: inemeth <[email protected]> Committed: Mon Oct 31 08:17:57 2016 +0100 ---------------------------------------------------------------------- .../org/apache/empire/spring/EmpireReader.java | 105 ------------------- .../org/apache/empire/spring/EmpireRecord.java | 68 ------------ .../apache/empire/spring/EmpireTemplate.java | 4 +- .../empire/spring/example1/EmpireAppImpl.java | 5 +- .../empire/spring/example2/EmployeeDaoImpl.java | 31 +++--- .../resources/example1/applicationContext.xml | 4 +- .../example2/applicationContext-employee.xml | 2 - 7 files changed, 20 insertions(+), 199 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/empire-db/blob/f9515027/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireReader.java ---------------------------------------------------------------------- diff --git a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireReader.java b/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireReader.java deleted file mode 100644 index 8cc2f54..0000000 --- a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireReader.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.empire.spring; - -import java.beans.PropertyDescriptor; -import java.lang.reflect.InvocationTargetException; - -import org.apache.commons.beanutils.BeanUtils; -import org.apache.commons.beanutils.BeanUtilsBean; -import org.apache.commons.beanutils.PropertyUtils; -import org.apache.empire.commons.ObjectUtils; -import org.apache.empire.commons.StringUtils; -import org.apache.empire.data.ColumnExpr; -import org.apache.empire.db.DBReader; -import org.apache.empire.exceptions.BeanPropertySetException; -import org.apache.empire.exceptions.InvalidArgumentException; -import org.apache.empire.exceptions.ItemNotFoundException; - -public class EmpireReader extends DBReader -{ - private static final long serialVersionUID = 1L; - - @Override - protected void setBeanProperty(ColumnExpr column, Object bean, String property, Object value) - { - try - { - if (bean == null) - throw new InvalidArgumentException("bean", bean); - if (StringUtils.isEmpty(property)) - throw new InvalidArgumentException("property", property); - - // Get descriptor - PropertyDescriptor descriptor = BeanUtilsBean.getInstance().getPropertyUtils().getPropertyDescriptor(bean, property); - if (descriptor == null) - { - return; // Skip this property setter - } - // Check enum - Class<?> type = descriptor.getPropertyType(); - if (type.isEnum()) - { - // Enum<?> ev = Enum.valueOf(type, value); - boolean found = false; - Enum<?>[] items = (Enum[]) type.getEnumConstants(); - for (int i = 0; i < items.length; i++) - { - Enum<?> item = items[i]; - if (ObjectUtils.compareEqual(item.name(), value)) - { - value = item; - found = true; - break; - } - } - // Enumeration value not found - if (!found) - throw new ItemNotFoundException(value); - } - - // Set Property Value - if (value != null) - { // Bean utils will convert if necessary - BeanUtils.setProperty(bean, property, value); - } - else - { // Don't convert, just set - PropertyUtils.setProperty(bean, property, null); - } - } - catch (IllegalAccessException e) - { log.error(bean.getClass().getName() + ": unable to set property '" + property + "'"); - throw new BeanPropertySetException(bean, property, e); - } - catch (InvocationTargetException e) - { log.error(bean.getClass().getName() + ": unable to set property '" + property + "'"); - throw new BeanPropertySetException(bean, property, e); - } - catch (NoSuchMethodException e) - { log.error(bean.getClass().getName() + ": unable to set property '" + property + "'"); - throw new BeanPropertySetException(bean, property, e); - } - catch (NullPointerException e) - { log.error(bean.getClass().getName() + ": unable to set property '" + property + "'"); - throw new BeanPropertySetException(bean, property, e); - } - } - -} http://git-wip-us.apache.org/repos/asf/empire-db/blob/f9515027/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireRecord.java ---------------------------------------------------------------------- diff --git a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireRecord.java b/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireRecord.java deleted file mode 100644 index aef674c..0000000 --- a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireRecord.java +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.empire.spring; - -import java.beans.PropertyDescriptor; -import java.lang.reflect.InvocationTargetException; - -import org.apache.commons.beanutils.BeanUtilsBean; -import org.apache.commons.beanutils.PropertyUtilsBean; -import org.apache.empire.data.Column; -import org.apache.empire.db.DBRecord; -import org.apache.empire.exceptions.BeanPropertyGetException; - -public class EmpireRecord extends DBRecord -{ - private static final long serialVersionUID = 1L; - - @Override - protected void setRecordValue(Column column, Object bean, String property) - { - try - { - // Get descriptor - Object value; - PropertyUtilsBean pub = BeanUtilsBean.getInstance().getPropertyUtils(); - PropertyDescriptor descriptor = pub.getPropertyDescriptor(bean, property); - if (descriptor == null) { - return; // Skip this property setter - } - - // Get Property Value - value = pub.getSimpleProperty(bean, property); - - // Check enum - if (value instanceof Enum<?>) - value = ((Enum<?>)value).name(); - - // Set the record value - setValue( column, value ); - - } catch (IllegalAccessException e) - { log.error(bean.getClass().getName() + ": unable to get property '" + property + "'"); - throw new BeanPropertyGetException(bean, property, e); - } catch (NoSuchMethodException e) - { log.error(bean.getClass().getName() + ": unable to get property '" + property + "'"); - throw new BeanPropertyGetException(bean, property, e); - } catch (InvocationTargetException e) - { log.error(bean.getClass().getName() + ": unable to get property '" + property + "'"); - throw new BeanPropertyGetException(bean, property, e); - } - } -} http://git-wip-us.apache.org/repos/asf/empire-db/blob/f9515027/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireTemplate.java ---------------------------------------------------------------------- diff --git a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireTemplate.java b/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireTemplate.java index ddf3301..b7b5cd7 100644 --- a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireTemplate.java +++ b/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireTemplate.java @@ -609,7 +609,7 @@ public class EmpireTemplate implements InitializingBean { class ReadRecordCallback implements ConnectionCallback<DBRecord> { public DBRecord doInConnection(Connection connection) throws SQLException, DataAccessException { - DBRecord record = new EmpireRecord(); + DBRecord record = EmpireTemplate.this.recordFactory.getObject(); record.read(table, keys, connection); return record; } @@ -650,7 +650,7 @@ public class EmpireTemplate implements InitializingBean { class ReadRecordCallback implements ConnectionCallback<DBRecord> { public DBRecord doInConnection(Connection connection) throws SQLException, DataAccessException { - DBRecord record = new EmpireRecord(); + DBRecord record = EmpireTemplate.this.recordFactory.getObject(); try { record.read(table, keys, connection); } catch (RecordNotFoundException e) { http://git-wip-us.apache.org/repos/asf/empire-db/blob/f9515027/empire-db-spring/src/main/java/org/apache/empire/spring/example1/EmpireAppImpl.java ---------------------------------------------------------------------- diff --git a/empire-db-spring/src/main/java/org/apache/empire/spring/example1/EmpireAppImpl.java b/empire-db-spring/src/main/java/org/apache/empire/spring/example1/EmpireAppImpl.java index f35ed89..ba5bd45 100644 --- a/empire-db-spring/src/main/java/org/apache/empire/spring/example1/EmpireAppImpl.java +++ b/empire-db-spring/src/main/java/org/apache/empire/spring/example1/EmpireAppImpl.java @@ -42,7 +42,6 @@ import org.apache.empire.spring.DBReaderExtractor; import org.apache.empire.spring.DBRecordCallbackHandler; import org.apache.empire.spring.DBRecordMapper; import org.apache.empire.spring.EmpireDaoSupport; -import org.apache.empire.spring.EmpireRecord; import org.apache.empire.xml.XMLWriter; import org.springframework.dao.DataAccessException; import org.springframework.jdbc.core.ConnectionCallback; @@ -70,7 +69,7 @@ public class EmpireAppImpl extends EmpireDaoSupport implements EmpireApp { public Integer insertDepartment(String departmentName, String businessUnit) { SampleDB db = getDatabase(); - DBRecord rec = new EmpireRecord(); + DBRecord rec = new DBRecord(); rec.create(db.DEPARTMENTS); rec.setValue(db.DEPARTMENTS.NAME, departmentName); rec.setValue(db.DEPARTMENTS.BUSINESS_UNIT, businessUnit); @@ -85,7 +84,7 @@ public class EmpireAppImpl extends EmpireDaoSupport implements EmpireApp { String gender, int departmentId) { SampleDB db = getDatabase(); - DBRecord rec = new EmpireRecord(); + DBRecord rec = new DBRecord(); rec.create(db.EMPLOYEES); rec.setValue(db.EMPLOYEES.FIRSTNAME, firstName); rec.setValue(db.EMPLOYEES.LASTNAME, lastName); http://git-wip-us.apache.org/repos/asf/empire-db/blob/f9515027/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDaoImpl.java ---------------------------------------------------------------------- diff --git a/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDaoImpl.java b/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDaoImpl.java index d605feb..37eb07b 100644 --- a/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDaoImpl.java +++ b/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDaoImpl.java @@ -29,7 +29,6 @@ import org.apache.empire.db.DBRecordData; import org.apache.empire.spring.DBRecordMapper; import org.apache.empire.spring.DBRecordWriter; import org.apache.empire.spring.EmpireDaoSupport; -import org.apache.empire.spring.EmpireRecord; import org.apache.empire.spring.example1.SampleDB; import org.apache.empire.spring.example1.SampleDB.Departments; import org.apache.empire.spring.example1.SampleDB.Employees; @@ -93,7 +92,7 @@ public class EmployeeDaoImpl extends EmpireDaoSupport implements EmployeeDao { @Transactional(readOnly = true) public List<Department> getDepartments() { - DBCommand cmd = createEmployeeSelectCommand(); + DBCommand cmd = createDepartmentSelectCommand(); return getEmpireTemplate().queryForBeanList(cmd, Department.class); } @@ -114,7 +113,7 @@ public class EmployeeDaoImpl extends EmpireDaoSupport implements EmployeeDao { @Transactional public Integer createEmployee(Employee employee) { - DBRecord record = new EmpireRecord(); + DBRecord record = new DBRecord(); record.create(EMPLOYEES); new EmployeeWriter().write(record, employee); getEmpireTemplate().updateRecord(record); @@ -130,7 +129,7 @@ public class EmployeeDaoImpl extends EmpireDaoSupport implements EmployeeDao { @Transactional public Integer createDepartment(Department department) { - DBRecord record = new EmpireRecord(); + DBRecord record = new DBRecord(); record.create(DEPARTMENTS); new DepartmentWriter().write(record, department); getEmpireTemplate().updateRecord(record); @@ -152,14 +151,14 @@ public class EmployeeDaoImpl extends EmpireDaoSupport implements EmployeeDao { public Employee mapRecord(DBRecordData record, int rowNum) { Employee result = new Employee(); // Auto-copy all properties - record.setBeanProperties(result); - /* + //record.setBeanProperties(result); + result.setEmployeeId(record.getInt(EMPLOYEES.EMPLOYEE_ID)); result.setFirstName(record.getString(EMPLOYEES.FIRSTNAME)); result.setLastName(record.getString(EMPLOYEES.LASTNAME)); result.setGender(Employee.Gender.valueOf(record.getString(EMPLOYEES.GENDER))); result.setPhoneNumber(record.getString(EMPLOYEES.PHONE_NUMBER)); - */ + result.setDepartment(departmentMapper.mapRecord(record, rowNum)); return result; } @@ -171,14 +170,14 @@ public class EmployeeDaoImpl extends EmpireDaoSupport implements EmployeeDao { @Override public void write(DBRecord record, Employee entity) { // Auto-copy all properties - record.setRecordValues(entity); - /* + //record.setRecordValues(entity); + record.setValue(EMPLOYEES.EMPLOYEE_ID, entity.getEmployeeId()); record.setValue(EMPLOYEES.FIRSTNAME, entity.getFirstName()); record.setValue(EMPLOYEES.LASTNAME, entity.getLastName()); record.setValue(EMPLOYEES.GENDER, entity.getGender().name()); record.setValue(EMPLOYEES.PHONE_NUMBER, entity.getPhoneNumber()); - */ + record.setValue(EMPLOYEES.DEPARTMENT_ID, entity.getDepartment().getDepartmentId()); } @@ -199,13 +198,13 @@ public class EmployeeDaoImpl extends EmpireDaoSupport implements EmployeeDao { if (department == null) { department = new Department(); // Auto-copy all properties - record.setBeanProperties(department); - /* + //record.setBeanProperties(department); + department.setDepartmentId(id); department.setName(record.getString(DEPARTMENTS.NAME)); department.setHead(record.getString(DEPARTMENTS.HEAD)); department.setBusinessUnit(record.getString(DEPARTMENTS.BUSINESS_UNIT)); - */ + cache.put(id, department); } return department; @@ -218,13 +217,13 @@ public class EmployeeDaoImpl extends EmpireDaoSupport implements EmployeeDao { @Override public void write(DBRecord record, Department entity) { // Auto-copy all properties - record.setRecordValues(entity); - /* + //record.setRecordValues(entity); + record.setValue(DEPARTMENTS.DEPARTMENT_ID, entity.getDepartmentId()); record.setValue(DEPARTMENTS.NAME, entity.getName()); record.setValue(DEPARTMENTS.HEAD, entity.getHead()); record.setValue(DEPARTMENTS.BUSINESS_UNIT, entity.getBusinessUnit()); - */ + } } http://git-wip-us.apache.org/repos/asf/empire-db/blob/f9515027/empire-db-spring/src/main/resources/example1/applicationContext.xml ---------------------------------------------------------------------- diff --git a/empire-db-spring/src/main/resources/example1/applicationContext.xml b/empire-db-spring/src/main/resources/example1/applicationContext.xml index 648b4b2..7987d5a 100644 --- a/empire-db-spring/src/main/resources/example1/applicationContext.xml +++ b/empire-db-spring/src/main/resources/example1/applicationContext.xml @@ -67,15 +67,13 @@ </bean> <bean id="empireDao" abstract="true"> - <property name="database" ref="sampleDb"/> + <property name="database" ref="empireDb"/> <property name="empireTemplate" ref="empireTemplate"/> </bean> <bean id="empireTemplate" class="org.apache.empire.spring.EmpireTemplate"> <property name="dataSource" ref="dataSource"/> - <property name="dBRecordClass" value="org.apache.empire.spring.EmpireRecord"/> - <property name="dBReaderClass" value="org.apache.empire.spring.EmpireReader"/> </bean> http://git-wip-us.apache.org/repos/asf/empire-db/blob/f9515027/empire-db-spring/src/main/resources/example2/applicationContext-employee.xml ---------------------------------------------------------------------- diff --git a/empire-db-spring/src/main/resources/example2/applicationContext-employee.xml b/empire-db-spring/src/main/resources/example2/applicationContext-employee.xml index 79799a7..08ce097 100644 --- a/empire-db-spring/src/main/resources/example2/applicationContext-employee.xml +++ b/empire-db-spring/src/main/resources/example2/applicationContext-employee.xml @@ -74,8 +74,6 @@ <bean id="empireTemplate" class="org.apache.empire.spring.EmpireTemplate"> <property name="dataSource" ref="dataSource"/> - <property name="dBRecordClass" value="org.apache.empire.spring.EmpireRecord"/> - <property name="dBReaderClass" value="org.apache.empire.spring.EmpireReader"/> </bean>
