本文整理汇总了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;
}
开发者ID:eBay,项目名称:restcommander,代码行数:23,代码来源:ConvertionUtils.java
示例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;
}
开发者ID:eBay,项目名称:restcommander,代码行数:45,代码来源:UniqueCheck.java
注:本文中的play.db.jpa.Model类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论