gt: 		ValueBatch batch = getValueBatch();
context: /*
   * Copyright Aduna (http://www.aduna-software.com/) (c) 2008.
   *
   * Licensed under the Aduna BSD-style license.
   */
  package org.openrdf.sail.generaldb.schema;
  
  import java.sql.PreparedStatement;
  import java.sql.ResultSet;
  import java.sql.SQLException;
  import java.sql.Types;
  import java.util.ArrayList;
  import java.util.List;
  import java.util.Map;
  import java.util.concurrent.BlockingQueue;
  
  import org.openrdf.sail.generaldb.GeneralDBSqlTable;
  import org.openrdf.sail.rdbms.schema.RdbmsTable;
  
  
  /**
   * Manages the rows in a value table. These tables have two columns: an internal
   * id column and a value column.
   * 
   * @author James Leigh
   * 
   */
  public class ValueTable  {
  
  	public static int BATCH_SIZE = 8 * 1024;
  
  	public static final long NIL_ID = 0; // TODO
  
  	private static final String[] PKEY = { "id" };
  
  	private static final String[] VALUE_INDEX = { "value" };
  
  	private int length = -1;
  
  	private int sqlType;
  
  	private int idType;
  
  	private String INSERT;
  
  	private String INSERT_SELECT;
  
  	private String EXPUNGE;
  
  	private RdbmsTable table;
  
  	private RdbmsTable temporary;
  
  	private ValueBatch batch;
  
  	private BlockingQueue<Batch> queue;
  
  	private boolean indexingValues;
  
  	private PreparedStatement insertSelect;
  
  	public void setQueue(BlockingQueue<Batch> queue) {
  		this.queue = queue;
  	}
  
  	public boolean isIndexingValues() {
  		return indexingValues;
  	}
  
  	public void setIndexingValues(boolean indexingValues) {
  		this.indexingValues = indexingValues;
  	}
  
  	public int getLength() {
  		return length;
  	}
  
  	public void setLength(int length) {
  		this.length = length;
  	}
  
  	public int getSqlType() {
  		return sqlType;
  	}
  
  	public void setSqlType(int sqlType) {
  		this.sqlType = sqlType;
  	}
  
  	public int getIdType() {
  		return idType;
  	}
  
  	public void setIdType(int sqlType) {
  		this.idType = sqlType;
  	}
  
  	public RdbmsTable getRdbmsTable() {
  		return table;
  	}
  
  	public void setRdbmsTable(RdbmsTable table) {
  		this.table = table;
  	}
  
  	public RdbmsTable getTemporaryTable() {
  		return temporary;
  	}
  
  	public void setTemporaryTable(RdbmsTable temporary) {
  		this.temporary = temporary;
  	}
  
  	public String getName() {
  		return table.getName();
  	}
  
  	public long size() {
  		return table.size();
  	}
  
  	public int getBatchSize() {
  		return BATCH_SIZE;
  	}
  
  	public void initialize()
  			throws SQLException
  			{
  		StringBuilder sb = new StringBuilder();
  		/****************/
  		//		sb.append("INSERT INTO ").append(getInsertTable().getName());
  		//		sb.append(" (id, value) VALUES (?, ?)");
  		sb.append("INSERT INTO ").append(getInsertTable().getName());
  		GeneralDBSqlTable table = (GeneralDBSqlTable)getInsertTable();
  		sb.append(table.buildInsertValue(sql(sqlType, length)));
  		/*******************/
  		INSERT = sb.toString();
  		sb.delete(0, sb.length());
  		sb.append("DELETE FROM ").append(table.getName()).append("\n");
  		sb.append(table.buildWhere());
  		EXPUNGE = sb.toString();
  		if (temporary != null) {
  			sb.delete(0, sb.length());
  			sb.append("INSERT INTO ").append(table.getName());
  			sb.append(" (id, value) SELECT DISTINCT id, value FROM ");
  			sb.append(temporary.getName()).append(" tmp\n");
  			sb.append("WHERE NOT EXISTS (SELECT id FROM ").append(table.getName());
  			sb.append(" val WHERE val.id = tmp.id)");
  			INSERT_SELECT = sb.toString();
  		}
  		if (!table.isCreated()) {
  			createTable(table);
  			table.primaryIndex(PKEY);
  			if (isIndexingValues()) {
  				table.index(VALUE_INDEX);
  			}
  		}
  		else {
  			//Adding index on datetime values to tackle the case of "deprecated" existing db dumps
  			if(this.getName().equalsIgnoreCase("datetime_values") || this.getName().equalsIgnoreCase("hash_values"))
  			{
  				Map<String, List<String>> allIndices = table.getIndexes();
  				if(allIndices.size()<2)
  				{
  					//Datetime values index does not exist - only primary key constraint is present
  					table.index(VALUE_INDEX);
  				}
  				
  			}
  			table.count();
  		}
  		if (temporary != null && !temporary.isCreated()) {
  			createTemporaryTable(temporary);
  		}
  			}
  
  	public void close()
  			throws SQLException
  			{
  		if (insertSelect != null) {
  			insertSelect.close();
  		}
  		if (temporary != null) {
  			temporary.close();
  		}
  		table.close();
  			}
  
  	public synchronized void insert(Number id, String value)
  			throws SQLException, InterruptedException
  			{
  		ValueBatch batch = getValueBatch();
  		if (isExpired(batch)) {
  			batch = newValueBatch();
  			initBatch(batch);
  		}
  		batch.setObject(1, id);
  		batch.setString(2, value);
  		batch.addBatch();
  		queue(batch);
  			}
  
  	public synchronized void insert(Number id, Number value)
  			throws SQLException, InterruptedException
  			{
  