MentaBean

Rev

Rev 161 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
22 soliveira 1
/*
2
 * This program is free software: you can redistribute it and/or modify
3
 * it under the terms of the GNU General Public License as published by
4
 * the Free Software Foundation, either version 3 of the License, or
5
 * (at your option) any later version.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
14
 *
15
 * MentaBean => http://www.mentabean.org
16
 * Author: Sergio Oliveira Jr. (sergio.oliveira.jr@gmail.com)
17
 */
5 soliveira 18
package org.mentabean;
19
 
20
/**
22 soliveira 21
 * The functionality of a MentaBean, in other words, the methods you can call on a mentabean to perform database operations like insert, load, reload, save, update and delete.
5 soliveira 22
 *
23
 * @author Sergio Oliveira Jr.
24
 */
25
public interface MentaBean {
26
 
27
        /**
196 soliveira 28
         * Attempt to insert a bean in the database.
7 soliveira 29
         *
22 soliveira 30
         * Note: This method can be called multiple times in the same bean. Of course the PK constraints will be enforced by the database, so you can change the PK by hand and call this method multiple times, to insert multiple beans. If the PK is an auto-generated database field (e.g. auto-increment),
31
         * you will not change the PK by hand and a new PK will be automatically assigned to the bean.
5 soliveira 32
         */
33
        public void insert();
34
 
35
        /**
7 soliveira 36
         * Attempt to load the bean properties from the database.
5 soliveira 37
         *
22 soliveira 38
         * This method will throw an exception if you try to load a bean without its primary key set.
5 soliveira 39
         *
40
         * @return true if the bean was loaded
41
         */
42
        public boolean load();
43
 
44
        /**
22 soliveira 45
         * Attempt to update the bean properties in the database. If this bean was previously loaded, this method will update only the properties that were modified (dirty).
5 soliveira 46
         *
47
         * @return true if it was updated
48
         */
49
        public boolean update();
50
 
51
        /**
22 soliveira 52
         * Attempt to update ALL the bean properties in the database, not just the ones that have been changed.
5 soliveira 53
         *
54
         * @return true if it was updated
55
         */
56
        public boolean updateAll();
57
 
58
        /**
22 soliveira 59
         * Attempt to delete a bean from the database. It will throw an exception if the bean does not have its PK set.
5 soliveira 60
         *
61
         * @return true if it was deleted
62
         */
63
        public boolean delete();
105 soliveira 64
 
65
        /**
150 erico 66
         * Attempt to save a bean in the database. It will try update first, then insert.
67
         *
68
         * @return <b>0</b> when UPDATE and <b>1</b> if operation was an INSERT
161 erico 69
         * @see BeanSession#save(Object, Object...)
150 erico 70
         */
161 erico 71
        public int save(Object... forceNull);
150 erico 72
 
73
        /**
105 soliveira 74
         * Return the bean session being used by this menta bean.
75
         *
76
         * @return the bean session
77
         */
78
        public BeanSession getBeanSession();
5 soliveira 79
}