{"id":21390499,"url":"https://github.com/tanuj-maheshwari/sql-executor","last_synced_at":"2026-05-19T00:37:04.975Z","repository":{"id":83744579,"uuid":"472415704","full_name":"tanuj-maheshwari/SQL-Executor","owner":"tanuj-maheshwari","description":"Java based library for executing SQL queries for CRUD operations against an RDBMS, built using gradle.","archived":false,"fork":false,"pushed_at":"2022-03-21T16:18:47.000Z","size":587,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-23T00:45:40.927Z","etag":null,"topics":["gradle","java","sql"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tanuj-maheshwari.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-03-21T16:12:33.000Z","updated_at":"2022-03-21T16:18:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"1a058c11-4aa2-428b-8fb0-f42c7d1693eb","html_url":"https://github.com/tanuj-maheshwari/SQL-Executor","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanuj-maheshwari%2FSQL-Executor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanuj-maheshwari%2FSQL-Executor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanuj-maheshwari%2FSQL-Executor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tanuj-maheshwari%2FSQL-Executor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tanuj-maheshwari","download_url":"https://codeload.github.com/tanuj-maheshwari/SQL-Executor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243871912,"owners_count":20361380,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gradle","java","sql"],"created_at":"2024-11-22T13:17:51.630Z","updated_at":"2026-05-19T00:37:04.942Z","avatar_url":"https://github.com/tanuj-maheshwari.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SQL Executor library\n\n\u003e Submitter name: Tanuj Maheshwari\n\u003e\n\u003e Roll No.: 2019CSB1125\n\u003e\n\u003e Course: CS305 (Software Engineering)\n\n\nJava based library for executing SQL queries for CRUD operations against an RDBMS.\n\n\n## What does this program do?\n\nThis is a Java library that can be used for executing basic SQL queries, i.e. `SELECT`, `INSERT`, `DELETE` and `UPDATE` (CRUD operations) against an RDMS such as MySQL, PostgreSQL, etc.\n\nThe SQL queries to be processed are grabbed from an XML file with a specific format, an example of which can be found [here](./lib/src/test/resources/SQLTest.xml). The queries can be complete on their own, or could be dynamically populated from user defined parameters at run time. The results from the SQL queries are used to populate plain old java objects (POJOs).\n\n\n## A description of how this program works (i.e. its logic)\n\n### Flow of logic\n\n#### Parsing the XML file\n\nFirst, the XML file is loaded from the path provided. The desired SQL query is then parsed from the XML file using the unique `id` parameter of each `\u003csql\u003e` tag. The subsequent query received is termed as \"raw query\".\n\n#### Populating the raw query\n\nNext, the raw query parsed from the XML file is populated (i.e. the `${...}` is replaced with the appropriate value(s)) from the parameter passed as an argument to the called function.\n\n#### Executing the SQL command\n\nThe SQL command then created, referred to as \"populated query\" is then executed through the database connection object\n\n#### Populating the POJO\n\nThe result of SQL query is then either returned to the user (in terms of number of rows affected in case of `INSERT`, `UPDATE` and `DELETE` commands), or used to populate a Java object (in case of `SELECT` command).\n\n### Usage of library\n\nThe library implements 5 functions that can be used to achieve the desired results. These are :-\n\n- `selectOne()` Picks the record received from the SELECT query and returns an object populated with it.\n- `selectMany()` Returns a `List\u003c\u003e` of objects populated with all the records from SELECT query.\n- `insert()` Runs an INSERT query and returns number of rows affected.\n- `update()` Runs an UPDATE query and returns number of rows affected.\n- `delete()` Runs an DELETE query and returns number of rows affected.\n\n\u003e NOTE - `selectOne()` returns `null` if the query selects 0 records, and throws an exception if the query selects more than one record.\n\n\u003e **IMPORTANT - The POJOs to be populated using `selectOne()` and `selectMany()` must have default getters and setters**\n\nTo use these functions, user needs to define an object of class `org.cs305.assignment1.SqlExecutor`, and call these functions accordingly.\n\nThe constructor for `SqlExecutor` takes two commands :-\n\n1. `pathToXMLFile` is a `String` which contains the **absolute** path to the XML file where SQL commands are stored.\n2. `dbConnection` is a `java.sql.Connection` object which contains the database connection object.\n\n### Types supported\n\nThe following types are supported to be provided as `queryParam`/`paramType`, with their corresponding `${...}` values to be specified in XML:-\n\n1. null - ~~${...}~~ (i.e. no ${} should be present in the query)\n2. Primitive types \u0026 their Wrappers - ${value}\n3. String - ${value} \n4. Arrays (of type 2, 3) - ${value}\n5. Collections (of type 2, 3) - ${value}\n6. Objects (with fields of type 2 to 5) - ${_field_name_}\n7. Date - ${value}\n8. Arrays/Collections of objects (with overridden toString() method) - ${value}\n9. Generic objects (with fields of type 2 to 5, or with overridden toString() methods) - ${_field_name_}\n\nFor fields 7, 8 and 9, the object types must have overridden toString() methods, like\n\n```\n@Override\npublic String toString() {\n    //return the string format for this object\n    //which will replace ${prop} in the raw SQL query\n}\n```\n\n### Exceptions raised by the program\n\nThe program can raise several exceptions, and all will be of the type `java.lang.RuntimeException`, some of which are :-\n\n- Passing a `null` object when paramType is not specified as \"null\"\n- paramType and `queryParam` class mismatch (note that paramType must contain the Fully Qualified Name for the class)\n- No query id match found\n- No field found in `queryParam` corresponding to \"${prop}\" name\n- No field found in POJO corresponding to column label\n- Failure to cast from SQL query result type to POJO field type\n- SQL query corresponding to `selectOne()` returning more than one record\n- Exception(s) raised in making database connection statement\n- Exception(s) raised while executing SQL commands\n\n\n## How to compile and run this program\n\n### Prerequisites\n\nThe library is built in java, using gradle, and hence JDK and gradle must be installed on the system.\n\nAlso, the built-in tests run on the MySQL Sakila database, hence to run those, MySQL is needed and [Sakila database](https://dev.mysql.com/doc/sakila/en/sakila-installation.html) must be loaded.\n\n### Clone the repository\n\nClone the repository from GitHub to get the code, and then change branch to assignment_1 by executing the following commands :-\n\n```\ngit clone https://github.com/tanuj-maheshwari/cs305_2022.git\ngit checkout assignment_1\n```\n\n### To run unit tests\n\nTo run unit tests provided within the implementation, \n\n1. Open [SqlExecutorTest](./lib/src/test/java/org/cs305/assignment1/SqlExecutorTest.java)\n\n    - Change line 31 as follows :-\n\n          dbConnection = DriverManager.getConnection(\"jdbc:mysql://localhost:3306/sakila\",\"\u003croot username\u003e\",\"\u003cpassword\u003e\");\n\n        \u003e Change 3306 to MySQL's port number (default is 3306)\n\n    - Remove line 32 if changes are to be committed in the database\n\n    - Change line 33 as follows :-\n\n          sqlExecutor = new SqlExecutor(\"\u003cAbsolute path to XML file\u003e\", dbConnection);\n\n2. Run the following command from the project directory (i.e. the directory where the repository is cloned) :-\n\n       ./gradlew test\n\n    \u003e NOTE - If running on Windows, replace ./gradlew with gradlew\n\n### To generate code coverage report using JaCoCo\n\nDetailed code coverage report can be generated using JaCoCo. To generate the report, run :-\n\n    ./gradlew jacocoTestReport\n\n\u003e NOTE - If running on Windows, replace ./gradlew with gradlew\n\nThe test report generated is located at `lib/build/reports/jacoco/test/html/index.html`\n\n### To build a JAR\n\nTo build a JAR so that the library could be used in any project, run :-\n\n    ./gradlew build\n\n\u003e NOTE - If running on Windows, replace ./gradlew with gradlew\n\nThe JAR file built will be located at `lib/build/libs/lib.jar`\n\n## Snapshot of a sample run\n\n### Test report through gradle\n\n![Gradle Report](./reports/Gradle_Report.png?raw=true \"Gradle Report\")\n\n### Coverage reports\n\nThe unit tests provided cover 100% percent of the code. Below is a snapshot of the code coverage report generated by IntelliJ and JaCoCo.\n\n#### IntelliJ report\n\n![IntelliJ Snapshot](./reports/IntelliJ_Report.png?raw=true \"IntelliJ Snapshot\")\n\n#### JaCoCo report\n\n![JaCoCo Snapshot](./reports/JaCoCo_Report.png?raw=true \"JaCoCo Snapshot\")\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanuj-maheshwari%2Fsql-executor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftanuj-maheshwari%2Fsql-executor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftanuj-maheshwari%2Fsql-executor/lists"}