use of org.springframework.cloud.gcp.data.spanner.core.mapping.SpannerPersistentProperty in project spring-cloud-gcp by spring-cloud.
the class SpannerSchemaUtils method getDdlStringForInterleavedHierarchy.
private void getDdlStringForInterleavedHierarchy(String parentTable, Class entityClass, List<String> ddlStrings, Set<Class> seenClasses, BiFunction<Class, String, String> generateSingleDdlStringFunc, boolean prependDdlString) {
if (seenClasses.contains(entityClass)) {
return;
}
seenClasses.add(entityClass);
ddlStrings.add(prependDdlString ? 0 : ddlStrings.size(), generateSingleDdlStringFunc.apply(entityClass, parentTable));
SpannerPersistentEntity spannerPersistentEntity = this.mappingContext.getPersistentEntity(entityClass);
spannerPersistentEntity.doWithInterleavedProperties((PropertyHandler<SpannerPersistentProperty>) (spannerPersistentProperty) -> getDdlStringForInterleavedHierarchy(spannerPersistentEntity.tableName(), spannerPersistentProperty.getColumnInnerType(), ddlStrings, seenClasses, generateSingleDdlStringFunc, prependDdlString));
}
use of org.springframework.cloud.gcp.data.spanner.core.mapping.SpannerPersistentProperty in project spring-cloud-gcp by spring-cloud.
the class SpannerStatementQueryExecutor method applySort.
public static StringBuilder applySort(Sort sort, StringBuilder sql, SpannerPersistentEntity<?> persistentEntity) {
if (sort == null || sort.isUnsorted()) {
return sql;
}
sql.append(" ORDER BY ");
StringJoiner sj = new StringJoiner(" , ");
sort.iterator().forEachRemaining((o) -> {
SpannerPersistentProperty property = persistentEntity.getPersistentProperty(o.getProperty());
String sortedPropertyName = (property != null) ? property.getColumnName() : o.getProperty();
String sortedProperty = o.isIgnoreCase() ? "LOWER(" + sortedPropertyName + ")" : sortedPropertyName;
sj.add(sortedProperty + (o.isAscending() ? " ASC" : " DESC"));
});
return sql.append(sj);
}
use of org.springframework.cloud.gcp.data.spanner.core.mapping.SpannerPersistentProperty in project spring-cloud-gcp by spring-cloud.
the class SpannerSchemaUtilsTests method assertColumnDdl.
private void assertColumnDdl(Class clazz, Class innerClazz, String name, OptionalLong length, String expectedDDL) {
SpannerPersistentProperty spannerPersistentProperty = mock(SpannerPersistentProperty.class);
// @formatter:off
Mockito.<Class>when(spannerPersistentProperty.getType()).thenReturn(clazz);
Mockito.<Class>when(spannerPersistentProperty.getColumnInnerType()).thenReturn(innerClazz);
// @formatter:on
when(spannerPersistentProperty.getColumnName()).thenReturn(name);
when(spannerPersistentProperty.getMaxColumnLength()).thenReturn(length);
assertThat(this.spannerSchemaUtils.getColumnDdlString(spannerPersistentProperty, this.spannerEntityProcessor)).isEqualTo(expectedDDL);
}
Aggregations