Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
AnalyzerBeans Copyright (C) 2014 Neopost - Customer Information Management This copyrighted material is made available to anyone wishing to use, modify, copy, or redistribute it subject to the terms and conditions of the GNU Lesser General Public License, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this distribution; if not, write to: Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor Boston, MA 02110-1301 USA
 
 package org.eobjects.analyzer.storage;
 
 import java.util.Set;
 
 final class SqlDatabaseSet<E> extends AbstractSet<E> implements Set<E>, SqlDatabaseCollection {
 
 	private final Connection _connection;
 	private final String _tableName;
 	private volatile int _size;
 
 	public SqlDatabaseSet(Connection connectionString tableNameString valueTypeName) {
 		 = connection;
 		 = tableName;
 
 		SqlDatabaseUtils.performUpdate(. + tableName + " (set_value " + valueTypeName
 				+ " PRIMARY KEY)");
 	}
 
 	public synchronized boolean add(E elem) {
 		if (contains(elem)) {
 			return false;
 		}
 		PreparedStatement st = null;
 		try {
 			st = .prepareStatement("INSERT INTO " +  + " VALUES(?)");
 			st.setObject(1, elem);
 			++;
 			return true;
 		} catch (SQLException e) {
 			throw new IllegalStateException(e);
 		} finally {
 			SqlDatabaseUtils.safeClose(nullst);
 		}
 	};
 
 	public boolean remove(Object o) {
 		if (!contains(o)) {
 			return false;
 		}
 
 		PreparedStatement st = null;
 		try {
 			st = .prepareStatement("DELETE FROM " +  + " WHERE set_value=?");
 			st.setObject(1, o);
 			--;
 			return true;
 		} catch (SQLException e) {
 			throw new IllegalStateException(e);
 		} finally {
 			SqlDatabaseUtils.safeClose(nullst);
 		}
 	}
 
 	public boolean contains(Object o) {
 		ResultSet rs = null;
 		PreparedStatement st = null;
 		try {
 			st = .prepareStatement("SELECT COUNT(*) FROM " +  + " WHERE set_value=?");
 			st.setObject(1, o);
 			rs = st.executeQuery();
 			if (rs.next()) {
 				return rs.getInt(1) > 0;
 			}
 			return false;
 		} catch (SQLException e) {
 			throw new IllegalStateException(e);
 		} finally {
 			SqlDatabaseUtils.safeClose(rsst);
 		}
 	}
	public Iterator<E> iterator() {
		PreparedStatement st = null;
		ResultSet rs = null;
		try {
			st = .prepareCall("SELECT set_value FROM " + );
			rs = st.executeQuery();
			return new SqlDatabaseSetIterator<E>(thisrsst);
catch (SQLException e) {
			SqlDatabaseUtils.safeClose(rsst);
			throw new IllegalStateException(e);
		}
	}
	public int size() {
		return ;
	}
	public String getTableName() {
		return ;
	}
	protected void finalize() throws Throwable {
		super.finalize();
		SqlDatabaseUtils.performUpdate("DROP TABLE " + getTableName());
	}
New to GrepCode? Check out our FAQ X