View Javadoc

1   /*--------------------------------------------------------------------------
2    *  Copyright 2007 utgenome.org
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *--------------------------------------------------------------------------*/
16  //--------------------------------------
17  // utgb-core Project
18  //
19  // SQLiteAccessSample.java
20  // Since: Oct 12, 2007
21  //
22  // $URL$ 
23  // $Author$
24  //--------------------------------------
25  package org.utgenome.gwt.utgb.server.app;
26  
27  import java.io.IOException;
28  import java.util.ArrayList;
29  import java.util.List;
30  
31  import javax.servlet.ServletException;
32  import javax.servlet.http.HttpServletRequest;
33  import javax.servlet.http.HttpServletResponse;
34  
35  import org.utgenome.UTGBException;
36  import org.utgenome.gwt.utgb.server.RequestHandlerBase;
37  import org.utgenome.gwt.utgb.server.UTGBMaster;
38  import org.xerial.db.DBException;
39  import org.xerial.db.sql.DatabaseAccess;
40  import org.xerial.util.StringUtil;
41  import org.xerial.util.log.Logger;
42  
43  /**
44   * Sample class to access SQLite database
45   * 
46   * @author leo
47   * 
48   */
49  public class SQLiteAccessSample extends RequestHandlerBase {
50  	/**
51  	 * 
52  	 */
53  	private static final long serialVersionUID = 1L;
54  
55  	private static Logger _logger = Logger.getLogger(SQLiteAccessSample.class);
56  
57  	public void handle(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
58  		ArrayList<String> speciesList = new ArrayList<String>();
59  		try {
60  			// this will load database file specified in config/development.silk file 
61  			DatabaseAccess sqlite = UTGBMaster.getDatabaseAccess("legacy-track");
62  			List<String> queryResult = sqlite.singleColumnQuery("select distinct species from tracks order by species", "species", String.class);
63  			_logger.debug("species: " + queryResult);
64  			speciesList.addAll(queryResult);
65  
66  			response.getWriter().println(StringUtil.join(queryResult, ", "));
67  		}
68  		catch (DBException e) {
69  			_logger.error(e);
70  		}
71  		catch (UTGBException e) {
72  			_logger.error(e);
73  		}
74  
75  	}
76  
77  }