Difference between revisions of "IT-SDK-Java"

From wiki.samerhijazi.net
Jump to navigation Jump to search
(Quarkus)
(Database)
Line 67: Line 67:
 
* '''JDBC''' is a low level standard for interaction with databases. '''JPA''' is higher level standard for the same purpose.
 
* '''JDBC''' is a low level standard for interaction with databases. '''JPA''' is higher level standard for the same purpose.
 
* '''JDBC''' allows you to do more things with the Database directly. '''JPA''' allows you to use an object model in your application.  
 
* '''JDBC''' allows you to do more things with the Database directly. '''JPA''' allows you to use an object model in your application.  
--------------------------------------
 
 
* Datasource & Pooling ('''JDBC''') >> '''Agroal'''
 
* Datasource & Pooling ('''JDBC''') >> '''Agroal'''
 
* Datasource & Pooling ('''Reactive''') >> '''Vert.x'''
 
* Datasource & Pooling ('''Reactive''') >> '''Vert.x'''
 
* '''Agroal''' is a datasource connection pool implementation with integration with transaction, security and other systems.
 
* '''Agroal''' is a datasource connection pool implementation with integration with transaction, security and other systems.
 
* '''Agroal''' library allows the definition of '''java.sql.DataSource''' with connection pooling.
 
* '''Agroal''' library allows the definition of '''java.sql.DataSource''' with connection pooling.
--------------------------------------
 
 
* '''JPA''' (Java Persistence API) & '''Hibernate ORM''' (Object-relational mapping). JPA is only a specification. Hibernate is an implementation of JPA.
 
* '''JPA''' (Java Persistence API) & '''Hibernate ORM''' (Object-relational mapping). JPA is only a specification. Hibernate is an implementation of JPA.
 
--------------------------------------
 
--------------------------------------

Revision as of 15:23, 18 March 2021

Links

Setting

  • JRE_HOME=C:\sdk\Java\jre_1.8.0_65
  • JAVA_HOME=C:\sdk\Java\jdk_1.8.0_65
  • JDK_HOME=C:\sdk\Java\jdk_1.8.0_65

Maven

wget https://www-us.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
sudo tar xzf apache-maven-3.6.3-bin.tar.gz
sudo ln -s apache-maven-3.6.3 maven
sudo vi /etc/profile.d/maven.sh
-------------------------------------
export MAVEN_HOME=/opt/maven
export PATH=${MAVEN_HOME}/bin:${PATH}
-------------------------------------
source /etc/profile.d/maven.sh
mvn -version

Code-Collections

import java.util.concurrent.TimeUnit;
---------------------------------------------
try {
    TimeUnit.SECONDS.sleep(secondsToSleep);
} catch (InterruptedException ie) {
    Thread.currentThread().interrupt();
}
---------------------------------------------
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import io.agroal.api.AgroalDataSource;

public class SettingDatabase{

  AgroalDataSource dataSource;
  String db = "jdbc:db2://localhost:5245/DATABASE:user=db2;password=db2;";
  String sql = "SELECT * FROM users";

  public void init_DriverManager()throws SQLException{
    try{		
      Connection connection = DriverManager.getConnection(db); //Connection connection = AgroalDataSource.getConnection(db);
      PreparedStatement ps = connection.prepareStatement(sql);
      ResultSet rs = ps.executeQuery();
    }
  }	
}

Architekture

Database

  • JDBC is a low level standard for interaction with databases. JPA is higher level standard for the same purpose.
  • JDBC allows you to do more things with the Database directly. JPA allows you to use an object model in your application.
  • Datasource & Pooling (JDBC) >> Agroal
  • Datasource & Pooling (Reactive) >> Vert.x
  • Agroal is a datasource connection pool implementation with integration with transaction, security and other systems.
  • Agroal library allows the definition of java.sql.DataSource with connection pooling.
  • JPA (Java Persistence API) & Hibernate ORM (Object-relational mapping). JPA is only a specification. Hibernate is an implementation of JPA.

RESTFul

  • RESTEasy is an implementation of JAX-RS and it is used to implement RestFul-services.
  • Microservices communicating either synchronously via REST or asynchronously using Kafka.

Sprin Boot

Quarkus

ref: Roadmap

ref: Colletions

docker pull maven:3.6-jdk-11-slim

Startup

mvn "io.quarkus:quarkus-maven-plugin:1.12.2.Final:create" \
    -DprojectGroupId="net.condolco" \
    -DprojectArtifactId="quarkus-app-00" \
    -DclassName="init.SayHello" \
    -Dpath="/hello" \
    -Dextensions="resteasy,resteasy-jackson"
mvn quarkus:dev
mvn compile quarkus:dev
mvn quarkus:list-extensions
mvn quarkus:add-extension -Dextensions="hibernate-validator"
mvn quarkus:add-extension -Dextensions="hibernate-*"
mvn quarkus:list-extensions
## mode: jvm
mvn clean package -DskipTests
java -jar target/tutorial-app-1.0-SNAPSHOT-runner.jar
## mode: native
mvn clean package -DskipTests -Pnative
./target/tutorial-app-1.0-SNAPSHOT-runner
## mode: native contianer
mvn package -DskipTests -Pnative -Dquarkus.native.container-build=true
docker build -f src/main/docker/Dockerfile.native -t example/tutorial-app:1.0-SNAPSHOT .
docker run -it --rm -p 8080:8080 example/tutorial-app:1.0-SNAPSHOT