@Test public void autoAddAttributes() { Table table = new Table(PFUserDO.class); table.autoAddAttributes(); assertAttribute(table, "username"); assertAttribute(table, "created"); table = new Table(UserRightDO.class); table.autoAddAttributes(); assertAttribute(table, "right_id"); }
public Table autoAddAttributes() { if (entityClass == null) { throw new IllegalStateException( "Entity class isn't set. Can't add attributes from property names. Please set entity class first."); } final Field[] fields; final List<Method> getter; if (this.superTable != null) { fields = entityClass.getDeclaredFields(); getter = BeanHelper.getAllGetterMethods(entityClass, false); } else { fields = BeanHelper.getAllDeclaredFields(entityClass); getter = BeanHelper.getAllGetterMethods(entityClass); } for (final Field field : fields) { final List<Annotation> annotations = handlePersistencyAnnotations(field); if (annotations == null) { continue; } final String fieldName = field.getName(); if (log.isDebugEnabled()) { log.debug(name + "." + fieldName); } addTableAttribute(fieldName, annotations); } for (final Method method : getter) { final List<Annotation> annotations = handlePersistencyAnnotations(method); if (annotations == null) { continue; } if (log.isDebugEnabled()) { log.debug(name + "." + method.getName()); } final String property = BeanHelper.getProperty(method); if (property != null) { addTableAttribute(property, annotations); } else { log.error("Can't determine property of getter method: '" + method.getName()); } } if (this.discriminatorColumn != null) { TableAttributeType type; if (this.discriminatorColumn.discriminatorType() == DiscriminatorType.CHAR) { type = TableAttributeType.CHAR; } else if (this.discriminatorColumn.discriminatorType() == DiscriminatorType.INTEGER) { type = TableAttributeType.INT; } else { type = TableAttributeType.VARCHAR; } final TableAttribute attr = new TableAttribute(this.discriminatorColumn.name(), type); if (type == TableAttributeType.VARCHAR) { attr.setLength(31); } addAttribute(attr); } return this; }
Table implements Serializable { public Table autoAddAttributes() { if (entityClass == null) { throw new IllegalStateException( "Entity class isn't set. Can't add attributes from property names. Please set entity class first."); } final Field[] fields; final List<Method> getter; if (this.superTable != null) { fields = entityClass.getDeclaredFields(); getter = BeanHelper.getAllGetterMethods(entityClass, false); } else { fields = BeanHelper.getAllDeclaredFields(entityClass); getter = BeanHelper.getAllGetterMethods(entityClass); } for (final Field field : fields) { final List<Annotation> annotations = handlePersistencyAnnotations(field); if (annotations == null) { continue; } final String fieldName = field.getName(); if (log.isDebugEnabled()) { log.debug(name + "." + fieldName); } addTableAttribute(fieldName, annotations); } for (final Method method : getter) { final List<Annotation> annotations = handlePersistencyAnnotations(method); if (annotations == null) { continue; } if (log.isDebugEnabled()) { log.debug(name + "." + method.getName()); } final String property = BeanHelper.getProperty(method); if (property != null) { addTableAttribute(property, annotations); } else { log.error("Can't determine property of getter method: '" + method.getName()); } } if (this.discriminatorColumn != null) { TableAttributeType type; if (this.discriminatorColumn.discriminatorType() == DiscriminatorType.CHAR) { type = TableAttributeType.CHAR; } else if (this.discriminatorColumn.discriminatorType() == DiscriminatorType.INTEGER) { type = TableAttributeType.INT; } else { type = TableAttributeType.VARCHAR; } final TableAttribute attr = new TableAttribute(this.discriminatorColumn.name(), type); if (type == TableAttributeType.VARCHAR) { attr.setLength(31); } addAttribute(attr); } return this; } }
Table implements Serializable { public Table autoAddAttributes() { if (entityClass == null) { throw new IllegalStateException( "Entity class isn't set. Can't add attributes from property names. Please set entity class first."); } final Field[] fields; final List<Method> getter; if (this.superTable != null) { fields = entityClass.getDeclaredFields(); getter = BeanHelper.getAllGetterMethods(entityClass, false); } else { fields = BeanHelper.getAllDeclaredFields(entityClass); getter = BeanHelper.getAllGetterMethods(entityClass); } for (final Field field : fields) { final List<Annotation> annotations = handlePersistencyAnnotations(field); if (annotations == null) { continue; } final String fieldName = field.getName(); if (log.isDebugEnabled()) { log.debug(name + "." + fieldName); } addTableAttribute(fieldName, annotations); } for (final Method method : getter) { final List<Annotation> annotations = handlePersistencyAnnotations(method); if (annotations == null) { continue; } if (log.isDebugEnabled()) { log.debug(name + "." + method.getName()); } final String property = BeanHelper.getProperty(method); if (property != null) { addTableAttribute(property, annotations); } else { log.error("Can't determine property of getter method: '" + method.getName()); } } if (this.discriminatorColumn != null) { TableAttributeType type; if (this.discriminatorColumn.discriminatorType() == DiscriminatorType.CHAR) { type = TableAttributeType.CHAR; } else if (this.discriminatorColumn.discriminatorType() == DiscriminatorType.INTEGER) { type = TableAttributeType.INT; } else { type = TableAttributeType.VARCHAR; } final TableAttribute attr = new TableAttribute(this.discriminatorColumn.name(), type); if (type == TableAttributeType.VARCHAR) { attr.setLength(31); } addAttribute(attr); } return this; } Table(final Class<?> entityClass);  Table(final String name); }
Table implements Serializable { public Table autoAddAttributes() { if (entityClass == null) { throw new IllegalStateException( "Entity class isn't set. Can't add attributes from property names. Please set entity class first."); } final Field[] fields; final List<Method> getter; if (this.superTable != null) { fields = entityClass.getDeclaredFields(); getter = BeanHelper.getAllGetterMethods(entityClass, false); } else { fields = BeanHelper.getAllDeclaredFields(entityClass); getter = BeanHelper.getAllGetterMethods(entityClass); } for (final Field field : fields) { final List<Annotation> annotations = handlePersistencyAnnotations(field); if (annotations == null) { continue; } final String fieldName = field.getName(); if (log.isDebugEnabled()) { log.debug(name + "." + fieldName); } addTableAttribute(fieldName, annotations); } for (final Method method : getter) { final List<Annotation> annotations = handlePersistencyAnnotations(method); if (annotations == null) { continue; } if (log.isDebugEnabled()) { log.debug(name + "." + method.getName()); } final String property = BeanHelper.getProperty(method); if (property != null) { addTableAttribute(property, annotations); } else { log.error("Can't determine property of getter method: '" + method.getName()); } } if (this.discriminatorColumn != null) { TableAttributeType type; if (this.discriminatorColumn.discriminatorType() == DiscriminatorType.CHAR) { type = TableAttributeType.CHAR; } else if (this.discriminatorColumn.discriminatorType() == DiscriminatorType.INTEGER) { type = TableAttributeType.INT; } else { type = TableAttributeType.VARCHAR; } final TableAttribute attr = new TableAttribute(this.discriminatorColumn.name(), type); if (type == TableAttributeType.VARCHAR) { attr.setLength(31); } addAttribute(attr); } return this; } Table(final Class<?> entityClass);  Table(final String name); Table setEntityClass(final Class<?> entityClass); TableAttribute getAttributeByProperty(final String property); TableAttribute getAttributeByName(final String name); Class<?> getEntityClass(); String getName(); Table getSuperTable(); Table setSuperTable(final Table superTable); UniqueConstraint[] getUniqueConstraints(); TableAttribute getPrimaryKey(); List<TableAttribute> getAttributes(); Table addAttribute(final TableAttribute attr); Table addAttributes(final String... properties); Table addDefaultBaseDOAttributes(); Table autoAddAttributes(); }
Table implements Serializable { public Table autoAddAttributes() { if (entityClass == null) { throw new IllegalStateException( "Entity class isn't set. Can't add attributes from property names. Please set entity class first."); } final Field[] fields; final List<Method> getter; if (this.superTable != null) { fields = entityClass.getDeclaredFields(); getter = BeanHelper.getAllGetterMethods(entityClass, false); } else { fields = BeanHelper.getAllDeclaredFields(entityClass); getter = BeanHelper.getAllGetterMethods(entityClass); } for (final Field field : fields) { final List<Annotation> annotations = handlePersistencyAnnotations(field); if (annotations == null) { continue; } final String fieldName = field.getName(); if (log.isDebugEnabled()) { log.debug(name + "." + fieldName); } addTableAttribute(fieldName, annotations); } for (final Method method : getter) { final List<Annotation> annotations = handlePersistencyAnnotations(method); if (annotations == null) { continue; } if (log.isDebugEnabled()) { log.debug(name + "." + method.getName()); } final String property = BeanHelper.getProperty(method); if (property != null) { addTableAttribute(property, annotations); } else { log.error("Can't determine property of getter method: '" + method.getName()); } } if (this.discriminatorColumn != null) { TableAttributeType type; if (this.discriminatorColumn.discriminatorType() == DiscriminatorType.CHAR) { type = TableAttributeType.CHAR; } else if (this.discriminatorColumn.discriminatorType() == DiscriminatorType.INTEGER) { type = TableAttributeType.INT; } else { type = TableAttributeType.VARCHAR; } final TableAttribute attr = new TableAttribute(this.discriminatorColumn.name(), type); if (type == TableAttributeType.VARCHAR) { attr.setLength(31); } addAttribute(attr); } return this; } Table(final Class<?> entityClass);  Table(final String name); Table setEntityClass(final Class<?> entityClass); TableAttribute getAttributeByProperty(final String property); TableAttribute getAttributeByName(final String name); Class<?> getEntityClass(); String getName(); Table getSuperTable(); Table setSuperTable(final Table superTable); UniqueConstraint[] getUniqueConstraints(); TableAttribute getPrimaryKey(); List<TableAttribute> getAttributes(); Table addAttribute(final TableAttribute attr); Table addAttributes(final String... properties); Table addDefaultBaseDOAttributes(); Table autoAddAttributes();  }