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?

  1. navigate to https://start.spring.io to create a project.

  2. Choose either Gradle or Maven and the language you want to use and language as java.

  3. Click Dependencies and select Spring Data JPA and then H2 Database.

  4. Click Generate. This will download a your project as Zip file.

  5. Extract the project created in you desired folder.

  6. Open the project in your favorite IDE

  7. Create an Entity Class Customer and add desired fields with JPA annotation

  8. Create CustomerRepository that extends CurdRepository which will provide the ability to perform CRUD operation into database.

  9. Add findByLastName, findById custom methods to fetch records based on lastName and id

  10. Create a CustomerController class that will accepts request from client to create, read, update and delete records.

  11.  Run the application

  12. 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]

 

 

  1. Open the code formatter from the link http://codeformatter.blogspot.com/ 
  2. Paste your source code block on the text area 
  3. Customized the source code formatter option. (Default options worked for me )
  4. Click format source code button
  5. 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

This command will download and run docker container
 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

Run Program in background Linux

To run the process in background use & at the end of bash command
 ./idea.sh &  

To view the jobs running in background
 jobs  
Useful links

Friday, March 16, 2018

Create React App

Install npm package manager before proceeding forward. Click Here

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  
Then you need to install 4.6.1 version globally with following command and follow the step one again.
 sudo npm i -g npm@4.6.1  

Useful links 
A re-introduction to JavaScript 
Reactjs

SQL INTERVIEW QUESTIONS AND ANSWERS