Skip to content

Commit df1d672

Browse files
mmoquiSilverYoCha
authored andcommitted
Bug #13726 Fix the error coming from an orderBy null value
1 parent 16fdf4f commit df1d672

19 files changed

+63
-140
lines changed

mydb/mydb-library/src/main/java/org/silverpeas/components/mydb/MyDBInstancePreDestruction.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import org.silverpeas.components.mydb.model.MyDBConnectionInfo;
2727
import org.silverpeas.core.admin.component.ComponentInstancePreDestruction;
28+
import org.silverpeas.core.annotation.Bean;
2829

2930
import javax.inject.Named;
3031
import javax.transaction.Transactional;
@@ -35,6 +36,7 @@
3536
* @author mmoquillon
3637
*/
3738
@Named
39+
@Bean
3840
public class MyDBInstancePreDestruction implements ComponentInstancePreDestruction {
3941

4042
/**

mydb/mydb-library/src/main/java/org/silverpeas/components/mydb/model/DataSourceDefinition.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
*/
3232
public class DataSourceDefinition {
3333

34-
private String dataSource;
35-
private String description;
34+
private final String dataSource;
35+
private final String description;
3636

3737
public static List<DataSourceDefinition> getAll() {
3838
return MyDBConnectionInfoService.get().getAllDataSourceDefinitions();

mydb/mydb-library/src/main/java/org/silverpeas/components/mydb/model/DbColumn.java

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@
4040
*/
4141
public class DbColumn {
4242

43-
private JdbcRequester.ColumnDescriptor descriptor;
43+
private final JdbcRequester.ColumnDescriptor descriptor;
4444

4545
/**
4646
* Constructs a new {@link DbColumn} instance of the specified SQL type and with the specified
4747
* name.
4848
* @param descriptor a descriptor of the column.
4949
*/
50-
public DbColumn(final JdbcRequester.ColumnDescriptor descriptor) {
50+
DbColumn(final JdbcRequester.ColumnDescriptor descriptor) {
5151
this.descriptor = descriptor;
5252
}
5353

@@ -85,7 +85,7 @@ public String getTypeName() {
8585
public int getSize() {
8686
int size = descriptor.getSize();
8787
if (getType() == Types.BIT && descriptor.getSize() == 1) {
88-
size = Math.max("true".length(), "false".length());
88+
size = "false".length();
8989
}
9090
return size;
9191
}
@@ -190,24 +190,6 @@ public boolean isOfTypeBinary() {
190190
return SqlTypes.isBinary(getType());
191191
}
192192

193-
/**
194-
* Is this column of type number (INTEGER, BIGDECIMAL, ...)?
195-
* @return true if the values of this column are numbers. False otherwise.
196-
*/
197-
public boolean isOfTypeNumber() {
198-
final int type = getType();
199-
return SqlTypes.isBigInteger(type) || SqlTypes.isDouble(type) || SqlTypes.isFloat(type) ||
200-
SqlTypes.isInteger(type) || SqlTypes.isDecimal(type);
201-
}
202-
203-
/**
204-
* Is this column of type date time (TIMESTAMP, TIMESTAMP_WITH_TIMEZONE, ...)?
205-
* @return true if the values of this column are date times. False otherwise.
206-
*/
207-
public boolean isOfTypeDateTime() {
208-
return SqlTypes.isTimestamp(getType());
209-
}
210-
211193
/**
212194
* Gets a JDBC value of given value. The aim is to get a value to fill into
213195
* JDBC query criteria filters.

mydb/mydb-library/src/main/java/org/silverpeas/components/mydb/model/DbTable.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,6 @@ public Optional<DbColumn> getColumn(final String name) {
166166
* content of this table. The number of table rows is limited by the
167167
* {@link MyDBConnectionInfo#getDataMaxNumber()} property.
168168
*/
169-
@SuppressWarnings("unchecked")
170169
public SilverpeasList<TableRow> getRows(final ColumnValuePredicate filter, final String orderBy,
171170
final PaginationPage pagination) {
172171
if (!(filter instanceof AbstractColumnValuePredicate)) {
@@ -175,7 +174,7 @@ public SilverpeasList<TableRow> getRows(final ColumnValuePredicate filter, final
175174
}
176175
return requester.perform((r, c) -> {
177176
final JdbcRequester.DataConverters<TableFieldValue, TableRow> converters =
178-
new JdbcRequester.DataConverters(TableFieldValue::new, TableRow::new);
177+
new JdbcRequester.DataConverters<>(TableFieldValue::new, TableRow::new);
179178
return r.request(c, this.name, (AbstractColumnValuePredicate) filter, orderBy, converters,
180179
pagination);
181180
});

mydb/mydb-library/src/main/java/org/silverpeas/components/mydb/model/JdbcRequester.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
import java.util.Map;
4848
import java.util.Objects;
4949

50+
import static org.silverpeas.core.util.StringUtil.isDefined;
51+
5052
/**
5153
* A requester of a remote enterprise data source by using the yet configured
5254
* {@link MyDBConnectionInfo} instance. If
@@ -225,7 +227,7 @@ <V, R> SilverpeasList<R> request(final Connection connection, final String table
225227
Objects.requireNonNull(tableName);
226228
Objects.requireNonNull(predicate);
227229
JdbcSqlQuery query = JdbcSqlQuery.select("*").from(tableName);
228-
query = predicate.apply(query).orderBy(orderBy);
230+
query = isDefined(orderBy) ? predicate.apply(query).orderBy(orderBy) : predicate.apply(query);
229231
if (pagination != null) {
230232
query.withPagination(pagination.asCriterion());
231233
}

mydb/mydb-library/src/main/java/org/silverpeas/components/mydb/model/MyDBConnectionInfo.java

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import javax.naming.NamingException;
3232
import javax.persistence.Column;
3333
import javax.persistence.Entity;
34-
import javax.persistence.NamedQueries;
3534
import javax.persistence.NamedQuery;
3635
import javax.persistence.Table;
3736
import javax.sql.DataSource;
@@ -46,10 +45,10 @@
4645
* @author mmoquillon
4746
*/
4847
@Entity
49-
@NamedQueries({@NamedQuery(name = "MyDBConnectionInfo.findByInstanceId",
50-
query = "select ds from MyDBConnectionInfo ds where ds.instanceId = :instanceId"),
51-
@NamedQuery(name = "MyDBConnectionInfo.deleteByInstanceId",
52-
query = "delete MyDBConnectionInfo where instanceId = :instanceId")})
48+
@NamedQuery(name = "MyDBConnectionInfo.findByInstanceId",
49+
query = "select ds from MyDBConnectionInfo ds where ds.instanceId = :instanceId")
50+
@NamedQuery(name = "MyDBConnectionInfo.deleteByInstanceId",
51+
query = "delete MyDBConnectionInfo where instanceId = :instanceId")
5352
@Table(name = "sc_mydb_connectinfo")
5453
public class MyDBConnectionInfo
5554
extends BasicJpaEntity<MyDBConnectionInfo, UniqueIntegerIdentifier> {
@@ -68,10 +67,6 @@ public class MyDBConnectionInfo
6867
@NotNull
6968
private String instanceId;
7069

71-
public static MyDBConnectionInfo getById(String id) {
72-
return MyDBConnectionInfoService.get().getConnectionInfo(id);
73-
}
74-
7570
public static List<MyDBConnectionInfo> getFromComponentInstance(String instanceId) {
7671
return MyDBConnectionInfoService.get().getConnectionInfoList(instanceId);
7772
}
@@ -90,9 +85,9 @@ public MyDBConnectionInfo(String dataSource, String instanceId) {
9085

9186
/**
9287
* Is this connection information defined? Information about a connection to a data source is
93-
* defined if both it is related to a ConnecteurJDBC application instance and the name of the
88+
* defined if both it is related to a myDB application instance and the name of the
9489
* data source is defined.
95-
* @return
90+
* @return true if the connection is defined. False otherwise.
9691
*/
9792
public boolean isDefined() {
9893
return StringUtil.isDefined(this.dataSource) && StringUtil.isDefined(this.instanceId);
@@ -149,14 +144,6 @@ public String getDataSourceName() {
149144
return dataSource;
150145
}
151146

152-
/**
153-
* Gets the unique identifier of the component instance this connection info belongs to.
154-
* @return the unique identifier of the component instance.
155-
*/
156-
public String getInstanceId() {
157-
return instanceId;
158-
}
159-
160147
/**
161148
* Gets the user identifier used in the data source authentication.
162149
* @return the login.
@@ -228,11 +215,7 @@ public void setDefaultTableName(String tableName) {
228215
* @param maxNumber the maximum number of data to return. 0 means all.
229216
*/
230217
public void setDataMaxNumber(int maxNumber) {
231-
if (maxNumber <= 0) {
232-
this.rowLimit = 0;
233-
} else {
234-
this.rowLimit = maxNumber;
235-
}
218+
this.rowLimit = Math.max(maxNumber, 0);
236219
}
237220

238221
/**
@@ -243,13 +226,6 @@ public void save() {
243226
MyDBConnectionInfoService.get().saveConnectionInfo(this);
244227
}
245228

246-
/**
247-
* Removes this connection information from the persistence context.
248-
*/
249-
public void remove() {
250-
MyDBConnectionInfoService.get().removeConnectionInfo(this);
251-
}
252-
253229
/**
254230
* Opens a connection to the data source targeted by this connection information.
255231
* @return a connection against the data source referred by this object.

mydb/mydb-library/src/main/java/org/silverpeas/components/mydb/model/TableFieldValue.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ public void update(final String value) {
123123
} else if (SqlTypes.isBoolean(this.type)) {
124124
this.value = StringUtil.getBooleanValue(value);
125125
} else if (SqlTypes.isBigInteger(this.type)) {
126-
this.value = BigInteger.valueOf(Long.valueOf(value));
126+
this.value = BigInteger.valueOf(Long.parseLong(value));
127127
} else if (SqlTypes.isDecimal(this.type)) {
128-
this.value = BigDecimal.valueOf(Double.valueOf(value));
128+
this.value = BigDecimal.valueOf(Double.parseDouble(value));
129129
} else if (SqlTypes.isInteger(this.type)) {
130130
this.value = Integer.valueOf(value);
131131
} else if (SqlTypes.isFloat(this.type)) {
@@ -172,7 +172,8 @@ public int compareTo(final TableFieldValue o) {
172172
final int compare;
173173
if (o.value == null && this.value == null) {
174174
compare = 0;
175-
} else if (this.value instanceof Comparable) {
175+
} else if (o.value != null && this.value instanceof Comparable) {
176+
//noinspection unchecked,rawtypes
176177
compare = ((Comparable) this.value).compareTo(o.value);
177178
} else if (o.value == null) {
178179
return 1;

mydb/mydb-library/src/main/java/org/silverpeas/components/mydb/model/TableRow.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424

2525
package org.silverpeas.components.mydb.model;
2626

27-
import java.util.ArrayList;
2827
import java.util.Collections;
2928
import java.util.HashMap;
30-
import java.util.List;
3129
import java.util.Map;
3230

3331
/**
@@ -49,14 +47,6 @@ public TableRow(final Map<String, TableFieldValue> fields) {
4947
this.fields = fields;
5048
}
5149

52-
/**
53-
* Gets the name of all the fields in this table row.
54-
* @return a list with the name of all of the fields in this table row.
55-
*/
56-
public List<String> getFieldNames() {
57-
return new ArrayList<>(fields.keySet());
58-
}
59-
6050
/**
6151
* Gets all the fields of this table row.
6252
* @return a {@link Map} between a field name and its value.

mydb/mydb-library/src/main/java/org/silverpeas/components/mydb/model/predicates/AbstractColumnValuePredicate.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public abstract class AbstractColumnValuePredicate implements ColumnValuePredica
3636
public static final String NULL_VALUE = "null";
3737
public static final String EMPTY_VALUE = "@empty@";
3838
private DbColumn column;
39-
private String value;
4039
private Object normalizedValue;
4140

4241
/**
@@ -47,7 +46,6 @@ public abstract class AbstractColumnValuePredicate implements ColumnValuePredica
4746
*/
4847
public AbstractColumnValuePredicate(final DbColumn column, final String refValue) {
4948
this.column = column;
50-
this.value = refValue;
5149
this.normalizedValue = normalizeValue(column, refValue);
5250
}
5351

@@ -80,11 +78,6 @@ public DbColumn getColumn() {
8078
return this.column;
8179
}
8280

83-
@Override
84-
public Comparable getReferenceValue() {
85-
return this.value;
86-
}
87-
8881
public abstract JdbcSqlQuery apply(final JdbcSqlQuery query);
8982
}
9083

mydb/mydb-library/src/main/java/org/silverpeas/components/mydb/model/predicates/ColumnValuePredicate.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,5 @@ public interface ColumnValuePredicate {
3939
*/
4040
DbColumn getColumn();
4141

42-
/**
43-
* Gets the value with which all the column's values will be compared when playing the predicate.
44-
* @return a {@link Comparable} value.
45-
*/
46-
Comparable getReferenceValue();
47-
4842
}
4943

mydb/mydb-library/src/main/java/org/silverpeas/components/mydb/model/predicates/Identity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.silverpeas.core.persistence.jdbc.sql.JdbcSqlQuery;
2929

3030
/**
31-
* Identity predicate. Similar to an empty predicate as it is always true: the columns'value is
31+
* Identity predicate. Similar to an empty predicate as it is always true: the column value is
3232
* compared with itself (identity).
3333
* @author mmoquillon
3434
*/

mydb/mydb-library/src/main/java/org/silverpeas/components/mydb/service/MyDBConnectionInfoService.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,10 @@ static MyDBConnectionInfoService get() {
3737

3838
List<MyDBConnectionInfo> getConnectionInfoList(String instanceId);
3939

40-
void removeConnectionInfo(MyDBConnectionInfo connectionInfo);
41-
4240
void removeConnectionInfoOfComponentInstance(String componentInstanceId);
4341

44-
MyDBConnectionInfo getConnectionInfo(String id);
4542

46-
MyDBConnectionInfo saveConnectionInfo(MyDBConnectionInfo connectionInfo);
43+
void saveConnectionInfo(MyDBConnectionInfo connectionInfo);
4744

4845
List<DataSourceDefinition> getAllDataSourceDefinitions();
4946

mydb/mydb-library/src/main/java/org/silverpeas/components/mydb/service/MyDBException.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ public MyDBException(final String message, final String... parameters) {
3535
super(message, parameters);
3636
}
3737

38-
public MyDBException(final String message, final Throwable cause) {
39-
super(message, cause);
40-
}
41-
4238
public MyDBException(final Throwable cause) {
4339
super(cause);
4440
}

mydb/mydb-library/src/main/java/org/silverpeas/components/mydb/service/MyDBRuntimeException.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@ public MyDBRuntimeException(final String message) {
3636
super(message);
3737
}
3838

39-
public MyDBRuntimeException(final String message, final Throwable cause) {
40-
super(message, cause);
41-
}
42-
4339
public MyDBRuntimeException(final Throwable cause) {
4440
super(cause);
4541
}

mydb/mydb-library/src/main/java/org/silverpeas/components/mydb/service/impl/SimpleMyDBConnectionInfoService.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,15 @@ public List<MyDBConnectionInfo> getConnectionInfoList(final String instanceId) {
5252
return repository.findByInstanceId(instanceId);
5353
}
5454

55-
@Override
56-
public void removeConnectionInfo(final MyDBConnectionInfo connectionInfo) {
57-
repository.delete(connectionInfo);
58-
}
59-
6055
@Override
6156
public void removeConnectionInfoOfComponentInstance(final String componentInstanceId) {
6257
repository.deleteByInstanceId(componentInstanceId);
6358
}
6459

6560
@Override
66-
public MyDBConnectionInfo getConnectionInfo(final String id) {
67-
return repository.getById(id);
68-
}
69-
70-
@Override
71-
public MyDBConnectionInfo saveConnectionInfo(
61+
public void saveConnectionInfo(
7262
final MyDBConnectionInfo connectionInfo) {
73-
return repository.save(connectionInfo);
63+
repository.save(connectionInfo);
7464
}
7565

7666
@Override

mydb/mydb-library/src/main/resources/META-INF/beans.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
55
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
66
http://xmlns.jcp.org/xml/ns/javaee/beans_2_0.xsd"
7-
bean-discovery-mode="all">
7+
bean-discovery-mode="annotated">
88
</beans>

mydb/mydb-war/src/main/java/org/silverpeas/components/mydb/web/MyDBMessageManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ private MyDBMessageManager() {
5252
// internal initialization
5353
}
5454

55+
@SuppressWarnings("unused")
5556
public boolean isError() {
5657
return error != null && isDefined(error.getFirst());
5758
}
5859

60+
@SuppressWarnings("unused")
5961
public Pair<String, String> getError() {
6062
return error;
6163
}

0 commit comments

Comments
 (0)