|
|
@ -0,0 +1,54 @@ |
|
|
|
package a8k.dbservice; |
|
|
|
|
|
|
|
import a8k.dbservice.type.A8kPresetProjInfo; |
|
|
|
import a8k.dbservice.type.SampleRecord; |
|
|
|
import a8k.service.appdata.UtilsProjectColorAllocer; |
|
|
|
import a8k.utils.ZSqliteJdbcHelper; |
|
|
|
import jakarta.annotation.PostConstruct; |
|
|
|
import jakarta.annotation.Resource; |
|
|
|
import lombok.SneakyThrows; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.jdbc.core.JdbcTemplate; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import java.sql.ResultSet; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
@Component |
|
|
|
public class SampleRecordDBService { |
|
|
|
private static final Logger logger = LoggerFactory.getLogger(SampleRecordDBService.class); |
|
|
|
private static final String tableName = "zapp_a8k_sample_record"; |
|
|
|
private static Class<?> tClass = SampleRecord.class; |
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
JdbcTemplate jdbcTemplate; |
|
|
|
|
|
|
|
@Resource |
|
|
|
UtilsProjectColorAllocer colorAllocer; |
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
void init() { |
|
|
|
if (!ZSqliteJdbcHelper.isTableExist(jdbcTemplate, tableName)) { |
|
|
|
ZSqliteJdbcHelper.createTable(jdbcTemplate, tableName, tClass); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@SneakyThrows public SampleRecord rowMapper(ResultSet rs, int rowNum) { |
|
|
|
return (SampleRecord) ZSqliteJdbcHelper.rowMapper(rs, tClass); |
|
|
|
} |
|
|
|
|
|
|
|
public List<SampleRecord> getAll() { |
|
|
|
return jdbcTemplate.query("select * from " + tableName, this::rowMapper); |
|
|
|
} |
|
|
|
|
|
|
|
public void add(SampleRecord record) { |
|
|
|
ZSqliteJdbcHelper.addObj(jdbcTemplate, tableName, tClass, record); |
|
|
|
} |
|
|
|
|
|
|
|
public void update(SampleRecord record) { |
|
|
|
ZSqliteJdbcHelper.updateObj(jdbcTemplate, tableName, tClass, record); |
|
|
|
} |
|
|
|
|
|
|
|
} |