提交按照数据库更新的所有数据库 ORM 对象

This commit is contained in:
YuCheng Hu 2017-07-25 15:08:17 -04:00
parent 2d416b95c4
commit 8c025667bb
7 changed files with 139 additions and 85 deletions

View File

@ -1,42 +1,25 @@
package com.usvisatrack.core.dao.model;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import com.usvisatrack.core.common.DataObject;
/**
* Merchant generated by hbm2java
* User ORM
*
* @author YuCheng
*
*/
public class User extends DataObject implements java.io.Serializable {
public class User extends DataObject {
/**
*
*/
private static final long serialVersionUID = -8094138967079219902L;
private String email;
private String userName;
private String password;
private String apiKey;
private String apiToken;
private String firstName;
private String lirstName;
private Date dateReg;
private String email;
private Date dateRegistered;
public User() {
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
this.dateRegistered = new Date();
}
public String getUserName() {
@ -55,46 +38,20 @@ public class User extends DataObject implements java.io.Serializable {
this.password = password;
}
public String getApiKey() {
return apiKey;
public String getEmail() {
return email;
}
public void setApiKey(String apiKey) {
this.apiKey = apiKey;
public void setEmail(String email) {
this.email = email;
}
public String getApiToken() {
return apiToken;
public Date getDateRegistered() {
return dateRegistered;
}
public void setApiToken(String apiToken) {
this.apiToken = apiToken;
public void setDateRegistered(Date dateRegistered) {
this.dateRegistered = dateRegistered;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLirstName() {
return lirstName;
}
public void setLirstName(String lirstName) {
this.lirstName = lirstName;
}
public Date getDateReg() {
return dateReg;
}
public void setDateReg(Date dateReg) {
this.dateReg = dateReg;
}
}

View File

@ -14,9 +14,10 @@ import com.usvisatrack.core.common.data.VisaStatus;
*/
public class Visa extends DataObject {
private String ds160Code;
private User user;
private USEmbassy usEmbassy;
private VisaClass visaClass;
private String ds160Code;
private VisaEntry visaEntry;
private VisaStatus visaStatus;
private String major;
@ -31,6 +32,14 @@ public class Visa extends DataObject {
super.setModifyDate(date);
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public String getDs160Code() {
return ds160Code;
}

View File

@ -1,16 +1,14 @@
package com.usvisatrack.core.factories;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Transaction;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.usvisatrack.core.common.Factory;
import com.usvisatrack.core.dao.model.USEmbassy;
import com.usvisatrack.core.dao.model.User;
import com.usvisatrack.core.dao.model.Visa;
public class UserFactory {
private static final int LISTING_PAGE_SIZE = 20;
@ -18,6 +16,58 @@ public class UserFactory {
private static Logger logger = LoggerFactory.getLogger(UserFactory.class);
public static User get(Long id) {
logger.debug("Get User OBJ by ID - [{}]", id);
Factory.beginTransaction();
User user = null;
try {
user = Factory.get(User.class, id);
Factory.commitTransaction();
} catch (Exception ex) {
logger.error("Get User by user ID error", ex);
} finally {
Factory.rollbackTransaction();
}
return user;
}
/**
* Get user by userName
*
* @param userName
* @return
*/
public static User get(String userName) {
logger.debug("Search USEmbassy - [{}]/[{}]", userName);
try {
Factory.beginTransaction();
Criteria criteria = Factory.createCriteria(User.class);
criteria.add(Restrictions.eq("userName", userName));
criteria.setMaxResults(1);
return (User) criteria.uniqueResult();
} catch (Exception ex) {
logger.error("Search USEmbassy data error", ex);
} finally {
Factory.commitTransaction();
}
return null;
}
/**
*
* @param user
*/
public static void save(User user) {
try {
Factory.beginTransaction();
Factory.saveOrUpdate(user);
Factory.commitTransaction();
} catch (Exception ex) {
logger.error("Save USER OBJ ERROR", ex);
Factory.rollbackTransaction();
}
}
}

View File

@ -7,6 +7,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.usvisatrack.core.common.Factory;
import com.usvisatrack.core.dao.model.CheckeeVisa;
import com.usvisatrack.core.dao.model.Visa;
import com.usvisatrack.core.dao.model.VisaClass;
@ -45,6 +46,34 @@ public class VisaFactory extends Factory {
return item;
}
/**
* Get Visa OBJ
*
* @param checkkeID
* @return
*/
public static Visa getVisaFromCheckee(Long checkkeID) {
logger.debug("Get Visa OBJ by checkkeID - [{}]", checkkeID);
Visa visa = null;
CheckeeVisa checkeeVisa = null;
Factory.beginTransaction();
try {
checkeeVisa = Factory.get(CheckeeVisa.class, checkkeID);
if (checkeeVisa != null) {
visa = get(checkeeVisa.getVisaID());
}
Factory.commitTransaction();
} catch (Exception ex) {
logger.error("Get Visa by item ID error", ex);
} finally {
Factory.rollbackTransaction();
}
return visa;
}
/**
*
* @return
@ -80,4 +109,15 @@ public class VisaFactory extends Factory {
}
}
public static void save(CheckeeVisa checkeeVisa) {
try {
Factory.beginTransaction();
Factory.saveOrUpdate(checkeeVisa);
Factory.commitTransaction();
} catch (Exception ex) {
logger.error("Save CheckeeVisa OBJ ERROR", ex);
Factory.rollbackTransaction();
}
}
}

View File

@ -3,34 +3,26 @@
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.usvisatrack.core.dao.model">
<class name="User" table="user" catalog="ntc_usvisatrack">
<id name="id" type="java.lang.Long">
<column name="uid" />
<class name="User" table="user" catalog="northtecom_usvisatrack">
<id name="id" type="long">
<column name="user_id" />
<generator class="identity" />
</id>
<property name="email" type="string">
<column name="email" />
</property>
<property name="userName" type="string">
<column name="username" />
<column name="username" length="64" />
</property>
<property name="password" type="string">
<column name="password" />
<column name="password" length="255" />
</property>
<property name="apiKey" type="string">
<column name="api_key" />
<property name="email" type="string">
<column name="email" length="255" />
</property>
<property name="apiToken" type="string">
<column name="api_token" />
</property>
<property name="dateReg" type="timestamp">
<column name="date_reg" />
<property name="dateRegistered" type="timestamp">
<column name="date_registered" />
</property>
</class>

View File

@ -9,13 +9,18 @@
<generator class="identity" />
</id>
<property name="ds160Code" type="string">
<column name="ds160_code" length="16" />
</property>
<many-to-one class="com.usvisatrack.core.dao.model.User" fetch="select" insert="true" name="user" update="true" lazy="proxy">
<column name="user_fk" not-null="true" />
</many-to-one>
<many-to-one class="com.usvisatrack.core.dao.model.USEmbassy" name="usEmbassy" column="us_embassy_fk" fetch="join" />
<many-to-one class="com.usvisatrack.core.dao.model.VisaClass" name="visaClass" column="visa_class_fk" fetch="join" />
<property name="ds160Code" type="string">
<column name="ds160_code" length="16" />
</property>
<property name="visaStatus" column="visa_status">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">com.usvisatrack.core.common.data.VisaStatus</param>

View File

@ -28,6 +28,7 @@
<property name="hibernate.c3p0.validate">true</property>
<!-- HBMs -->
<mapping resource="hbm/CheckeeVisa.hbm.xml" />
<mapping resource="hbm/USEmbassy.hbm.xml" />
<mapping resource="hbm/User.hbm.xml" />
<mapping resource="hbm/Visa.hbm.xml" />