MentaBean

Rev

Rev 196 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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