Created
November 14, 2016 01:27
-
-
Save 4noha/b537c2ab47c12bf68a266542f19b0361 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package test_project; | |
| import java.sql.SQLException; | |
| import java.util.ArrayList; | |
| import java.util.Map; | |
| import jp.co.itc.db.DbInstanceDao; | |
| import jp.co.itc.db.DbStaticDao; | |
| public class Employee extends DbInstanceDao<Employee>{ | |
| //ORMはTABLE_NAME, THIS_CLASSの入力とカラムと同名のフィールドを定義すれば後は大体コピペで使える | |
| // ORMでクラスをテーブルにマッピングするのに必要 | |
| private final static String TABLE_NAME = "employee"; // <=ここと | |
| private final static Class<Employee> THIS_CLASS = Employee.class; // <=ここと | |
| private static ArrayList<String> columnNames; | |
| private static DbStaticDao<Employee> dbStaticAdapter = null; | |
| private static DbInstanceDao<Employee> dbAdapter = null; | |
| // 同名のカラムと対応 | |
| public int id_employee; // <=このへん | |
| public String nm_employee; | |
| public String kn_employee; | |
| public String mail_address; | |
| public String password; | |
| public int id_department; | |
| //newしてsaveするとcreateが走る | |
| public Employee() throws SQLException { | |
| super(THIS_CLASS, TABLE_NAME); | |
| adapterStandby(); | |
| } | |
| public Employee(Map<String, Object> params) throws SQLException { | |
| super(THIS_CLASS, TABLE_NAME); | |
| adapterStandby(); | |
| this.id_employee = (int) params.get("id_employee"); | |
| this.nm_employee = (String) params.get("nm_employee"); | |
| this.kn_employee = (String) params.get("kn_employee"); | |
| this.mail_address = (String) params.get("mail_address"); | |
| this.password = (String) params.get("password"); | |
| this.id_department = (int) params.get("id_department"); | |
| newFlag = true; | |
| } | |
| // 検索関数を定義 | |
| public static Employee findBy(String column_name, Object value) throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchFieldException, SecurityException{ | |
| adapterStandby(); | |
| return dbStaticAdapter.findBy(column_name, value); | |
| } | |
| public static ArrayList<Employee> findPartial(String column_name, String value) throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException, NoSuchFieldException, SecurityException{ | |
| adapterStandby(); | |
| return dbStaticAdapter.findPartial(column_name, value); | |
| } | |
| // クラスの設定が初期化されていないときに呼ばれる | |
| private static void adapterStandby() throws SQLException{ | |
| if (dbStaticAdapter == null || dbAdapter == null){ | |
| // クラスメソッドを使うための設定 | |
| dbStaticAdapter = new DbStaticDao<Employee>(THIS_CLASS, TABLE_NAME); | |
| // インスタンスメソッドを使うための設定 | |
| dbAdapter = new DbInstanceDao<Employee>(THIS_CLASS, TABLE_NAME); | |
| // クラスのカラム名一覧を設定 | |
| columnNames = dbStaticAdapter.getColumnNames(); | |
| } | |
| } | |
| // クラスのモデルのカラム名一覧を取得 | |
| public static ArrayList<String> getColumnNames(){ | |
| return columnNames; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment