Skip to content

Commit

Permalink
Merge pull request #80 from yuu-nkjm/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
yuu-nkjm authored Apr 17, 2024
2 parents b007d58 + 9fb32fe commit 508d5a2
Show file tree
Hide file tree
Showing 60 changed files with 1,251 additions and 643 deletions.
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,28 @@ The latest release is available at [Maven Central Repository](https://mvnreposit
<dependency>
<groupId>org.nkjmlab</groupId>
<artifactId>sorm4j</artifactId>
<version>2.1.0</version>
<version>2.1.5</version>
</dependency>
```
We assume the following customer table in example: `create table customer (id int primary key, name varchar, address varchar)`

Create a class with public fields and a default constructor matching a table name. For example:
Create a Record class that has components and names matching the columns and the table name. For example:


```java
public record Customer (int id, String name, String address){}
```

You could also use a class with public fields and a default constructor matching a table name. For example:


```java
public class Customer {
public int id;
public String name;
public String address;
}
```

You could also use Record class. For example:

```java
@OrmRecord
public record Customer (int id, String name, String address){}
```

Create an entry point:
Expand Down
5 changes: 2 additions & 3 deletions sorm4j-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.nkjmlab</groupId>
<artifactId>sorm4j-example</artifactId>
<version>2.1.0</version>
<version>2.1.4</version>
<description>Example of Sorm4j</description>

<properties>
<sorm4j-version>${project.version}</sorm4j-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<additionalparam>-Xdoclint:none</additionalparam>
<downloadSources>true</downloadSources>
Expand All @@ -20,7 +19,7 @@
<dependency>
<groupId>org.nkjmlab</groupId>
<artifactId>sorm4j</artifactId>
<version>${sorm4j-version}</version>
<version>${project.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.h2database/h2 -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import org.nkjmlab.sorm4j.Sorm;
import org.nkjmlab.sorm4j.annotation.OrmRecord;
import org.nkjmlab.sorm4j.table.TableConnection;
import org.nkjmlab.sorm4j.util.h2.BasicH2Table;
import org.nkjmlab.sorm4j.util.h2.H2BasicTable;

public class TableExample {

Expand All @@ -12,7 +12,7 @@ public static void main(String[] args) {
Sorm sorm = Sorm.create("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;");

// Create a table access object.
BasicH2Table<Customer> customerTable = new BasicH2Table<>(sorm, Customer.class);
H2BasicTable<Customer> customerTable = new H2BasicTable<>(sorm, Customer.class);

// Create the table based on Customer.class
customerTable.createTableIfNotExists();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import org.nkjmlab.sorm4j.example.opendata.LoadOpenDataExample.ModClothsTable.ModCloth;
import org.nkjmlab.sorm4j.example.opendata.LoadOpenDataExample.TwitchsTable.Twitch;
import org.nkjmlab.sorm4j.internal.util.Try;
import org.nkjmlab.sorm4j.util.h2.BasicH2Table;
import org.nkjmlab.sorm4j.util.h2.datasource.H2LocalDataSourceFactory;
import org.nkjmlab.sorm4j.util.h2.H2BasicTable;
import org.nkjmlab.sorm4j.util.h2.datasource.H2DataSourceFactory;
import org.nkjmlab.sorm4j.util.h2.functions.table.CsvRead;
import org.nkjmlab.sorm4j.util.h2.server.H2Startup;
import org.nkjmlab.sorm4j.util.table_def.annotation.PrimaryKeyColumns;
Expand All @@ -26,8 +26,8 @@ public class LoadOpenDataExample {
private static final org.apache.logging.log4j.Logger log =
org.apache.logging.log4j.LogManager.getLogger();

private static final H2LocalDataSourceFactory dataSourceFactory =
H2LocalDataSourceFactory.builder(new File("$TMPDIR/sorm4j"), "sorm4j_example", "sa", "")
private static final H2DataSourceFactory dataSourceFactory =
H2DataSourceFactory.builder(new File("$TMPDIR/sorm4j"), "sorm4j_example", "sa", "")
.build();

static {
Expand Down Expand Up @@ -108,7 +108,7 @@ private static File downloadFile(String fileURL, String fileName) {
* @see <a href="https://github.com/MengtingWan/marketBias/tree/master/data">marketBias/data at
* master · MengtingWan/marketBias</a>
*/
public static class ModClothsTable extends BasicH2Table<ModCloth> {
public static class ModClothsTable extends H2BasicTable<ModCloth> {

@OrmRecord
@PrimaryKeyColumns({"item_id", "user_id"})
Expand Down Expand Up @@ -137,7 +137,7 @@ public File getCsv() {
}
}

public static class ElectronicsTable extends BasicH2Table<Electronic> {
public static class ElectronicsTable extends H2BasicTable<Electronic> {

@OrmRecord
@PrimaryKeyColumns({"item_id", "user_id"})
Expand All @@ -164,7 +164,7 @@ public File getCsv() {
}
}

public static class TwitchsTable extends BasicH2Table<Twitch> {
public static class TwitchsTable extends H2BasicTable<Twitch> {

/**
* This is a dataset of users consuming streaming content on Twitch. We retrieved all streamers,
Expand Down Expand Up @@ -194,7 +194,7 @@ public File getCsv() {
}

private void load(String logLabel, String tableName, Consumer<Sorm> func) {
Sorm mem = Sorm.create(H2LocalDataSourceFactory.createTemporalInMemoryDataSource());
Sorm mem = Sorm.create(H2DataSourceFactory.createTemporalInMemoryDataSource());
long start = System.currentTimeMillis();
log.info("[START] {} - {}", logLabel, tableName);
func.accept(mem);
Expand Down
Loading

0 comments on commit 508d5a2

Please sign in to comment.