Merge branch 'master' into develop
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
All checks were successful
IntegryManagementSystem_Multi/pipeline/head This commit looks good
This commit is contained in:
@@ -70,6 +70,9 @@ public class UtilityDB {
|
||||
if (indexTableDTO.getColumnsIndex() == null || indexTableDTO.getColumnsIndex().isEmpty())
|
||||
throw new Exception("Inserire l'elenco delle colonne su ci creare l'indice");
|
||||
|
||||
if(indexTableDTO.isClustered() && indexTableDTO.getColumnsIndex().stream().anyMatch(IndexTableDTO.ColumnIndex::isExcludeNulls))
|
||||
throw new Exception("Impossibile applicare la condizione di excludeNulls sulle colonne quando l'indice è CLUSTERED");
|
||||
|
||||
String sql = Query.format("SELECT CAST(Count(*) as bit) from sys.sysindexes where name = %s", indexTableDTO.getIndexName());
|
||||
|
||||
boolean existIndex = UtilityDB.executeSimpleQueryOnlyFirstRowFirstColumn(conn, sql);
|
||||
@@ -104,13 +107,16 @@ public class UtilityDB {
|
||||
if(!options.isEmpty())
|
||||
options = "WITH (" + options + ")";
|
||||
|
||||
sql = String.format("CREATE %s %s INDEX %s ON dbo.%s ( %s ) %s %s %s",
|
||||
String whereCondFields = indexTableDTO.getColumnsWhereCondString();
|
||||
|
||||
sql = String.format("CREATE %s %s INDEX %s ON dbo.%s ( %s ) %s %s %s %s",
|
||||
indexTableDTO.isUnique() ? "UNIQUE" : "",
|
||||
indexTableDTO.isClustered() ? "CLUSTERED" : "NONCLUSTERED",
|
||||
indexTableDTO.getIndexName(),
|
||||
indexTableDTO.getTableName(),
|
||||
indexTableDTO.getColumnsIndexString(),
|
||||
indexTableDTO.getColumnsIncludeString(),
|
||||
!whereCondFields.isEmpty() ? "WHERE " + whereCondFields : "",
|
||||
options,
|
||||
UtilityString.streNull(fileGroup));
|
||||
sqls.add(sql);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package it.integry.ems_model.utility.dto;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class IndexTableDTO {
|
||||
private String tableName;
|
||||
@@ -96,26 +96,36 @@ public class IndexTableDTO {
|
||||
return this;
|
||||
}
|
||||
|
||||
public IndexTableDTO setColumnsInclude(String... columnInclude ) {
|
||||
public IndexTableDTO setColumnsInclude(String... columnInclude) {
|
||||
if (this.columnsInclude == null)
|
||||
this.columnsInclude = new ArrayList<>();
|
||||
for(String c:columnInclude){
|
||||
for (String c : columnInclude) {
|
||||
this.columnsInclude.add(c);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getColumnsIndexString() {
|
||||
if (columnsIndex == null || columnsIndex.isEmpty())
|
||||
return "";
|
||||
|
||||
String columnsIndexString =
|
||||
StringUtils.join(
|
||||
Stream.of(columnsIndex)
|
||||
.map(x-> x.getColumnName() + " " + x.getSort())
|
||||
.toList(), ",");
|
||||
|
||||
return columnsIndexString;
|
||||
return StringUtils.join(
|
||||
columnsIndex.stream()
|
||||
.map(x -> x.getColumnName() + " " + x.getSort())
|
||||
.collect(Collectors.toList()), ",");
|
||||
}
|
||||
|
||||
public String getColumnsWhereCondString() {
|
||||
if (columnsIndex == null || columnsIndex.isEmpty())
|
||||
return "";
|
||||
|
||||
return StringUtils.join(
|
||||
columnsIndex.stream()
|
||||
.filter(ColumnIndex::isExcludeNulls)
|
||||
.map(x -> x.getColumnName() + " IS NOT NULL ")
|
||||
.collect(Collectors.toList()), " AND ");
|
||||
}
|
||||
|
||||
public List<ColumnIndex> getColumnsIndex() {
|
||||
return columnsIndex;
|
||||
}
|
||||
@@ -128,11 +138,13 @@ public class IndexTableDTO {
|
||||
public static class ColumnIndex {
|
||||
private String columnName;
|
||||
private String sort;
|
||||
private boolean excludeNulls;
|
||||
|
||||
public ColumnIndex(String columnName, String sort) {
|
||||
this.columnName = columnName;
|
||||
this.sort = sort;
|
||||
}
|
||||
|
||||
public ColumnIndex(String columnName) {
|
||||
this.columnName = columnName;
|
||||
this.sort = "ASC";
|
||||
@@ -151,13 +163,22 @@ public class IndexTableDTO {
|
||||
}
|
||||
|
||||
public String getSort() {
|
||||
return sort==null?"ASC":sort;
|
||||
return sort == null ? "ASC" : sort;
|
||||
}
|
||||
|
||||
public ColumnIndex setSort(String sort) {
|
||||
this.sort = sort;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isExcludeNulls() {
|
||||
return excludeNulls;
|
||||
}
|
||||
|
||||
public ColumnIndex setExcludeNulls(boolean excludeNulls) {
|
||||
this.excludeNulls = excludeNulls;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -57,10 +57,11 @@ public class ExchangeImportDataManagerService {
|
||||
.setTableName(tempTableName)
|
||||
.setIndexName("IX_PK_" + tempTableName)
|
||||
.setUnique(true)
|
||||
.setClustered(true)
|
||||
.setClustered(false)
|
||||
.setColumnsIndex(primaryKeyFields.stream()
|
||||
.map(x -> new IndexTableDTO.ColumnIndex()
|
||||
.setColumnName(x.getSqlField().value()))
|
||||
.setColumnName(x.getSqlField().value())
|
||||
.setExcludeNulls(true))
|
||||
.collect(Collectors.toList()));
|
||||
UtilityDB.createIndex(connection, indexTableToCreate);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user