本文整理汇总了Java中javax.jdo.metadata.FieldMetadata类的典型用法代码示例。如果您正苦于以下问题:Java FieldMetadata类的具体用法?Java FieldMetadata怎么用?Java FieldMetadata使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FieldMetadata类属于javax.jdo.metadata包,在下文中一共展示了FieldMetadata类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addDefaultFetchGroupMetadata
import javax.jdo.metadata.FieldMetadata; //导入依赖的package包/类
private void addDefaultFetchGroupMetadata(FieldMetadata fmd, Class<?> definition) {
java.lang.reflect.Field field = FieldUtils.getField(definition, fmd.getName(), true);
if (field == null) {
LOGGER.warn("Unable to retrieve field {} from class {}. Putting the field in the default fetch group by default.",
fmd.getName(), definition.getName());
fmd.setDefaultFetchGroup(true);
} else {
Persistent persistentAnnotation = ReflectionsUtil.getAnnotationSelfOrAccessor(field, Persistent.class);
// set to true, unless there is a JDO annotation that specifies otherwise
if (persistentAnnotation == null || StringUtils.isBlank(persistentAnnotation.defaultFetchGroup())) {
fmd.setDefaultFetchGroup(true);
}
}
}
示例2: setFieldMetadata
import javax.jdo.metadata.FieldMetadata; //导入依赖的package包/类
private FieldMetadata setFieldMetadata(ClassMetadata cmd, ClassData classData, EntityDto entity,
EntityType entityType, FieldDto field, Class<?> definition) {
String name = getNameForMetadata(field);
TypeDto type = field.getType();
Class<?> typeClass = type.getClassObjectForType();
if (ArrayUtils.contains(FIELD_VALUE_GENERATOR, name)) {
return setAutoGenerationMetadata(cmd, name);
} else if (type.isCombobox()) {
return setComboboxMetadata(cmd, entity, field, definition, entityType);
} else if (type.isRelationship()) {
return setRelationshipMetadata(cmd, classData, entity, field, entityType, definition);
} else if (Map.class.isAssignableFrom(typeClass)) {
return setMapMetadata(cmd, entity, field, definition, entityType);
} else if (Time.class.isAssignableFrom(typeClass)) {
return setTimeMetadata(cmd, name);
}
return cmd.newFieldMetadata(name);
}
示例3: addColumnMetadata
import javax.jdo.metadata.FieldMetadata; //导入依赖的package包/类
private void addColumnMetadata(FieldMetadata fmd, FieldDto field, Value valueAnnotation) {
SettingDto maxLengthSetting = field.getSetting(Constants.Settings.STRING_MAX_LENGTH);
ColumnMetadata colMd = fmd.newColumnMetadata();
// text(clob) fields don't have length
if (maxLengthSetting != null && !isClob(field)) {
colMd.setLength(Integer.parseInt(maxLengthSetting.getValueAsString()));
}
// if TextArea then change length
if (field.getSetting(Constants.Settings.STRING_TEXT_AREA) != null &&
"true".equalsIgnoreCase(field.getSetting(Constants.Settings.STRING_TEXT_AREA).getValueAsString())) {
fmd.setIndexed(false);
colMd.setSQLType("CLOB");
}
if (field.getMetadata(DATABASE_COLUMN_NAME) != null) {
colMd.setName(field.getMetadata(DATABASE_COLUMN_NAME).getValue());
}
if (valueAnnotation != null) {
copyParametersFromValueAnnotation(fmd, valueAnnotation);
}
}
示例4: setRelationshipMetadata
import javax.jdo.metadata.FieldMetadata; //导入依赖的package包/类
private FieldMetadata setRelationshipMetadata(ClassMetadata cmd, ClassData classData,
EntityDto entity, FieldDto field,
EntityType entityType, Class<?> definition) {
RelationshipHolder holder = new RelationshipHolder(classData, field);
FieldMetadata fmd = cmd.newFieldMetadata(getNameForMetadata(field));
addDefaultFetchGroupMetadata(fmd, definition);
if (entityType == EntityType.STANDARD) {
processRelationship(fmd, holder, entity, field, definition);
} else {
processHistoryTrashRelationship(cmd, fmd, holder);
}
return fmd;
}
示例5: processHistoryTrashRelationship
import javax.jdo.metadata.FieldMetadata; //导入依赖的package包/类
private void processHistoryTrashRelationship(ClassMetadata cmd, FieldMetadata fmd, RelationshipHolder holder) {
if (holder.isOneToOne() || holder.isManyToOne()) {
fmd.setColumn(holder.getFieldName() + ID_SUFFIX);
} else {
fmd.setTable(cmd.getTable() + '_' + holder.getFieldName());
CollectionMetadata collMd = fmd.newCollectionMetadata();
collMd.setElementType(Long.class.getName());
JoinMetadata joinMd = fmd.newJoinMetadata();
ColumnMetadata joinColumnMd = joinMd.newColumnMetadata();
joinColumnMd.setName(cmd.getName() + ID_SUFFIX);
ElementMetadata elementMd = fmd.newElementMetadata();
elementMd.setColumn(holder.getFieldName() + ID_SUFFIX);
}
}
示例6: setComboboxMetadata
import javax.jdo.metadata.FieldMetadata; //导入依赖的package包/类
private FieldMetadata setComboboxMetadata(ClassMetadata cmd, EntityDto entity, FieldDto field,
Class<?> definition, EntityType entityType) {
ComboboxHolder holder = new ComboboxHolder(entity, field);
String fieldName = getNameForMetadata(field);
FieldMetadata fmd = cmd.newFieldMetadata(fieldName);
if (holder.isCollection()) {
addDefaultFetchGroupMetadata(fmd, definition);
fmd.setTable(ClassTableName.getTableName(cmd.getTable(), fieldName));
JoinMetadata jm = fmd.newJoinMetadata();
ForeignKeyMetadata fkmd = getOrCreateFkMetadata(jm);
fkmd.setName(KeyNames.cbForeignKeyName(entity.getName(), entity.getId(), fieldName, entityType));
jm.setDeleteAction(ForeignKeyAction.CASCADE);
jm.newColumnMetadata().setName(fieldName + "_OID");
}
return fmd;
}
示例7: addIdField
import javax.jdo.metadata.FieldMetadata; //导入依赖的package包/类
private void addIdField(ClassMetadata cmd, String className, Class<?> definition) {
boolean containsID;
boolean isBaseClass;
try {
CtClass ctClass = MotechClassPool.getDefault().getOrNull(className);
containsID = null != ctClass && null != ctClass.getField(ID_FIELD_NAME);
isBaseClass = null != ctClass && (null == ctClass.getSuperclass() || Object.class.getName().equalsIgnoreCase(ctClass.getSuperclass().getName()));
} catch (NotFoundException e) {
containsID = false;
isBaseClass = false;
}
if (containsID && isBaseClass) {
FieldMetadata metadata = cmd.newFieldMetadata(ID_FIELD_NAME);
metadata.setValueStrategy(getIdGeneratorStrategy(metadata, definition));
metadata.setPrimaryKey(true);
}
}
示例8: shouldAddOneToManyRelationshipMetadata
import javax.jdo.metadata.FieldMetadata; //导入依赖的package包/类
@Test
public void shouldAddOneToManyRelationshipMetadata() {
FieldDto oneToManyField = fieldDto("oneToManyName", OneToManyRelationship.class);
oneToManyField.addMetadata(new MetadataDto(RELATED_CLASS, "org.motechproject.test.MyClass"));
FieldMetadata fmd = mock(FieldMetadata.class);
CollectionMetadata collMd = mock(CollectionMetadata.class);
when(entity.getName()).thenReturn(ENTITY_NAME);
when(entity.getId()).thenReturn(2L);
when(schemaHolder.getFields(entity)).thenReturn(singletonList(oneToManyField));
when(entity.getTableName()).thenReturn(TABLE_NAME);
when(jdoMetadata.newPackageMetadata(PACKAGE)).thenReturn(packageMetadata);
when(packageMetadata.newClassMetadata(ENTITY_NAME)).thenReturn(classMetadata);
when(classMetadata.newFieldMetadata("oneToManyName")).thenReturn(fmd);
when(fmd.getCollectionMetadata()).thenReturn(collMd);
when(fmd.getName()).thenReturn("oneToManyName");
entityMetadataBuilder.addEntityMetadata(jdoMetadata, entity, Sample.class, schemaHolder);
verifyCommonClassMetadata();
verify(fmd).setDefaultFetchGroup(true);
verify(collMd).setEmbeddedElement(false);
verify(collMd).setSerializedElement(false);
verify(collMd).setElementType("org.motechproject.test.MyClass");
}
示例9: shouldNotSetDefaultFetchGroupIfSpecified
import javax.jdo.metadata.FieldMetadata; //导入依赖的package包/类
@Test
public void shouldNotSetDefaultFetchGroupIfSpecified() {
when(entity.getName()).thenReturn(ENTITY_NAME);
when(entity.getTableName()).thenReturn(TABLE_NAME);
when(jdoMetadata.newPackageMetadata(anyString())).thenReturn(packageMetadata);
when(packageMetadata.newClassMetadata(anyString())).thenReturn(classMetadata);
FieldDto field = fieldDto("notInDefFg", OneToOneRelationship.class);
when(schemaHolder.getFields(CLASS_NAME)).thenReturn(singletonList(field));
FieldMetadata fmd = mock(FieldMetadata.class);
when(fmd.getName()).thenReturn("notInDefFg");
when(classMetadata.newFieldMetadata("notInDefFg")).thenReturn(fmd);
entityMetadataBuilder.addEntityMetadata(jdoMetadata, entity, Sample.class, schemaHolder);
verify(fmd, never()).setDefaultFetchGroup(anyBoolean());
}
示例10: processField
import javax.jdo.metadata.FieldMetadata; //导入依赖的package包/类
public void processField(ClassMetadata cmd, ClassData classData, EntityDto entity, EntityType entityType,
Class<?> definition, String fieldName, FieldDto field, SchemaHolder schemaHolder) {
// Metadata for ID field has been added earlier in addIdField() method
if (!fieldName.equals(ID_FIELD_NAME)) {
FieldMetadata fmd = null;
if (isFieldNotInherited(fieldName, entity, schemaHolder)) {
fmd = setFieldMetadata(cmd, classData, entity, entityType, field, definition);
}
// when field is in Lookup, we set field metadata indexed to retrieve instance faster
if (!field.getLookups().isEmpty() && entityType.equals(EntityType.STANDARD)) {
if (fmd == null) {
String inheritedFieldName = ClassName.getSimpleName(entity.getSuperClass()) + "." + fieldName;
fmd = cmd.newFieldMetadata(inheritedFieldName);
}
if (!isBlobOrClob(field)) {
IndexMetadata imd = getOrCreateIndexMetadata(fmd);
imd.setName(KeyNames.lookupIndexKeyName(entity.getName(), entity.getId(), fieldName, entityType));
}
fmd.setIndexed(false);
for (LookupDto lookupDto : field.getLookups()) {
if (lookupDto.isIndexRequired()) {
fmd.setIndexed(true);
break;
}
}
}
if (fmd != null) {
customizeFieldMd(fmd, entity, field, entityType, definition);
}
}
}
示例11: customizeFieldMd
import javax.jdo.metadata.FieldMetadata; //导入依赖的package包/类
private void customizeFieldMd(FieldMetadata fmd, EntityDto entity, FieldDto field, EntityType entityType,
Class<?> definition) {
setColumnParameters(fmd, field, definition);
// Check whether the field is required and set appropriate metadata
fmd.setNullValue(isFieldRequired(field, entityType) ? NullValue.EXCEPTION : NullValue.NONE);
// Non DDE fields have controllable unique
if (!field.isReadOnly() && entityType == EntityType.STANDARD && field.getBasic().isUnique()) {
UniqueMetadata umd = fmd.newUniqueMetadata();
// TODO: Move to KeyNames class (to be introduced in MOTECH-1991)
umd.setName(KeyNames.uniqueKeyName(entity.getName(), getNameForMetadata(field)));
}
}
示例12: setColumnParameters
import javax.jdo.metadata.FieldMetadata; //导入依赖的package包/类
private void setColumnParameters(FieldMetadata fmd, FieldDto field, Class<?> definition) {
Value valueAnnotation = null;
java.lang.reflect.Field fieldDefinition = FieldUtils.getDeclaredField(definition, field.getBasic().getName(), true);
//@Value in datanucleus is used with maps.
if (fieldDefinition != null && java.util.Map.class.isAssignableFrom(field.getType().getClassObjectForType())) {
valueAnnotation = ReflectionsUtil.getAnnotationSelfOrAccessor(fieldDefinition, Value.class);
}
if ((field.getMetadata(DATABASE_COLUMN_NAME) != null || field.getSetting(Constants.Settings.STRING_MAX_LENGTH) != null
|| field.getSetting(Constants.Settings.STRING_TEXT_AREA) != null) || (valueAnnotation != null)) {
addColumnMetadata(fmd, field, valueAnnotation);
}
}
示例13: copyParametersFromValueAnnotation
import javax.jdo.metadata.FieldMetadata; //导入依赖的package包/类
private void copyParametersFromValueAnnotation(FieldMetadata fmd, Value valueAnnotation) {
ValueMetadata valueMetadata = fmd.newValueMetadata();
for (Column column : valueAnnotation.columns()) {
ColumnMetadata colMd = valueMetadata.newColumnMetadata();
colMd.setName(column.name());
colMd.setLength(column.length());
colMd.setAllowsNull(Boolean.parseBoolean(column.allowsNull()));
colMd.setDefaultValue(column.defaultValue());
colMd.setInsertValue(column.insertValue());
colMd.setJDBCType(column.jdbcType());
colMd.setSQLType(column.sqlType());
}
}
示例14: setTimeMetadata
import javax.jdo.metadata.FieldMetadata; //导入依赖的package包/类
private FieldMetadata setTimeMetadata(ClassMetadata cmd, String name) {
// for time we register our converter which persists as string
FieldMetadata fmd = cmd.newFieldMetadata(name);
fmd.setPersistenceModifier(PersistenceModifier.PERSISTENT);
fmd.setDefaultFetchGroup(true);
fmd.newExtensionMetadata(DATANUCLEUS, "type-converter-name", "dn.time-string");
return fmd;
}
示例15: setMapMetadata
import javax.jdo.metadata.FieldMetadata; //导入依赖的package包/类
private FieldMetadata setMapMetadata(ClassMetadata cmd, EntityDto entity, FieldDto field,
Class<?> definition, EntityType entityType) {
FieldMetadata fmd = cmd.newFieldMetadata(getNameForMetadata(field));
MetadataDto keyMetadata = field.getMetadata(MAP_KEY_TYPE);
MetadataDto valueMetadata = field.getMetadata(MAP_VALUE_TYPE);
boolean serialized = shouldSerializeMap(keyMetadata, valueMetadata);
// Depending on the types of key and value of the map we either serialize the map or create a separate table for it
fmd.setSerialized(serialized);
addDefaultFetchGroupMetadata(fmd, definition);
MapMetadata mmd = fmd.newMapMetadata();
if (serialized) {
mmd.setSerializedKey(true);
mmd.setSerializedValue(true);
} else {
mmd.setKeyType(keyMetadata.getValue());
mmd.setValueType(valueMetadata.getValue());
fmd.setTable(ClassTableName.getTableName(cmd.getTable(), getNameForMetadata(field)));
JoinMetadata jmd = fmd.newJoinMetadata();
ForeignKeyMetadata fkmd = getOrCreateFkMetadata(jmd);
fkmd.setDeleteAction(ForeignKeyAction.CASCADE);
fkmd.setName(KeyNames.mapForeignKeyName(entity.getName(), entity.getId(), field.getBasic().getName(),
entityType));
}
return fmd;
}