Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@
import java.sql.RowIdLifetime;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.Set;
Expand Down Expand Up @@ -871,13 +872,13 @@ public ResultSet getPrimaryKeys(final String catalog, final String schema, final
final Set<OIndex> classIndexes =
database.getMetadata().getIndexManagerInternal().getClassIndexes(database, table);

final Set<OIndex> uniqueIndexes = new HashSet<>();
final List<OIndex> uniqueIndexes = new ArrayList<>();

for (OIndex oIndex : classIndexes) {
if (oIndex.getType().equals(INDEX_TYPE.UNIQUE.name())) uniqueIndexes.add(oIndex);
}

final OResultSetReady resultSet = new OResultSetReady();
final List<OResultInternal> rows = new ArrayList<>();

for (OIndex unique : uniqueIndexes) {
int keyFiledSeq = 1;
Expand All @@ -891,10 +892,15 @@ public ResultSet getPrimaryKeys(final String catalog, final String schema, final
res.setProperty("PK_NAME", unique.getName());
keyFiledSeq++;

resultSet.add(res);
rows.add(res);
}
}

rows.sort(Comparator.comparing(r -> r.getProperty("COLUMN_NAME")));

final OResultSetReady resultSet = new OResultSetReady();
rows.forEach(resultSet::add);

return new OrientJdbcResultSet(
new OrientJdbcStatement(connection),
resultSet,
Expand Down Expand Up @@ -1094,13 +1100,14 @@ public ResultSet getIndexInfo(
final Set<OIndex> classIndexes =
metadata.getIndexManagerInternal().getClassIndexes(database, table);

final Set<OIndex> indexes = new HashSet<>();
final List<OIndex> indexes = new ArrayList<>();

for (OIndex oIndex : classIndexes) {
if (!unique || oIndex.getType().equals(INDEX_TYPE.UNIQUE.name())) indexes.add(oIndex);
}

final OResultSetReady resultSet = new OResultSetReady();
final List<OResultInternal> rows = new ArrayList<>();

for (OIndex idx : indexes) {
boolean notUniqueIndex = !(idx.getType().equals(INDEX_TYPE.UNIQUE.name()));

Expand All @@ -1118,9 +1125,18 @@ public ResultSet getIndexInfo(
res.setProperty("COLUMN_NAME", fieldNames.substring(1, fieldNames.length() - 1));
res.setProperty("ASC_OR_DESC", "ASC");

resultSet.add(res);
rows.add(res);
}

rows.sort(
Comparator.comparing((OResultInternal r) -> (Boolean) r.getProperty("NON_UNIQUE"))
.thenComparing(r -> (String) r.getProperty("TYPE"))
.thenComparing(r -> (String) r.getProperty("INDEX_NAME"))
.thenComparingInt(r -> (Integer) r.getProperty("ORDINAL_POSITION")));

final OResultSetReady resultSet = new OResultSetReady();
rows.forEach(resultSet::add);

return new OrientJdbcResultSet(
new OrientJdbcStatement(connection),
resultSet,
Expand Down