Skip to content

Commit

Permalink
Merge pull request #483 from nipunayf/fix-get-functions
Browse files Browse the repository at this point in the history
Remove connections and action calls from the default functions list
  • Loading branch information
nipunayf authored Nov 9, 2024
2 parents 95bacde + e6d516b commit 10fb694
Show file tree
Hide file tree
Showing 4 changed files with 968 additions and 3,427 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private void buildUtilityNodes(Map<String, String> queryMap) {
DatabaseManager dbManager = DatabaseManager.getInstance();

List<FunctionResult> functionResults = CommonUtils.hasNoKeyword(queryMap, "q") ?
dbManager.getFunctionsByOrg("ballerina") :
dbManager.getFunctionsByOrg("ballerina", DatabaseManager.FunctionKind.FUNCTION) :
dbManager.searchFunctions(queryMap, DatabaseManager.FunctionKind.FUNCTION);

for (FunctionResult functionResult : functionResults) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public List<FunctionResult> getAllFunctions(FunctionKind kind) {
}
}

public List<FunctionResult> getFunctionsByOrg(String orgName) {
public List<FunctionResult> getFunctionsByOrg(String orgName, FunctionKind functionKind) {
String sql = "SELECT " +
"f.function_id, " +
"f.name AS function_name, " +
Expand All @@ -152,11 +152,12 @@ public List<FunctionResult> getFunctionsByOrg(String orgName) {
"p.version " +
"FROM Function f " +
"JOIN Package p ON f.package_id = p.package_id " +
"WHERE p.org = ?;";
"WHERE f.kind = ? AND p.org = ?;";

try (Connection conn = DriverManager.getConnection(dbPath);
PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, orgName);
stmt.setString(1, functionKind.name());
stmt.setString(2, orgName);
ResultSet rs = stmt.executeQuery();
List<FunctionResult> functionResults = new ArrayList<>();
while (rs.next()) {
Expand Down Expand Up @@ -306,7 +307,7 @@ public Optional<FunctionResult> getAction(String org, String module, String symb
} else {
sql.append("AND f.name = ?;");
}

try (Connection conn = DriverManager.getConnection(dbPath);
PreparedStatement stmt = conn.prepareStatement(sql.toString())) {
stmt.setString(1, org);
Expand Down
Loading

0 comments on commit 10fb694

Please sign in to comment.