本文整理汇总了Java中org.apache.ojb.broker.metadata.FieldDescriptor.isAutoIncrement方法的典型用法代码示例。如果您正苦于以下问题:Java FieldDescriptor.isAutoIncrement方法的具体用法?Java FieldDescriptor.isAutoIncrement怎么用?Java FieldDescriptor.isAutoIncrement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.ojb.broker.metadata.FieldDescriptor
的用法示例。
在下文中一共展示了FieldDescriptor.isAutoIncrement方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAnnotationNodes
import org.apache.ojb.broker.metadata.FieldDescriptor; //导入方法依赖的package包/类
@Override
protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) {
final FieldDescriptor fd = OjbUtil.findFieldDescriptor(mappedClass, fieldName, descriptorRepositories);
if (fd != null) {
final boolean autoInc = fd.isAutoIncrement();
final String seqName = fd.getSequenceName();
if (autoInc && StringUtils.isBlank(seqName)) {
LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has autoincrement set to true but sequenceName is blank.");
}
if (!autoInc && StringUtils.isNotBlank(seqName)) {
LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has autoincrement set to false but sequenceName is " + seqName + ".");
}
if (autoInc || StringUtils.isNotBlank(seqName)) {
return new NodeData(new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), Collections.singletonList(new MemberValuePair("name", new StringLiteralExpr(upperCaseTableName ? seqName.toUpperCase() : seqName)))),
new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false));
}
}
return null;
}
示例2: getAnnotationNodes
import org.apache.ojb.broker.metadata.FieldDescriptor; //导入方法依赖的package包/类
@Override
protected NodeData getAnnotationNodes(String enclosingClass, String fieldName, String mappedClass) {
final FieldDescriptor fd = OjbUtil.findFieldDescriptor(mappedClass, fieldName, descriptorRepositories);
if (fd != null) {
final boolean autoInc = fd.isAutoIncrement();
final String seqName = fd.getSequenceName();
if (autoInc && StringUtils.isBlank(seqName)) {
LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has autoincrement set to true but sequenceName is blank.");
}
if (!autoInc && StringUtils.isNotBlank(seqName)) {
LOG.error(ResolverUtil.logMsgForField(enclosingClass, fieldName, mappedClass) + " field has autoincrement set to false but sequenceName is " + seqName + ".");
}
if (autoInc || StringUtils.isNotBlank(seqName)) {
return new NodeData(new NormalAnnotationExpr(new NameExpr(SIMPLE_NAME), Collections.singletonList(new MemberValuePair("generator", new StringLiteralExpr(upperCaseTableName ? seqName.toUpperCase() : seqName)))),
new ImportDeclaration(new QualifiedNameExpr(new NameExpr(PACKAGE), SIMPLE_NAME), false, false));
}
}
return null;
}
示例3: assignAutoincrementSequences
import org.apache.ojb.broker.metadata.FieldDescriptor; //导入方法依赖的package包/类
protected void assignAutoincrementSequences(ClassDescriptor cld, Object target) throws SequenceManagerException
{
// TODO: refactor auto-increment handling, auto-increment should only be supported by PK fields?
// FieldDescriptor[] fields = cld.getPkFields();
FieldDescriptor[] fields = cld.getFieldDescriptor(false);
FieldDescriptor field;
for(int i = 0; i < fields.length; i++)
{
field = fields[i];
if(field.isAutoIncrement() && !field.isAccessReadOnly())
{
Object value = field.getPersistentField().get(target);
if(broker.serviceBrokerHelper().representsNull(field, value))
{
Object id = broker.serviceSequenceManager().getUniqueValue(field);
field.getPersistentField().set(target, id);
}
}
}
}
示例4: assertValidPksForStore
import org.apache.ojb.broker.metadata.FieldDescriptor; //导入方法依赖的package包/类
/**
* returns true if the primary key fields are valid for store, else false.
* PK fields are valid if each of them is either an OJB managed
* attribute (autoincrement or locking) or if it contains
* a valid non-null value
* @param fieldDescriptors the array of PK fielddescriptors
* @param pkValues the array of PK values
* @return boolean
*/
public boolean assertValidPksForStore(FieldDescriptor[] fieldDescriptors, Object[] pkValues)
{
int fieldDescriptorSize = fieldDescriptors.length;
for(int i = 0; i < fieldDescriptorSize; i++)
{
FieldDescriptor fld = fieldDescriptors[i];
/**
* a pk field is valid if it is either managed by OJB
* (autoincrement or locking) or if it does contain a
* valid non-null value.
*/
if(!(fld.isAutoIncrement()
|| fld.isLocking()
|| !representsNull(fld, pkValues[i])))
{
return false;
}
}
return true;
}
示例5: getValuesForObject
import org.apache.ojb.broker.metadata.FieldDescriptor; //导入方法依赖的package包/类
/**
* Get the values of the fields for an obj
* Autoincrement values are automatically set.
* @param fields
* @param obj
* @throws PersistenceBrokerException
*/
public ValueContainer[] getValuesForObject(FieldDescriptor[] fields, Object obj, boolean convertToSql, boolean assignAutoincrement) throws PersistenceBrokerException
{
ValueContainer[] result = new ValueContainer[fields.length];
for(int i = 0; i < fields.length; i++)
{
FieldDescriptor fd = fields[i];
Object cv = fd.getPersistentField().get(obj);
/*
handle autoincrement attributes if
- is a autoincrement field
- field represents a 'null' value, is nullified
and generate a new value
*/
if(assignAutoincrement && fd.isAutoIncrement() && representsNull(fd, cv))
{
/*
setAutoIncrementValue returns a value that is
properly typed for the java-world. This value
needs to be converted to it's corresponding
sql type so that the entire result array contains
objects that are properly typed for sql.
*/
cv = setAutoIncrementValue(fd, obj);
}
if(convertToSql)
{
// apply type and value conversion
cv = fd.getFieldConversion().javaToSql(cv);
}
// create ValueContainer
result[i] = new ValueContainer(cv, fd.getJdbcType());
}
return result;
}