Finish RethinkDBService
Add TestRepo Set debug log level
This commit is contained in:
parent
375722e3a4
commit
d1710a2a9c
@ -3,13 +3,13 @@ package de.w665.fluidcms.db;
|
||||
import com.rethinkdb.RethinkDB;
|
||||
import com.rethinkdb.gen.exc.ReqlOpFailedError;
|
||||
import com.rethinkdb.net.Connection;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import io.quarkus.runtime.Startup;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Singleton;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@ApplicationScoped
|
||||
@Singleton
|
||||
public class RethinkDBService {
|
||||
|
||||
@Inject
|
||||
@ -21,7 +21,7 @@ public class RethinkDBService {
|
||||
private Connection connection;
|
||||
private RethinkDB r;
|
||||
|
||||
@PostConstruct
|
||||
@Startup
|
||||
public void init() {
|
||||
this.r = connector.getR();
|
||||
this.connection = connector.getConnection();
|
||||
|
43
src/main/java/de/w665/fluidcms/db/repo/TestRepo.java
Normal file
43
src/main/java/de/w665/fluidcms/db/repo/TestRepo.java
Normal file
@ -0,0 +1,43 @@
|
||||
package de.w665.fluidcms.db.repo;
|
||||
|
||||
import com.rethinkdb.RethinkDB;
|
||||
import com.rethinkdb.net.Connection;
|
||||
import de.w665.fluidcms.db.RethinkDBConfig;
|
||||
import de.w665.fluidcms.db.RethinkDBConnector;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@ApplicationScoped
|
||||
public class TestRepo {
|
||||
|
||||
@Inject
|
||||
RethinkDBConnector connector;
|
||||
|
||||
@Inject
|
||||
RethinkDBConfig config;
|
||||
|
||||
private final String TABLE_NAME = "test";
|
||||
private RethinkDB r;
|
||||
private Connection connection;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
this.r = this.connector.getR();
|
||||
this.connection = this.connector.getConnection();
|
||||
|
||||
// Check if table exists
|
||||
try {
|
||||
r.db(config.getDatabase()).tableCreate(TABLE_NAME).run(connection);
|
||||
log.debug("Table " + TABLE_NAME + " created");
|
||||
} catch (Exception e) {
|
||||
log.debug("Table " + TABLE_NAME + " already exists");
|
||||
}
|
||||
}
|
||||
|
||||
public void insert(String value) {
|
||||
r.db(config.getDatabase()).table(TABLE_NAME).insert(r.hashMap("value", value)).run(connection);
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package de.w665.fluidcms.rest.mapping;
|
||||
|
||||
import de.w665.fluidcms.db.RethinkDBConfig;
|
||||
import de.w665.fluidcms.db.RethinkDBService;
|
||||
import de.w665.fluidcms.db.repo.TestRepo;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.GET;
|
||||
import jakarta.ws.rs.Path;
|
||||
@ -13,15 +12,12 @@ import org.jboss.resteasy.reactive.RestResponse;
|
||||
public class TestResource {
|
||||
|
||||
@Inject
|
||||
RethinkDBConfig rethinkDBConfig;
|
||||
|
||||
@Inject
|
||||
RethinkDBService rethinkDBService;
|
||||
TestRepo testRepo;
|
||||
|
||||
@GET
|
||||
@Produces(MediaType.TEXT_PLAIN)
|
||||
public RestResponse<String> test() {
|
||||
this.rethinkDBService.initialize();
|
||||
return RestResponse.ResponseBuilder.ok(rethinkDBConfig.getHost()).build();
|
||||
testRepo.insert("testString");
|
||||
return RestResponse.ResponseBuilder.ok("test").build();
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ quarkus.quinoa.dev-server.port=4200
|
||||
quarkus.quinoa.build-dir=dist
|
||||
quarkus.http.port=80
|
||||
quarkus.resteasy-reactive.path=/api/v1
|
||||
quarkus.log.category."de.w665.fluidcms".level=DEBUG
|
||||
|
||||
# Database
|
||||
fluidcms.database.host=localhost
|
||||
|
Loading…
x
Reference in New Issue
Block a user