<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          Persistence4J小型Java持久層框架

          聯(lián)合創(chuàng)作 · 2023-09-30 03:31

          persistence4j 是一個小型、輕量級的 Java 對象持久層類庫,實現(xiàn)關(guān)系數(shù)據(jù)庫和 Java 對象之間的持久化。

          示例代碼:

          //First lets create a simple pojo which you like to persist.
          @Entity(table="book")
          public class Book{
          @Column(isPrimaryKey=true)
          private String isbn;
          @Column
          private String title;
          @Column
          private int authorid;
          public Book(){

          }
          public Book(String isbn, String title, int authorid){
           
          this.isbn = isbn;
           
          this.title = title;
           
          this.authorid = authorid;
          }
          // getters
          }

          DataProviderFactory dataProviderFactory = new DataProviderFactoryImpl(config);
          String databaseName = "library";
          String dbmsName = "mysql"
          boolean isTransactional = false;
          DataProvider dataProvider =  dataProviderFactory.getDataProvider(databaseName, dbmsName, isTransactional);

          // Now lets create a object of Book class and persist it
          Book book = new Book("123432","TestBook",5);
          TransferUtil.registerClass(Book.class, database);
          GenericDAO<Book> genericDAO = new GenericDaoImpl<Book>(dataProvider.getDataFetcher());

          //Persist Book
          genericDAO
          .createEntity(book);

          //Remove Book
          genericDAO
          .deleteEntity(book);

          //Test if Entity Exists
          genericDAO
          .isEntityExists(book);

          // findByPrimaryKey
          Object obj[] = new Object[1];
          obj
          [0] = "123432";
          genericDAO
          .findByPrimaryKey(Book.class, obj);

          //If you want to use transactions.This how to get TransactionService.Make sure //isTransactional variable should be true and underlying dbms supports ACID.
          TransactionService ts = dataProvider.getTransactionService();
          try{
              ts
          .beginTransaction();
              genericDAO
          .createEntity(book);
              ts
          .commitTransaction();
          }catch(Exception exp){
          ts
          .rollbackTransaction();
          }
          瀏覽 15
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點贊
          評論
          收藏
          分享

          手機掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  日本高清不卡视频 | 日本亚洲欧洲免费 | 欧美大片豆花视频免费观看网站 | 黄樱桃网站 | 黄色三级艹逼视频 |