2 * Copyright (C) 2015 Roland Haeder
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package org.mxchange.jcore.database.result;
19 import java.sql.PreparedStatement;
20 import java.sql.SQLException;
21 import java.sql.SQLWarning;
22 import java.text.MessageFormat;
23 import java.util.Iterator;
24 import java.util.SortedSet;
25 import java.util.TreeSet;
26 import org.mxchange.jcore.BaseFrameworkSystem;
27 import org.mxchange.jcore.database.storage.Storeable;
31 * @author Roland Haeder
33 public class DatabaseResult extends BaseFrameworkSystem implements Result<Storeable> {
35 * Set of all found Storeable instances
37 private final SortedSet<Storeable> result;
40 * Status value from previous executeUpdate() call
47 private SQLWarning warnings;
52 public DatabaseResult () {
54 this.getLogger().trace("CALLED!"); //NOI18N
57 this.result = new TreeSet<>();
61 * A constructor that accepts a status integer from previous executeUpdate()
62 * call and a the prepared statement instance.
64 * @param status Status code
65 * @param statement A PreparedStatement instance
66 * @throws java.sql.SQLException If any SQL error occurs
68 public DatabaseResult (final int status, final PreparedStatement statement) throws SQLException {
69 // Call parent constructor
73 this.getLogger().trace(MessageFormat.format("status={0},statement={1} - CALLED!", status, statement)); //NOI18N
76 this.setWarnings(statement.getWarnings());
83 * Given Storeable instance as a query result.
85 * @param storeable An instance of a Storeable class
88 public final void add (final Storeable storeable) {
90 this.result.add(storeable);
96 * @return SQLQarning from ResultSet instance
99 public final SQLWarning getWarnings () {
100 return this.warnings;
104 * Setter for warnings
106 * @param warnings SQLQarning from ResultSet instance
109 public final void setWarnings (final SQLWarning warnings) {
110 this.warnings = warnings;
114 public final boolean hasNext () {
115 // Call iterator's method
116 return this.iterator().hasNext();
120 public final Iterator<Storeable> iterator () {
121 // Return iterator from result set
122 return this.result.iterator();
126 public final Storeable next () {
127 // Call iterator's method
128 return this.iterator().next();
132 public final void remove () {
133 // Call iterator's method
134 this.iterator().remove();
138 public final int size () {
139 return this.result.size();