use of cn.taketoday.beans.BeanProperty in project today-infrastructure by TAKETODAY.
the class Dialect method insert.
public String insert(SQLParams sqlParams) {
StringBuilder sql = new StringBuilder();
sql.append("INSERT INTO ").append(sqlParams.getTableName());
StringBuilder columnNames = new StringBuilder();
StringBuilder placeholder = new StringBuilder();
JdbcBeanMetadata beanMetadata = new JdbcBeanMetadata(sqlParams.getModelClass());
Object model = sqlParams.getModel();
for (BeanProperty property : beanMetadata) {
Object value = property.getValue(model);
if (value != null) {
columnNames.append(",").append(" ").append(property.getName());
placeholder.append(", ?");
}
}
if (columnNames.length() > 0 && placeholder.length() > 0) {
sql.append("(").append(columnNames.substring(2)).append(")");
sql.append(" VALUES (").append(placeholder.substring(2)).append(")");
}
return sql.toString();
}
use of cn.taketoday.beans.BeanProperty in project today-infrastructure by TAKETODAY.
the class DefaultResultSetHandlerFactory method getAccessor.
private JdbcPropertyAccessor getAccessor(String propertyName, JdbcBeanMetadata metadata) {
int index = propertyName.indexOf('.');
if (index <= 0) {
// Simple path - fast way
BeanProperty beanProperty = metadata.getBeanProperty(propertyName);
// behavior change: do not throw if POJO contains less properties
if (beanProperty == null) {
return null;
}
TypeHandler<?> typeHandler = registry.getTypeHandler(beanProperty.getType());
return new TypeHandlerPropertyAccessor(typeHandler, beanProperty);
}
// dot path - long way
// i'm too lazy now to rewrite this case so I just call old unoptimized code...
TypeHandler<?> typeHandler = registry.getTypeHandler(metadata.getType());
class PropertyPathPropertyAccessor extends JdbcPropertyAccessor {
@Override
public Object get(Object obj) {
return metadata.getProperty(obj, propertyName);
}
@Override
public void set(Object obj, ResultSet resultSet, int columnIndex) throws SQLException {
Object result = typeHandler.getResult(resultSet, columnIndex);
metadata.setProperty(obj, propertyName, result);
}
}
return new PropertyPathPropertyAccessor();
}
use of cn.taketoday.beans.BeanProperty in project today-infrastructure by TAKETODAY.
the class JmxUtilsTests method getAttributeNameWithoutStrictCasing.
@Test
void getAttributeNameWithoutStrictCasing() {
BeanProperty pd = new BeanWrapperImpl(AttributeTestBean.class).getBeanProperty("name");
String attributeName = JmxUtils.getAttributeName(pd, false);
assertThat(attributeName).as("Incorrect casing on attribute name").isEqualTo("name");
}
use of cn.taketoday.beans.BeanProperty in project today-infrastructure by TAKETODAY.
the class JmxUtilsTests method getAttributeNameWithStrictCasing.
@Test
void getAttributeNameWithStrictCasing() {
BeanProperty pd = new BeanWrapperImpl(AttributeTestBean.class).getBeanProperty("name");
String attributeName = JmxUtils.getAttributeName(pd, true);
assertThat(attributeName).as("Incorrect casing on attribute name").isEqualTo("Name");
}
use of cn.taketoday.beans.BeanProperty in project today-infrastructure by TAKETODAY.
the class BeanPropertySqlParameterSource method getReadablePropertyNames.
/**
* Provide access to the property names of the wrapped bean.
* Uses support provided in the {@link PropertyAccessor} interface.
*
* @return an array containing all the known property names
*/
public String[] getReadablePropertyNames() {
if (this.propertyNames == null) {
ArrayList<String> names = new ArrayList<>();
for (BeanProperty property : beanWrapper.getBeanProperties()) {
if (property.isReadable()) {
names.add(property.getName());
}
}
this.propertyNames = StringUtils.toStringArray(names);
}
return this.propertyNames;
}
Aggregations