BrightSide Workbench Full Report + Source Code
TagOccurrenceAPI.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2021 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.occurrence;
20 
21 import java.util.List;
22 import org.turro.elephant.db.ElephantPU;
23 import org.turro.elephant.db.WhereClause;
24 import org.turro.elephant.entities.db.Tag;
25 import org.turro.i18n.I_;
26 import org.turro.jpa.Dao;
27 
32 public class TagOccurrenceAPI extends AbstractOccurrenceAPI<Tag> {
33 
34  @Override
35  public String getName() {
36  return I_.get("Tags");
37  }
38 
39  @Override
40  public List<String> getPossibles(String value) {
41  WhereClause wc = new WhereClause();
42  wc.addClause("select distinct t.tagName from Tag t");
43  wc.setPrefix("where");
44  wc.addLikeFields(new String[] { "t.tagName" }, value);
45  return getDao().getResultList(String.class, wc);
46  }
47 
48  @Override
49  protected List<Tag> getOccurrences(String value) {
50  WhereClause wc = new WhereClause();
51  wc.addClause("select t from Tag t");
52  wc.addClause("where t.tagName = :value");
53  wc.addNamedValue("value", value);
54  return getDao().getResultList(Tag.class, wc);
55  }
56 
57  @Override
58  protected String getValue(Tag value) {
59  return value.getTagName();
60  }
61 
62  @Override
63  protected void setValue(Tag value, String newValue) {
64  getDao().deleteObject(value);
65  value.setTagName(newValue);
66  }
67 
68  @Override
69  protected Dao createDao() {
70  return new ElephantPU();
71  }
72 
73 }
void addLikeFields(String[] fields, String value)
void addNamedValue(String name, Object value)
void setTagName(String tagName)
Definition: Tag.java:51
static String get(String msg)
Definition: I_.java:41
void deleteObject(Object obj)
Definition: Dao.java:162
void setValue(Tag value, String newValue)
List< String > getPossibles(String value)
List< Tag > getOccurrences(String value)