01 /*
02  * Pojo Artist mapped to table artist
03  * Generated by iBatis-Ext
04  */
05 package com.asimovt.ibatisext.samples.crud;
06 
07 import java.util.Date;
08 
09 /**
10  * Pojo Artist mapped to table artist
11  */
12 public class Artist implements java.io.Serializable {
13 
14     private Integer id = null;
15 
16     private String name = null;
17 
18     private Date birthDay = null;
19 
20 
21     public Artist() {
22         // Empty default constructor
23     }
24 
25     public Artist(Integer id, String name) {
26         this.id = id;
27         this.name = name;
28     }
29 
30     public Artist(String name) {
31         this.name = name;
32     }
33 
34     public Integer getId() {
35         return id;
36     }
37 
38     public String getName() {
39         return name;
40     }
41 
42     public Date getBirthDay() {
43         return birthDay;
44     }
45 
46     public void setId(Integer id) {
47         this.id = id;
48     }
49 
50     public void setName(String name) {
51         this.name = name;
52     }
53 
54     public void setBirthDay(Date birthDay) {
55         this.birthDay = birthDay;
56     }
57 
58 }
Java2html

01 /*
02  * DAO ArtistDAO for management of Artist(artist)
03  * Generated by iBatis-Ext
04  */
05 package com.asimovt.ibatisext.samples.crud;
06 
07 import com.asimovt.ibatisext.annotations.*;
08 import java.util.List;
09 
10 /**
11  * DAO ArtistDAO for management of Artist(artist)
12  */
13 @DAO
14 public interface ArtistDAO {
15 
16     /**
17      * Returns a Artist instance from the database.
18      @param pk primary key value used for lookup.
19      @return A Artist instance with a primary key value equals to pk. null if there is no matching row.
20      */
21     @SelectStatement
22     public Artist findByPk(Integer pk);
23 
24     /**
25      * Loads a Artist instance from the database.
26      @param pk primary key value used for lookup.
27      @param model precreated instance to be filled.
28      */
29     @SelectStatement
30     public void loadByPk(Integer pk, Artist model);
31 
32     /**
33      * Returns the list of all Artist instances from the database.
34      @return The list of all Artist instances from the database.
35      */
36     @SelectStatement
37     public List<Artist> findAll();
38 
39     /**
40      * Returns a partial list of Artist instances from the database.
41      @param skipRecords number of records to be skiped.
42      @param maxRecords maximum number of records to be returned.
43      @return a partial list of Artist instances from the database.
44      */
45     @SelectStatement
46     public List<Artist> findAll(int skipRecords, int maxRecords);
47 
48     /**
49      * Insert an instance of Artist into the database.
50      @param model the instance to be persisted.
51      @return a generated primary key value if apply.
52      */
53     @InsertStatement
54     public Object insert(Artist model);
55 
56     /**
57      * Updates an instance of Artist in the database.
58      @param model the instance to be updated.
59      @return number of records affected.
60      */
61     @UpdateStatement
62     public int update(Artist model);
63 
64     /**
65      * Delete an instance of Artist from the database.
66      @param pk primary key value of the instance to be deleted.
67      @return number of records affected.
68      */
69     @DeleteStatement
70     public int delete(Integer pk);
71 
72 }
Java2html

01 /*
02  * To change this template, choose Tools | Templates
03  * and open the template in the editor.
04  */
05 
06 package com.asimovt.ibatisext.samples.crud;
07 
08 import com.asimovt.ibatisext.IBatisExtSession;
09 import com.asimovt.ibatisext.IBatisExtSessionFactory;
10 import java.util.List;
11 
12 /**
13  *
14  @author mnesarco
15  */
16 public class Main {
17 
18     /**
19      @param args the command line arguments
20      */
21     public static void main(String[] args) {
22         
23         IBatisExtSessionFactory factory = 
24             IBatisExtSessionFactory.build("com/asimovt/ibatisext/samples/crud/config.ibatis.xml");
25         IBatisExtSession session = factory.createSession();
26         final ArtistDAO dao = session.getDAO(ArtistDAO.class);
27         
28         System.out.println("=================================================");
29         System.out.println("Existing artists");
30         System.out.println("=================================================");
31         
32         // List artists
33         List<Artist> artists = dao.findAll();
34         for (Artist artist : artists) {
35             System.out.println("Artist: " + artist.getId() " - " + artist.getName());
36         }
37         
38         // Insert some artists
39         dao.insert(new Artist("Prueba iBatis XXX-XY"));
40         dao.insert(new Artist("Prueba iBatis XXXXZ"));
41         
42         System.out.println("=================================================");
43         System.out.println("Inserted artists");
44         System.out.println("=================================================");
45         
46         // List artists
47         artists = dao.findAll();
48         for (Artist artist : artists) {
49             System.out.println("Artist: " + artist.getId() " - " + artist.getName());
50         }
51         
52         // Delete artists
53         for (Artist artist : artists) {
54             dao.delete(artist.getId());
55         }
56         
57         System.out.println("=================================================");
58         System.out.println("Existing artists after deletion");
59         System.out.println("=================================================");
60         
61         // List artists
62         artists = dao.findAll();
63         for (Artist artist : artists) {
64             System.out.println("Artist: " + artist.getId() " - " + artist.getName());
65         }
66         
67     }
68 
69 }
Java2html