/**
This file is automatically generated. Do not modify
*/
package org.kairosdb.datastore.h2.orm;
import java.util.Locale;
import java.util.Date;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;
import java.sql.Timestamp;
import org.xml.sax.ContentHandler;
import org.xml.sax.Attributes;
import org.agileclick.genorm.runtime.*;
/**
*/
public class MetricNamesQuery extends org.agileclick.genorm.runtime.SQLQuery
{
private static final Logger s_logger = LoggerFactory.getLogger(MetricNamesQuery.class.getName());
public static final String QUERY_NAME = "metric_names";
public static final String QUERY = "select distinct \"name\" from metric";
private static final int ATTRIBUTE_COUNT = 1;
private static Map<String, Integer> s_attributeIndex;
private static String[] s_attributeNames = {
"name" };
static
{
s_attributeIndex = new HashMap<String, Integer>();
for (int I = 0; I < ATTRIBUTE_COUNT; I++)
s_attributeIndex.put(s_attributeNames[I], I);
}
private boolean m_serializable;
//---------------------------------------------------------------------------
public MetricNamesQuery()
{
super();
}
//---------------------------------------------------------------------------
public String getQueryName() { return (QUERY_NAME); }
//---------------------------------------------------------------------------
public String getQuery() { return (QUERY); }
//---------------------------------------------------------------------------
public void setSerializable(boolean serializable)
{
m_serializable = serializable;
}
//---------------------------------------------------------------------------
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append(this.getClass().getName());
return (sb.toString());
}
//---------------------------------------------------------------------------
public void serializeQuery(ContentHandler ch, String tagName)
throws org.xml.sax.SAXException
{
boolean prevSerializeState = m_serializable;
m_serializable = true;
ResultSet rs = runQuery();
while (rs.next())
{
MetricNamesData rec = rs.getRecord();
ch.startElement("", tagName, tagName, rec);
ch.endElement("", tagName, tagName);
}
rs.close();
m_serializable = prevSerializeState;
}
//---------------------------------------------------------------------------
public ResultSet runQuery()
{
java.sql.PreparedStatement genorm_statement = null;
try
{
String genorm_query = QUERY;
genorm_statement = org.kairosdb.datastore.h2.orm.GenOrmDataSource.prepareStatement(genorm_query);
long genorm_queryTimeStart = 0L;
if (s_logger.isInfo())
{
genorm_queryTimeStart = System.currentTimeMillis();
}
java.sql.ResultSet genorm_resultSet = genorm_statement.executeQuery();
if (genorm_queryTimeStart != 0L)
{
long genorm_quryTime = System.currentTimeMillis() - genorm_queryTimeStart;
s_logger.info(genorm_quryTime);
}
ResultSet genorm_ret = new SQLResultSet(genorm_resultSet, genorm_statement, genorm_query);
return (genorm_ret);
}
catch (java.sql.SQLException sqle)
{
try
{
if (genorm_statement != null)
genorm_statement.close();
}
catch (java.sql.SQLException sqle2) { }
throw new GenOrmException(sqle);
}
}
//===========================================================================
//Plugin Classes and Methods
//===========================================================================
public interface ResultSet extends GenOrmQueryResultSet<MetricNamesData>
{
public List<MetricNamesData> getArrayList(int maxRows);
public List<MetricNamesData> getArrayList();
public MetricNamesData getRecord();
public MetricNamesData getOnlyRecord();
}
//===========================================================================
private class SQLResultSet
implements ResultSet
{
private java.sql.ResultSet m_resultSet;
private java.sql.Statement m_statement;
private String m_query;
private boolean m_onFirstResult;
//------------------------------------------------------------------------
//need to pass in the statement so it can be closed after the result set
protected SQLResultSet(java.sql.ResultSet resultSet, java.sql.Statement statement,
String query)
{
m_resultSet = resultSet;
m_statement = statement;
m_query = query;
m_onFirstResult = false;
}
//------------------------------------------------------------------------
/**
Closes any underlying java.sql.Result set and java.sql.Statement
that was used to create this results set.
*/
public void close()
{
try
{
m_resultSet.close();
m_statement.close();
}
catch (java.sql.SQLException sqle)
{
throw new GenOrmException(sqle);
}
}
//------------------------------------------------------------------------
/**
Returns the reults as an ArrayList of Record objects.
The Result set is closed within this call
*/
public List<MetricNamesData> getArrayList(int maxRows)
{
ArrayList<MetricNamesData> results = new ArrayList<MetricNamesData>();
int count = 0;
try
{
if (m_onFirstResult)
{
count ++;
results.add(new MetricNamesData(MetricNamesQuery.this, m_resultSet));
}
while (m_resultSet.next() && (count < maxRows))
{
count ++;
results.add(new MetricNamesData(MetricNamesQuery.this, m_resultSet));
}
if (m_resultSet.next())
throw new GenOrmException("Bound of "+maxRows+" is too small for query ["+m_query+"]");
}
catch (java.sql.SQLException sqle)
{
throw new GenOrmException(sqle);
}
close();
return (results);
}
//------------------------------------------------------------------------
/**
Returns the reults as an ArrayList of Record objects.
The Result set is closed within this call
*/
public List<MetricNamesData> getArrayList()
{
ArrayList<MetricNamesData> results = new ArrayList<MetricNamesData>();
try
{
if (m_onFirstResult)
results.add(new MetricNamesData(MetricNamesQuery.this, m_resultSet));
while (m_resultSet.next())
results.add(new MetricNamesData(MetricNamesQuery.this, m_resultSet));
}
catch (java.sql.SQLException sqle)
{
throw new GenOrmException(sqle);
}
close();
return (results);
}
//------------------------------------------------------------------------
/**
Returns the underlying java.sql.ResultSet object
*/
public java.sql.ResultSet getResultSet()
{
return (m_resultSet);
}
//------------------------------------------------------------------------
/**
Returns the current record in the result set
*/
public MetricNamesData getRecord()
{
MetricNamesData ret = null;
try
{
ret = new MetricNamesData(MetricNamesQuery.this, m_resultSet);
}
catch (java.sql.SQLException sqle)
{
throw new GenOrmException(sqle);
}
return (ret);
}
//------------------------------------------------------------------------
/**
This call expects only one record in the result set. If multiple records
are found an excpetion is thrown.
The ResultSet object is automatically closed by this call.
*/
public MetricNamesData getOnlyRecord()
{
MetricNamesData ret = null;
try
{
if (m_resultSet.next())
ret = new MetricNamesData(MetricNamesQuery.this, m_resultSet);
if (m_resultSet.next())
throw new GenOrmException("Multiple rows returned in call from MetricNamesQuery.ResultSet.getOnlyRecord");
}
catch (java.sql.SQLException sqle)
{
throw new GenOrmException(sqle);
}
close();
return (ret);
}
//------------------------------------------------------------------------
/**
Returns true if there is another record in the result set.
*/
public boolean next()
{
boolean ret = false;
m_onFirstResult = true;
try
{
ret = m_resultSet.next();
}
catch (java.sql.SQLException sqle)
{
throw new GenOrmException(sqle);
}
return (ret);
}
}
//===========================================================================
public class Record implements GenOrmQueryRecord, Attributes
{
protected String m_name;
protected String[] m_attrValues;
protected Record(java.sql.ResultSet rs)
throws java.sql.SQLException
{
m_name = (String)rs.getString(1);
if (m_serializable)
{
m_attrValues = new String[ATTRIBUTE_COUNT];
m_attrValues[0] = MetricNamesQuery.this.m_formatter.toString(s_attributeNames[0], m_name);
}
}
public String getName() { return (m_name); }
//------------------------------------------------------------------------
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append(" name=\"");
sb.append(m_name);
sb.append("\"");
return (sb.toString().trim());
}
//------------------------------------------------------------------------
/*Attributes*/
public int getIndex(String qName)
{
Integer index = s_attributeIndex.get(qName);
if (index == null)
return (-1);
else
return (index);
}
//------------------------------------------------------------------------
/*Attributes*/
public int getIndex(String uri, String localName)
{
if (uri == null || uri.equals(""))
return (getIndex(localName));
else
return (-1);
}
//------------------------------------------------------------------------
/*Attributes*/
public int getLength() { return (ATTRIBUTE_COUNT); }
//------------------------------------------------------------------------
/*Attributes*/
public String getLocalName(int index)
{
if (index < 0 || index >= ATTRIBUTE_COUNT)
return (null);
else
return (s_attributeNames[index]);
}
//------------------------------------------------------------------------
/*Attributes*/
public String getQName(int index)
{
if (index < 0 || index >= ATTRIBUTE_COUNT)
return (null);
else
return (s_attributeNames[index]);
}
//------------------------------------------------------------------------
/*Attributes*/
public String getType(int index) { return ("CDATA"); }
//------------------------------------------------------------------------
/*Attributes*/
public String getType(String qName) { return ("CDATA"); }
//------------------------------------------------------------------------
/*Attributes*/
public String getType(String uri, String localName) { return ("CDATA"); }
//------------------------------------------------------------------------
/*Attributes*/
public String getURI(int index)
{
if (index < 0 || index >= ATTRIBUTE_COUNT)
return (null);
else
return ("");
}
//------------------------------------------------------------------------
/*Attributes*/
public String getValue(int index)
{
if (index < 0 || index >= ATTRIBUTE_COUNT)
return (null);
else
return (m_attrValues[index]);
}
//------------------------------------------------------------------------
/*Attributes*/
public String getValue(String qName)
{
return (getValue(getIndex(qName)));
}
//------------------------------------------------------------------------
/*Attributes*/
public String getValue(String uri, String localName)
{
return (getValue(getIndex(uri, localName)));
}
}
}