use of javax.persistence.Column in project hibernate-orm by hibernate.
the class AbstractPropertyHolder method buildColumnOverride.
private static Map<String, Column[]> buildColumnOverride(XAnnotatedElement element, String path) {
Map<String, Column[]> columnOverride = new HashMap<String, Column[]>();
if (element != null) {
AttributeOverride singleOverride = element.getAnnotation(AttributeOverride.class);
AttributeOverrides multipleOverrides = element.getAnnotation(AttributeOverrides.class);
AttributeOverride[] overrides;
if (singleOverride != null) {
overrides = new AttributeOverride[] { singleOverride };
} else if (multipleOverrides != null) {
overrides = multipleOverrides.value();
} else {
overrides = null;
}
if (overrides != null) {
Map<String, List<Column>> columnOverrideList = new HashMap<>();
for (AttributeOverride depAttr : overrides) {
String qualifiedName = StringHelper.qualify(path, depAttr.name());
if (columnOverrideList.containsKey(qualifiedName)) {
columnOverrideList.get(qualifiedName).add(depAttr.column());
} else {
columnOverrideList.put(qualifiedName, new ArrayList<>(Arrays.asList(depAttr.column())));
}
}
for (Map.Entry<String, List<Column>> entry : columnOverrideList.entrySet()) {
columnOverride.put(entry.getKey(), entry.getValue().toArray(new Column[entry.getValue().size()]));
}
}
}
return columnOverride;
}
use of javax.persistence.Column in project jeesuite-libs by vakinge.
the class EntityHelper method getEntityMapper.
/**
* 由传入的实体的class构建TableMapper对象,构建好的对象存入缓存中,以后使用时直接从缓存中获取
*
* @param entityClass
* @return TableMapper
*/
public static EntityMapper getEntityMapper(Class<?> entityClass) {
synchronized (entityClass) {
// 先从map中获取实体映射信息
EntityMapper entityMapper = tableMapperCache.get(entityClass);
// 如果存在直接返回
if (entityMapper != null) {
return entityMapper;
}
TableMapper tableMapper = getTableMapper(entityClass);
// 获取实体ID泛型
Class<?> idClass = getIdClass(entityClass);
// 获取实体字段列表
List<Field> fields = getAllField(entityClass);
// 全部列
Set<ColumnMapper> columnMapperSet = new HashSet<ColumnMapper>();
// 主键
ColumnMapper idColumn = null;
GenerationType idStrategy = null;
for (Field field : fields) {
// 排除字段
if (field.isAnnotationPresent(Transient.class)) {
continue;
}
ColumnMapper columnMapper = new ColumnMapper();
// 数据库字段名
String columnName = null;
if (field.isAnnotationPresent(Column.class)) {
Column column = field.getAnnotation(Column.class);
columnName = column.name();
columnMapper.setInsertable(column.insertable());
columnMapper.setUpdatable(column.updatable());
}
// 如果为空,使用属性名并替换为下划线风格
if (columnName == null || columnName.equals("")) {
columnName = camelhumpToUnderline(field.getName());
}
columnMapper.setProperty(field.getName());
columnMapper.setColumn(columnName);
columnMapper.setJavaType(field.getType());
// 是否主键
if (field.isAnnotationPresent(Id.class)) {
columnMapper.setId(true);
if (field.isAnnotationPresent(GeneratedValue.class)) {
idStrategy = field.getAnnotation(GeneratedValue.class).strategy();
}
idColumn = columnMapper;
}
// 添加到所有字段映射信息
columnMapperSet.add(columnMapper);
}
if (columnMapperSet.size() <= 0) {
throw new RuntimeException("实体" + entityClass.getName() + "不存在映射字段");
}
if (idColumn == null) {
throw new RuntimeException("实体" + entityClass.getName() + "不存在主键或者");
}
// 解析实体映射信息
entityMapper = new EntityMapper();
entityMapper.setTableMapper(tableMapper);
entityMapper.setColumnsMapper(columnMapperSet);
entityMapper.setIdClass(idClass);
entityMapper.setIdColumn(idColumn);
entityMapper.setIdStrategy(idStrategy);
tableMapperCache.put(entityClass, entityMapper);
return entityMapper;
}
}
use of javax.persistence.Column in project jdbi by jdbi.
the class JpaClass method inspectProperties.
private static void inspectProperties(Class<?> clazz, Map<String, JpaMember> members, boolean hasColumnAnnotation) {
try {
Stream.of(Introspector.getBeanInfo(clazz).getPropertyDescriptors()).filter(property -> !members.containsKey(property.getName())).filter(property -> !(property instanceof IndexedPropertyDescriptor)).filter(property -> !"class".equals(property.getName())).forEach(property -> {
Method getter = property.getReadMethod();
Method setter = property.getWriteMethod();
Column column = Stream.of(getter, setter).filter(Objects::nonNull).map(method -> method.getAnnotation(Column.class)).filter(Objects::nonNull).findFirst().orElse(null);
if ((column != null) == hasColumnAnnotation) {
members.put(property.getName(), new JpaMember(clazz, column, property));
}
});
} catch (IntrospectionException e) {
logger.warn("Unable to introspect " + clazz, e);
}
}
use of javax.persistence.Column in project tephra by heisedebaise.
the class ModelTablesImpl method parse.
private void parse(Class<? extends Model> modelClass) {
Table table = modelClass.getAnnotation(Table.class);
if (table == null)
return;
ModelTable modelTable = BeanFactory.getBean(ModelTable.class);
modelTable.setModelClass(modelClass);
DataSource dataSource = modelClass.getAnnotation(DataSource.class);
if (dataSource != null)
modelTable.setDataSource(dataSource.key());
modelTable.setTableName(table.name());
Memory memory = modelClass.getAnnotation(Memory.class);
if (memory != null)
modelTable.setMemoryName(memory.name());
Method[] methods = modelClass.getMethods();
for (Method method : methods) {
String name = method.getName();
if (name.length() < 3)
continue;
if (name.equals("getId")) {
modelTable.setIdColumnName(method.getAnnotation(Column.class).name());
GenericGenerator generator = method.getAnnotation(GenericGenerator.class);
if (generator != null && generator.name().toLowerCase().startsWith("uuid"))
modelTable.setUuid(true);
continue;
}
String propertyName = converter.toFirstLowerCase(name.substring(3));
if (startsWith(name, 'g')) {
modelTable.addGetMethod(propertyName, method);
Column column = method.getAnnotation(Column.class);
if (column != null)
modelTable.addColumn(propertyName, column);
continue;
}
if (startsWith(name, 's'))
modelTable.addSetMethod(propertyName, method);
}
map.put(modelClass, modelTable);
}
use of javax.persistence.Column in project BroadleafCommerce by BroadleafCommerce.
the class OracleRequiredFieldManagerModifier method canHandle.
@Override
public boolean canHandle(Field field, Object value, EntityManager em) {
if (!dialectHelper.isOracle(em)) {
return false;
}
Column column = field.getAnnotation(Column.class);
AdminPresentation adminPresentation = field.getAnnotation(AdminPresentation.class);
return adminPresentation != null && isRequiredField(adminPresentation, column) && isStringFieldType(field, adminPresentation);
}
Aggregations