replace PdbRepository with @Bean annotated method
This commit is contained in:
@@ -1,5 +1,13 @@
|
|||||||
package org.lucares.pdbui;
|
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.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.scheduling.annotation.EnableAsync;
|
import org.springframework.scheduling.annotation.EnableAsync;
|
||||||
@@ -9,4 +17,14 @@ import org.springframework.scheduling.annotation.EnableAsync;
|
|||||||
@ComponentScan("org.lucares.pdbui")
|
@ComponentScan("org.lucares.pdbui")
|
||||||
public class MySpringConfiguration {
|
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.PlotRequest;
|
||||||
import org.lucares.pdbui.domain.PlotResponse;
|
import org.lucares.pdbui.domain.PlotResponse;
|
||||||
import org.lucares.performance.db.CollectionUtils;
|
import org.lucares.performance.db.CollectionUtils;
|
||||||
|
import org.lucares.performance.db.PerformanceDb;
|
||||||
import org.lucares.recommind.logs.DataSeries;
|
import org.lucares.recommind.logs.DataSeries;
|
||||||
import org.lucares.recommind.logs.InternalPlottingException;
|
import org.lucares.recommind.logs.InternalPlottingException;
|
||||||
import org.lucares.recommind.logs.NoDataPointsException;
|
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 static final DateTimeFormatter DATE_FORMAT_END = DateTimeFormatter.ofPattern("yyyy-MM-dd 23:59:59");
|
||||||
|
|
||||||
private final Plotter plotter;
|
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.db = db;
|
||||||
this.plotter = plotter;
|
this.plotter = plotter;
|
||||||
}
|
}
|
||||||
@@ -113,7 +114,7 @@ public class PdbController implements HardcodedValues, CollectionUtils {
|
|||||||
)
|
)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
List<String> fields() {
|
List<String> fields() {
|
||||||
final List<String> fields = db.getDb().getFields();
|
final List<String> fields = db.getFields();
|
||||||
|
|
||||||
return fields;
|
return fields;
|
||||||
}
|
}
|
||||||
@@ -128,7 +129,7 @@ public class PdbController implements HardcodedValues, CollectionUtils {
|
|||||||
@RequestParam(name = "query") final String query) {
|
@RequestParam(name = "query") final String query) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final List<String> fields = db.getDb().getFieldsValues(query, fieldName);
|
final List<String> fields = db.getFieldsValues(query, fieldName);
|
||||||
|
|
||||||
return fields;
|
return fields;
|
||||||
} catch (final FieldNotExistsException e) {
|
} 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;
|
private final Path outputDir;
|
||||||
|
|
||||||
@Autowired
|
@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) {
|
@Value("${" + PATH_GENERATED_IMAGES + "}") final String outputDir) {
|
||||||
this.db = dbRepository.getDb();
|
this.db = db;
|
||||||
this.tmpDir = Paths.get(tmpDir);
|
this.tmpDir = Paths.get(tmpDir);
|
||||||
this.outputDir = Paths.get(outputDir);
|
this.outputDir = Paths.get(outputDir);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -167,8 +167,8 @@ public class TcpIngestor implements Ingestor, AutoCloseable, DisposableBean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public TcpIngestor(final PdbRepository pdbRepository) {
|
public TcpIngestor(final PerformanceDb db) {
|
||||||
db = pdbRepository.getDb();
|
this.db = db;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Async
|
@Async
|
||||||
|
|||||||
Reference in New Issue
Block a user