BrightSide Workbench Full Report + Source Code
RelationOccurrenceAPI.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.contacts.BusinessRelation;
23 import org.turro.contacts.db.ContactsPU;
24 import org.turro.elephant.db.WhereClause;
25 import org.turro.i18n.I_;
26 import org.turro.jpa.Dao;
27 import org.turro.jpa.DaoTransaction;
28 
33 public class RelationOccurrenceAPI extends AbstractOccurrenceAPI<BusinessRelation> {
34 
35  @Override
36  public String getName() {
37  return I_.get("Relations");
38  }
39 
40  @Override
41  public List<String> getPossibles(String value) {
42  WhereClause wc = new WhereClause();
43  wc.addClause("select distinct t.description from BusinessRelation t");
44  wc.setPrefix("where");
45  wc.addLikeFields(new String[] { "t.description" }, value);
46  return getDao().getResultList(String.class, wc);
47  }
48 
49  @Override
50  public void removeOccurrences() {
51  try(DaoTransaction transaction = new DaoTransaction(getDao())) {
52  for(BusinessRelation e : getList()) {
53  e.setDescription(null);
54  transaction.saveObject(e);
55  }
56  }
57  }
58 
59  @Override
60  protected List<BusinessRelation> getOccurrences(String value) {
61  WhereClause wc = new WhereClause();
62  wc.addClause("select t from BusinessRelation t");
63  wc.addClause("where t.description = :value");
64  wc.addNamedValue("value", value);
65  return getDao().getResultList(BusinessRelation.class, wc);
66  }
67 
68  @Override
69  protected String getValue(BusinessRelation value) {
70  return value.getDescription();
71  }
72 
73  @Override
74  protected void setValue(BusinessRelation value, String newValue) {
75  value.setDescription(newValue);
76  }
77 
78  @Override
79  protected Dao createDao() {
80  return new ContactsPU();
81  }
82 
83 }
void setDescription(String description)
void addLikeFields(String[] fields, String value)
void addNamedValue(String name, Object value)
static String get(String msg)
Definition: I_.java:41
List< BusinessRelation > getOccurrences(String value)
void setValue(BusinessRelation value, String newValue)