/** * The contents of this file are subject to the OpenMRS Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://license.openmrs.org * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * Copyright (C) OpenMRS, LLC. All Rights Reserved. */ package org.eclipse.datatools.connectivity.oda.openmrs.impl; import java.math.BigDecimal; import java.sql.Date; import java.sql.Time; import java.sql.Timestamp; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import org.eclipse.datatools.connectivity.oda.IParameterMetaData; import org.eclipse.datatools.connectivity.oda.IQuery; import org.eclipse.datatools.connectivity.oda.IResultSet; import org.eclipse.datatools.connectivity.oda.IResultSetMetaData; import org.eclipse.datatools.connectivity.oda.OdaException; import org.eclipse.datatools.connectivity.oda.SortSpec; /** * Implementation class of IQuery for OpenMRS ODA runtime driver. */ public class Query implements IQuery { private int m_maxRows = 0; private String path, user, pass; private Filter filter; private List tokens; private ResultSetMetaData resultSetMetaData; String dataStyle; private Logger log = Logger.getLogger(Query.class.getName()); /* * Constructor featuring a setting of username and password */ public Query(String path, String user, String pass) { log.setLevel(Level.INFO); this.path = path; this.user = user; this.pass = pass; } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#prepare(java.lang.String) * Format to queryText: filter:token_1:token_2:...:token_n */ public void prepare(String queryText) throws OdaException { log.info("Query text: " + queryText); /* * String[] quer = queryText.split(":"); if (quer.length < 2) { // * should have at least one token throw new OdaException( "Query is not * full; enter full specification."); } */ filter = XMLParser.getFilterMap(path, user, pass).get( QueryBuilder.getFilter(queryText)); tokens = new ArrayList(); Map tokenMap = XMLParser.getTokenMap(path, user, pass, ""); tokens = QueryBuilder.getTokens(queryText, tokenMap); dataStyle = QueryBuilder.getDataStyle(queryText); resultSetMetaData = new ResultSetMetaData(tokens, dataStyle); } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#setAppContext(java.lang.Object) */ public void setAppContext(Object context) throws OdaException { // do nothing; assumes no support for pass-through context } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#close() */ public void close() throws OdaException { path = null; user = null; pass = null; filter = null; tokens = null; } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#getMetaData() */ public IResultSetMetaData getMetaData() throws OdaException { return resultSetMetaData; } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#executeQuery() */ public IResultSet executeQuery() throws OdaException { IResultSet resultSet = new ResultSet(resultSetMetaData, XMLParser .getData(path, user, pass, filter, tokens, dataStyle, resultSetMetaData)); resultSet.setMaxRows(getMaxRows()); return resultSet; } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#setProperty(java.lang.String, * java.lang.String) */ public void setProperty(String name, String value) throws OdaException { // do nothing; assumes no data set query property } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#setMaxRows(int) */ public void setMaxRows(int max) throws OdaException { m_maxRows = max; } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#getMaxRows() */ public int getMaxRows() throws OdaException { return m_maxRows; } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#clearInParameters() */ public void clearInParameters() throws OdaException { // only applies to input parameter throw new UnsupportedOperationException(); } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#setInt(java.lang.String, * int) */ public void setInt(String parameterName, int value) throws OdaException { // only applies to named input parameter throw new UnsupportedOperationException(); } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#setInt(int, int) */ public void setInt(int parameterId, int value) throws OdaException { // only applies to input parameter throw new UnsupportedOperationException(); } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#setDouble(java.lang.String, * double) */ public void setDouble(String parameterName, double value) throws OdaException { // only applies to named input parameter throw new UnsupportedOperationException(); } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#setDouble(int, double) */ public void setDouble(int parameterId, double value) throws OdaException { // only applies to input parameter throw new UnsupportedOperationException(); } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#setBigDecimal(java.lang.String, * java.math.BigDecimal) */ public void setBigDecimal(String parameterName, BigDecimal value) throws OdaException { // only applies to named input parameter throw new UnsupportedOperationException(); } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#setBigDecimal(int, * java.math.BigDecimal) */ public void setBigDecimal(int parameterId, BigDecimal value) throws OdaException { // only applies to input parameter throw new UnsupportedOperationException(); } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#setString(java.lang.String, * java.lang.String) */ public void setString(String parameterName, String value) throws OdaException { // only applies to named input parameter throw new UnsupportedOperationException(); } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#setString(int, * java.lang.String) */ public void setString(int parameterId, String value) throws OdaException { // only applies to input parameter throw new UnsupportedOperationException(); } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#setBoolean(java.lang.String, * boolean) */ public void setBoolean(String parameterName, boolean value) throws OdaException { // only applies to named input parameter } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#setBoolean(int, * boolean) */ public void setBoolean(int parameterId, boolean value) throws OdaException { // only applies to input parameter throw new UnsupportedOperationException(); } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#setDate(java.lang.String, * java.sql.Date) */ public void setDate(String parameterName, Date value) throws OdaException { // only applies to named input parameter throw new UnsupportedOperationException(); } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#setDate(int, * java.sql.Date) */ public void setDate(int parameterId, Date value) throws OdaException { // only applies to input parameter throw new UnsupportedOperationException(); } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#setTime(java.lang.String, * java.sql.Time) */ public void setTime(String parameterName, Time value) throws OdaException { // only applies to named input parameter throw new UnsupportedOperationException(); } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#setTime(int, * java.sql.Time) */ public void setTime(int parameterId, Time value) throws OdaException { // only applies to input parameter throw new UnsupportedOperationException(); } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#setTimestamp(java.lang.String, * java.sql.Timestamp) */ public void setTimestamp(String parameterName, Timestamp value) throws OdaException { // only applies to named input parameter throw new UnsupportedOperationException(); } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#setTimestamp(int, * java.sql.Timestamp) */ public void setTimestamp(int parameterId, Timestamp value) throws OdaException { // only applies to input parameter throw new UnsupportedOperationException(); } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#setNull(java.lang.String) */ public void setNull(String parameterName) throws OdaException { // only applies to input parameter throw new UnsupportedOperationException(); } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#setNull(int) */ public void setNull(int parameterId) throws OdaException { // only applies to input parameter throw new UnsupportedOperationException(); } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#findInParameter(java.lang.String) */ public int findInParameter(String parameterName) throws OdaException { // only applies to named input parameter throw new UnsupportedOperationException(); } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#getParameterMetaData() */ public IParameterMetaData getParameterMetaData() throws OdaException { // only applies to input parameters return null; } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#setSortSpec(org.eclipse.datatools.connectivity.oda.SortSpec) */ public void setSortSpec(SortSpec sortBy) throws OdaException { // only applies to sorting throw new UnsupportedOperationException(); } /* * @see org.eclipse.datatools.connectivity.oda.IQuery#getSortSpec() */ public SortSpec getSortSpec() throws OdaException { // only applies to sorting throw new UnsupportedOperationException(); } }