replace PdbRepository with @Bean annotated method
This commit is contained in:
@@ -1,5 +1,13 @@
|
||||
package org.lucares.pdbui;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.lucares.performance.db.PerformanceDb;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
@@ -9,4 +17,14 @@ import org.springframework.scheduling.annotation.EnableAsync;
|
||||
@ComponentScan("org.lucares.pdbui")
|
||||
public class MySpringConfiguration {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(MySpringConfiguration.class);
|
||||
|
||||
@Bean
|
||||
PerformanceDb performanceDb(@Value("${db.base}") final String dbBaseDir) {
|
||||
final Path dataDirectory = Paths.get(dbBaseDir);
|
||||
|
||||
LOGGER.info("using database in {}", dataDirectory.toAbsolutePath());
|
||||
|
||||
return new PerformanceDb(dataDirectory);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ import org.lucares.pdbui.domain.AutocompleteResponse;
|
||||
import org.lucares.pdbui.domain.PlotRequest;
|
||||
import org.lucares.pdbui.domain.PlotResponse;
|
||||
import org.lucares.performance.db.CollectionUtils;
|
||||
import org.lucares.performance.db.PerformanceDb;
|
||||
import org.lucares.recommind.logs.DataSeries;
|
||||
import org.lucares.recommind.logs.InternalPlottingException;
|
||||
import org.lucares.recommind.logs.NoDataPointsException;
|
||||
@@ -46,9 +47,9 @@ public class PdbController implements HardcodedValues, CollectionUtils {
|
||||
private static final DateTimeFormatter DATE_FORMAT_END = DateTimeFormatter.ofPattern("yyyy-MM-dd 23:59:59");
|
||||
|
||||
private final Plotter plotter;
|
||||
private final PdbRepository db;
|
||||
private final PerformanceDb db;
|
||||
|
||||
public PdbController(final PdbRepository db, final Plotter plotter) {
|
||||
public PdbController(final PerformanceDb db, final Plotter plotter) {
|
||||
this.db = db;
|
||||
this.plotter = plotter;
|
||||
}
|
||||
@@ -113,7 +114,7 @@ public class PdbController implements HardcodedValues, CollectionUtils {
|
||||
)
|
||||
@ResponseBody
|
||||
List<String> fields() {
|
||||
final List<String> fields = db.getDb().getFields();
|
||||
final List<String> fields = db.getFields();
|
||||
|
||||
return fields;
|
||||
}
|
||||
@@ -128,7 +129,7 @@ public class PdbController implements HardcodedValues, CollectionUtils {
|
||||
@RequestParam(name = "query") final String query) {
|
||||
|
||||
try {
|
||||
final List<String> fields = db.getDb().getFieldsValues(query, fieldName);
|
||||
final List<String> fields = db.getFieldsValues(query, fieldName);
|
||||
|
||||
return fields;
|
||||
} catch (final FieldNotExistsException e) {
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
package org.lucares.pdbui;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
import org.lucares.ludb.Proposal;
|
||||
import org.lucares.performance.db.PerformanceDb;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class PdbRepository implements DisposableBean {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(PdbRepository.class);
|
||||
|
||||
private final PerformanceDb db;
|
||||
|
||||
public PdbRepository(@Value("${db.base}") final String dbBaseDir) {
|
||||
final Path dataDirectory = Paths.get(dbBaseDir);
|
||||
|
||||
LOGGER.info("using database in {}", dataDirectory.toAbsolutePath());
|
||||
|
||||
this.db = new PerformanceDb(dataDirectory);
|
||||
}
|
||||
|
||||
public PerformanceDb getDb() {
|
||||
return db;
|
||||
}
|
||||
|
||||
public List<Proposal> autocomplete(final String query, final int caretIndex) {
|
||||
return db.autocomplete(query, caretIndex);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
db.close();
|
||||
}
|
||||
}
|
||||
@@ -19,9 +19,9 @@ public class PlotterBeanFactory extends AbstractFactoryBean<Plotter> implements
|
||||
private final Path outputDir;
|
||||
|
||||
@Autowired
|
||||
public PlotterBeanFactory(final PdbRepository dbRepository, @Value("${" + TMP_DIR + "}") final String tmpDir,
|
||||
public PlotterBeanFactory(final PerformanceDb db, @Value("${" + TMP_DIR + "}") final String tmpDir,
|
||||
@Value("${" + PATH_GENERATED_IMAGES + "}") final String outputDir) {
|
||||
this.db = dbRepository.getDb();
|
||||
this.db = db;
|
||||
this.tmpDir = Paths.get(tmpDir);
|
||||
this.outputDir = Paths.get(outputDir);
|
||||
}
|
||||
|
||||
@@ -167,8 +167,8 @@ public class TcpIngestor implements Ingestor, AutoCloseable, DisposableBean {
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public TcpIngestor(final PdbRepository pdbRepository) {
|
||||
db = pdbRepository.getDb();
|
||||
public TcpIngestor(final PerformanceDb db) {
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
@Async
|
||||
|
||||
Reference in New Issue
Block a user