Skip to content
Snippets Groups Projects
Commit 0a01e695 authored by gwen-soleil's avatar gwen-soleil
Browse files

- WIP: start implementing MariaDB

parent c3e9ad56
Branches
No related tags found
No related merge requests found
...@@ -53,6 +53,7 @@ import fr.soleil.tango.archiving.exception.AttributeInsertionException; ...@@ -53,6 +53,7 @@ import fr.soleil.tango.archiving.exception.AttributeInsertionException;
import org.tango.attribute.AttributeTangoType; import org.tango.attribute.AttributeTangoType;
import org.tango.utils.ArrayUtils; import org.tango.utils.ArrayUtils;
@Deprecated
public class LegacyAttributeInserter implements IAttributeInserter { public class LegacyAttributeInserter implements IAttributeInserter {
private final IHdbAttributeInsert inserter; private final IHdbAttributeInsert inserter;
......
/*
* Copyright (c) 2024.
*
* Synchrotron Soleil
* L'Orme des merisiers
* Saint Aubin
* BP48
* 91192 GIF-SUR-YVETTE CEDEX
*
* gwenaelle.abeille@synchrotron-soleil.fr
*
* This software is a computer program whose purpose is to provide an Java API for managing insertion and fetching of Tango data into a database
*
* This software is governed by the CeCILL license under French law and abiding by the rules of distribution of free software.
* You can use, modify and/ or redistribute the software under the terms of the CeCILL license as circulated by CEA, CNRS and
* INRIA at the following URL "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users
* are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive
* licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or
* reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to
* manipulate, and that also therefore means that it is reserved for developers and experienced professionals having
* in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and
* operate it in the same conditions as regards security.
*
* The fact that you are presently reading this means that you have had knowledge of the CeCILL license and that you accept its
* terms.
*/
package fr.soleil.tango.archiving.event.db.mariadb.insert;
import com.google.inject.Inject;
import fr.esrf.Tango.AttrWriteType;
import fr.soleil.tango.archiving.config.AttributeConfig;
import fr.soleil.tango.archiving.config.db.timescale.select.ArchivingConfigFetcher;
import fr.soleil.tango.archiving.event.db.timescale.tables.AttributeEventScalarTable;
import fr.soleil.tango.archiving.event.insert.AttributeEvent;
import fr.soleil.tango.archiving.event.insert.IAttributeInserter;
import org.jdbi.v3.core.Jdbi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MariaAttributeInserter implements IAttributeInserter {
private final Logger logger = LoggerFactory.getLogger(MariaAttributeInserter.class);
@Inject
private Jdbi jdbi;
@Inject
private ArchivingConfigFetcher config;
@Override
public void insertScalar(AttributeEvent value, boolean withError) {
AttributeConfig attributeConfigDB = config.getAttribute(value.getFullName());
AttributeEventScalarTable toInsert = buildAttributeEvent(value, attributeConfigDB);
// insert value in db tableName = att_id
String tableName = getTableName(attributeConfigDB.getId());
logger.debug("inserting {} into {}", toInsert, tableName);
if (attributeConfigDB.getWriteType() == AttrWriteType._READ_WRITE) {
jdbi.useExtension(MariaAttributeScalarCommands.class, dao -> dao.insertRW(tableName, toInsert));
} else {
jdbi.useExtension(MariaAttributeScalarCommands.class, dao -> dao.insert(tableName, toInsert));
}
}
private AttributeEventScalarTable buildAttributeEvent(AttributeEvent value, AttributeConfig attributeConfigDB) {
AttributeEventScalarTable toInsert = new AttributeEventScalarTable();
toInsert.setValueR(value.getValueR());
toInsert.setValueW(value.getValueW());
toInsert.setDataTime(value.getDataTime());
return toInsert;
}
public String getTableName(final int index) {
String tableName = "att_";
if (index < 10) {
tableName = tableName + "0000" + index;
} else if (index < 100) {
tableName = tableName + "000" + index;
} else if (index < 1000) {
tableName = tableName + "00" + index;
} else { // if (index < 10000) {
tableName = tableName + "0" + index;
}
return tableName;
}
@Override
public void insertArray(AttributeEvent value, boolean withError) {
}
@Override
public void batchInsertScalar(String tableName, boolean withError, AttributeEvent... values) {
}
}
/*
* Copyright (c) 2024.
*
* Synchrotron Soleil
* L'Orme des merisiers
* Saint Aubin
* BP48
* 91192 GIF-SUR-YVETTE CEDEX
*
* gwenaelle.abeille@synchrotron-soleil.fr
*
* This software is a computer program whose purpose is to provide TANGO archived data through a GraphQL API.
*
* This software is governed by the CeCILL license under French law and abiding by the rules of distribution of free software.
* You can use, modify and/ or redistribute the software under the terms of the CeCILL license as circulated by CEA, CNRS and
* INRIA at the following URL "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users
* are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive
* licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or
* reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to
* manipulate, and that also therefore means that it is reserved for developers and experienced professionals having
* in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and
* operate it in the same conditions as regards security.
*
* The fact that you are presently reading this means that you have had knowledge of the CeCILL license and that you accept its
* terms.
*/
package fr.soleil.tango.archiving.event.db.mariadb.insert;
import fr.soleil.tango.archiving.event.db.timescale.tables.AttributeEventScalarTable;
import org.jdbi.v3.sqlobject.customizer.BindBean;
import org.jdbi.v3.sqlobject.customizer.Define;
import org.jdbi.v3.sqlobject.statement.SqlUpdate;
public interface MariaAttributeScalarCommands {
@SqlUpdate("insert into <tableName> (time, value) values (:dataTime, :valueR)")
void insert(@Define("tableName") String tableName, @BindBean AttributeEventScalarTable attributeEventScalarTable);
@SqlUpdate("insert into <tableName> (time, read_value, write_value) values (:dataTime, :valueR, valueW)")
void insertRW(@Define("tableName") String tableName, @BindBean AttributeEventScalarTable attributeEventScalarTable);
}
/*
* Copyright (c) 2024.
*
* Synchrotron Soleil
* L'Orme des merisiers
* Saint Aubin
* BP48
* 91192 GIF-SUR-YVETTE CEDEX
*
* gwenaelle.abeille@synchrotron-soleil.fr
*
* This software is a computer program whose purpose is to provide TANGO archived data through a GraphQL API.
*
* This software is governed by the CeCILL license under French law and abiding by the rules of distribution of free software.
* You can use, modify and/ or redistribute the software under the terms of the CeCILL license as circulated by CEA, CNRS and
* INRIA at the following URL "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy, modify and redistribute granted by the license, users
* are provided only with a limited warranty and the software's author, the holder of the economic rights, and the successive
* licensors have only limited liability.
*
* In this respect, the user's attention is drawn to the risks associated with loading, using, modifying and/or developing or
* reproducing the software by the user in light of its specific status of free software, that may mean that it is complicated to
* manipulate, and that also therefore means that it is reserved for developers and experienced professionals having
* in-depth computer knowledge. Users are therefore encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or data to be ensured and, more generally, to use and
* operate it in the same conditions as regards security.
*
* The fact that you are presently reading this means that you have had knowledge of the CeCILL license and that you accept its
* terms.
*/
package fr.soleil.tango.archiving.infra.injection;
import com.google.inject.AbstractModule;
import com.zaxxer.hikari.HikariDataSource;
import fr.soleil.tango.archiving.event.db.mariadb.insert.MariaAttributeInserter;
import fr.soleil.tango.archiving.event.insert.IAttributeInserter;
import fr.soleil.tango.archiving.infra.db.DataSourceConnection;
import fr.soleil.tango.archiving.infra.tango.ITangoAttributeCache;
import fr.soleil.tango.archiving.infra.tango.TangoAttributeCache;
import org.jdbi.v3.core.Jdbi;
public class MariaDBModuleInjector extends AbstractModule {
private final HikariDataSource hikariDataSource;
public MariaDBModuleInjector(final HikariDataSource hikariDataSource) {
this.hikariDataSource = hikariDataSource;
}
@Override
protected void configure() {
Jdbi jdbi = Jdbi.create(hikariDataSource);
bind(Jdbi.class).toInstance(jdbi);
DataSourceConnection connection = new DataSourceConnection();
connection.configureJdbi(jdbi);
bind(DataSourceConnection.class).toInstance(connection);
bind(ITangoAttributeCache.class).toInstance(new TangoAttributeCache());
bind(IAttributeInserter.class).toInstance(new MariaAttributeInserter());
// TODO MariaDB implementations
// bind(ArchivingAttributeFetcher.class).toInstance(new ArchivingAttributeFetcher());
// bind(ArchivingConfigFetcher.class).toInstance(new ArchivingConfigFetcher());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment