Skip to content

Commit b4a860b

Browse files
FrankSpitulskimp911de
authored andcommitted
Defer non-constant assert messages to improve performance.
Original pull request: #1079.
1 parent 57406d6 commit b4a860b

File tree

6 files changed

+17
-10
lines changed

6 files changed

+17
-10
lines changed

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/convert/MappingCassandraConverter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
* @author Antoine Toulme
8787
* @author John Blum
8888
* @author Christoph Strobl
89+
* @author Frank Spitulski
8990
*/
9091
public class MappingCassandraConverter extends AbstractCassandraConverter
9192
implements ApplicationContextAware, BeanClassLoaderAware {
@@ -522,7 +523,7 @@ private void writeWhereFromObject(Object source, Where sink, CassandraPersistent
522523

523524
Object id = extractId(source, entity);
524525

525-
Assert.notNull(id, String.format("No Id value found in object %s", source));
526+
Assert.notNull(id, () -> String.format("No Id value found in object %s", source));
526527

527528
CassandraPersistentProperty idProperty = entity.getIdProperty();
528529
CassandraPersistentProperty compositeIdProperty = null;
@@ -601,7 +602,7 @@ private void writeWhere(MapId id, Where sink, CassandraPersistentEntity<?> entit
601602
private void writeWhere(ConvertingPropertyAccessor<?> accessor, Where sink, CassandraPersistentEntity<?> entity) {
602603

603604
Assert.isTrue(entity.isCompositePrimaryKey(),
604-
String.format("Entity [%s] is not a composite primary key", entity.getName()));
605+
() -> String.format("Entity [%s] is not a composite primary key", entity.getName()));
605606

606607
for (CassandraPersistentProperty property : entity) {
607608
TypeCodec<Object> codec = getCodec(property);
@@ -685,7 +686,7 @@ public Object getId(Object object, CassandraPersistentEntity<?> entity) {
685686
ConvertingPropertyAccessor<?> propertyAccessor = newConvertingPropertyAccessor(object, entity);
686687

687688
Assert.isTrue(entity.getType().isAssignableFrom(object.getClass()),
688-
String.format("Given instance of type [%s] is not compatible with expected type [%s]",
689+
() -> String.format("Given instance of type [%s] is not compatible with expected type [%s]",
689690
object.getClass().getName(), entity.getType().getName()));
690691

691692
if (object instanceof MapIdentifiable) {

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/convert/RowReader.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* Helpful class to read a column's value from a row, with possible type conversion.
3636
*
3737
* @author Mark Paluch
38+
* @author Frank Spitulski
3839
* @since 3.0
3940
*/
4041
class RowReader {
@@ -165,7 +166,7 @@ private int getColumnIndex(String columnName) {
165166

166167
int index = columns.firstIndexOf(columnName);
167168

168-
Assert.isTrue(index > -1, String.format("Column [%s] does not exist in table", columnName));
169+
Assert.isTrue(index > -1, () -> String.format("Column [%s] does not exist in table", columnName));
169170

170171
return index;
171172
}

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/generator/AlterUserTypeCqlGenerator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
*
2828
* @author Fabio J. Mendes
2929
* @author Mark Paluch
30+
* @author Frank Spitulski
3031
* @since 1.5
3132
* @see AlterUserTypeSpecification
3233
* @see AddColumnSpecification
@@ -58,7 +59,7 @@ public StringBuilder toCql(StringBuilder cql) {
5859
Assert.notNull(getSpecification().getName(), "User type name must not be null");
5960

6061
Assert.isTrue(!getSpecification().getChanges().isEmpty(),
61-
String.format("User type [%s] does not contain fields", getSpecification().getName()));
62+
() -> String.format("User type [%s] does not contain fields", getSpecification().getName()));
6263

6364
return changesCql(preambleCql(cql)).append(";");
6465
}

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/cql/generator/CreateUserTypeCqlGenerator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*
2525
* @author Fabio J. Mendes
2626
* @author Mark Paluch
27+
* @author Frank Spitulski
2728
* @since 1.5
2829
* @see CreateUserTypeSpecification
2930
*/
@@ -52,7 +53,7 @@ public StringBuilder toCql(StringBuilder cql) {
5253
Assert.notNull(getSpecification().getName(), "User type name must not be null");
5354

5455
Assert.isTrue(!getSpecification().getFields().isEmpty(),
55-
String.format("User type [%s] does not contain fields", getSpecification().getName().asCql(true)));
56+
() -> String.format("User type [%s] does not contain fields", getSpecification().getName().asCql(true)));
5657

5758
return columns(preambleCql(cql)).append(";");
5859
}

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/mapping/BasicCassandraPersistentTupleProperty.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* Cassandra Tuple specific {@link CassandraPersistentProperty} implementation.
2828
*
2929
* @author Mark Paluch
30+
* @author Frank Spitulski
3031
* @since 2.1
3132
* @see Element
3233
*/
@@ -68,7 +69,8 @@ private Integer findOrdinal() {
6869
}
6970

7071
Assert.isTrue(ordinal >= 0,
71-
String.format("Element ordinal must be greater or equal to zero for property [%s] in entity [%s]", getName(),
72+
() -> String.format("Element ordinal must be greater or equal to zero for property [%s] in entity [%s]",
73+
getName(),
7274
getOwner().getName()));
7375

7476
return ordinal;

spring-data-cassandra/src/main/java/org/springframework/data/cassandra/core/mapping/CassandraPersistentProperty.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
* @author Mark Paluch
3636
* @author John Blum
3737
* @author Christoph Strobl
38+
* @author Frank Spitulski
3839
*/
3940
public interface CassandraPersistentProperty
4041
extends PersistentProperty<CassandraPersistentProperty>, ApplicationContextAware {
@@ -81,8 +82,8 @@ default CqlIdentifier getRequiredColumnName() {
8182

8283
CqlIdentifier columnName = getColumnName();
8384

84-
Assert.state(columnName != null, String.format("No column name available for this persistent property [%1$s.%2$s]",
85-
getOwner().getName(), getName()));
85+
Assert.state(columnName != null, () -> String
86+
.format("No column name available for this persistent property [%1$s.%2$s]", getOwner().getName(), getName()));
8687

8788
return columnName;
8889
}
@@ -115,7 +116,7 @@ default int getRequiredOrdinal() {
115116

116117
Integer ordinal = getOrdinal();
117118

118-
Assert.state(ordinal != null, String.format("No ordinal available for this persistent property [%1$s.%2$s]",
119+
Assert.state(ordinal != null, () -> String.format("No ordinal available for this persistent property [%1$s.%2$s]",
119120
getOwner().getName(), getName()));
120121

121122
return ordinal;

0 commit comments

Comments
 (0)