BrightSide Workbench Full Report + Source Code
JpaCombobox.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2015 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.jpa.input;
20 
21 import java.util.LinkedList;
22 import org.turro.elephant.db.SQLHelper;
23 import org.turro.elephant.db.WhereClause;
24 import org.turro.jpa.Dao;
25 import org.turro.zkoss.input.GenericCombobox;
26 
31 public abstract class JpaCombobox<V> extends GenericCombobox<V> {
32 
33  private Dao dao;
34  private String query;
35  private WhereClause wc;
36 
37  public JpaCombobox() {
38  super();
39  }
40 
41  public JpaCombobox(Dao dao, String query) {
42  this.dao = dao;
43  this.query = query;
44  this.wc = null;
45  }
46 
47  public JpaCombobox(Dao dao, WhereClause wc) {
48  this.dao = dao;
49  this.query = null;
50  this.wc = wc;
51  }
52 
53  public Dao getDao() {
54  return dao;
55  }
56 
57  public void setDao(Dao dao) {
58  this.dao = dao;
59  }
60 
61  public String getQuery() {
62  return query;
63  }
64 
65  public void setQuery(String query) {
66  this.query = query;
67  }
68 
69  @Override
70  public void populateList(String value, LinkedList list, int nRows) {
71  if(wc != null) {
72  wc.addNamedValue("value", SQLHelper.convertToPartialLike(value));
73  list.addAll(dao.getResultList(wc, nRows));
74  } else {
75  if(query.contains("?")) {
76  list.addAll(dao.getResultList(query, new Object[] { SQLHelper.convertToPartialLike(value) }, nRows));
77  } else {
78  list.addAll(dao.getResultList(query));
79  }
80  }
81  }
82 
83 }
static String convertToPartialLike(String value)
Definition: SQLHelper.java:38
void addNamedValue(String name, Object value)
JpaCombobox(Dao dao, WhereClause wc)
JpaCombobox(Dao dao, String query)
void populateList(String value, LinkedList list, int nRows)