Java Code Examples for javax.persistence.Column#length()
The following examples show how to use
javax.persistence.Column#length() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CheckCore.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
public static void checkEnum(List<Class<?>> classes) throws Exception { for (Class<?> cls : classes) { List<Field> fields = FieldUtils.getFieldsListWithAnnotation(cls, FieldDescribe.class); for (Field field : fields) { if (field.getType().isEnum()) { Enumerated enumerated = field.getAnnotation(Enumerated.class); Column column = field.getAnnotation(Column.class); if (null == enumerated || (!Objects.equals(EnumType.STRING, enumerated.value())) || (null == column) || column.length() > 200) { System.err.println(String.format("checkEnum error: class: %s, field: %s.", cls.getName(), field.getName())); } } } } }
Example 2
Source File: JpaObjectTools.java From o2oa with GNU Affero General Public License v3.0 | 6 votes |
public static <T extends JpaObject> Integer definedLength(Class<T> clz, Field field) throws Exception { if (null == field) { throw new Exception( "can not find field with Class:" + clz + ", attribute:" + Objects.toString(field) + "."); } Integer length = null; for (int i = 0; i < 1; i++) { Column column = field.getAnnotation(Column.class); if (null != column) { length = column.length(); break; } ElementColumn elementColumn = field.getAnnotation(ElementColumn.class); if (null != elementColumn) { length = elementColumn.length(); } } if (null == length) { throw new Exception("can not find @Column or @ElementColumn with Class:" + clz + ", attribute:" + Objects.toString(field) + "."); } return length; }
Example 3
Source File: AbstractCellPostParser.java From bdf3 with Apache License 2.0 | 6 votes |
@Override public void parse(Context context) { if (context.getValue() != null) { MappingRule mappingRule =context.getCurrentMappingRule(); BeanMap beanMap = BeanMap.create(context.getCurrentEntity()); if (context.getValue() != Constants.IGNORE_ERROR_FORMAT_DATA) { Field field = ReflectionUtils.findField(context.getEntityClass(), mappingRule.getPropertyName()); Column column = field.getAnnotation(Column.class); if (column.nullable()) { if (context.getValue() == null) { throw new DataNullableException(context.getCurrentCell().getRow(), context.getCurrentCell().getCol()); } } if (field.getType() == String.class && !field.isAnnotationPresent(Lob.class)) { String value = (String) context.getValue(); if (value.getBytes().length > column.length()) { throw new DataLengthException(context.getCurrentCell().getRow(), context.getCurrentCell().getCol(), value, column.length()); } } beanMap.put(mappingRule.getPropertyName(), context.getValue()); } } }
Example 4
Source File: CheckCore.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
public static void checkColumnLength(List<Class<?>> classes) throws Exception { for (Class<?> cls : classes) { List<Field> fields = FieldUtils.getFieldsListWithAnnotation(cls, Column.class); for (Field field : fields) { if ((!String.class.isAssignableFrom(field.getType())) && (!field.getType().isEnum())) { Column column = field.getAnnotation(Column.class); if (column.length() != 255) { System.err.println(String.format("checkColumnLength error: class: %s, field: %s.", cls.getName(), field.getName())); } } } } }
Example 5
Source File: StringValuePersistChecker.java From o2oa with GNU Affero General Public License v3.0 | 5 votes |
private void length(Field field, String value, JpaObject jpa, CheckPersist checkPersist, CheckPersistType checkPersistType) throws Exception { Column column = field.getAnnotation(Column.class); int len = Objects.toString(value).getBytes(Charset.forName("UTF-8")).length; if (len > column.length()) { throw new Exception("check persist stirngValue length error, class:" + jpa.getClass().getName() + ", field:" + field.getName() + ", value:" + value + ", length:" + len + ", max:" + column.length() + "."); } }
Example 6
Source File: JPAEdmFacets.java From olingo-odata2 with Apache License 2.0 | 4 votes |
private static void setMaxLength(final Column column, final SimpleProperty edmProperty) { if (column.length() > 0) { ((Facets) edmProperty.getFacets()).setMaxLength(column.length()); } }
Example 7
Source File: JPAEdmFacets.java From cloud-odata-java with Apache License 2.0 | 4 votes |
private static void setMaxLength(final Column column, final SimpleProperty edmProperty) { if (column.length() > 0) { ((Facets) edmProperty.getFacets()).setMaxLength(column.length()); } }