|
|||||||||||||||||||
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
ResultSetIterator.java | 0% | 0% | 0% | 0% |
|
1 |
// Copyright 2004, 2005 The Apache Software Foundation
|
|
2 |
//
|
|
3 |
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4 |
// you may not use this file except in compliance with the License.
|
|
5 |
// You may obtain a copy of the License at
|
|
6 |
//
|
|
7 |
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8 |
//
|
|
9 |
// Unless required by applicable law or agreed to in writing, software
|
|
10 |
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12 |
// See the License for the specific language governing permissions and
|
|
13 |
// limitations under the License.
|
|
14 |
|
|
15 |
package org.apache.tapestry.contrib.table.model.sql;
|
|
16 |
|
|
17 |
import java.sql.ResultSet;
|
|
18 |
import java.sql.SQLException;
|
|
19 |
import java.util.Iterator;
|
|
20 |
|
|
21 |
import org.apache.commons.logging.Log;
|
|
22 |
import org.apache.commons.logging.LogFactory;
|
|
23 |
|
|
24 |
/**
|
|
25 |
*
|
|
26 |
* @author mindbridge
|
|
27 |
*/
|
|
28 |
public class ResultSetIterator implements Iterator |
|
29 |
{ |
|
30 |
private static final Log LOG = LogFactory.getLog(ResultSetIterator.class); |
|
31 |
|
|
32 |
private ResultSet m_objResultSet;
|
|
33 |
private boolean m_bFetched; |
|
34 |
private boolean m_bAvailable; |
|
35 |
|
|
36 | 0 |
public ResultSetIterator(ResultSet objResultSet)
|
37 |
{ |
|
38 | 0 |
m_objResultSet = objResultSet; |
39 | 0 |
m_bFetched = false;
|
40 |
} |
|
41 |
|
|
42 |
/**
|
|
43 |
* @see java.util.Iterator#hasNext()
|
|
44 |
*/
|
|
45 | 0 |
public synchronized boolean hasNext() |
46 |
{ |
|
47 | 0 |
if (getResultSet() == null) return false; |
48 |
|
|
49 | 0 |
if (!m_bFetched)
|
50 |
{ |
|
51 | 0 |
m_bFetched = true;
|
52 |
|
|
53 | 0 |
try
|
54 |
{ |
|
55 | 0 |
m_bAvailable = !getResultSet().isLast(); |
56 |
} |
|
57 |
catch (SQLException e)
|
|
58 |
{ |
|
59 | 0 |
LOG.warn( |
60 |
"SQLException while testing for end of the ResultSet",
|
|
61 |
e); |
|
62 | 0 |
m_bAvailable = false;
|
63 |
} |
|
64 |
|
|
65 | 0 |
if (!m_bAvailable)
|
66 | 0 |
notifyEnd(); |
67 |
} |
|
68 |
|
|
69 | 0 |
return m_bAvailable;
|
70 |
} |
|
71 |
|
|
72 |
/**
|
|
73 |
* @see java.util.Iterator#next()
|
|
74 |
*/
|
|
75 | 0 |
public synchronized Object next() |
76 |
{ |
|
77 | 0 |
ResultSet objResultSet = getResultSet(); |
78 |
|
|
79 | 0 |
try
|
80 |
{ |
|
81 | 0 |
if (!objResultSet.next())
|
82 | 0 |
return null; |
83 |
} |
|
84 |
catch (SQLException e)
|
|
85 |
{ |
|
86 | 0 |
LOG.warn("SQLException while iterating over the ResultSet", e);
|
87 | 0 |
return null; |
88 |
} |
|
89 |
|
|
90 | 0 |
m_bFetched = false;
|
91 | 0 |
return objResultSet;
|
92 |
} |
|
93 |
|
|
94 |
/**
|
|
95 |
* @see java.util.Iterator#remove()
|
|
96 |
*/
|
|
97 | 0 |
public void remove() |
98 |
{ |
|
99 | 0 |
try
|
100 |
{ |
|
101 | 0 |
getResultSet().deleteRow(); |
102 |
} |
|
103 |
catch (SQLException e)
|
|
104 |
{ |
|
105 | 0 |
LOG.error("Cannot delete record", e);
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
/**
|
|
110 |
* Returns the resultSet.
|
|
111 |
* @return ResultSet
|
|
112 |
*/
|
|
113 | 0 |
public ResultSet getResultSet()
|
114 |
{ |
|
115 | 0 |
return m_objResultSet;
|
116 |
} |
|
117 |
|
|
118 | 0 |
protected void notifyEnd() |
119 |
{ |
|
120 |
} |
|
121 |
|
|
122 |
} |
|
123 |
|
|