|
| 1 | +# Todo Web API with Oracle Database |
| 2 | + |
| 3 | +This sample application demonstrates a Spring Boot REST API for managing Todo items using an Oracle database with JPA. The application showcases Oracle-specific SQL features and data types such as VARCHAR2. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- CRUD operations for Todo items |
| 8 | +- Spring Data JPA with Oracle database |
| 9 | +- Custom SQL queries using Oracle-specific features |
| 10 | +- Oracle-specific data types and functions |
| 11 | +- RESTful API endpoints |
| 12 | + |
| 13 | +## Prerequisites |
| 14 | + |
| 15 | +- Java 17 or higher |
| 16 | +- Maven 3.8 or higher |
| 17 | +- Docker (for running Oracle database container) |
| 18 | +- Postman or any API testing tool (optional) |
| 19 | + |
| 20 | +## Technology Stack |
| 21 | + |
| 22 | +- Spring Boot 3.2.4 |
| 23 | +- Spring Data JPA |
| 24 | +- Oracle Database 21c XE |
| 25 | +- Project Lombok |
| 26 | +- Maven |
| 27 | + |
| 28 | +## Getting Started |
| 29 | + |
| 30 | +### 1. Setting up Oracle Database with Docker |
| 31 | + |
| 32 | +Run the following command to start an Oracle Database XE container: |
| 33 | + |
| 34 | +```bash |
| 35 | +docker run -d --name oracle-xe \ |
| 36 | + -p 1521:1521 \ |
| 37 | + -e ORACLE_PWD=oracle \ |
| 38 | + container-registry.oracle.com/database/express:latest |
| 39 | +``` |
| 40 | + |
| 41 | +Note: The first time you run this, it may take a few minutes for the database to initialize (typically 5-10 minutes). You can check if the database is ready by running: |
| 42 | + |
| 43 | +```bash |
| 44 | +docker logs oracle-xe | grep "DATABASE IS READY TO USE" |
| 45 | +``` |
| 46 | + |
| 47 | +When you see the "DATABASE IS READY TO USE" message, the database is initialized and ready. |
| 48 | + |
| 49 | +### 2. Clone the repository |
| 50 | + |
| 51 | +```bash |
| 52 | +git clone <repository-url> |
| 53 | +cd todo-web-api-use-oracle-db |
| 54 | +``` |
| 55 | + |
| 56 | +### 3. Build and run the application |
| 57 | + |
| 58 | +Once the Oracle database is ready, you can build and run the application: |
| 59 | + |
| 60 | +```bash |
| 61 | +mvn clean spring-boot:run |
| 62 | +``` |
| 63 | + |
| 64 | +The application will automatically: |
| 65 | +1. Connect to the Oracle database using the SYSTEM account |
| 66 | +2. Create the necessary tables using the schema.sql file (via Spring Boot's automatic schema initialization) |
| 67 | +3. Insert sample data using the data.sql file (via Spring Boot's automatic data initialization) |
| 68 | +4. Start the web server on port 8080 |
| 69 | + |
| 70 | +### 4. Access Sample Requests |
| 71 | + |
| 72 | +### Get All Todos |
| 73 | + |
| 74 | +```bash |
| 75 | +curl -X GET http://localhost:8080/api/todos |
| 76 | +``` |
| 77 | + |
| 78 | +### Create a Todo Item |
| 79 | + |
| 80 | +```bash |
| 81 | +curl -X POST http://localhost:8080/api/todos \ |
| 82 | + -H "Content-Type: application/json" \ |
| 83 | + -d '{ |
| 84 | + "title": "Learn Oracle Database", |
| 85 | + "description": "Study Oracle-specific features and SQL syntax", |
| 86 | + "priority": 7, |
| 87 | + "dueDate": "2023-12-31T23:59:59" |
| 88 | + }' |
| 89 | +``` |
| 90 | + |
| 91 | +## API Endpoints |
| 92 | + |
| 93 | +| Method | URL | Description | |
| 94 | +|--------|----------------------------------- |------------------------------------------------| |
| 95 | +| GET | /api/todos | Get all todo items | |
| 96 | +| GET | /api/todos/{id} | Get a specific todo item by ID | |
| 97 | +| POST | /api/todos | Create a new todo item | |
| 98 | +| PUT | /api/todos/{id} | Update a todo item | |
| 99 | +| DELETE | /api/todos/{id} | Delete a todo item | |
| 100 | +| GET | /api/todos/completed?completed=true| Get completed or incomplete todos | |
| 101 | +| GET | /api/todos/high-priority?minPriority=5 | Get todos with priority >= minPriority | |
| 102 | +| GET | /api/todos/search?keyword=project | Search todos by keyword | |
| 103 | +| GET | /api/todos/top-priority | Get top priority tasks | |
| 104 | +| GET | /api/todos/overdue | Get overdue tasks | |
| 105 | +| PUT | /api/todos/update-priority | Update priority for tasks before cutoff date | |
| 106 | +| GET | /api/todos/oracle-search?term=demo | Search using Oracle-specific functions | |
| 107 | +| GET | /api/todos/oracle-demo | Demonstrate Oracle-specific query features | |
| 108 | +| POST | /api/todos/run-oracle-operations | Run Oracle-specific database operations | |
| 109 | + |
| 110 | +## Oracle-Specific Features |
| 111 | + |
| 112 | +This sample demonstrates several Oracle-specific features: |
| 113 | + |
| 114 | +1. Oracle data types (VARCHAR2) |
| 115 | +2. Oracle date functions (SYSDATE, SYSTIMESTAMP) |
| 116 | +3. Oracle string functions (SUBSTR, INSTR) |
| 117 | +4. Oracle-specific SQL syntax (ROWNUM) |
| 118 | +5. PL/SQL blocks for complex operations |
| 119 | + |
| 120 | +## Migrate form Oracle DB to PostgreSQL |
| 121 | + |
| 122 | +## Migration Prerequisites |
| 123 | + |
| 124 | +- [Visual Studio Code](https://code.visualstudio.com/download) |
| 125 | +- [VS Code extension: GitHub Copilot app modernization for Java](https://marketplace.visualstudio.com/items?itemName=vscjava.migrate-java-to-azure) |
| 126 | + |
| 127 | +## Migration Steps |
| 128 | + |
| 129 | +1. Open current sample in Visual Studio Code. |
| 130 | +1. Click `GitHub Copilot app modernization for Java`. |
| 131 | + >  |
| 132 | +1. Find `Oracle to PostgreSQL`. |
| 133 | +1. Click `Run formula`. |
| 134 | + >  |
| 135 | +1. GitHub Copilot makes a plan for migrating this sample. |
| 136 | + >  |
| 137 | +1. Click `Confirm` or `Continue` in the GitHub Copilot chat window if necessary, until the whole migration process finishes. |
| 138 | +1. If everything goes well, it will finish migration work and give a summary file. |
| 139 | +1. Click `keep` to save the changes. |
| 140 | + >  |
0 commit comments