Integrated Guide between Genormous Framework and Java Library
Integrated Guide between Genormous Framework and Java Library
Overview:
Genormous is a powerful and flexible Java framework for simplifying database operations.Unlike other popular ORM frameworks, Genormous focuses on database access for high performance and low memory consumption.This article will introduce how to integrate Genormous and Java libraries in order to use and expand.
Step 1: Add dependencies
First, add Genormous dependencies to the construction configuration of the project.You can add dependencies to download the jar file by Maven, Gradle or manually.The following is an example of a Maven project:
<dependency>
<groupId>com.genormous</groupId>
<artifactId>genormous-core</artifactId>
<version>1.0.0</version>
</dependency>
Step 2: Configure database connection
Before integrated Genormous, you need to configure an appropriate database connection.You can use the connection pool provided in the Java library or a customized database connection.Below is an example of using the HikaricP connection pool:
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
// Configure the connection pool
HikariConfig config = new HikariConfig();
config.setJdbcUrl("jdbc:mysql://localhost:3306/mydatabase");
config.setUsername("username");
config.setPassword("password");
// Create a data source
HikariDataSource dataSource = new HikariDataSource(config);
Step 3: Define the physical class and mapping
Define the physical class in the Java library, and you can use ordinary POJO (PLAIN OLD JAVA OBject) class.The mapping relationship between the physical class and the database table is then defined by annotations.The following is an example:
import com.genormous.annotations.Column;
import com.genormous.annotations.Id;
import com.genormous.annotations.Table;
@Table("users")
public class User {
@Id
@Column("id")
private int id;
@Column("name")
private String name;
// omit the getter and setter method
}
Step 4: Use Genormous for database operation
In the Java class library, you can use various methods provided by Genormous for database operations, such as inserting, updating and querying.The following are examples of some common operations:
Insert data:
User user = new User();
user.setName("John Doe");
Genormous.insert(user, dataSource);
update data:
User user = Genormous.select(User.class, dataSource, "id = ?", 1);
user.setName("Jane Smith");
Genormous.update(user, dataSource);
Query data:
List<User> users = Genormous.selectAll(User.class, dataSource);
for (User user : users) {
System.out.println(user.getName());
}
Summarize:
This article introduces the steps that integrate the Genormous framework with the Java class library.First, add the dependencies of Genormous; then, configure the appropriate database connection; then, define the physical class and database mapping; finally, use Genormous for database operation.Through these steps, you can easily use the Genormous framework to simplify and optimize database access.