PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 7ms RepoModel.GetById 34ms app.codeStats 0ms

/src/mpv5/db/objects/UserProperty.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 110 lines | 65 code | 13 blank | 32 comment | 2 complexity | 014d86f784953f7d7f1fa93906455386 MD5 | raw file
  1/*
  2 *  This file is part of YaBS.
  3 *
  4 *      YaBS is free software: you can redistribute it and/or modify
  5 *      it under the terms of the GNU General Public License as published by
  6 *      the Free Software Foundation, either version 3 of the License, or
  7 *      (at your option) any later version.
  8 *
  9 *      YaBS is distributed in the hope that it will be useful,
 10 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 11 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12 *      GNU General Public License for more details.
 13 *
 14 *      You should have received a copy of the GNU General Public License
 15 *      along with YaBS.  If not, see <http://www.gnu.org/licenses/>.
 16 */
 17package mpv5.db.objects;
 18
 19import java.util.Date;
 20import mpv5.db.common.NodataFoundException;
 21import mpv5.db.common.QueryParameter;
 22import javax.swing.JComponent;
 23
 24import mpv5.db.common.Context;
 25import mpv5.db.common.DatabaseObject;
 26import mpv5.db.common.QueryCriteria;
 27import mpv5.db.common.QueryCriteria2;
 28import mpv5.db.common.QueryData;
 29import mpv5.db.common.QueryHandler;
 30import mpv5.logging.Log;
 31import mpv5.utils.date.DateConverter;
 32import static mpv5.db.common.QueryParameter.*;
 33
 34/**
 35 *
 36 *  
 37 */
 38public class UserProperty extends DatabaseObject {
 39
 40    public UserProperty() {
 41        setContext(Context.getUserProperties());
 42    }
 43    private String value = "";
 44    private int usersids;
 45
 46    @Override
 47    public JComponent getView() {
 48        throw new UnsupportedOperationException("Not supported yet.");
 49    }
 50
 51    /**
 52     * @return the value
 53     */
 54    public String __getValue() {
 55        return value;
 56    }
 57
 58    /**
 59     * @param value the value to set
 60     */
 61    public void setValue(String value) {
 62        this.value = value;
 63    }
 64
 65    @Override
 66    public boolean save() {
 67        if (value == null) {
 68            value = "";
 69        }
 70        QueryCriteria2 q = new QueryCriteria2();
 71        q.and(new QueryParameter(getContext(), "usersids", usersids, EQUALS),
 72                new QueryParameter(getContext(), "groupsids", __getGroupsids(), EQUALS),
 73                new QueryParameter(getContext(), "cname", getCname(), EQUALS));
 74        
 75        try {
 76            update(q);
 77            return true;
 78        } catch (Exception e) {
 79            Log.Debug(this, e.getMessage());
 80            QueryHandler.instanceOf().clone(Context.getUserProperties()).delete(q);
 81            return super.save(true);
 82        }
 83    }
 84
 85    private void update(QueryCriteria2 q) throws NodataFoundException {
 86        QueryData d = new QueryData();
 87        d.add("value", value);
 88        d.add("dateadded", DateConverter.getSQLDateString(new Date()));
 89        QueryHandler.instanceOf().clone(Context.getUserProperties()).updateOrCreate(d, q, null);
 90    }
 91
 92    /**
 93     * @return the usersids
 94     */
 95    public int __getUsersids() {
 96        return usersids;
 97    }
 98
 99    /**
100     * @param usersids the usersids to set
101     */
102    public void setUsersids(int usersids) {
103        this.usersids = usersids;
104    }
105
106    @Override
107    public mpv5.utils.images.MPIcon getIcon() {
108        return null;
109    }
110}