use of cn.taketoday.beans.BeanProperty in project today-framework by TAKETODAY.
the class Dialect method update.
public String update(SQLParams sqlParams) {
StringBuilder sql = new StringBuilder();
sql.append("UPDATE ").append(sqlParams.getTableName()).append(" SET ");
StringBuilder setSQL = new StringBuilder();
Map<String, Object> updateColumns = sqlParams.getUpdateColumns();
if (CollectionUtils.isNotEmpty(updateColumns)) {
updateColumns.forEach((key, value) -> setSQL.append(key).append(" = ?, "));
} else {
Object model = sqlParams.getModel();
if (model != null) {
JdbcBeanMetadata beanMetadata = new JdbcBeanMetadata(sqlParams.getModelClass());
for (BeanProperty property : beanMetadata) {
Object value = property.getValue(model);
if (value == null) {
continue;
}
setSQL.append(property.getName()).append(" = ?, ");
}
}
}
sql.append(setSQL.substring(0, setSQL.length() - 2));
if (sqlParams.getConditionSQL().length() > 0) {
sql.append(" WHERE ").append(sqlParams.getConditionSQL().substring(5));
}
return sql.toString();
}
use of cn.taketoday.beans.BeanProperty in project today-framework by TAKETODAY.
the class TypeDescriptorTests method propertyGenericClassList.
@Test
void propertyGenericClassList() throws Exception {
IntegerClass genericBean = new IntegerClass();
BeanProperty property = BeanProperty.valueOf(genericBean.getClass().getMethod("getListProperty"), genericBean.getClass().getMethod("setListProperty", List.class), IntegerClass.class);
TypeDescriptor desc = property.getTypeDescriptor();
assertThat(desc.getType()).isEqualTo(List.class);
assertThat(desc.getElementDescriptor().getType()).isEqualTo(Integer.class);
assertThat(desc.getAnnotation(MethodAnnotation1.class)).isNotNull();
assertThat(desc.hasAnnotation(MethodAnnotation1.class)).isTrue();
}
use of cn.taketoday.beans.BeanProperty in project today-framework by TAKETODAY.
the class TypeDescriptorTests method propertyTypeCovariance.
@Test
void propertyTypeCovariance() throws Exception {
GenericType<Number> genericBean = new NumberType();
BeanProperty property = BeanProperty.valueOf(genericBean.getClass().getMethod("getProperty"), genericBean.getClass().getMethod("setProperty", Number.class));
TypeDescriptor desc = property.getTypeDescriptor();
assertThat(desc.getType()).isEqualTo(Integer.class);
}
use of cn.taketoday.beans.BeanProperty in project today-framework by TAKETODAY.
the class TypeDescriptorTests method propertyGenericType.
@Test
void propertyGenericType() throws Exception {
GenericType<Integer> genericBean = new IntegerType();
BeanProperty property = BeanProperty.valueOf(genericBean.getClass().getMethod("getProperty"), genericBean.getClass().getMethod("setProperty", Integer.class));
TypeDescriptor desc = property.getTypeDescriptor();
assertThat(desc.getType()).isEqualTo(Integer.class);
}
use of cn.taketoday.beans.BeanProperty in project today-framework by TAKETODAY.
the class TypeDescriptorTests method property.
@Test
public void property() throws Exception {
final BeanProperty property = BeanProperty.valueOf(getClass(), "property");
TypeDescriptor desc = property.getTypeDescriptor();
assertThat(desc.getType()).isEqualTo(Map.class);
assertThat(desc.getMapKeyDescriptor().getElementDescriptor().getType()).isEqualTo(Integer.class);
assertThat(desc.getMapValueDescriptor().getElementDescriptor().getType()).isEqualTo(Long.class);
PropertyAccessor propertyAccessor = property.obtainAccessor();
Method writeMethod = propertyAccessor.getWriteMethod();
Method readMethod = propertyAccessor.getReadMethod();
assertThat(writeMethod).isNotNull();
assertThat(readMethod).isNotNull();
assertThat(readMethod.getAnnotation(MethodAnnotation1.class)).isNotNull();
assertThat(writeMethod.getAnnotation(MethodAnnotation2.class)).isNotNull();
assertThat(desc.getAnnotation(MethodAnnotation3.class)).isNotNull();
}
Aggregations