[ https://issues.apache.org/jira/browse/PHOENIX-2186?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14705624#comment-14705624 ]
ASF GitHub Bot commented on PHOENIX-2186: ----------------------------------------- Github user ndimiduk commented on a diff in the pull request: https://github.com/apache/phoenix/pull/111#discussion_r37572381 --- Diff: phoenix-tracing-webapp/src/main/java/org/apache/phoenix/tracingwebapp/http/EntityFactory.java --- @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.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://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.phoenix.tracingwebapp.http; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class EntityFactory { + + private final String queryString; + protected Connection connection; + + public EntityFactory(Connection connection, String queryString) { + this.queryString = queryString; + this.connection = connection; + } + + public Map<String, Object> findSingle(Object[] params) throws SQLException { + List<Map<String, Object>> objects = this.findMultiple(params); + + if (objects.size() != 1) { + throw new SQLException("Query did not produce one object it produced: " + + objects.size() + " objects."); + } + + Map<String, Object> object = objects.get(0); // get first record; + + return object; + } + + public List<Map<String, Object>> findMultiple(Object[] params) + throws SQLException { + ResultSet rs = null; + PreparedStatement ps = null; + try { + ps = this.connection.prepareStatement(this.queryString); + for (int i = 0; i < params.length; ++i) { + ps.setObject(1, params[i]); + } + + rs = ps.executeQuery(); + return getEntitiesFromResultSet(rs); + } catch (SQLException e) { + throw (e); + } finally { + if (rs != null) { + rs.close(); + } + if (ps != null) { + ps.close(); + } + } + } + + protected List<Map<String, Object>> getEntitiesFromResultSet( --- End diff -- this can also be made a static method. > Creating backend services for the Phoenix Tracing Web App > --------------------------------------------------------- > > Key: PHOENIX-2186 > URL: https://issues.apache.org/jira/browse/PHOENIX-2186 > Project: Phoenix > Issue Type: Sub-task > Reporter: Nishani > Assignee: Nishani > > This will include the following components. > Main class > Pom file > Launch script > Backend trace service API -- This message was sent by Atlassian JIRA (v6.3.4#6332)