BrightSide Workbench Full Report + Source Code
ChallengesVM.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2019 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.students.model;
20 
21 import java.util.List;
22 import org.turro.string.Strings;
23 import org.turro.elephant.db.SQLHelper;
24 import org.turro.elephant.db.WhereClause;
25 import org.turro.jpa.Dao;
26 import org.turro.students.db.StudentsPU;
27 import org.turro.students.entities.Challenge;
28 import org.zkoss.bind.annotation.Command;
29 import org.zkoss.bind.annotation.NotifyChange;
30 
35 public class ChallengesVM {
36 
37  private String searchValue;
38 
39  public ChallengesVM() {
40  }
41 
42  @NotifyChange("model")
43  @Command("update")
44  public void update() {}
45 
46  public List<Challenge> getModel() {
47  WhereClause wc = new WhereClause();
48  wc.addClause("select s from Challenge s");
49  wc.addClause("where 1=1");
50  if(!Strings.isBlank(searchValue)) {
51  wc.addClause("and s.question like :searchValue");
52  wc.addNamedValue("searchValue", SQLHelper.convertToPartialLike(searchValue));
53  }
54  wc.addClause("order by s.creation desc");
55 
56  return getDao().getResultList(wc);
57  }
58 
59  public String getSearchValue() {
60  return searchValue;
61  }
62 
63  public void setSearchValue(String searchValue) {
64  this.searchValue = searchValue;
65  }
66 
67  /* Dao */
68 
69  private Dao _dao;
70 
71  private Dao getDao() {
72  if(_dao == null) {
73  _dao = new StudentsPU();
74  }
75  return _dao;
76  }
77 
78 }
static String convertToPartialLike(String value)
Definition: SQLHelper.java:38
void addNamedValue(String name, Object value)
void setSearchValue(String searchValue)