mirror of
https://github.com/ClaytonWWilson/Listify.git
synced 2026-03-10 18:55:03 +00:00
Start Lambda connection infrastructure
This commit is contained in:
32
Lambdas/Lists/src/main/java/DBConnector.java
Normal file
32
Lambdas/Lists/src/main/java/DBConnector.java
Normal file
@@ -0,0 +1,32 @@
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
public class DBConnector {
|
||||
|
||||
Connection connection;
|
||||
|
||||
DBConnector() throws IOException, SQLException {
|
||||
this(loadProperties("dbProperties.json"));
|
||||
}
|
||||
|
||||
DBConnector(Properties dbProperties) throws SQLException {
|
||||
System.out.println(dbProperties);
|
||||
connection = DriverManager.getConnection(dbProperties.get("url").toString(), dbProperties);
|
||||
|
||||
}
|
||||
|
||||
public static Properties loadProperties(String path) throws IOException {
|
||||
Properties toReturn = new Properties();
|
||||
String propertiesJSONString = Files.readString(Path.of(path));
|
||||
JSONObject propertiesJSON = new JSONObject(propertiesJSONString);
|
||||
propertiesJSON.keys().forEachRemaining(key -> toReturn.setProperty(key, propertiesJSON.get(key).toString()));
|
||||
return toReturn;
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Map;
|
||||
|
||||
import com.amazonaws.services.lambda.runtime.Context;
|
||||
@@ -17,6 +19,13 @@ public class ListAdd implements RequestHandler<Map<String,Object>, String>{
|
||||
}
|
||||
System.out.println(inputMap.get("context"));
|
||||
System.out.println(contextMap.get("sub"));
|
||||
try {
|
||||
System.out.println(new DBConnector());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
4
Lambdas/Lists/src/main/java/ListAdder.java
Normal file
4
Lambdas/Lists/src/main/java/ListAdder.java
Normal file
@@ -0,0 +1,4 @@
|
||||
public class ListAdder {
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user