Repository: empire-db
Updated Branches:
  refs/heads/master 0bcef5a81 -> 2945b5df2


1. Removed some trivial classes (EmpireStringValueReader etc.)
2. Renamed classes to match both Empire and Sring naming conventions
                EmpireDataReader => DbRecordMapper
                EmpireRowCallbackHandler => DbRecordCallbackHandler
                EmpireReaderExtractor => DbReaderExtractor
                EmpireRecordWriter => DbRecordWriter
3. New methods in EmpireTemplate (getBeanList etc.)
4. Example updates

Project: http://git-wip-us.apache.org/repos/asf/empire-db/repo
Commit: http://git-wip-us.apache.org/repos/asf/empire-db/commit/d4079f57
Tree: http://git-wip-us.apache.org/repos/asf/empire-db/tree/d4079f57
Diff: http://git-wip-us.apache.org/repos/asf/empire-db/diff/d4079f57

Branch: refs/heads/master
Commit: d4079f5750a0bfc4b8f930b6a6ce186b07c6b63a
Parents: 06bd6f1
Author: inemeth <[email protected]>
Authored: Thu Oct 22 08:39:25 2015 +0200
Committer: inemeth <[email protected]>
Committed: Thu Oct 22 08:39:25 2015 +0200

----------------------------------------------------------------------
 .../apache/empire/spring/DbReaderExtractor.java |  27 +++
 .../empire/spring/DbRecordCallbackHandler.java  |  27 +++
 .../apache/empire/spring/DbRecordMapper.java    |  34 ++++
 .../apache/empire/spring/DbRecordWriter.java    |  28 ++++
 .../apache/empire/spring/EmpireDataReader.java  |  27 ---
 .../empire/spring/EmpireIntegerValueReader.java |  39 -----
 .../empire/spring/EmpireLongValueReader.java    |  39 -----
 .../empire/spring/EmpireReaderExtractor.java    |  27 ---
 .../empire/spring/EmpireRecordWriter.java       |  28 ----
 .../empire/spring/EmpireRowCallbackHandler.java |  27 ---
 .../empire/spring/EmpireStringValueReader.java  |  37 -----
 .../apache/empire/spring/EmpireTemplate.java    | 163 ++++++++++++++-----
 .../apache/empire/spring/EmpireValueReader.java |  37 -----
 .../empire/spring/example1/EmpireAppImpl.java   |  14 +-
 .../empire/spring/example2/Department.java      |  11 +-
 .../empire/spring/example2/EmployeeDao.java     |   2 +
 .../empire/spring/example2/EmployeeDaoImpl.java |  23 ++-
 .../spring/example2/EmployeeSpringApp.java      |   9 +-
 18 files changed, 283 insertions(+), 316 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/empire-db/blob/d4079f57/empire-db-spring/src/main/java/org/apache/empire/spring/DbReaderExtractor.java
----------------------------------------------------------------------
diff --git 
a/empire-db-spring/src/main/java/org/apache/empire/spring/DbReaderExtractor.java
 
b/empire-db-spring/src/main/java/org/apache/empire/spring/DbReaderExtractor.java
new file mode 100644
index 0000000..5d8cf8c
--- /dev/null
+++ 
b/empire-db-spring/src/main/java/org/apache/empire/spring/DbReaderExtractor.java
@@ -0,0 +1,27 @@
+/*
+ * 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 org.apache.empire.db.DBReader;
+
+public interface DbReaderExtractor<K> {
+
+       K process(DBReader reader);
+
+}

http://git-wip-us.apache.org/repos/asf/empire-db/blob/d4079f57/empire-db-spring/src/main/java/org/apache/empire/spring/DbRecordCallbackHandler.java
----------------------------------------------------------------------
diff --git 
a/empire-db-spring/src/main/java/org/apache/empire/spring/DbRecordCallbackHandler.java
 
b/empire-db-spring/src/main/java/org/apache/empire/spring/DbRecordCallbackHandler.java
new file mode 100644
index 0000000..6fcd15a
--- /dev/null
+++ 
b/empire-db-spring/src/main/java/org/apache/empire/spring/DbRecordCallbackHandler.java
@@ -0,0 +1,27 @@
+/*
+ * 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 org.apache.empire.db.DBRecordData;
+
+public interface DbRecordCallbackHandler {
+
+       void processRow(DBRecordData record);
+
+}

http://git-wip-us.apache.org/repos/asf/empire-db/blob/d4079f57/empire-db-spring/src/main/java/org/apache/empire/spring/DbRecordMapper.java
----------------------------------------------------------------------
diff --git 
a/empire-db-spring/src/main/java/org/apache/empire/spring/DbRecordMapper.java 
b/empire-db-spring/src/main/java/org/apache/empire/spring/DbRecordMapper.java
new file mode 100644
index 0000000..226f3b4
--- /dev/null
+++ 
b/empire-db-spring/src/main/java/org/apache/empire/spring/DbRecordMapper.java
@@ -0,0 +1,34 @@
+/*
+ * 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 org.apache.empire.db.DBRecordData;
+
+/**
+ * Interface used by {@link EmpireTemplate} for mapping a
+ * {@link org.apache.empire.db.DBRecordData}. 
+ * 
+ */
+
+
+public interface DbRecordMapper<K> {
+
+       public abstract K read(DBRecordData record);
+       
+}

http://git-wip-us.apache.org/repos/asf/empire-db/blob/d4079f57/empire-db-spring/src/main/java/org/apache/empire/spring/DbRecordWriter.java
----------------------------------------------------------------------
diff --git 
a/empire-db-spring/src/main/java/org/apache/empire/spring/DbRecordWriter.java 
b/empire-db-spring/src/main/java/org/apache/empire/spring/DbRecordWriter.java
new file mode 100644
index 0000000..2bc9a39
--- /dev/null
+++ 
b/empire-db-spring/src/main/java/org/apache/empire/spring/DbRecordWriter.java
@@ -0,0 +1,28 @@
+/*
+ * 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 org.apache.empire.db.DBRecord;
+
+
+public interface DbRecordWriter<K> {
+
+       public abstract void write(DBRecord record, K entity);
+       
+}

http://git-wip-us.apache.org/repos/asf/empire-db/blob/d4079f57/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireDataReader.java
----------------------------------------------------------------------
diff --git 
a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireDataReader.java 
b/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireDataReader.java
deleted file mode 100644
index b0b2f76..0000000
--- 
a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireDataReader.java
+++ /dev/null
@@ -1,27 +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 org.apache.empire.db.DBRecordData;
-
-public interface EmpireDataReader<K> {
-
-       public abstract K read(DBRecordData record);
-       
-}

http://git-wip-us.apache.org/repos/asf/empire-db/blob/d4079f57/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireIntegerValueReader.java
----------------------------------------------------------------------
diff --git 
a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireIntegerValueReader.java
 
b/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireIntegerValueReader.java
deleted file mode 100644
index f707a8c..0000000
--- 
a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireIntegerValueReader.java
+++ /dev/null
@@ -1,39 +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 org.apache.empire.db.DBColumnExpr;
-import org.apache.empire.db.DBRecordData;
-
-public class EmpireIntegerValueReader implements EmpireDataReader<Integer> {
-
-       DBColumnExpr column;
-       Integer defaultValue = null;
-
-       public EmpireIntegerValueReader(DBColumnExpr column, Integer 
defaultValue) {
-               super();
-               this.column = column;
-               this.defaultValue = defaultValue;
-       }
-
-       public Integer read(DBRecordData record) {
-               return record.isNull(column) ? defaultValue : 
record.getInt(column);
-       }
-
-}

http://git-wip-us.apache.org/repos/asf/empire-db/blob/d4079f57/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireLongValueReader.java
----------------------------------------------------------------------
diff --git 
a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireLongValueReader.java
 
b/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireLongValueReader.java
deleted file mode 100644
index 7e68f22..0000000
--- 
a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireLongValueReader.java
+++ /dev/null
@@ -1,39 +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 org.apache.empire.db.DBColumnExpr;
-import org.apache.empire.db.DBRecordData;
-
-public class EmpireLongValueReader implements EmpireDataReader<Long> {
-
-       DBColumnExpr column;
-       private Long defaultValue;
-
-       public EmpireLongValueReader(DBColumnExpr column, Long defaultValue) {
-               super();
-               this.column = column;
-               this.defaultValue = defaultValue;
-       }
-
-       public Long read(DBRecordData record) {
-               return record.isNull(column) ? defaultValue : 
record.getLong(column);
-       }
-
-}

http://git-wip-us.apache.org/repos/asf/empire-db/blob/d4079f57/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireReaderExtractor.java
----------------------------------------------------------------------
diff --git 
a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireReaderExtractor.java
 
b/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireReaderExtractor.java
deleted file mode 100644
index 81255d7..0000000
--- 
a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireReaderExtractor.java
+++ /dev/null
@@ -1,27 +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 org.apache.empire.db.DBReader;
-
-public interface EmpireReaderExtractor<K> {
-
-       K process(DBReader reader);
-
-}

http://git-wip-us.apache.org/repos/asf/empire-db/blob/d4079f57/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireRecordWriter.java
----------------------------------------------------------------------
diff --git 
a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireRecordWriter.java
 
b/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireRecordWriter.java
deleted file mode 100644
index 2ecea4d..0000000
--- 
a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireRecordWriter.java
+++ /dev/null
@@ -1,28 +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 org.apache.empire.db.DBRecord;
-
-
-public interface EmpireRecordWriter<K> {
-
-       public abstract void write(DBRecord record, K entity);
-       
-}

http://git-wip-us.apache.org/repos/asf/empire-db/blob/d4079f57/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireRowCallbackHandler.java
----------------------------------------------------------------------
diff --git 
a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireRowCallbackHandler.java
 
b/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireRowCallbackHandler.java
deleted file mode 100644
index 9a24bce..0000000
--- 
a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireRowCallbackHandler.java
+++ /dev/null
@@ -1,27 +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 org.apache.empire.db.DBRecordData;
-
-public interface EmpireRowCallbackHandler {
-
-       void processRow(DBRecordData record);
-
-}

http://git-wip-us.apache.org/repos/asf/empire-db/blob/d4079f57/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireStringValueReader.java
----------------------------------------------------------------------
diff --git 
a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireStringValueReader.java
 
b/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireStringValueReader.java
deleted file mode 100644
index 9f16a6c..0000000
--- 
a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireStringValueReader.java
+++ /dev/null
@@ -1,37 +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 org.apache.empire.db.DBColumnExpr;
-import org.apache.empire.db.DBRecordData;
-
-public class EmpireStringValueReader implements EmpireDataReader<String> {
-
-       DBColumnExpr column;
-
-       public EmpireStringValueReader(DBColumnExpr column) {
-               super();
-               this.column = column;
-       }
-
-       public String read(DBRecordData record) {
-               return record.getString(column);
-       }
-
-}

http://git-wip-us.apache.org/repos/asf/empire-db/blob/d4079f57/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 9202bbc..558ae84 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
@@ -21,6 +21,7 @@ package org.apache.empire.spring;
 import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 
 import javax.sql.DataSource;
@@ -29,6 +30,7 @@ import org.apache.empire.db.DBColumnExpr;
 import org.apache.empire.db.DBCommand;
 import org.apache.empire.db.DBReader;
 import org.apache.empire.db.DBRecord;
+import org.apache.empire.db.DBRecordData;
 import org.apache.empire.db.DBRowSet;
 import org.apache.empire.db.DBTable;
 import org.apache.empire.db.exceptions.RecordNotFoundException;
@@ -52,7 +54,8 @@ public class EmpireTemplate implements InitializingBean {
        }
 
        public final void setDataSource(DataSource dataSource) {
-               if (this.jdbcTemplate == null || dataSource != 
this.jdbcTemplate.getDataSource()) {
+               if (this.jdbcTemplate == null
+                               || dataSource != 
this.jdbcTemplate.getDataSource()) {
                        this.jdbcTemplate = new JdbcTemplate(dataSource);
                        this.jdbcTemplate.afterPropertiesSet();
                }
@@ -60,50 +63,93 @@ public class EmpireTemplate implements InitializingBean {
 
        public void afterPropertiesSet() throws Exception {
                if (getJdbcTemplate() == null) {
-                       throw new IllegalArgumentException("Property 
'jdbcTemplate' is required");
+                       throw new IllegalArgumentException(
+                                       "Property 'jdbcTemplate' is required");
                }
 
        }
 
-       public <K> List<K> query(final DBCommand cmd, final EmpireDataReader<K> 
dataReader) {
-               return query(cmd, new EmpireDataReaderExtractor<K>(dataReader));
+       public <K> List<K> query(final DBCommand cmd,
+                       final DbRecordMapper<K> dataReader) {
+               return query(cmd, new DbRecordMapperExtractor<K>(dataReader));
 
        }
 
        public List<Object> queryForList(final DBCommand cmd, final 
DBColumnExpr col) {
-               return query(cmd, new EmpireValueReader(col));
+               class SingleValueMapper implements DbRecordMapper<Object> {
+
+                       @Override
+                       public Object read(DBRecordData record) {
+                               return record.getValue(col);
+                       }
+
+               }
+               return query(cmd, new SingleValueMapper());
 
        }
 
-       public Long queryForLong(final DBCommand cmd, final DBColumnExpr col, 
Long defaultValue) {
-               return DataAccessUtils.uniqueResult(queryForLongList(cmd, col, 
defaultValue));
+       public Long queryForLong(final DBCommand cmd, final DBColumnExpr col,
+                       Long defaultValue) {
+               return DataAccessUtils.uniqueResult(queryForLongList(cmd, col,
+                               defaultValue));
        }
 
-       public List<Long> queryForLongList(final DBCommand cmd, final 
DBColumnExpr col, final Long defaultValue) {
-               return query(cmd, new EmpireLongValueReader(col, defaultValue));
+       public List<Long> queryForLongList(final DBCommand cmd,
+                       final DBColumnExpr col, final Long defaultValue) {
+               class SingleLongMapper implements DbRecordMapper<Long> {
+
+                       @Override
+                       public Long read(DBRecordData record) {
+                               return record.isNull(col) ? defaultValue : 
record.getLong(col);
+                       }
+
+               }
+               return query(cmd, new SingleLongMapper());
 
        }
 
-       public Integer queryForInteger(final DBCommand cmd, final DBColumnExpr 
col, Integer defaultValue) {
-               return DataAccessUtils.uniqueResult(queryForIntegerList(cmd, 
col, defaultValue));
+       public Integer queryForInteger(final DBCommand cmd, final DBColumnExpr 
col,
+                       Integer defaultValue) {
+               return DataAccessUtils.uniqueResult(queryForIntegerList(cmd, 
col,
+                               defaultValue));
        }
 
-       public List<Integer> queryForIntegerList(final DBCommand cmd, final 
DBColumnExpr col, final Integer defaultValue) {
-               return query(cmd, new EmpireIntegerValueReader(col, 
defaultValue));
+       public List<Integer> queryForIntegerList(final DBCommand cmd,
+                       final DBColumnExpr col, final Integer defaultValue) {
+               class SingleIntegerMapper implements DbRecordMapper<Integer> {
+
+                       @Override
+                       public Integer read(DBRecordData record) {
+                               return record.isNull(col) ? defaultValue : 
record.getInt(col);
+                       }
+
+               }
+               return query(cmd, new SingleIntegerMapper());
        }
 
        public String queryForString(final DBCommand cmd, final DBColumnExpr 
col) {
                return DataAccessUtils.uniqueResult(queryForStringList(cmd, 
col));
        }
 
-       public List<String> queryForStringList(final DBCommand cmd, final 
DBColumnExpr col) {
-               return query(cmd, new EmpireStringValueReader(col));
+       public List<String> queryForStringList(final DBCommand cmd,
+                       final DBColumnExpr col) {
+               class SingleStringMapper implements DbRecordMapper<String> {
+
+                       @Override
+                       public String read(DBRecordData record) {
+                               return record.getString(col);
+                       }
+
+               }
+               return query(cmd, new SingleStringMapper());
        }
 
-       public <K> K query(final DBCommand cmd, final EmpireReaderExtractor<K> 
readerHandler) {
+       public <K> K query(final DBCommand cmd,
+                       final DbReaderExtractor<K> readerHandler) {
 
                class QueryCallback implements ConnectionCallback<K> {
-                       public K doInConnection(Connection connection) throws 
SQLException, DataAccessException {
+                       public K doInConnection(Connection connection) throws 
SQLException,
+                                       DataAccessException {
                                return query(connection, cmd, readerHandler);
                        }
                }
@@ -111,11 +157,13 @@ public class EmpireTemplate implements InitializingBean {
 
        }
 
-       public void query(final DBCommand cmd, final EmpireRowCallbackHandler 
rowCallbackHandler) {
-               query(cmd, new 
EmpireRowCallbackHandlerExtractor(rowCallbackHandler));
+       public void query(final DBCommand cmd,
+                       final DbRecordCallbackHandler rowCallbackHandler) {
+               query(cmd, new 
DbRecordCallbackHandlerExtractor(rowCallbackHandler));
        }
 
-       public <K> K queryForObject(final DBCommand cmd, final 
EmpireDataReader<K> dataReader) {
+       public <K> K queryForObject(final DBCommand cmd,
+                       final DbRecordMapper<K> dataReader) {
 
                return DataAccessUtils.uniqueResult(query(cmd, dataReader));
 
@@ -124,7 +172,8 @@ public class EmpireTemplate implements InitializingBean {
        public void deleteRecord(final DBRecord record) {
 
                class DeleteRecordCallback implements 
ConnectionCallback<Object> {
-                       public Object doInConnection(Connection connection) 
throws SQLException, DataAccessException {
+                       public Object doInConnection(Connection connection)
+                                       throws SQLException, 
DataAccessException {
                                record.delete(connection);
                                return null;
                        }
@@ -140,7 +189,8 @@ public class EmpireTemplate implements InitializingBean {
        public void deleteRecord(final DBTable table, final Object[] keys) {
 
                class DeleteRecordCallback implements 
ConnectionCallback<Object> {
-                       public Object doInConnection(Connection connection) 
throws SQLException, DataAccessException {
+                       public Object doInConnection(Connection connection)
+                                       throws SQLException, 
DataAccessException {
                                DBRecord record = new EmpireRecord();
                                record.read(table, keys, connection);
                                record.delete(connection);
@@ -154,7 +204,8 @@ public class EmpireTemplate implements InitializingBean {
        public DBRecord updateRecord(final DBRecord record) {
 
                class UpdateRecordCallback implements 
ConnectionCallback<DBRecord> {
-                       public DBRecord doInConnection(Connection connection) 
throws SQLException, DataAccessException {
+                       public DBRecord doInConnection(Connection connection)
+                                       throws SQLException, 
DataAccessException {
                                record.update(connection);
                                return record;
                        }
@@ -167,7 +218,8 @@ public class EmpireTemplate implements InitializingBean {
        public int executeUpdate(final DBCommand cmd) {
 
                class UpdateRecordCallback implements 
ConnectionCallback<Integer> {
-                       public Integer doInConnection(Connection connection) 
throws SQLException, DataAccessException {
+                       public Integer doInConnection(Connection connection)
+                                       throws SQLException, 
DataAccessException {
                                return cmd.getDatabase().executeUpdate(cmd, 
connection);
                        }
                }
@@ -179,7 +231,8 @@ public class EmpireTemplate implements InitializingBean {
        public int executeDelete(final DBTable table, final DBCommand cmd) {
 
                class DeleteRecordCallback implements 
ConnectionCallback<Integer> {
-                       public Integer doInConnection(Connection connection) 
throws SQLException, DataAccessException {
+                       public Integer doInConnection(Connection connection)
+                                       throws SQLException, 
DataAccessException {
                                return cmd.getDatabase().executeDelete(table, 
cmd, connection);
                        }
                }
@@ -191,7 +244,8 @@ public class EmpireTemplate implements InitializingBean {
        public int executeInsert(final DBCommand cmd) {
 
                class InsertRecordCallback implements 
ConnectionCallback<Integer> {
-                       public Integer doInConnection(Connection connection) 
throws SQLException, DataAccessException {
+                       public Integer doInConnection(Connection connection)
+                                       throws SQLException, 
DataAccessException {
                                return cmd.getDatabase().executeInsert(cmd, 
connection);
                        }
                }
@@ -213,7 +267,8 @@ public class EmpireTemplate implements InitializingBean {
        public DBRecord openRecord(final DBRowSet table, final Object[] keys) {
 
                class ReadRecordCallback implements 
ConnectionCallback<DBRecord> {
-                       public DBRecord doInConnection(Connection connection) 
throws SQLException, DataAccessException {
+                       public DBRecord doInConnection(Connection connection)
+                                       throws SQLException, 
DataAccessException {
                                DBRecord record = new EmpireRecord();
                                try {
                                        record.read(table, keys, connection);
@@ -228,11 +283,40 @@ public class EmpireTemplate implements InitializingBean {
 
        }
 
+       public <C extends Collection<T>, T> C queryForBeanList(final DBCommand 
cmd,
+                       final C c, final Class<T> t, final int maxCount) {
+
+               class GetBeanListCallback implements DbReaderExtractor<C> {
+
+                       @Override
+                       public C process(DBReader reader) {
+                               return reader.getBeanList(c, t, maxCount);
+                       }
+               }
+
+               return query(cmd, new GetBeanListCallback());
+
+       }
+
+       public <T> List<T> queryForBeanList(DBCommand cmd, Class<T> t, int 
maxItems) {
+               return queryForBeanList(cmd, new ArrayList<T>(), t, maxItems);
+       }
+
+       public <T> List<T> queryForBeanList(DBCommand cmd, Class<T> t) {
+               return queryForBeanList(cmd, t, -1);
+       }
+       
+       public <T> T queryForBean(DBCommand cmd, Class<T> t) {
+               return DataAccessUtils.uniqueResult(queryForBeanList(cmd, t, 
-1));
+       }
+
+
        public <K> K execute(ConnectionCallback<K> connectionCallback) {
                return getJdbcTemplate().execute(connectionCallback);
        }
 
-       private <K> K query(Connection connection, DBCommand command, 
EmpireReaderExtractor<K> callback) {
+       private <K> K query(Connection connection, DBCommand command,
+                       DbReaderExtractor<K> callback) {
                DBReader reader = newDBReader();
                try {
                        reader.open(command, connection);
@@ -247,17 +331,19 @@ public class EmpireTemplate implements InitializingBean {
        private DBReader newDBReader() {
                return new EmpireReader();
        }
-       
-       public static class EmpireRowCallbackHandlerExtractor implements 
EmpireReaderExtractor<Object> {
 
-               private final EmpireRowCallbackHandler rowCallbackHandler;
+       private static class DbRecordCallbackHandlerExtractor implements
+                       DbReaderExtractor<Object> {
 
-               public 
EmpireRowCallbackHandlerExtractor(EmpireRowCallbackHandler rowCallbackHandler) {
+               private final DbRecordCallbackHandler rowCallbackHandler;
+
+               public DbRecordCallbackHandlerExtractor(
+                               DbRecordCallbackHandler rowCallbackHandler) {
                        Assert.notNull(rowCallbackHandler, "RowCallbackHandler 
is required");
                        this.rowCallbackHandler = rowCallbackHandler;
                }
 
-//             @Override
+               // @Override
                public Object process(DBReader reader) {
                        try {
                                while (reader.moveNext()) {
@@ -268,19 +354,20 @@ public class EmpireTemplate implements InitializingBean {
                                reader.close();
                        }
                }
-               
+
        }
 
-       public static class EmpireDataReaderExtractor<K> implements 
EmpireReaderExtractor<List<K>> {
+       private static class DbRecordMapperExtractor<K> implements
+                       DbReaderExtractor<List<K>> {
 
-               private final EmpireDataReader<K> dataReader;
+               private final DbRecordMapper<K> dataReader;
 
-               public EmpireDataReaderExtractor(EmpireDataReader<K> rowMapper) 
{
+               public DbRecordMapperExtractor(DbRecordMapper<K> rowMapper) {
                        Assert.notNull(rowMapper, "DataReader is required");
                        this.dataReader = rowMapper;
                }
 
-//             @Override
+               // @Override
                public List<K> process(DBReader reader) {
                        try {
                                List<K> results = new ArrayList<K>();

http://git-wip-us.apache.org/repos/asf/empire-db/blob/d4079f57/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireValueReader.java
----------------------------------------------------------------------
diff --git 
a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireValueReader.java
 
b/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireValueReader.java
deleted file mode 100644
index 95e1b9b..0000000
--- 
a/empire-db-spring/src/main/java/org/apache/empire/spring/EmpireValueReader.java
+++ /dev/null
@@ -1,37 +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 org.apache.empire.db.DBColumnExpr;
-import org.apache.empire.db.DBRecordData;
-
-public class EmpireValueReader implements EmpireDataReader<Object> {
-
-       DBColumnExpr column;
-
-       public EmpireValueReader(DBColumnExpr column) {
-               super();
-               this.column = column;
-       }
-
-       public Object read(DBRecordData record) {
-               return record.getValue(column);
-       }
-
-}

http://git-wip-us.apache.org/repos/asf/empire-db/blob/d4079f57/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 41fcd52..3c152ff 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
@@ -39,10 +39,10 @@ import org.apache.empire.db.h2.DBDatabaseDriverH2;
 import org.apache.empire.db.hsql.DBDatabaseDriverHSql;
 import org.apache.empire.db.postgresql.DBDatabaseDriverPostgreSQL;
 import org.apache.empire.spring.EmpireDaoSupport;
-import org.apache.empire.spring.EmpireDataReader;
-import org.apache.empire.spring.EmpireReaderExtractor;
+import org.apache.empire.spring.DbRecordMapper;
+import org.apache.empire.spring.DbReaderExtractor;
 import org.apache.empire.spring.EmpireRecord;
-import org.apache.empire.spring.EmpireRowCallbackHandler;
+import org.apache.empire.spring.DbRecordCallbackHandler;
 import org.apache.empire.xml.XMLWriter;
 import org.springframework.dao.DataAccessException;
 import org.springframework.jdbc.core.ConnectionCallback;
@@ -174,7 +174,7 @@ public class EmpireAppImpl extends EmpireDaoSupport 
implements EmpireApp {
                        switch (type) {
                        case BeanList:
                                // Text-Output by iterating through all records.
-                               EmpireRowCallbackHandler readerImpl = new 
EmpireRowCallbackHandler() {
+                               DbRecordCallbackHandler readerImpl = new 
DbRecordCallbackHandler() {
 
                                        public void processRow(DBRecordData 
reader) {
                                                
System.out.println(reader.getString(EMP.EMPLOYEE_ID)
@@ -193,7 +193,7 @@ public class EmpireAppImpl extends EmpireDaoSupport 
implements EmpireApp {
                        case Reader:
                                // Text-Output using a list of Java Beans 
supplied by the
                                // DBReader
-                               EmpireReaderExtractor<List<SampleBean>> 
beanListImpl = new EmpireReaderExtractor<List<SampleBean>>() {
+                               DbReaderExtractor<List<SampleBean>> 
beanListImpl = new DbReaderExtractor<List<SampleBean>>() {
 
                                        public List<SampleBean> 
process(DBReader reader) {
                                                return 
reader.getBeanList(SampleBean.class);
@@ -254,7 +254,7 @@ public class EmpireAppImpl extends EmpireDaoSupport 
implements EmpireApp {
        }
 
        public static class XmlDocumentExtractor implements
-                       EmpireReaderExtractor<Document> {
+                       DbReaderExtractor<Document> {
 
                public Document process(DBReader reader) {
                        return reader.getXmlDocument();
@@ -263,7 +263,7 @@ public class EmpireAppImpl extends EmpireDaoSupport 
implements EmpireApp {
        }
 
        public static class RowToObjectMapDataMapper implements
-                       EmpireDataReader<Map<Object, Object>> {
+                       DbRecordMapper<Map<Object, Object>> {
 
                DBTable table;
 

http://git-wip-us.apache.org/repos/asf/empire-db/blob/d4079f57/empire-db-spring/src/main/java/org/apache/empire/spring/example2/Department.java
----------------------------------------------------------------------
diff --git 
a/empire-db-spring/src/main/java/org/apache/empire/spring/example2/Department.java
 
b/empire-db-spring/src/main/java/org/apache/empire/spring/example2/Department.java
index e56953c..08d8943 100644
--- 
a/empire-db-spring/src/main/java/org/apache/empire/spring/example2/Department.java
+++ 
b/empire-db-spring/src/main/java/org/apache/empire/spring/example2/Department.java
@@ -59,7 +59,15 @@ public class Department {
 
        @Override
        public String toString() {
-               return this.name;
+               StringBuffer buf = new StringBuffer();
+               buf.append(departmentId);
+               buf.append("\t");
+               buf.append(name);
+               buf.append(" ");
+               buf.append(businessUnit);
+               buf.append("\t");
+               buf.append(head);
+               return buf.toString();
        }
        
        @Override
@@ -87,4 +95,5 @@ public class Department {
                return 1;
        }
 
+       
 }

http://git-wip-us.apache.org/repos/asf/empire-db/blob/d4079f57/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDao.java
----------------------------------------------------------------------
diff --git 
a/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDao.java
 
b/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDao.java
index ad02b46..b2dd39f 100644
--- 
a/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDao.java
+++ 
b/empire-db-spring/src/main/java/org/apache/empire/spring/example2/EmployeeDao.java
@@ -23,6 +23,8 @@ import java.util.List;
 public interface EmployeeDao {
 
        public List<Employee> getEmployees();
+       
+       public List<Department> getDepartments();
 
        public Integer createEmployee(Employee employee);
 

http://git-wip-us.apache.org/repos/asf/empire-db/blob/d4079f57/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 7a384f9..5d1fe50 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
@@ -27,9 +27,9 @@ 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.DbRecordMapper;
 import org.apache.empire.spring.EmpireRecord;
-import org.apache.empire.spring.EmpireRecordWriter;
+import org.apache.empire.spring.DbRecordWriter;
 import org.apache.empire.spring.example1.SampleDB;
 import org.apache.empire.spring.example1.SampleDB.Departments;
 import org.apache.empire.spring.example1.SampleDB.Employees;
@@ -81,16 +81,23 @@ public class EmployeeDaoImpl extends EmpireDaoSupport 
implements EmployeeDao {
        public Department openDepartment(Integer id) {
                DBCommand cmd = createDepartmentSelectCommand();
                cmd.where(DEPARTMENTS.DEPARTMENT_ID.is(id));
-               return getEmpireTemplate().queryForObject(cmd, new 
DepartmentMapper());
+               return getEmpireTemplate().queryForBean(cmd, Department.class);
        }
 
        @Transactional(readOnly = true)
        public Department findDepartment(String name) {
                DBCommand cmd = createDepartmentSelectCommand();
                cmd.where(DEPARTMENTS.NAME.is(name));
-               return getEmpireTemplate().queryForObject(cmd, new 
DepartmentMapper());
+               return getEmpireTemplate().queryForBean(cmd, Department.class);
        }
 
+       @Transactional(readOnly = true)
+       public List<Department> getDepartments() {
+               DBCommand cmd = createEmployeeSelectCommand();
+               return getEmpireTemplate().queryForBeanList(cmd, 
Department.class);
+       }
+
+       
        @Transactional
        public void renameDepartment(Integer id, String name) {
                DBCommand cmd = getDatabase().createCommand();
@@ -137,7 +144,7 @@ public class EmployeeDaoImpl extends EmpireDaoSupport 
implements EmployeeDao {
                getEmpireTemplate().updateRecord(record);
        }
 
-       private class EmployeeMapper implements EmpireDataReader<Employee> {
+       private class EmployeeMapper implements DbRecordMapper<Employee> {
 
                DepartmentMapper departmentMapper = new DepartmentMapper();
 
@@ -159,7 +166,7 @@ public class EmployeeDaoImpl extends EmpireDaoSupport 
implements EmployeeDao {
 
        }
 
-       private class EmployeeWriter implements EmpireRecordWriter<Employee> {
+       private class EmployeeWriter implements DbRecordWriter<Employee> {
 
         @Override
                public void write(DBRecord record, Employee entity) {
@@ -177,7 +184,7 @@ public class EmployeeDaoImpl extends EmpireDaoSupport 
implements EmployeeDao {
 
        }
 
-       private class DepartmentMapper implements EmpireDataReader<Department> {
+       private class DepartmentMapper implements DbRecordMapper<Department> {
 
                // reader cache, in case of joined resultset the same object is 
returned
 
@@ -206,7 +213,7 @@ public class EmployeeDaoImpl extends EmpireDaoSupport 
implements EmployeeDao {
 
        }
 
-       private class DepartmentWriter implements 
EmpireRecordWriter<Department> {
+       private class DepartmentWriter implements DbRecordWriter<Department> {
 
                @Override
         public void write(DBRecord record, Department entity) {

http://git-wip-us.apache.org/repos/asf/empire-db/blob/d4079f57/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
index 90d964a..3b641a7 100644
--- 
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
@@ -134,7 +134,14 @@ public class EmployeeSpringApp {
                        System.out.println(employee);
                }
         
-        
+        System.out.println("*** List departments ***");
+
+        List<Department> departments = employeeDao.getDepartments();
+        for (Iterator<Department> iterator = departments.iterator(); 
iterator.hasNext();) {
+                       Department department = iterator.next();
+                       System.out.println(department);
+               }
+
     }
 
     private static void clearDatabase() {

Reply via email to