本文整理汇总了Java中play.db.jpa.Model类的典型用法代码示例。如果您正苦于以下问题:Java Model类的具体用法?Java Model怎么用?Java Model使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Model类属于play.db.jpa包,在下文中一共展示了Model类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getIdValueFor
import play.db.jpa.Model; //导入依赖的package包/类
/**
* Lookups the id field, being a Long id for Model and an annotated field @Id
* for JPABase and returns the field value.
*
* @param jpaBase is a Play! Framework that supports JPA
* @return the field value (a Long or a String for UUID)
*/
public static Object getIdValueFor(JPABase jpaBase) {
if (jpaBase instanceof Model) {
return ((Model ) jpaBase).id;
}
java.lang.reflect.Field field = getIdField(jpaBase.getClass());
Object val = null;
try {
val = field.get(jpaBase);
} catch (IllegalAccessException e) {
Logger.error("Unable to read the field value of a field annotated with @Id " + field.getName() + " due to "
+ e.getMessage(), e);
}
return val;
}
示例2: isSatisfied
import play.db.jpa.Model; //导入依赖的package包/类
/**
*
* {@inheritDoc}
*/
@Override
public boolean isSatisfied(Object validatedObject, Object value,
OValContext context, Validator validator) {
requireMessageVariablesRecreation();
if (value == null) {
return true;
}
final String[] propertyNames = getPropertyNames(
((FieldContext) context).getField().getName());
final GenericModel model = (GenericModel) validatedObject;
final Model.Factory factory = Model.Manager.factoryFor(model.getClass());
final String keyProperty = StringUtils.capitalize(factory.keyName());
final Object keyValue = factory.keyValue(model);
//In case of an update make sure that we won't read the current record from database.
final boolean isUpdate = (keyValue != null);
final String entityName = model.getClass().getName();
final StringBuffer jpql = new StringBuffer("SELECT COUNT(o) FROM ");
jpql.append(entityName).append(" AS o where ");
final Object[] values = new Object[isUpdate ? propertyNames.length + 1 :
propertyNames.length];
final Class clazz = validatedObject.getClass();
for (int i = 0; i < propertyNames.length; i++) {
Field field = getField(clazz, propertyNames[i]);
field.setAccessible(true);
try {
values[i] = field.get(model);
} catch (Exception ex) {
throw new UnexpectedException(ex);
}
if (i > 0) {
jpql.append(" And ");
}
jpql.append("o.").append(propertyNames[i]).append(" = ? ");
}
if (isUpdate) {
values[propertyNames.length] = keyValue;
jpql.append(" and ").append(keyProperty).append(" <> ?");
}
return JPQL.instance.count(entityName, jpql.toString(), values) == 0L;
}