Wednesday, August 28, 2024
Wednesday, August 23, 2023
Accessing Data with JPA with memory-based h2 database
What You need
Java and OOP concepts (if not you can see my videos on java)
A favorite text editor or IDE : Intellj , Eclipse, VS code
Java 8 or later
Gradle 7.5+ or Maven 3.5+
Postman
Overview:
In this tutorial will walk you through the process of building Springboot application that uses Spring Data JPA to store and retrieve data using in memory h2 relation database. Spring Data JPA make it easier to integrated data access technologies i.e. relational and non-relational databases, map-reduce frameworks, and cloud-based data services through java code.
Features
• Powerful repository and custom object-mapping abstractions
• Dynamic query derivation from repository method names
• Implementation domain base classes providing basic properties
• Support for transparent auditing (created, last changed)
• Possibility to integrate custom repository code
• Easy Spring integration via JavaConfig and custom XML namespaces
• Advanced integration with Spring MVC controllers
• Experimental support for cross-store persistence
Architecture:
Draw a diagram
How to Accessing Data with JPA with New project or existing project?
navigate to https://start.spring.io to create a project.
Choose either Gradle or Maven and the language you want to use and language as java.
Click Dependencies and select Spring Data JPA and then H2 Database.
Click Generate. This will download a your project as Zip file.
Extract the project created in you desired folder.
Open the project in your favorite IDE
Create an Entity Class Customer and add desired fields with JPA annotation
Create CustomerRepository that extends CurdRepository which will provide the ability to perform CRUD operation into database.
Add findByLastName, findById custom methods to fetch records based on lastName and id
Create a CustomerController class that will accepts request from client to create, read, update and delete records.
Run the application
Using Postman send request to server and verify its working as expected
Summary
Congratulations! You have written a simple application that uses Spring Data JPA to save objects to and fetch them from a database, all without writing a concrete repository implementation.
Sunday, August 6, 2023
How to format code block in blogger? [Blogger Code Formatter]
- Open the code formatter from the link http://codeformatter.blogspot.com/
- Paste your source code block on the text area
- Customized the source code formatter option. (Default options worked for me )
- Click format source code button
- Copy paste the code and switch to html view in your blogger post and paste the html copied to your blogger.
Image Reference
Source Code Formatter for Blogger, Blogspot , Blog & Blogging, Format Formatting Tool
Source Code Beautifier And Formatter For Blogger and Websites, Format Source Code , Format Source code for blog or blogging & website, Online line source code formatter tool, blogger code format tool, Format source code for blogspot,Insert formatted source code
Tuesday, March 5, 2019
Install json-server to Mock your data with zero coding
Install JSON Server
npm install -g json-server
if there is any issue with permission on Mac/Linux
sudo npm install -g json-server
Create a db.json file with some data
{
"posts": [
{ "id": 1, "title": "json-server", "author": "typicode" }
],
"comments": [
{ "id": 1, "body": "some comment", "postId": 1 }
],
"profile": { "name": "typicode" }
}
Start JSON Server
json-server --watch db.json
Now if you go to http://localhost:3000/posts/1, you'll get
{ "id": 1, "title": "json-server", "author": "typicode" }
Resource: https://www.npmjs.com/package/json-server
Thursday, April 12, 2018
Getting Started with Postgres Docker image
sudo docker run --name dipen-postgres
-p 5432:5432 -e POSTGRES_PASSWORD=<your-password> -d postgres
Note: username = postgres
To run the image and expose the port 5442 of docker image to host port
sudo docker run -p 5432:5432 postgres
If you need to download postgresql client
sudo apt-get install postgresql-client
To connect the postgres data hosted in docker container with psql client
psql -h localhost -p 5432 -U postgres
https://docs.docker.com/samples/library/postgres/
https://zaiste.net/posts/docker_postgresql_how_to/
https://hub.docker.com/_/postgres/
https://docs.docker.com/engine/examples/postgresql_service/#connecting-from-your-host-system
Friday, March 16, 2018
Create React App
Step: 1 Creating react app npm package manager
sudo npm install -g create-react-app
create-react-app my-app
Navigate into my-app directory
cd my-app
Start your application
npm start
Now your application is served and you will be able to see output on your browser
http://localhost:3000/
Note :
If you run into error specified below
ERROR: npm 5 is not supported yet
sudo npm i -g npm@4.6.1
Useful links
A re-introduction to JavaScript
Reactjs
-
Step 1: Run the command to install LTS Release version. sudo apt-get install python-software-properties curl -sL https://deb.nodeso...
-
Integrating PMD plugin on STS (subclipse) /Eclipse 1. Open STS -> click on Help 2. Click ->Install New software 3. C...