19
19
import java .util .Optional ;
20
20
import java .util .stream .Collectors ;
21
21
22
+ import static java .util .stream .Collectors .toList ;
23
+
22
24
public class DataSourcesComponentMetadata implements ProjectComponent {
23
25
24
26
private CypherMetadataProviderService cypherMetadataProviderService ;
@@ -57,11 +59,16 @@ private DataSourceMetadata getNeo4jBoltMetadata(DataSourceApi dataSource) {
57
59
GraphDatabaseApi db = databaseManager .getDatabaseFor (dataSource );
58
60
Neo4jBoltCypherDataSourceMetadata metadata = new Neo4jBoltCypherDataSourceMetadata ();
59
61
62
+ GraphQueryResult indexesResult = db .execute ("CALL db.indexes()" );
63
+ GraphQueryResult constraintsResult = db .execute ("CALL db.constraints()" );
60
64
GraphQueryResult labelsQueryResult = db .execute ("CALL db.labels()" );
61
65
GraphQueryResult relationshipQueryResult = db .execute ("CALL db.relationshipTypes()" );
62
66
GraphQueryResult propertyKeysResult = db .execute ("CALL db.propertyKeys()" );
63
67
GraphQueryResult storedProceduresResult = db .execute ("CALL dbms.procedures()" );
64
68
69
+ metadata .addIndexes (indexesResult );
70
+ metadata .addConstraints (constraintsResult );
71
+
65
72
List <String > listOfLabels = extractLabels (labelsQueryResult );
66
73
if (!listOfLabels .isEmpty ()) {
67
74
GraphQueryResult labelCount = db .execute (queryLabelCount (listOfLabels ));
@@ -78,8 +85,8 @@ private DataSourceMetadata getNeo4jBoltMetadata(DataSourceApi dataSource) {
78
85
metadata .addStoredProcedures (storedProceduresResult );
79
86
80
87
boolean supportsUserFunctions = metadata .getMetadata (Neo4jBoltCypherDataSourceMetadata .STORED_PROCEDURES )
81
- .stream ()
82
- .anyMatch ((map ) -> map .get ("name" ).equals ("dbms.functions" ));
88
+ .stream ()
89
+ .anyMatch ((map ) -> map .get ("name" ).equals ("dbms.functions" ));
83
90
84
91
if (supportsUserFunctions ) {
85
92
GraphQueryResult userFunctionsResult = db .execute ("CALL dbms.functions()" );
@@ -92,31 +99,31 @@ private DataSourceMetadata getNeo4jBoltMetadata(DataSourceApi dataSource) {
92
99
private List <String > extractRelationshipTypes (GraphQueryResult relationshipQueryResult ) {
93
100
GraphQueryResultColumn column = relationshipQueryResult .getColumns ().get (0 );
94
101
return relationshipQueryResult .getRows ()
95
- .stream ()
96
- .map (row -> (String ) row .getValue (column ))
97
- .collect (Collectors . toList ());
102
+ .stream ()
103
+ .map (row -> (String ) row .getValue (column ))
104
+ .collect (toList ());
98
105
}
99
106
100
107
private List <String > extractLabels (GraphQueryResult labelsQueryResult ) {
101
108
GraphQueryResultColumn column = labelsQueryResult .getColumns ().get (0 );
102
109
return labelsQueryResult .getRows ()
103
- .stream ()
104
- .map (row -> (String ) row .getValue (column ))
105
- .collect (Collectors . toList ());
110
+ .stream ()
111
+ .map (row -> (String ) row .getValue (column ))
112
+ .collect (toList ());
106
113
}
107
114
108
115
private String queryRelationshipTypeCount (List <String > relationshipTypes ) {
109
116
return relationshipTypes
110
- .stream ()
111
- .map (relationshipType -> "MATCH ()-[r:" + relationshipType + "]->() RETURN count(r)" )
112
- .collect (Collectors .joining (" UNION " ));
117
+ .stream ()
118
+ .map (relationshipType -> "MATCH ()-[r:" + relationshipType + "]->() RETURN count(r)" )
119
+ .collect (Collectors .joining (" UNION " ));
113
120
}
114
121
115
122
private String queryLabelCount (List <String > labels ) {
116
123
return labels
117
- .stream ()
118
- .map (label -> "MATCH (n:" + label + ") RETURN count(n)" )
119
- .collect (Collectors .joining (" UNION " ));
124
+ .stream ()
125
+ .map (label -> "MATCH (n:" + label + ") RETURN count(n)" )
126
+ .collect (Collectors .joining (" UNION " ));
120
127
}
121
128
122
129
private void updateNeo4jBoltMetadata (DataSourceApi dataSource , Neo4jBoltCypherDataSourceMetadata metadata ) {
@@ -125,23 +132,23 @@ private void updateNeo4jBoltMetadata(DataSourceApi dataSource, Neo4jBoltCypherDa
125
132
CypherMetadataContainer container = cypherMetadataProviderService .getContainer (dataSource .getName ());
126
133
127
134
metadata .getLabels ()
128
- .stream ()
129
- .map (Neo4jLabelMetadata ::getName )
130
- .forEach (container ::addLabel );
135
+ .stream ()
136
+ .map (Neo4jLabelMetadata ::getName )
137
+ .forEach (container ::addLabel );
131
138
metadata .getRelationshipTypes ()
132
- .stream ()
133
- .map (Neo4jRelationshipTypeMetadata ::getName )
134
- .forEach (container ::addRelationshipType );
139
+ .stream ()
140
+ .map (Neo4jRelationshipTypeMetadata ::getName )
141
+ .forEach (container ::addRelationshipType );
135
142
metadata .getMetadata (Neo4jBoltCypherDataSourceMetadata .PROPERTY_KEYS ).stream ()
136
- .map ((row ) -> row .get ("propertyKey" ))
137
- .forEach (container ::addPropertyKey );
143
+ .map ((row ) -> row .get ("propertyKey" ))
144
+ .forEach (container ::addPropertyKey );
138
145
metadata .getMetadata (Neo4jBoltCypherDataSourceMetadata .STORED_PROCEDURES )
139
- .forEach (row -> container .addProcedure (row .get ("name" ), row .get ("signature" ), row .get ("description" )));
146
+ .forEach (row -> container .addProcedure (row .get ("name" ), row .get ("signature" ), row .get ("description" )));
140
147
141
148
List <Map <String , String >> userFunctionMetadata = metadata .getMetadata (Neo4jBoltCypherDataSourceMetadata .USER_FUNCTIONS );
142
149
if (userFunctionMetadata != null ) {
143
150
userFunctionMetadata
144
- .forEach (row -> container .addUserFunction (row .get ("name" ), row .get ("signature" ), row .get ("description" )));
151
+ .forEach (row -> container .addUserFunction (row .get ("name" ), row .get ("signature" ), row .get ("description" )));
145
152
}
146
153
}
147
154
0 commit comments