Visa 数据库工厂类,在这个类中添加了获得对象和保存对象的方法

This commit is contained in:
Yucheng Hu 2017-07-23 11:07:43 -04:00
parent 18c9868519
commit 7f19b9e1ca
1 changed files with 42 additions and 14 deletions

View File

@ -1,18 +1,10 @@
package com.usvisatrack.core.factories;
import java.util.ArrayList;
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.Visa;
/**
* Item Data Factory
@ -21,12 +13,48 @@ import com.usvisatrack.core.common.Factory;
*
*/
public class VisaFactory extends Factory {
private static final int LISTING_PAGE_SIZE = 20;
public static final int DEFAULT_AUTH_EXPIRATION = 10;
private static Logger logger = LoggerFactory.getLogger(VisaFactory.class);
private static final int LISTING_PAGE_SIZE = 20;
public static final int DEFAULT_AUTH_EXPIRATION = 10;
/**
* Get VISA
*
* @param id
* @return
*/
public static Visa get(Long id) {
logger.debug("Get Visa OBJ by ID - [{}]", id);
Factory.beginTransaction();
Visa item = null;
try {
item = Factory.get(Visa.class, id);
Factory.commitTransaction();
} catch (Exception ex) {
item = null;
logger.error("Get Visa by item ID error", ex);
} finally {
Factory.rollbackTransaction();
}
return item;
}
/**
* Save VISA
*
* @param visa
*/
public static void save(Visa visa) {
try {
Factory.beginTransaction();
Factory.saveOrUpdate(visa);
Factory.commitTransaction();
} catch (Exception ex) {
logger.error("Save Visa OBJ ERROR", ex);
Factory.rollbackTransaction();
}
}
}