use of org.springframework.data.jdbc.mapping.model.JdbcPersistentProperty in project spring-data-jdbc by spring-projects.
the class DefaultDataAccessStrategy method delete.
@Override
public void delete(Object rootId, PropertyPath propertyPath) {
JdbcPersistentEntity<?> rootEntity = context.getRequiredPersistentEntity(propertyPath.getOwningType());
JdbcPersistentProperty referencingProperty = rootEntity.getRequiredPersistentProperty(propertyPath.getSegment());
Assert.notNull(referencingProperty, "No property found matching the PropertyPath " + propertyPath);
String format = sql(rootEntity.getType()).createDeleteByPath(propertyPath);
HashMap<String, Object> parameters = new HashMap<>();
parameters.put("rootId", rootId);
operations.update(format, parameters);
}
use of org.springframework.data.jdbc.mapping.model.JdbcPersistentProperty in project spring-data-jdbc by spring-projects.
the class DefaultDataAccessStrategy method getPropertyMap.
private <S> MapSqlParameterSource getPropertyMap(final S instance, JdbcPersistentEntity<S> persistentEntity) {
MapSqlParameterSource parameters = new MapSqlParameterSource();
persistentEntity.doWithProperties((PropertyHandler<JdbcPersistentProperty>) property -> {
if (!property.isEntity()) {
Object value = persistentEntity.getPropertyAccessor(instance).getProperty(property);
Object convertedValue = convert(value, property.getColumnType());
parameters.addValue(property.getColumnName(), convertedValue, JdbcUtil.sqlTypeFor(property.getColumnType()));
}
});
return parameters;
}
use of org.springframework.data.jdbc.mapping.model.JdbcPersistentProperty in project spring-data-jdbc by spring-projects.
the class EntityRowMapper method mapRow.
/*
* (non-Javadoc)
* @see org.springframework.jdbc.core.RowMapper#mapRow(java.sql.ResultSet, int)
*/
@Override
public T mapRow(ResultSet resultSet, int rowNumber) throws SQLException {
T result = createInstance(resultSet);
ConvertingPropertyAccessor propertyAccessor = new ConvertingPropertyAccessor(entity.getPropertyAccessor(result), conversions);
Object id = idProperty == null ? null : readFrom(resultSet, idProperty, "");
for (JdbcPersistentProperty property : entity) {
if (property.isCollectionLike()) {
propertyAccessor.setProperty(property, accessStrategy.findAllByProperty(id, property));
} else if (property.isMap()) {
Iterable<Object> allByProperty = accessStrategy.findAllByProperty(id, property);
propertyAccessor.setProperty(property, ITERABLE_OF_ENTRY_TO_MAP_CONVERTER.convert(allByProperty));
} else {
propertyAccessor.setProperty(property, readFrom(resultSet, property, ""));
}
}
return result;
}
use of org.springframework.data.jdbc.mapping.model.JdbcPersistentProperty in project spring-data-jdbc by spring-projects.
the class SqlGenerator method createDeleteAllSql.
String createDeleteAllSql(PropertyPath path) {
if (path == null) {
return String.format("DELETE FROM %s", entity.getTableName());
}
JdbcPersistentEntity<?> entityToDelete = context.getRequiredPersistentEntity(path.getLeafType());
JdbcPersistentEntity<?> owningEntity = context.getRequiredPersistentEntity(path.getOwningType());
JdbcPersistentProperty property = owningEntity.getRequiredPersistentProperty(path.getSegment());
String innerMostCondition = String.format("%s IS NOT NULL", property.getReverseColumnName());
String condition = cascadeConditions(innerMostCondition, path.next());
return String.format("DELETE FROM %s WHERE %s", entityToDelete.getTableName(), condition);
}
use of org.springframework.data.jdbc.mapping.model.JdbcPersistentProperty in project spring-data-jdbc by spring-projects.
the class MyBatisDataAccessStrategyUnitTests method findAllByProperty.
@SuppressWarnings("unchecked")
// DATAJDBC-123
@Test
public void findAllByProperty() {
JdbcPersistentProperty property = mock(JdbcPersistentProperty.class, Mockito.RETURNS_DEEP_STUBS);
when(property.getOwner().getType()).thenReturn((Class) String.class);
doReturn(Number.class).when(property).getType();
doReturn("propertyName").when(property).getName();
accessStrategy.findAllByProperty("id", property);
verify(session).selectList(eq("java.lang.StringMapper.findAllByProperty-propertyName"), captor.capture());
//
assertThat(captor.getValue()).isNotNull().extracting(//
MyBatisContext::getInstance, //
MyBatisContext::getId, //
MyBatisContext::getDomainType, //
c -> c.get("key")).containsExactly(//
null, //
"id", //
Number.class, //
null);
}
Aggregations