From debd50c8a238e6de8ee784672f6db9473ea50867 Mon Sep 17 00:00:00 2001 From: Arnaud Jelmoni <arnaud.jelmoni@keyconsulting.fr> Date: Mon, 8 Mar 2021 13:36:27 +0000 Subject: [PATCH] Refact --- .../archiving/snap/api/DataBaseAPI.java | 1728 +++++------------ .../snap/api/extractor/tools/Tools.java | 8 +- .../snap/api/manager/SnapManagerApi.java | 7 +- .../snap/api/manager/SnapManagerImpl.java | 6 +- .../archiving/snap/api/tools/Criterions.java | 10 +- .../archiving/snap/api/tools/ScalarEvent.java | 5 +- .../snap/api/tools/SnapAttributeExtract.java | 287 +-- .../archiving/snap/api/tools/SnapConst.java | 202 +- .../snap/api/tools/SnapSpectrumEvent_RW.java | 30 +- .../archiving/snap/api/DataBaseAPITest.java | 159 ++ 10 files changed, 827 insertions(+), 1615 deletions(-) create mode 100644 src/test/java/fr/soleil/archiving/snap/api/DataBaseAPITest.java diff --git a/src/main/java/fr/soleil/archiving/snap/api/DataBaseAPI.java b/src/main/java/fr/soleil/archiving/snap/api/DataBaseAPI.java index d8362b9..c99f5eb 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/DataBaseAPI.java +++ b/src/main/java/fr/soleil/archiving/snap/api/DataBaseAPI.java @@ -172,6 +172,8 @@ //-====================================================================== package fr.soleil.archiving.snap.api; +import java.lang.reflect.Array; + /* * Import classes */ @@ -179,7 +181,6 @@ package fr.soleil.archiving.snap.api; import java.sql.CallableStatement; import java.sql.Clob; import java.sql.Connection; -import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; @@ -202,6 +203,9 @@ import fr.esrf.Tango.AttrDataFormat; import fr.esrf.Tango.AttrWriteType; import fr.esrf.Tango.ErrSeverity; import fr.esrf.TangoDs.TangoConst; +import fr.soleil.archiving.common.api.ConnectionFactory; +import fr.soleil.archiving.common.api.exception.ArchivingException; +import fr.soleil.archiving.common.api.tools.GlobalConst; import fr.soleil.archiving.common.api.tools.StringFormater; import fr.soleil.archiving.snap.api.tools.SnapAttributeExtract; import fr.soleil.archiving.snap.api.tools.SnapAttributeHeavy; @@ -211,6 +215,9 @@ import fr.soleil.archiving.snap.api.tools.SnapContext; import fr.soleil.archiving.snap.api.tools.Snapshot; import fr.soleil.archiving.snap.api.tools.SnapshotLight; import fr.soleil.archiving.snap.api.tools.SnapshotingException; +import fr.soleil.database.connection.AbstractDataBaseConnector; +import fr.soleil.database.connection.DataBaseParameters; +import fr.soleil.database.connection.DataBaseParameters.DataBaseType; import fr.soleil.lib.project.math.MathConst; /** @@ -230,25 +237,19 @@ public class DataBaseAPI { /** * Connection dbatabase type (<I>MySQL</I>, <I>Oracle</I>, ...) */ - private int db_type; /* JDBC driver used for the connection */ - private String driver; /* Database Host adress */ - private final String dbHostName; /* User's name for the connection */ - private final String userName; /* User's password for the connection */ - private final String password; /* database name */ - private final String dbName; /** * database'schema' used */ - private final String dbSchemaName; - private final boolean isRac; - private int currentSpectrumDimX; + + private DataBaseParameters params ; + private AbstractDataBaseConnector connector; /** * Constructor using host name, user name, password and database name. @@ -266,18 +267,34 @@ public class DataBaseAPI { * Password to use to connect */ public DataBaseAPI(final String dbHostName, final String dbName, final String dbSchemaName, final String userName, - final String password, final boolean isRac) { - this.dbHostName = dbHostName; - this.dbName = dbName; - this.userName = userName; - this.password = password; + final String password, final boolean isRac) { + params = new DataBaseParameters(); + params.setHost(dbHostName); + params.setName(dbName); + params.setSchema(dbSchemaName); + params.setUser(userName); + params.setPassword(password); if (!dbSchemaName.equals("")) { - this.dbSchemaName = dbSchemaName; + params.setSchema(dbSchemaName); } else { - this.dbSchemaName = dbName; + params.setSchema(dbName); } - this.isRac = isRac; - } + + try { + params.setDbType(DataBaseType.ORACLE); + connector = ConnectionFactory.connect(params); + } catch (Exception e) { + params.setDbType(DataBaseType.MYSQL); + try { + connector = ConnectionFactory.connect(params); + } catch (ArchivingException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + } + } + + /** * <b>Description : </b> Gets the database name @@ -285,7 +302,7 @@ public class DataBaseAPI { * @return The database name */ public String getDbName() { - return dbName; + return params.getName(); } /** @@ -294,16 +311,7 @@ public class DataBaseAPI { * @return The database name */ public String getDbSchema() { - return dbSchemaName; - } - - /** - * <b>Description : </b> Gets the driver's name for the connection - * - * @return The driver used for the connection - */ - public String getDriver() { - return driver; + return params.getSchema(); } /** @@ -312,7 +320,7 @@ public class DataBaseAPI { * @return The host where the connection is done */ public String getHost() { - return dbHostName; + return params.getHost(); } /** @@ -321,7 +329,7 @@ public class DataBaseAPI { * @return The user's name for the connection */ public String getUser() { - return userName; + return params.getUser(); } /** @@ -330,7 +338,7 @@ public class DataBaseAPI { * @return The user's password for the connection */ public String getPassword() { - return password; + return params.getPassword(); } /** @@ -339,8 +347,8 @@ public class DataBaseAPI { * * @return The type of database being used */ - public int getDb_type() { - return db_type; + public DataBaseType getDb_type() { + return params.getDbType(); } /** @@ -367,146 +375,6 @@ public class DataBaseAPI { return arrayCount; } - /** - * <b>Description : </b> Allows to connect to the database <I>Snap</I>, - * independently of its type (<I>mySQL</I>/<I>Oracle</I>) - */ - public void connect_auto() throws SnapshotingException { - SnapshotingException archivingException1 = null, archivingException2 = null; - try { - // try oracle - logger.info("DataBaseApi.connect_auto oracle: " + getUser() + "@" + getHost()); - connect_oracle(); - logger.info("connection to oracle OK"); - return; - } catch (final SnapshotingException e) { - // e.printStackTrace(); - logger.error("connection to oracle KO"); - final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + "CONNECTION FAILED !"; - final String reason = "Failed while executing DataBaseApi.connect_auto() method..."; - final String desc = "Failed while connecting to the Oracle archiving database"; - archivingException1 = new SnapshotingException(message, reason, ErrSeverity.PANIC, desc, "", e); - } - try { - // try MySQL; - logger.info("DataBaseApi.connect_auto MySQL: " + getUser() + "@" + getHost()); - connect_mysql(); - logger.info("connection to MySQL OK"); - return; - } catch (final SnapshotingException e) { - // e.printStackTrace(); - logger.error("connection to MySQL KO"); - final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + "CONNECTION FAILED !"; - final String reason = "Failed while executing DataBaseApi.connect_auto() method..."; - final String desc = "Failed while connecting to the MySQL archiving database"; - archivingException2 = new SnapshotingException(message, reason, ErrSeverity.PANIC, desc, "", e); - - final String _desc = "Failed while connecting to the archiving database"; - - final SnapshotingException archivingException = new SnapshotingException(message, reason, - ErrSeverity.PANIC, _desc, "", archivingException1); - archivingException.addStack(message, reason, ErrSeverity.PANIC, _desc, "", archivingException2); - throw archivingException; - } - } - - /** - * <b>Description : </b> Allows to connect to the <I>Snap</I> database when - * of <I>mySQL</I> type. - * - * @throws SnapshotingException - */ - private Connection connect_mysql() throws SnapshotingException { - // Load the driver - Connection connection = null; - try { - Class.forName("org.gjt.mm.mysql.Driver"); - final String url = ConfigConst.DRIVER_MYSQL + "://" + dbHostName + "/" + dbName + "?autoReconnect=true"; - logger.debug("mysql URL " + url); - connection = DriverManager.getConnection(url, userName, password); - if (useLog4JDBC) { - connection = new net.sf.log4jdbc.ConnectionSpy(connection); - } - connection.setAutoCommit(true); - db_type = ConfigConst.BD_MYSQL; - driver = ConfigConst.DRIVER_MYSQL; - return connection; - } catch (final ClassNotFoundException e) { - final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.DRIVER_MISSING; - final String reason = "Failed while executing DataBaseApi.connect_mysql() method..."; - final String desc = "No MySQL driver available..., please check !"; - throw new SnapshotingException(message, reason, ErrSeverity.PANIC, desc, "", e); - } catch (final SQLException e) { - final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.ADB_CONNECTION_FAILURE; - final String reason = "Failed while executing DataBaseApi.connect_mysql() method..."; - final String desc = e.getMessage().indexOf(SnapConst.NO_HOST_EXCEPTION) != -1 ? "The 'host' property (" - + dbHostName + ") might be wrong... please check it..." - : "The loggin parameters (host, database name, user, password) seem to be wrong..."; - throw new SnapshotingException(message, reason, ErrSeverity.PANIC, desc, "", e); - } catch (final Exception e) { - final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.ADB_CONNECTION_FAILURE; - final String reason = "Failed while executing DataBaseApi.connect_mysql() method..."; - final String desc = e.getMessage().indexOf(SnapConst.NO_HOST_EXCEPTION) != -1 ? "The 'host' property (" - + dbHostName + ") might be wrong... please check it..." - : "The loggin parameters (host, database name, user, password) seem to be wrong..."; - throw new SnapshotingException(message, reason, ErrSeverity.PANIC, desc, "", e); - } - } - - /** - * <b>Description : </b> Allows to connect to the <I>Snap</I> database when - * of <I>Oracle</I> type. - * - * @throws SnapshotingException - */ - private Connection connect_oracle() throws SnapshotingException { - // Load the driver - Connection connection = null; - String url = null; - try { - Class.forName("oracle.jdbc.driver.OracleDriver"); - if (isRac) { - url = ConfigConst.DRIVER_ORACLE + ":@" + dbHostName; - } else { - url = ConfigConst.DRIVER_ORACLE + ":@" + dbHostName + ":" + ConfigConst.ORACLE_PORT + ":" + dbName; - } - logger.trace("ORACLE url: {}", url); - connection = DriverManager.getConnection(url, userName, password); - - if (useLog4JDBC) { - connection = new net.sf.log4jdbc.ConnectionSpy(connection); - } - connection.setAutoCommit(true); - db_type = ConfigConst.BD_ORACLE; - driver = ConfigConst.DRIVER_ORACLE; - alterSession(connection); - return connection; - } catch (final ClassNotFoundException e) { - final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.DRIVER_MISSING; - final String reason = "Failed while executing DataBaseApi.connect_oracle() method..."; - final String desc = "No Oracle driver available..., please check !"; - throw new SnapshotingException(message, reason, ErrSeverity.PANIC, desc, "", e); - } catch (final SQLException e) { - final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.ADB_CONNECTION_FAILURE; - final String reason = "Failed while executing DataBaseApi.connect_oracle() method..."; - StringBuilder builder = new StringBuilder( - "The loggin parameters (host, database name, user, password) seem to be wrong..."); - builder.append("\n- URL: ").append(url); - builder.append("\n- user: ").append(userName); - builder.append("\n- password: ").append(password); - final String desc = builder.toString(); - throw new SnapshotingException(message, reason, ErrSeverity.PANIC, desc, "", e); - } - } - - private Connection getConnection() throws SnapshotingException { - - if (db_type == ConfigConst.BD_ORACLE) { - return connect_oracle(); - } else { - return connect_mysql(); - } - } /** * ************************************************************************ @@ -517,49 +385,9 @@ public class DataBaseAPI { * * ********* */ public void close(final Connection conn) { - if (conn != null) { - try { - conn.close(); - } catch (final SQLException e) { - - } - } + closeConnection(conn); } - public void alterSession(final Connection conn) throws SnapshotingException { - Statement stmt = null; - String sqlStr1, sqlStr2, sqlStr3; - sqlStr1 = "alter session set NLS_NUMERIC_CHARACTERS = \". \""; - sqlStr2 = "alter session set NLS_TIMESTAMP_FORMAT = 'DD-MM-YYYY HH24:MI:SS.FF'"; - sqlStr3 = "alter session set NLS_DATE_FORMAT = 'DD-MM-YYYY HH24:MI:SS'"; - try { - stmt = conn.createStatement(); - stmt.executeQuery(sqlStr1); - stmt.executeQuery(sqlStr2); - stmt.executeQuery(sqlStr3); - } catch (final SQLException e) { - String message = ""; - if (e.getMessage().equalsIgnoreCase(SnapConst.COMM_FAILURE_ORACLE) - || e.getMessage().indexOf(SnapConst.COMM_FAILURE_MYSQL) != -1) { - message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.ADB_CONNECTION_FAILURE; - } else { - message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.STATEMENT_FAILURE; - } - - final String reason = SnapConst.STATEMENT_FAILURE; - final String desc = "Failed while executing DataBaseApi.alterSession() method..."; - final String queryDebug = sqlStr1 + "\n" + sqlStr2 + "\n" + sqlStr3; - throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.WARN, desc, this.getClass() - .getName(), e); - } finally { - if (stmt != null) { - try { - stmt.close(); - } catch (final SQLException e) { - } - } - } - } /***************************************************************************** * @@ -586,19 +414,19 @@ public class DataBaseAPI { ResultSet rset = null; PreparedStatement ps_get_att_id = null; - final String table_name = getDbSchema() + "." + SnapConst.TABS[0]; + final String table_name = getDbSchema() + "." + SnapConst.AST; StringBuilder selectStringBuilder = new StringBuilder(); try { // Preparing statement... - selectStringBuilder.append("SELECT ").append(SnapConst.TAB_DEF[0]).append(" FROM ").append(table_name) + selectStringBuilder.append("SELECT ").append(SnapConst.ID).append(" FROM ").append(table_name) .append(" WHERE "); - if (db_type == ConfigConst.BD_ORACLE) { - selectStringBuilder.append("LOWER(").append(SnapConst.TAB_DEF[2]).append(") like LOWER(?)"); + if (params.getDbType() == DataBaseType.ORACLE) { + selectStringBuilder.append("LOWER(").append(SnapConst.fullName).append(") like LOWER(?)"); } else { - selectStringBuilder.append(SnapConst.TAB_DEF[2]).append(" like ?"); + selectStringBuilder.append(SnapConst.fullName).append(" like ?"); } // if (m_dataSource == null) { - conn = getConnection(); + conn = connector.getConnection(); ps_get_att_id = conn.prepareStatement(selectStringBuilder.toString()); // } else { // conn = m_dataSource.getConnection(); @@ -661,11 +489,11 @@ public class DataBaseAPI { ResultSet rset = null; String query; int res = 0; - query = "SELECT MAX(" + SnapConst.TAB_CONTEXT[0] + ") FROM " + getDbSchema() + "." + SnapConst.TABS[1]; + query = "SELECT MAX(" + SnapConst.ID_CONTEXT + ") FROM " + getDbSchema() + "." + SnapConst.CONTEXT; Connection conn = null; try { - conn = getConnection(); + conn = connector.getConnection(); stmt = conn.createStatement(); rset = stmt.executeQuery(query); // Gets the result of the query @@ -704,19 +532,16 @@ public class DataBaseAPI { List<SnapContext> contextList = new ArrayList<SnapContext>(); String query = ""; Statement stmt = null; - String select_field = ""; - select_field = select_field + SnapConst.TAB_CONTEXT[0] + ", " + SnapConst.TAB_CONTEXT[1] + ", " - + SnapConst.TAB_CONTEXT[2] + ", " + SnapConst.TAB_CONTEXT[3] + ", " + SnapConst.TAB_CONTEXT[4] + ", " - + SnapConst.TAB_CONTEXT[5]; - final String table_1 = getDbSchema() + "." + SnapConst.TABS[1]; - final String clause_1 = " ORDER BY " + SnapConst.TAB_CONTEXT[0]; + String select_field = String.join(", ", SnapConst.TAB_CONTEXT); + final String table_1 = getDbSchema() + "." + SnapConst.CONTEXT; + final String clause_1 = " ORDER BY " + SnapConst.ID_CONTEXT; query = "SELECT " + select_field + " FROM " + table_1 + clause_1; ResultSet resultSet = null; Connection conn = null; try { - conn = getConnection(); + conn = connector.getConnection(); stmt = conn.createStatement(); resultSet = stmt.executeQuery(query.toString()); while (resultSet.next()) { @@ -759,18 +584,14 @@ public class DataBaseAPI { Statement stmt = null; List<SnapContext> contextList = new ArrayList<SnapContext>(); String query = ""; - String select_field = ""; - // Selection des champs des contexts a afficher. - select_field = select_field + SnapConst.TAB_CONTEXT[0] + ", " + SnapConst.TAB_CONTEXT[1] + ", " - + SnapConst.TAB_CONTEXT[2] + ", " + SnapConst.TAB_CONTEXT[3] + ", " + SnapConst.TAB_CONTEXT[4] + ", " - + SnapConst.TAB_CONTEXT[5]; + String select_field = String.join(", ", SnapConst.TAB_CONTEXT); // Choix de la table dans laquelle effectuer la requete SQL. - final String table_1 = getDbSchema() + "." + SnapConst.TABS[1]; + final String table_1 = getDbSchema() + "." + SnapConst.CONTEXT; // Affichage des resusltats par ordre croissant d'ID du context. - final String clause_1 = " ORDER BY " + SnapConst.TAB_CONTEXT[0]; + final String clause_1 = " ORDER BY " + SnapConst.ID_CONTEXT; query = "SELECT " + select_field + " FROM " + table_1; try { - conn = getConnection(); + conn = connector.getConnection(); if (id_context != -1) { // Cas ou l'id_context est donne. query = query + clause; @@ -827,59 +648,6 @@ public class DataBaseAPI { return contextList; } - /** - * ************************************************************************ - * <b>Description : </b> Gets all attributs from a given context - * - * @return array of strings - * @throws SnapshotingException - * ************************************************************* - * * ********* - */ - public String[] get_AttFromContext(final String nom_context) throws SnapshotingException { - final List<String> argout = new ArrayList<String>(); - PreparedStatement preparedStatement = null; - ResultSet rset = null; - - // Create and execute the SQL query string - String query; - final String select_field = SnapConst.TAB_DEF[2]; - final String table_1 = getDbSchema() + "." + SnapConst.TABS[0]; - final String clause_1 = SnapConst.TABS[0] + "." + SnapConst.TAB_DEF[0] + " = " + SnapConst.TABS[3] + "." - + SnapConst.TAB_LIST[1]; - final String clause_2 = SnapConst.TABS[3] + "." + SnapConst.TAB_SNAP[0] + " = " + SnapConst.TABS[1] + "." - + SnapConst.TAB_CONTEXT[0]; - final String clause_3 = SnapConst.TABS[1] + "." + SnapConst.TAB_CONTEXT[2] + " = ?"; - - query = "SELECT DISTINCT " + select_field + " FROM " + table_1 + " WHERE " + clause_1 + " AND " + clause_2 - + " AND " + clause_3; - Connection conn = null; - try { - conn = getConnection(); - preparedStatement = conn.prepareStatement(query); - preparedStatement.setString(1, nom_context); - rset = preparedStatement.executeQuery(); - - // Gets the result of the query - while (rset.next()) { - argout.add(rset.getString(1)); - } - - } catch (final SQLException e) { - final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.ERROR_RET_ATT; - final String reason = "Failed while executing DataBaseAPI.get_AttFromContext() method..."; - final String desc = ""; - final String queryDebug = query + " => " + nom_context; - throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e); - } finally { - closeResultSet(rset); - closeStatement(preparedStatement); - closeConnection(conn); - } - - // Returns the families list - return argout.toArray(new String[argout.size()]); - } /** * ************************************************************************ @@ -898,14 +666,14 @@ public class DataBaseAPI { // Create and execute the SQL query string String query; - final String select_field = SnapConst.TAB_SNAP[0] + ", " + SnapConst.TAB_SNAP[2]; - final String table_1 = getDbSchema() + "." + SnapConst.TABS[3]; - final String clause_2 = SnapConst.TABS[3] + "." + SnapConst.TAB_SNAP[1] + " = ?"; + final String select_field = SnapConst.ID_SNAP + ", " +SnapConst.time; + final String table_1 = getDbSchema() + "." + SnapConst.SNAPSHOT; + final String clause_2 = SnapConst.SNAPSHOT + "." + SnapConst.TAB_SNAP[1] + " = ?"; query = "SELECT " + select_field + " FROM " + table_1 + " WHERE " + clause_2; Connection conn = null; try { - conn = getConnection(); + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); preparedStatement.setInt(1, id_context); rset = preparedStatement.executeQuery(); @@ -958,19 +726,14 @@ public class DataBaseAPI { // Create and execute the SQL query string String query; - final String select_field = SnapConst.TAB_SNAP[0] + ", " + SnapConst.TAB_SNAP[2] + ", " + SnapConst.TAB_SNAP[3] // todo - // ajouter - // le - // champ - // 'commentaire' - ; + final String select_field = SnapConst.ID_SNAP + ", " + SnapConst.time + ", " + SnapConst.snap_comment; // recuperation de la table des snapshot. - final String table_1 = getDbSchema() + "." + SnapConst.TABS[3]; - final String clause_4 = " ORDER BY " + SnapConst.TAB_SNAP[0]; + final String table_1 = getDbSchema() + "." + SnapConst.SNAPSHOT; + final String clause_4 = " ORDER BY " + SnapConst.ID_SNAP; query = "SELECT " + select_field + " FROM " + table_1 + clause; try { - conn = getConnection(); + conn = connector.getConnection(); if (id_context != -1 && id_snap != -1) { // Cas ou l'id_context et l'id_snap sont donnes. query = query + clause_4; @@ -1061,148 +824,6 @@ public class DataBaseAPI { return associatedSnapshots; } - /** - * ************************************************************************ - * <b>Description : </b> Gets number of attributs from a given context - * - * @return array of strings - * @throws SnapshotingException - * ************************************************************* - * * ********* - */ - public double get_nbAttFromContext(final String nom_context) throws SnapshotingException { - double result = 0; - PreparedStatement preparedStatement = null; - ResultSet rset = null; - - // Create and execute the SQL query string - String query; - final String select_field = " COUNT(*) "; - final String table_1 = getDbSchema() + "." + SnapConst.TABS[3]; - final String clause_1 = SnapConst.TABS[3] + "." + SnapConst.TAB_SNAP[0] + " = " + SnapConst.TABS[1] + "." - + SnapConst.TAB_CONTEXT[0]; - final String clause_2 = SnapConst.TABS[1] + "." + SnapConst.TAB_CONTEXT[2] + " = ?"; - - // the SQL request is : select count(*) from snap.list where - query = "SELECT " + select_field + " FROM " + table_1 + " WHERE " + clause_1 + " AND " + clause_2; - Connection conn = null; - try { - conn = getConnection(); - preparedStatement = conn.prepareStatement(query); - preparedStatement.setString(1, nom_context); - rset = preparedStatement.executeQuery(); - - // Gets the result of the query - while (rset.next()) { - result = rset.getDouble(1); - preparedStatement.close(); - } - } catch (final SQLException e) { - final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.ERROR_RET_ATT; - final String reason = "Failed while executing DataBaseAPI.get_nbAttFromContext() method..."; - final String desc = ""; - final String queryDebug = query + " => " + nom_context; - throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e); - } finally { - closeResultSet(rset); - closeStatement(preparedStatement); - closeConnection(conn); - } - - // Returns the result - return result; - } - - /** - * ************************************************************************ - * <b>Description : </b> Gets the given attribute format - * - * @return the given attribute format - * @throws SnapshotingException - * ************************************************************* - * * ********* - */ - public int get_FormatFromAtt(final String nom_attribut) throws SnapshotingException { - int result = 0; - PreparedStatement preparedStatement = null; - ResultSet rset = null; - - // Create and execute the SQL query string - String query; - final String select_field = SnapConst.TAB_DEF[9]; - final String table_1 = getDbSchema() + "." + SnapConst.TABS[0]; - final String clause_1 = SnapConst.TAB_DEF[2] + " = ?"; - - // the SQL request is : select data_format from AST where name = 'nom'; - query = "SELECT " + select_field + " FROM " + table_1 + " WHERE " + clause_1; - Connection conn = null; - try { - conn = getConnection(); - preparedStatement = conn.prepareStatement(query); - preparedStatement.setString(1, nom_attribut); - rset = preparedStatement.executeQuery(); - - // Gets the result of the query - while (rset.next()) { - result = rset.getInt(1); - preparedStatement.close(); - } - } catch (final SQLException e) { - final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.ERROR_RET_ATT; - final String reason = "Failed while executing DataBaseAPI.get_FormatFromAtt() method..."; - final String desc = ""; - final String queryDebug = query + " => " + nom_attribut; - throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e); - } finally { - closeResultSet(rset); - closeStatement(preparedStatement); - closeConnection(conn); - } - - // Returns the result - return result; - } - - /** - * Retrieves the creation time of the given snapshot. - * - * @param snapID - * The identifier of the snapshot - * @return the creation time - * @throws SnapshotingException - */ - public Timestamp getSnapRegistrationTime(final int snapID) throws SnapshotingException { - java.sql.Timestamp time = null; - ResultSet rset = null; - PreparedStatement statement = null; - final String table_name = getDbSchema() + "." + SnapConst.TABS[3]; - String query = ""; - Connection conn = null; - try { - conn = getConnection(); - query = "SELECT " + SnapConst.TAB_SNAP[2] + " FROM " + table_name + " WHERE " + SnapConst.TAB_SNAP[0] - + " like ?"; - statement = conn.prepareStatement(query); - statement.setInt(1, snapID); - rset = statement.executeQuery(); - // Gets the result of the query - if (rset.next()) { - time = rset.getTimestamp(1); - } - statement.close(); - } catch (final SQLException e) { - final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE; - final String reason = "Failed while executing DataBaseAPI.getSnapRegistrationTime() method..."; - final String desc = ""; - final String queryDebug = query + " => " + snapID; - throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e); - } finally { - closeResultSet(rset); - closeStatement(statement); - closeConnection(conn); - } - return time; - } /** * Retrieves the context identifier to wich the given snapshot identifier is @@ -1219,18 +840,13 @@ public class DataBaseAPI { PreparedStatement preparedStatement = null; Connection conn = null; String query; - final String select_field = SnapConst.TAB_SNAP[1]; - final String table_1 = getDbSchema() + "." + SnapConst.TABS[3]; - final String clause_1 = SnapConst.TAB_SNAP[0] + " like ?"; + final String select_field = SnapConst.ID_CONTEXT; + final String table_1 = getDbSchema() + "." + SnapConst.SNAPSHOT; + final String clause_1 = SnapConst.ID_SNAP + " like ?"; query = "SELECT " + select_field + " FROM " + table_1 + " WHERE " + clause_1; try { - conn = getConnection(); // Preparing preparedStatement... - // if (m_dataSource == null) { + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); - // } else { - // conn = m_dataSource.getConnection(); - // preparedStatement = conn.prepareStatement(query); - // } preparedStatement.setInt(1, snapID); rset = preparedStatement.executeQuery(); // Gets the result of the query @@ -1260,49 +876,17 @@ public class DataBaseAPI { PreparedStatement preparedStatement = null; ResultSet resultSet = null; // SELECT id_att, value FROM t_sc_num_1val WHERE id_snap = ? - final String query = selectRO + getDbSchema() + "." + SnapConst.TABS[8] + where; + final String query = selectRO + getDbSchema() + "." + SnapConst.T_SC_NUM_1VAL + where; try { - conn = getConnection(); + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); - resultSet = preparedStatement.executeQuery(); + resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { - for (final SnapAttributeExtract snapAttributeExtract : attributes) { - if (snapAttributeExtract.getAttId() == resultSet.getInt(1)) { - // fill data - switch (snapAttributeExtract.getDataType()) { - case TangoConst.Tango_DEV_BOOLEAN: - snapAttributeExtract.setValue(Boolean.valueOf(resultSet.getInt(2) != 0), - Boolean.valueOf(resultSet.wasNull())); - break; - case TangoConst.Tango_DEV_UCHAR: - case TangoConst.Tango_DEV_CHAR: - snapAttributeExtract.setValue(Byte.valueOf((byte) resultSet.getDouble(2)), - Boolean.valueOf(resultSet.wasNull())); - break; - case TangoConst.Tango_DEV_USHORT: - case TangoConst.Tango_DEV_SHORT: - snapAttributeExtract.setValue(Short.valueOf((short) resultSet.getDouble(2)), - Boolean.valueOf(resultSet.wasNull())); - break; - case TangoConst.Tango_DEV_STATE: - case TangoConst.Tango_DEV_LONG: - case TangoConst.Tango_DEV_ULONG: - snapAttributeExtract.setValue(Integer.valueOf((int) resultSet.getDouble(2)), - Boolean.valueOf(resultSet.wasNull())); - break; - case TangoConst.Tango_DEV_FLOAT: - snapAttributeExtract.setValue(Float.valueOf((float) resultSet.getDouble(2)), - Boolean.valueOf(resultSet.wasNull())); - break; - case TangoConst.Tango_DEV_DOUBLE: - default: - snapAttributeExtract.setValue(Double.valueOf(resultSet.getDouble(2)), - Boolean.valueOf(resultSet.wasNull())); - break; - } - break; - } - } + int attId = resultSet.getInt(1); + final SnapAttributeExtract snapAttributeExtract = attributes.stream() + .filter(att -> att.getAttId() == attId).findFirst().get(); + snapAttributeExtract.setValue(castResultSetAsObject(snapAttributeExtract.getDataType(), resultSet, 2), + Boolean.valueOf(resultSet.wasNull())); } } finally { closeResultSet(resultSet); @@ -1323,22 +907,20 @@ public class DataBaseAPI { // SELECT id_att, value FROM t_sp_1val WHERE id_snap = ? final String query = selectRO + getDbSchema() + "." + tableName + where; try { - conn = getConnection(); + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { - for (final SnapAttributeExtract snapAttributeExtract : attributes) { - if (snapAttributeExtract.getAttId() == resultSet.getInt(1)) { - // fill data - final Clob readClob = resultSet.getClob(2); - if (readClob != null) { - final String value = readClob.getSubString(1, (int) readClob.length()); - NullableData<?, ?> data = getSpectrumValue(value, null, snapAttributeExtract.getDataType(), - false); - snapAttributeExtract.setValue(data.getValue(), data.getNullElements()); - } - break; - } + int attId = resultSet.getInt(1); + final SnapAttributeExtract snapAttributeExtract = attributes.stream() + .filter(att -> att.getAttId() == attId).findFirst().get(); + // fill data + final Clob readClob = resultSet.getClob(2); + if (readClob != null) { + final String value = readClob.getSubString(1, (int) readClob.length()); + NullableData<?, ?> data = getSpectrumValue(value, null, snapAttributeExtract.getDataType(), + false); + snapAttributeExtract.setValue(data.getValue(), data.getNullElements()); } } } finally { @@ -1357,12 +939,13 @@ public class DataBaseAPI { // t_sp_2val WHERE id_snap = ? final String query = selectRW + getDbSchema() + "." + tableName + where; try { - conn = getConnection(); + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { - for (final SnapAttributeExtract snapAttributeExtract : attributes) { - if (snapAttributeExtract.getAttId() == resultSet.getInt(1)) { + int attId = resultSet.getInt(1); + final SnapAttributeExtract snapAttributeExtract = attributes.stream() + .filter(att -> att.getAttId() == attId).findFirst().get(); // fill data String readValue = null; String writeValue = null; @@ -1378,10 +961,7 @@ public class DataBaseAPI { snapAttributeExtract.getDataType(), true); snapAttributeExtract.setValue(data.getValue(), data.getNullElements()); snapAttributeExtract.setDimX(resultSet.getInt(4)); - break; - } - } - } + } } finally { closeResultSet(resultSet); closeStatement(preparedStatement); @@ -1396,76 +976,25 @@ public class DataBaseAPI { ResultSet resultSet = null; // SELECT id_att, read_value, write_value FROM t_sc_num_2val WHERE // id_snap = ? - final String query = selectRW + getDbSchema() + "." + SnapConst.TABS[9] + where; + final String query = selectRW + getDbSchema() + "." + SnapConst.T_SC_NUM_2VAL + where; try { - conn = getConnection(); + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { - for (final SnapAttributeExtract snapAttributeExtract : attributes) { - if (snapAttributeExtract.getAttId() == resultSet.getInt(1)) { + int attId = resultSet.getInt(1); + final SnapAttributeExtract snapAttributeExtract = attributes.stream() + .filter(att -> att.getAttId() == attId).findFirst().get(); // fill data - final Object value; + final Object value = initPrimitiveArray(snapAttributeExtract.getDataType(), 2); final boolean[] nullElements = new boolean[2]; - switch (snapAttributeExtract.getDataType()) { - case TangoConst.Tango_DEV_BOOLEAN: - boolean[] boolValue = new boolean[2]; - boolValue[0] = (resultSet.getInt(2) != 0); - nullElements[0] = resultSet.wasNull(); - boolValue[1] = (resultSet.getInt(3) != 0); - nullElements[1] = resultSet.wasNull(); - value = boolValue; - break; - case TangoConst.Tango_DEV_UCHAR: - case TangoConst.Tango_DEV_CHAR: - byte[] byteValue = new byte[2]; - byteValue[0] = (byte) resultSet.getDouble(2); - nullElements[0] = resultSet.wasNull(); - byteValue[1] = (byte) resultSet.getDouble(3); - nullElements[1] = resultSet.wasNull(); - value = byteValue; - break; - case TangoConst.Tango_DEV_USHORT: - case TangoConst.Tango_DEV_SHORT: - short[] shortValue = new short[2]; - shortValue[0] = (short) resultSet.getDouble(2); - nullElements[0] = resultSet.wasNull(); - shortValue[1] = (short) resultSet.getDouble(3); - nullElements[1] = resultSet.wasNull(); - value = shortValue; - break; - case TangoConst.Tango_DEV_STATE: - case TangoConst.Tango_DEV_LONG: - case TangoConst.Tango_DEV_ULONG: - int[] intValue = new int[2]; - intValue[0] = (int) resultSet.getDouble(2); - nullElements[0] = resultSet.wasNull(); - intValue[1] = (int) resultSet.getDouble(3); - nullElements[1] = resultSet.wasNull(); - value = intValue; - break; - case TangoConst.Tango_DEV_FLOAT: - float[] floatValue = new float[2]; - floatValue[0] = (float) resultSet.getDouble(2); - nullElements[0] = resultSet.wasNull(); - floatValue[1] = (float) resultSet.getDouble(3); - nullElements[1] = resultSet.wasNull(); - value = floatValue; - break; - case TangoConst.Tango_DEV_DOUBLE: - default: - double[] doubleValue = new double[2]; - doubleValue[0] = resultSet.getDouble(2); - nullElements[0] = resultSet.wasNull(); - doubleValue[1] = resultSet.getDouble(3); - nullElements[1] = resultSet.wasNull(); - value = doubleValue; - break; - } + + Array.set(value, 0, castResultSetAsPrimitive(snapAttributeExtract.getDataType(), resultSet, 2)); + nullElements[0] = resultSet.wasNull(); + Array.set(value, 1, castResultSetAsPrimitive(snapAttributeExtract.getDataType(), resultSet, 3)); + nullElements[1] = resultSet.wasNull(); + snapAttributeExtract.setValue(value, nullElements); - break; - } - } } } finally { @@ -1481,9 +1010,9 @@ public class DataBaseAPI { PreparedStatement preparedStatement = null; ResultSet resultSet = null; // SELECT id_att, value FROM t_sc_str_1val WHERE id_snap = ? - final String query = selectRO + getDbSchema() + "." + SnapConst.TABS[10] + where; + final String query = selectRO + getDbSchema() + "." + SnapConst.T_SC_STR_1VAL + where; try { - conn = getConnection(); + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { @@ -1510,14 +1039,15 @@ public class DataBaseAPI { ResultSet resultSet = null; // SELECT id_att, read_value, write_value FROM t_sc_str_2val WHERE // id_snap = ? - final String query = selectRW + getDbSchema() + "." + SnapConst.TABS[11] + where; + final String query = selectRW + getDbSchema() + "." + SnapConst.T_SC_STR_2VAL + where; try { - conn = getConnection(); + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); resultSet = preparedStatement.executeQuery(); while (resultSet.next()) { - for (final SnapAttributeExtract snapAttributeExtract : attributes) { - if (snapAttributeExtract.getAttId() == resultSet.getInt(1)) { + int attId = resultSet.getInt(1); + final SnapAttributeExtract snapAttributeExtract = attributes.stream() + .filter(att -> att.getAttId() == attId).findFirst().get(); // fill data final Object[] value = new Object[2]; final boolean[] nullElements = new boolean[2]; @@ -1526,9 +1056,6 @@ public class DataBaseAPI { value[1] = resultSet.getString(3); nullElements[1] = resultSet.wasNull(); snapAttributeExtract.setValue(value, nullElements); - break; - } - } } } finally { closeResultSet(resultSet); @@ -1556,17 +1083,14 @@ public class DataBaseAPI { } } else { // one sql request per table - final String selectRO = "SELECT " + SnapConst.TAB_SC_RO_NUM[1] + "," + SnapConst.TAB_SC_RO_NUM[2] + final String selectRO = "SELECT " + SnapConst.ID_ATT + "," + SnapConst.value + " FROM "; - final String selectRW = "SELECT " + SnapConst.TAB_SC_RW_NUM[1] + "," + SnapConst.TAB_SC_RW_NUM[2] + "," - + SnapConst.TAB_SC_RW_NUM[3] + " FROM "; - final String selectRWSpectrum = "SELECT " + SnapConst.TAB_SP_RW_NUM[1] + "," + SnapConst.TAB_SP_RW_NUM[3] - + "," + SnapConst.TAB_SP_RW_NUM[4] + "," + SnapConst.TAB_SP_RW_NUM[2] + " FROM "; - // final String selectRWImage = "SELECT " + - // GlobalConst.TAB_IM_RW_NUM[1] + "," + GlobalConst.TAB_IM_RW_NUM[4] - // + "," + GlobalConst.TAB_IM_RW_NUM[5] + "," + - // GlobalConst.TAB_IM_RW_NUM[2] + " FROM "; - final String where = " WHERE " + SnapConst.TAB_SC_RO_NUM[0] + "=" + snapID; + final String selectRW = "SELECT " + SnapConst.ID_ATT + "," + SnapConst.read_value + "," + + SnapConst.write_value + " FROM "; + final String selectRWSpectrum = "SELECT " + SnapConst.ID_ATT + "," + SnapConst.read_value + "," + + SnapConst.write_value + "," + SnapConst.dim_x + " FROM "; + + final String where = " WHERE " + SnapConst.ID_SNAP + "=" + snapID; try { // --- Get scalar numeric read only values selectNumericScalarRO(attributes, selectRO, where); @@ -1601,7 +1125,7 @@ public class DataBaseAPI { } try { // --- Get spectrum read values - selectRO(attributes, selectRO, where, SnapConst.TABS[6]); + selectRO(attributes, selectRO, where, SnapConst.T_SP_1VAL); } catch (final SQLException e) { logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e); } catch (final SnapshotingException e) { @@ -1609,25 +1133,12 @@ public class DataBaseAPI { } try { // --- Get spectrum read write values - selectRW(attributes, selectRWSpectrum, where, SnapConst.TABS[7]); + selectRW(attributes, selectRWSpectrum, where, SnapConst.T_SP_2VAL); } catch (final SQLException e) { logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e); } catch (final SnapshotingException e) { logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e); } - /* - * TODO IMAGE not correctly supported try { // --- Get image read - * values selectRO(attributes, selectRWImage, where, - * GlobalConst.TABS[4]); } catch (final SQLException e) { - * logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e); } catch (final - * SnapshotingException e) { - * logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e); } try { // --- - * Get image read write values selectRW(attributes, selectRWImage, - * where, GlobalConst.TABS[5]); } catch (final SQLException e) { - * logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e); } catch (final - * SnapshotingException e) { - * logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e); } - */ } } @@ -1638,25 +1149,17 @@ public class DataBaseAPI { case AttrDataFormat._SCALAR: switch (snapAttributeExtract.getWritable()) { case AttrWriteType._READ: + case AttrWriteType._WRITE: NullableData<Object, Boolean> roData = extract_ScalarData_RO(id_snap, attID, snapAttributeExtract.getDataType()); snapAttributeExtract.setValue(roData.getValue(), roData.getNullElements()); break; case AttrWriteType._READ_WITH_WRITE: + case AttrWriteType._READ_WRITE: NullableData<Object, boolean[]> rwwData = extract_ScalarData_RW(id_snap, attID, snapAttributeExtract.getDataType()); snapAttributeExtract.setValue(rwwData.getValue(), rwwData.getNullElements()); break; - case AttrWriteType._WRITE: - NullableData<Object, Boolean> woData = extract_ScalarData_WO(id_snap, attID, - snapAttributeExtract.getDataType()); - snapAttributeExtract.setValue(woData.getValue(), woData.getNullElements()); - break; - case AttrWriteType._READ_WRITE: - NullableData<Object, boolean[]> rwData = extract_ScalarData_RW(id_snap, attID, - snapAttributeExtract.getDataType()); - snapAttributeExtract.setValue(rwData.getValue(), rwData.getNullElements()); - break; } break; case AttrDataFormat._SPECTRUM: @@ -1709,101 +1212,26 @@ public class DataBaseAPI { String query = ""; PreparedStatement preparedStatement = null; ResultSet resultSet = null; - String select_field = ""; - select_field = select_field + SnapConst.TAB_SC_RO_NUM[2]; + String select_field = SnapConst.value; final String table_1 = getDbSchema() + "." - + (data_type != TangoConst.Tango_DEV_STRING ? SnapConst.TABS[8] : SnapConst.TABS[10]); - final String clause_1 = (data_type != TangoConst.Tango_DEV_STRING ? SnapConst.TAB_SC_RO_NUM[0] - : SnapConst.TAB_SC_RO_STR[0]) + "=?"; - final String clause_2 = (data_type != TangoConst.Tango_DEV_STRING ? SnapConst.TAB_SC_RO_NUM[1] - : SnapConst.TAB_SC_RO_STR[1]) + "=?"; + + (data_type != TangoConst.Tango_DEV_STRING ? SnapConst.T_SC_NUM_1VAL : SnapConst.T_SC_STR_1VAL); + final String clause_1 = (SnapConst.ID_SNAP) + "=?"; + final String clause_2 = (SnapConst.ID_ATT) + "=?"; query = "SELECT " + select_field + " FROM " + table_1 + " WHERE " + clause_1 + " AND " + clause_2; Connection conn = null; try { - conn = getConnection(); - // if (m_dataSource == null) { + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); - // } else { - // conn = m_dataSource.getConnection(); - // preparedStatement = conn.prepareStatement(query); - // } preparedStatement.setInt(1, snapID); preparedStatement.setInt(2, snapAtt); resultSet = preparedStatement.executeQuery(); if (resultSet.next()) { - switch (data_type) { - case TangoConst.Tango_DEV_STRING: - value = resultSet.getString(1); - if (resultSet.wasNull()) { - value = null; - nullElements = Boolean.TRUE; - } - break; - case TangoConst.Tango_DEV_STATE: - value = Integer.valueOf(resultSet.getInt(1)); - if (resultSet.wasNull()) { - value = null; - nullElements = Boolean.TRUE; - } - break; - case TangoConst.Tango_DEV_UCHAR: - value = Byte.valueOf(resultSet.getByte(1)); - if (resultSet.wasNull()) { - value = null; - nullElements = Boolean.TRUE; - } - break; - case TangoConst.Tango_DEV_LONG: - value = Integer.valueOf(resultSet.getInt(1)); - if (resultSet.wasNull()) { - value = null; - nullElements = Boolean.TRUE; - } - break; - case TangoConst.Tango_DEV_ULONG: - value = Integer.valueOf(resultSet.getInt(1)); - if (resultSet.wasNull()) { - value = null; - nullElements = Boolean.TRUE; - } - break; - case TangoConst.Tango_DEV_BOOLEAN: - value = Boolean.valueOf(resultSet.getInt(1) != 0); - if (resultSet.wasNull()) { - value = null; - nullElements = Boolean.TRUE; - } - break; - case TangoConst.Tango_DEV_SHORT: - value = Short.valueOf(resultSet.getShort(1)); - if (resultSet.wasNull()) { - value = null; - nullElements = Boolean.TRUE; - } - break; - case TangoConst.Tango_DEV_FLOAT: - value = Float.valueOf(resultSet.getFloat(1)); - if (resultSet.wasNull()) { - value = null; - nullElements = Boolean.TRUE; - } - break; - case TangoConst.Tango_DEV_DOUBLE: - value = Double.valueOf(resultSet.getDouble(1)); - if (resultSet.wasNull()) { - value = null; - nullElements = Boolean.TRUE; - } - break; - default: - value = Double.valueOf(resultSet.getDouble(1)); - if (resultSet.wasNull()) { - value = null; - nullElements = Boolean.TRUE; - } - break; - } + value = castResultSetAsObject(data_type, resultSet, 1); + if (resultSet.wasNull()) { + value = null; + nullElements = Boolean.TRUE; + } } } catch (final SQLException e) { e.printStackTrace(); @@ -1878,120 +1306,29 @@ public class DataBaseAPI { PreparedStatement preparedStatement = null; ResultSet resultSet = null; String select_field = ""; - select_field = select_field + SnapConst.TAB_SC_RW_NUM[2] + ", " + SnapConst.TAB_SC_RW_NUM[3]; + select_field = select_field + SnapConst.read_value + ", " + SnapConst.write_value; final String table_1 = getDbSchema() + "." - + (data_type != TangoConst.Tango_DEV_STRING ? SnapConst.TABS[9] : SnapConst.TABS[11]); - final String clause_1 = (data_type != TangoConst.Tango_DEV_STRING ? SnapConst.TAB_SC_RW_NUM[0] - : SnapConst.TAB_SC_RW_STR[0]) + "=?"; - final String clause_2 = (data_type != TangoConst.Tango_DEV_STRING ? SnapConst.TAB_SC_RW_NUM[1] - : SnapConst.TAB_SC_RW_STR[1]) + "=?"; + + (data_type != TangoConst.Tango_DEV_STRING ? SnapConst.T_SC_NUM_2VAL : SnapConst.T_SC_STR_2VAL); + final String clause_1 = (SnapConst.ID_SNAP) + "=?"; + final String clause_2 = (SnapConst.ID_ATT) + "=?"; query = "SELECT " + select_field + " FROM " + table_1 + " WHERE " + clause_1 + " AND " + clause_2; try { - conn = getConnection(); - // if (m_dataSource == null) { + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); - // } else { - // conn = m_dataSource.getConnection(); - // preparedStatement = conn.prepareStatement(query); - // } preparedStatement.setInt(1, snapID); preparedStatement.setInt(2, snapAtt); resultSet = preparedStatement.executeQuery(); if (resultSet.next()) { - switch (data_type) { - case TangoConst.Tango_DEV_STRING: - String[] stval = new String[2]; - stval[0] = resultSet.getString(1); - if (resultSet.wasNull()) { - nullElements[0] = true; - } - stval[1] = resultSet.getString(2); - if (resultSet.wasNull()) { - nullElements[1] = true; - } - value = stval; - break; - case TangoConst.Tango_DEV_STATE: - case TangoConst.Tango_DEV_LONG: - case TangoConst.Tango_DEV_ULONG: - int[] ival = new int[2]; - ival[0] = resultSet.getInt(1); - if (resultSet.wasNull()) { - nullElements[0] = true; - } - ival[1] = resultSet.getInt(2); - if (resultSet.wasNull()) { - nullElements[1] = true; - } - value = ival; - break; - case TangoConst.Tango_DEV_UCHAR: - byte[] bval = new byte[2]; - bval[0] = resultSet.getByte(1); - if (resultSet.wasNull()) { - nullElements[0] = true; - } - bval[1] = resultSet.getByte(2); - if (resultSet.wasNull()) { - nullElements[1] = true; - } - value = bval; - break; - case TangoConst.Tango_DEV_BOOLEAN: - boolean[] boolval = new boolean[2]; - boolval[0] = (resultSet.getInt(1) != 0); - if (resultSet.wasNull()) { - nullElements[0] = true; - } - boolval[1] = (resultSet.getInt(2) != 0); - if (resultSet.wasNull()) { - nullElements[1] = true; - } - value = boolval; - break; - case TangoConst.Tango_DEV_SHORT: - short[] sval = new short[2]; - sval[0] = resultSet.getShort(1); - if (resultSet.wasNull()) { - nullElements[0] = true; - } - sval[1] = resultSet.getShort(2); - if (resultSet.wasNull()) { - nullElements[1] = true; - } - value = sval; - break; - case TangoConst.Tango_DEV_FLOAT: - float[] fval = new float[2]; - fval[0] = resultSet.getFloat(1); - if (resultSet.wasNull()) { - fval[0] = Float.NaN; - nullElements[0] = true; - } - fval[1] = resultSet.getFloat(2); - if (resultSet.wasNull()) { - fval[1] = Float.NaN; - nullElements[1] = true; - } - value = fval; - break; - case TangoConst.Tango_DEV_DOUBLE: - default: - double[] dval = new double[2]; - dval[0] = resultSet.getDouble(1); - if (resultSet.wasNull()) { - nullElements[0] = true; - dval[0] = MathConst.NAN_FOR_NULL; - } - dval[1] = resultSet.getDouble(2); - if (resultSet.wasNull()) { - nullElements[1] = true; - dval[1] = MathConst.NAN_FOR_NULL; - } - value = dval; - break; - } + value = initPrimitiveArray(data_type, 2); + Array.set(value, 0, castResultSetAsPrimitive(data_type, resultSet, 1)); + if (resultSet.wasNull()) { + nullElements[0] = true; + } + Array.set(value, 1, castResultSetAsPrimitive(data_type, resultSet, 2)); + if (resultSet.wasNull()) { + nullElements[1] = true; + } } } catch (final SQLException e) { logger.error("ERROR !! " + "\r\n" + "\t Origin : \t " + "DataBaseAPI.extract_ScalarData_RW" + "\r\n" @@ -2007,123 +1344,11 @@ public class DataBaseAPI { return new NullableData<Object, boolean[]>(value, nullElements); } - private NullableData<Object, Boolean> extract_ScalarData_WO(final int snapID, final int snapAtt, final int data_type) - throws SnapshotingException { - Object value = null; - Boolean nullElements = Boolean.FALSE; - String query = ""; - Connection conn = null; - PreparedStatement preparedStatement = null; - ResultSet resultSet = null; - String select_field = ""; - select_field = select_field + SnapConst.TAB_SC_WO_NUM[2]; - final String table_1 = getDbSchema() + "." + SnapConst.TABS[8]; - final String clause_1 = SnapConst.TAB_SC_WO_NUM[0] + "=?"; - final String clause_2 = SnapConst.TAB_SC_WO_NUM[1] + "=?"; - query = "SELECT " + select_field + " FROM " + table_1 + " WHERE " + clause_1 + " AND " + clause_2; - try { - conn = getConnection(); - // if (m_dataSource == null) { - preparedStatement = conn.prepareStatement(query); - // } else { - // conn = m_dataSource.getConnection(); - // preparedStatement = conn.prepareStatement(query); - // } - preparedStatement.setInt(1, snapID); - preparedStatement.setInt(2, snapAtt); - resultSet = preparedStatement.executeQuery(); - if (resultSet.next()) { - switch (data_type) { - case TangoConst.Tango_DEV_STRING: - value = resultSet.getString(1); - if (resultSet.wasNull()) { - value = null; - nullElements = Boolean.TRUE; - } - break; - case TangoConst.Tango_DEV_STATE: - value = new Integer(resultSet.getInt(1)); - if (resultSet.wasNull()) { - value = null; - nullElements = Boolean.TRUE; - } - break; - case TangoConst.Tango_DEV_UCHAR: - value = new Byte(resultSet.getByte(1)); - if (resultSet.wasNull()) { - value = null; - nullElements = Boolean.TRUE; - } - break; - case TangoConst.Tango_DEV_LONG: - value = new Integer(resultSet.getInt(1)); - if (resultSet.wasNull()) { - value = null; - nullElements = Boolean.TRUE; - } - break; - case TangoConst.Tango_DEV_ULONG: - value = new Integer(resultSet.getInt(1)); - if (resultSet.wasNull()) { - value = null; - nullElements = Boolean.TRUE; - } - break; - case TangoConst.Tango_DEV_BOOLEAN: - value = new Boolean(resultSet.getInt(1) != 0); - if (resultSet.wasNull()) { - value = null; - nullElements = Boolean.TRUE; - } - break; - case TangoConst.Tango_DEV_SHORT: - value = new Short(resultSet.getShort(1)); - if (resultSet.wasNull()) { - value = null; - nullElements = Boolean.TRUE; - } - break; - case TangoConst.Tango_DEV_FLOAT: - value = new Float(resultSet.getFloat(1)); - if (resultSet.wasNull()) { - value = null; - nullElements = Boolean.TRUE; - } - break; - case TangoConst.Tango_DEV_DOUBLE: - value = new Double(resultSet.getDouble(1)); - if (resultSet.wasNull()) { - value = null; - nullElements = Boolean.TRUE; - } - break; - default: - value = new Double(resultSet.getDouble(1)); - if (resultSet.wasNull()) { - value = null; - nullElements = Boolean.TRUE; - } - break; - } - } - } catch (final SQLException e) { - logger.error("ERROR !! " + "\r\n" + "\t Origin : \t " + "DataBaseAPI.extract_ScalarData_WO" + "\r\n" - + "\t Reason : \t " + getDbSchema().toUpperCase().trim() + "_FAILURE" + "\r\n" - + "\t Description : \t " + e.getMessage() + "\r\n" + "\t Additional information : \r\n" - + "\t\t Statement : " + query + "\r\n"); - // throw e; - } finally { - closeResultSet(resultSet); - closeStatement(preparedStatement); - closeConnection(conn); - } - return new NullableData<Object, Boolean>(value, nullElements); - } private NullableData<?, ?> extract_SpectrumData_RO(final int snapID, final int snapAtt, final int data_type) throws SnapshotingException { - if (db_type == ConfigConst.BD_MYSQL) { + if (params.getDbType() == DataBaseType.MYSQL) { return extract_SpectrumData_RO_MySQL(snapID, snapAtt, data_type); } else { return extract_SpectrumData_RO_Oracle(snapID, snapAtt, data_type); @@ -2143,22 +1368,17 @@ public class DataBaseAPI { PreparedStatement preparedStatement = null; ResultSet resultSet = null; String select_field = ""; - select_field = select_field + SnapConst.TAB_SP_RO_NUM[3]; - final String table_1 = getDbSchema() + "." + SnapConst.TABS[6]; - final String clause_1 = SnapConst.TAB_SP_RO_NUM[0] + "=?"; - final String clause_2 = SnapConst.TAB_SP_RO_NUM[1] + "=?"; + select_field = select_field + SnapConst.value; + final String table_1 = getDbSchema() + "." + SnapConst.T_SP_1VAL; + final String clause_1 = SnapConst.ID_SNAP + "=?"; + final String clause_2 = SnapConst.ID_ATT + "=?"; query = "SELECT " + select_field + " FROM " + table_1 + " WHERE " + clause_1 + " AND " + clause_2; String readString = null; try { - conn = getConnection(); - // if (m_dataSource == null) { + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); - // } else { - // conn = m_dataSource.getConnection(); - // preparedStatement = conn.prepareStatement(query); - // } preparedStatement.setInt(1, snapID); preparedStatement.setInt(2, snapAtt); @@ -2199,14 +1419,14 @@ public class DataBaseAPI { PreparedStatement preparedStatement = null; ResultSet resultSet = null; Connection conn = null; - final String select_field = SnapConst.TAB_SP_RO_NUM[3]; + final String select_field = SnapConst.value; final String select_field2 = "CAST(" + select_field + " AS CHAR)"; - final String table_1 = getDbSchema() + "." + SnapConst.TABS[6]; - final String clause_1 = SnapConst.TAB_SP_RO_NUM[0] + "=?"; - final String clause_2 = SnapConst.TAB_SP_RO_NUM[1] + "=?"; + final String table_1 = getDbSchema() + "." + SnapConst.T_SP_1VAL; + final String clause_1 = SnapConst.ID_SNAP + "=?"; + final String clause_2 = SnapConst.ID_ATT + "=?"; query = "SELECT " + select_field2 + " FROM " + table_1 + " WHERE " + clause_1 + " AND " + clause_2; try { - conn = getConnection(); + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); preparedStatement.setInt(1, snapID); preparedStatement.setInt(2, snapAtt); @@ -2233,7 +1453,7 @@ public class DataBaseAPI { private NullableData<?, ?> extract_SpectrumData_RW(final int snapID, final int snapAtt, final int data_type) throws SnapshotingException { - if (db_type == ConfigConst.BD_MYSQL) { + if (params.getDbType() == DataBaseType.MYSQL) { return extract_SpectrumData_RW_MySQL(snapID, snapAtt, data_type); } else { return extract_SpectrumData_RW_Oracle(snapID, snapAtt, data_type); @@ -2249,14 +1469,14 @@ public class DataBaseAPI { PreparedStatement preparedStatement = null; ResultSet resultSet = null; String select_field = ""; - select_field = "CAST(" + SnapConst.TAB_SP_RW_NUM[3] + " AS CHAR)" + ", " + "CAST(" + SnapConst.TAB_SP_RW_NUM[4] - + " AS CHAR)" + ", " + SnapConst.TAB_SP_RW_NUM[2]; - final String table_1 = getDbSchema() + "." + SnapConst.TABS[7]; - final String clause_1 = SnapConst.TAB_SP_RW_NUM[0] + "=?"; - final String clause_2 = SnapConst.TAB_SP_RW_NUM[1] + "=?"; + select_field = "CAST(" + SnapConst.read_value + " AS CHAR)" + ", " + "CAST(" + SnapConst.write_value + + " AS CHAR)" + ", " + SnapConst.dim_x; + final String table_1 = getDbSchema() + "." + SnapConst.T_SP_2VAL; + final String clause_1 = SnapConst.ID_SNAP + "=?"; + final String clause_2 = SnapConst.ID_ATT + "=?"; query = "SELECT " + select_field + " FROM " + table_1 + " WHERE " + clause_1 + " AND " + clause_2; try { - conn = getConnection(); + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); preparedStatement.setInt(1, snapID); preparedStatement.setInt(2, snapAtt); @@ -2293,17 +1513,16 @@ public class DataBaseAPI { PreparedStatement preparedStatement = null; ResultSet resultSet = null; String select_field = ""; - select_field = select_field + SnapConst.TAB_SP_RW_NUM[3] + ", " + SnapConst.TAB_SP_RW_NUM[4] + ", " - + SnapConst.TAB_SP_RW_NUM[2]; + select_field = select_field + SnapConst.read_value + ", " + SnapConst.write_value + ", " + SnapConst.dim_x; - final String table_1 = getDbSchema() + "." + SnapConst.TABS[7]; - final String clause_1 = SnapConst.TAB_SP_RW_NUM[0] + "=?"; - final String clause_2 = SnapConst.TAB_SP_RW_NUM[1] + "=?"; + final String table_1 = getDbSchema() + "." + SnapConst.T_SP_2VAL; + final String clause_1 = SnapConst.ID_SNAP + "=?"; + final String clause_2 = SnapConst.ID_ATT + "=?"; query = "SELECT " + select_field + " FROM " + table_1 + " WHERE " + clause_1 + " AND " + clause_2; Connection conn = null; try { - conn = getConnection(); + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); preparedStatement.setInt(1, snapID); preparedStatement.setInt(2, snapAtt); @@ -2343,7 +1562,7 @@ public class DataBaseAPI { private NullableData<Object[], boolean[][]> extract_ImageData_RO(final int snapID, final int snapAtt, final int data_type) throws SnapshotingException { - if (db_type == ConfigConst.BD_MYSQL) { + if (params.getDbType() == DataBaseType.MYSQL) { return extract_ImageData_RO_MySQL(snapID, snapAtt, data_type); } else { return extract_ImageData_RO_Oracle(snapID, snapAtt, data_type); @@ -2352,7 +1571,7 @@ public class DataBaseAPI { private NullableData<Object[][], boolean[][][]> extract_ImageData_RW(final int snapID, final int snapAtt, final int data_type) throws SnapshotingException { - if (db_type == ConfigConst.BD_MYSQL) { + if (params.getDbType() == DataBaseType.MYSQL) { return extract_ImageData_RW_MySQL(snapID, snapAtt, data_type); } else { return extract_ImageData_RW_Oracle(snapID, snapAtt, data_type); @@ -2372,14 +1591,14 @@ public class DataBaseAPI { PreparedStatement preparedStatement = null; ResultSet resultSet = null; String select_field = ""; - select_field = select_field + SnapConst.TAB_IM_RO_NUM[4]; - final String table_1 = getDbSchema() + "." + SnapConst.TABS[4]; - final String clause_1 = SnapConst.TAB_IM_RO_NUM[0] + "=?"; - final String clause_2 = SnapConst.TAB_IM_RO_NUM[1] + "=?"; + select_field = select_field + SnapConst.value; + final String table_1 = getDbSchema() + "." + SnapConst.T_IM_1VAL; + final String clause_1 = SnapConst.ID_SNAP + "=?"; + final String clause_2 = SnapConst.ID_ATT + "=?"; query = "SELECT " + select_field + " FROM " + table_1 + " WHERE " + clause_1 + " AND " + clause_2; Connection conn = null; try { - conn = getConnection(); + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); preparedStatement.setInt(1, snapID); preparedStatement.setInt(2, snapAtt); @@ -2421,16 +1640,16 @@ public class DataBaseAPI { PreparedStatement preparedStatement = null; ResultSet resultSet = null; String select_field = ""; - select_field = select_field + SnapConst.TAB_IM_RO_NUM[3]; - final String table_1 = getDbSchema() + "." + SnapConst.TABS[4]; - final String clause_1 = SnapConst.TAB_IM_RO_NUM[0] + "=?"; - final String clause_2 = SnapConst.TAB_IM_RO_NUM[1] + "=?"; + select_field = select_field + SnapConst.value; + final String table_1 = getDbSchema() + "." + SnapConst.T_IM_1VAL; + final String clause_1 = SnapConst.ID_SNAP + "=?"; + final String clause_2 = SnapConst.ID_ATT + "=?"; query = "SELECT " + select_field + " FROM " + table_1 + " WHERE " + clause_1 + " AND " + clause_2; String readString = null; Connection conn = null; try { - conn = getConnection(); + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); preparedStatement.setInt(1, snapID); preparedStatement.setInt(2, snapAtt); @@ -2474,15 +1693,15 @@ public class DataBaseAPI { PreparedStatement preparedStatement = null; ResultSet resultSet = null; String select_field = ""; - select_field = select_field + "CAST(" + SnapConst.TAB_IM_RW_NUM[4] + " AS CHAR)" + ", " + "CAST(" - + SnapConst.TAB_IM_RW_NUM[5] + " AS CHAR)"; - final String table_1 = getDbSchema() + "." + SnapConst.TABS[5]; - final String clause_1 = SnapConst.TAB_IM_RW_NUM[0] + "=?"; - final String clause_2 = SnapConst.TAB_IM_RW_NUM[1] + "=?"; + select_field = select_field + "CAST(" + SnapConst.read_value + " AS CHAR)" + ", " + "CAST(" + + SnapConst.write_value + " AS CHAR)"; + final String table_1 = getDbSchema() + "." + SnapConst.T_IM_2VAL; + final String clause_1 = SnapConst.ID_SNAP + "=?"; + final String clause_2 = SnapConst.ID_ATT + "=?"; query = "SELECT " + select_field + " FROM " + table_1 + " WHERE " + clause_1 + " AND " + clause_2; Connection conn = null; try { - conn = getConnection(); + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); preparedStatement.setInt(1, snapID); preparedStatement.setInt(2, snapAtt); @@ -2539,10 +1758,10 @@ public class DataBaseAPI { PreparedStatement preparedStatement = null; ResultSet resultSet = null; String select_field = ""; - select_field = select_field + SnapConst.TAB_IM_RW_NUM[3] + ", " + SnapConst.TAB_IM_RW_NUM[4]; - final String table_1 = getDbSchema() + "." + SnapConst.TABS[5]; - final String clause_1 = SnapConst.TAB_IM_RW_NUM[0] + "=?"; - final String clause_2 = SnapConst.TAB_IM_RW_NUM[1] + "=?"; + select_field = select_field + SnapConst.read_value + ", " + SnapConst.write_value; + final String table_1 = getDbSchema() + "." + SnapConst.T_IM_2VAL; + final String clause_1 = SnapConst.ID_SNAP + "=?"; + final String clause_2 = SnapConst.ID_ATT + "=?"; query = "SELECT " + select_field + " FROM " + table_1 + " WHERE " + clause_1 + " AND " + clause_2; String readString = null; @@ -2550,7 +1769,7 @@ public class DataBaseAPI { Connection conn = null; try { - conn = getConnection(); + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); preparedStatement.setInt(1, snapID); preparedStatement.setInt(2, snapAtt); @@ -2615,7 +1834,7 @@ public class DataBaseAPI { if ("".equals(readString) || "null".equals(readString) || "NaN".equalsIgnoreCase(readString)) { readTokenizer = null; } else { - readTokenizer = new StringTokenizer(readString, SnapConst.CLOB_SEPARATOR); + readTokenizer = new StringTokenizer(readString, GlobalConst.CLOB_SEPARATOR); readSize += readTokenizer.countTokens(); } } @@ -2628,7 +1847,7 @@ public class DataBaseAPI { if ("".equals(writeString) || "null".equals(writeString) || "NaN".equalsIgnoreCase(writeString)) { writeTokenizer = null; } else { - writeTokenizer = new StringTokenizer(writeString, SnapConst.CLOB_SEPARATOR); + writeTokenizer = new StringTokenizer(writeString, GlobalConst.CLOB_SEPARATOR); writeSize += writeTokenizer.countTokens(); } } @@ -2636,68 +1855,12 @@ public class DataBaseAPI { boolean[] nullRead = null; boolean[] nullWrite = null; - double[] dvalueArr_read = null, dvalueArr_write = null; - byte[] cvalueArr_read = null, cvalueArr_write = null; - int[] lvalueArr_read = null, lvalueArr_write = null; - short[] svalueArr_read = null, svalueArr_write = null; - boolean[] bvalueArr_read = null, bvalueArr_write = null; - float[] fvalueArr_read = null, fvalueArr_write = null; - String[] stvalueArr_read = null, stvalueArr_write = null; - switch (dataType) { - case TangoConst.Tango_DEV_BOOLEAN: - bvalueArr_read = new boolean[readSize]; - break; - case TangoConst.Tango_DEV_CHAR: - case TangoConst.Tango_DEV_UCHAR: - cvalueArr_read = new byte[readSize]; - break; - case TangoConst.Tango_DEV_STATE: - case TangoConst.Tango_DEV_LONG: - case TangoConst.Tango_DEV_ULONG: - lvalueArr_read = new int[readSize]; - break; - case TangoConst.Tango_DEV_SHORT: - case TangoConst.Tango_DEV_USHORT: - svalueArr_read = new short[readSize]; - break; - case TangoConst.Tango_DEV_FLOAT: - fvalueArr_read = new float[readSize]; - break; - case TangoConst.Tango_DEV_STRING: - stvalueArr_read = new String[readSize]; - break; - case TangoConst.Tango_DEV_DOUBLE: - default: - dvalueArr_read = new double[readSize]; - } + Object valueArr_read = initPrimitiveArray(dataType, readSize); + Object valueArr_write = null; + + if (returnAsReadWrite) { - switch (dataType) { - case TangoConst.Tango_DEV_BOOLEAN: - bvalueArr_write = new boolean[writeSize]; - break; - case TangoConst.Tango_DEV_CHAR: - case TangoConst.Tango_DEV_UCHAR: - cvalueArr_write = new byte[writeSize]; - break; - case TangoConst.Tango_DEV_STATE: - case TangoConst.Tango_DEV_LONG: - case TangoConst.Tango_DEV_ULONG: - lvalueArr_write = new int[writeSize]; - break; - case TangoConst.Tango_DEV_SHORT: - case TangoConst.Tango_DEV_USHORT: - svalueArr_write = new short[writeSize]; - break; - case TangoConst.Tango_DEV_FLOAT: - fvalueArr_write = new float[writeSize]; - break; - case TangoConst.Tango_DEV_STRING: - stvalueArr_write = new String[writeSize]; - break; - case TangoConst.Tango_DEV_DOUBLE: - default: - dvalueArr_write = new double[writeSize]; - } + valueArr_write = initPrimitiveArray(dataType, writeSize); } int i = 0; @@ -2712,26 +1875,26 @@ public class DataBaseAPI { case TangoConst.Tango_DEV_BOOLEAN: try { if (isNullOrNaN(currentValRead)) { - bvalueArr_read[i] = false; + Array.set(valueArr_read, i, false); nullRead[i] = true; } else { - bvalueArr_read[i] = (((int) Double.parseDouble(currentValRead)) != 0); + Array.set(valueArr_read, i, ((int) Double.parseDouble(currentValRead)) != 0); } } catch (final NumberFormatException n) { - bvalueArr_read[i] = "true".equalsIgnoreCase(currentValRead.trim()); + Array.set(valueArr_read, i, "true".equalsIgnoreCase(currentValRead.trim())); } break; case TangoConst.Tango_DEV_CHAR: case TangoConst.Tango_DEV_UCHAR: try { if (isNullOrNaN(currentValRead)) { - cvalueArr_read[i] = 0; + Array.set(valueArr_read, i, (byte)0); nullRead[i] = true; } else { - cvalueArr_read[i] = Byte.parseByte(currentValRead); + Array.set(valueArr_read, i,Byte.parseByte(currentValRead)); } } catch (final NumberFormatException n) { - cvalueArr_read[i] = (byte) Double.parseDouble(currentValRead); + Array.set(valueArr_read, i,(byte) Double.parseDouble(currentValRead)); } break; case TangoConst.Tango_DEV_STATE: @@ -2739,51 +1902,51 @@ public class DataBaseAPI { case TangoConst.Tango_DEV_ULONG: try { if (isNullOrNaN(currentValRead)) { - lvalueArr_read[i] = 0; + Array.set(valueArr_read, i, (int)0); nullRead[i] = true; } else { - lvalueArr_read[i] = Integer.parseInt(currentValRead); + Array.set(valueArr_read, i,Integer.parseInt(currentValRead)); } } catch (final NumberFormatException n) { - lvalueArr_read[i] = (int) Double.parseDouble(currentValRead); + Array.set(valueArr_read, i,(int) Double.parseDouble(currentValRead)); } break; case TangoConst.Tango_DEV_SHORT: case TangoConst.Tango_DEV_USHORT: try { if (isNullOrNaN(currentValRead)) { - svalueArr_read[i] = 0; + Array.set(valueArr_read, i, (short)0); nullRead[i] = true; } else { - svalueArr_read[i] = Short.parseShort(currentValRead); + Array.set(valueArr_read, i,Short.parseShort(currentValRead)); } } catch (final NumberFormatException n) { - svalueArr_read[i] = (short) Double.parseDouble(currentValRead); + Array.set(valueArr_read, i, (short) Double.parseDouble(currentValRead)); } break; case TangoConst.Tango_DEV_FLOAT: if (isNullOrNaN(currentValRead)) { - fvalueArr_read[i] = Float.NaN; + Array.set(valueArr_read, i, Float.NaN); nullRead[i] = true; } else { - fvalueArr_read[i] = Float.parseFloat(currentValRead); + } break; case TangoConst.Tango_DEV_STRING: if (isNullOrNaN(currentValRead)) { - stvalueArr_read[i] = null; + Array.set(valueArr_read, i, null); nullRead[i] = true; } else { - stvalueArr_read[i] = StringFormater.formatStringToRead(new String(currentValRead)); + Array.set(valueArr_read, i, StringFormater.formatStringToRead(new String(currentValRead))); } break; case TangoConst.Tango_DEV_DOUBLE: default: if (isNullOrNaN(currentValRead)) { - dvalueArr_read[i] = MathConst.NAN_FOR_NULL; + Array.set(valueArr_read, i, MathConst.NAN_FOR_NULL); nullRead[i] = true; } else { - dvalueArr_read[i] = Double.parseDouble(currentValRead); + Array.set(valueArr_read, i, Double.parseDouble(currentValRead)); } } i++; @@ -2799,146 +1962,114 @@ public class DataBaseAPI { break; } switch (dataType) { - case TangoConst.Tango_DEV_BOOLEAN: - try { - if (isNullOrNaN(currentValWrite)) { - bvalueArr_write[i] = false; - nullWrite[i] = true; - } else { - bvalueArr_write[i] = (((int) Double.parseDouble(currentValWrite)) != 0); - } - } catch (final NumberFormatException n) { - bvalueArr_write[i] = "true".equalsIgnoreCase(currentValWrite.trim()); - } - break; - case TangoConst.Tango_DEV_CHAR: - case TangoConst.Tango_DEV_UCHAR: - try { - if (isNullOrNaN(currentValWrite)) { - cvalueArr_write[i] = 0; - nullWrite[i] = true; - } else { - cvalueArr_write[i] = Byte.parseByte(currentValWrite); - } - } catch (final NumberFormatException n) { - cvalueArr_write[i] = (byte) Double.parseDouble(currentValWrite); - } - break; - case TangoConst.Tango_DEV_STATE: - case TangoConst.Tango_DEV_LONG: - case TangoConst.Tango_DEV_ULONG: - try { - if (isNullOrNaN(currentValWrite)) { - lvalueArr_write[i] = 0; - nullWrite[i] = true; - } else { - lvalueArr_write[i] = Integer.parseInt(currentValWrite); - } - } catch (final NumberFormatException n) { - lvalueArr_write[i] = (int) Double.parseDouble(currentValWrite); - } - break; - case TangoConst.Tango_DEV_SHORT: - case TangoConst.Tango_DEV_USHORT: - try { - if (isNullOrNaN(currentValWrite)) { - svalueArr_write[i] = 0; - nullWrite[i] = true; - } else { - svalueArr_write[i] = Short.parseShort(currentValWrite); - } - } catch (final NumberFormatException n) { - svalueArr_write[i] = (short) Double.parseDouble(currentValWrite); + case TangoConst.Tango_DEV_BOOLEAN: + try { + if (isNullOrNaN(currentValWrite)) { + Array.set(valueArr_write, i, false); + nullRead[i] = true; + } else { + Array.set(valueArr_write, i, ((int) Double.parseDouble(currentValWrite)) != 0); } - break; - case TangoConst.Tango_DEV_FLOAT: + } catch (final NumberFormatException n) { + Array.set(valueArr_write, i, "true".equalsIgnoreCase(currentValWrite.trim())); + } + break; + case TangoConst.Tango_DEV_CHAR: + case TangoConst.Tango_DEV_UCHAR: + try { if (isNullOrNaN(currentValWrite)) { - fvalueArr_write[i] = Float.NaN; - nullWrite[i] = true; + Array.set(valueArr_write, i, (byte) 0); + nullRead[i] = true; } else { - fvalueArr_write[i] = Float.parseFloat(currentValWrite); + Array.set(valueArr_write, i, Byte.parseByte(currentValWrite)); } - break; - case TangoConst.Tango_DEV_STRING: + } catch (final NumberFormatException n) { + Array.set(valueArr_write, i, (byte) Double.parseDouble(currentValWrite)); + } + break; + case TangoConst.Tango_DEV_STATE: + case TangoConst.Tango_DEV_LONG: + case TangoConst.Tango_DEV_ULONG: + try { if (isNullOrNaN(currentValWrite)) { - stvalueArr_write[i] = null; - nullWrite[i] = true; + Array.set(valueArr_write, i, (int) 0); + nullRead[i] = true; } else { - stvalueArr_write[i] = StringFormater.formatStringToRead(new String(currentValWrite)); + Array.set(valueArr_write, i, Integer.parseInt(currentValWrite)); } - break; - case TangoConst.Tango_DEV_DOUBLE: - default: + } catch (final NumberFormatException n) { + Array.set(valueArr_write, i, (int) Double.parseDouble(currentValWrite)); + } + break; + case TangoConst.Tango_DEV_SHORT: + case TangoConst.Tango_DEV_USHORT: + try { if (isNullOrNaN(currentValWrite)) { - dvalueArr_write[i] = MathConst.NAN_FOR_NULL; - nullWrite[i] = true; + Array.set(valueArr_write, i, (short) 0); + nullRead[i] = true; } else { - dvalueArr_write[i] = Double.parseDouble(currentValWrite); + Array.set(valueArr_write, i, Short.parseShort(currentValWrite)); } - } + } catch (final NumberFormatException n) { + Array.set(valueArr_write, i, (short) Double.parseDouble(currentValWrite)); + } + break; + case TangoConst.Tango_DEV_FLOAT: + if (isNullOrNaN(currentValWrite)) { + Array.set(valueArr_write, i, Float.NaN); + nullRead[i] = true; + } else { + + } + break; + case TangoConst.Tango_DEV_STRING: + if (isNullOrNaN(currentValWrite)) { + Array.set(valueArr_write, i, null); + nullRead[i] = true; + } else { + Array.set(valueArr_write, i, StringFormater.formatStringToRead(new String(currentValWrite))); + } + break; + case TangoConst.Tango_DEV_DOUBLE: + default: + if (isNullOrNaN(currentValWrite)) { + Array.set(valueArr_write, i, MathConst.NAN_FOR_NULL); + nullRead[i] = true; + } else { + Array.set(valueArr_write, i, Double.parseDouble(currentValWrite)); + } + } + i++; } } if (returnAsReadWrite) { - final Object[] result = new Object[2]; + final Object[] result = new Object[] { valueArr_read, valueArr_write }; final boolean[][] nullElements = new boolean[][] { nullRead, nullWrite }; - switch (dataType) { - case TangoConst.Tango_DEV_BOOLEAN: - result[0] = bvalueArr_read; - result[1] = bvalueArr_write; - break; - case TangoConst.Tango_DEV_CHAR: - case TangoConst.Tango_DEV_UCHAR: - result[0] = cvalueArr_read; - result[1] = cvalueArr_write; - break; - case TangoConst.Tango_DEV_STATE: - case TangoConst.Tango_DEV_LONG: - case TangoConst.Tango_DEV_ULONG: - result[0] = lvalueArr_read; - result[1] = lvalueArr_write; - break; - case TangoConst.Tango_DEV_SHORT: - case TangoConst.Tango_DEV_USHORT: - result[0] = svalueArr_read; - result[1] = svalueArr_write; - break; - case TangoConst.Tango_DEV_FLOAT: - result[0] = fvalueArr_read; - result[1] = fvalueArr_write; - break; - case TangoConst.Tango_DEV_STRING: - result[0] = stvalueArr_read; - result[1] = stvalueArr_write; - break; - case TangoConst.Tango_DEV_DOUBLE: - default: - result[0] = dvalueArr_read; - result[1] = dvalueArr_write; - } + return new NullableData<Object[], boolean[][]>(result, nullElements); } else { switch (dataType) { case TangoConst.Tango_DEV_BOOLEAN: - return new NullableData<boolean[], boolean[]>(bvalueArr_read, nullRead); + return new NullableData<boolean[], boolean[]>((boolean[]) valueArr_read, nullRead); case TangoConst.Tango_DEV_CHAR: case TangoConst.Tango_DEV_UCHAR: - return new NullableData<byte[], boolean[]>(cvalueArr_read, nullRead); + return new NullableData<byte[], boolean[]>((byte[]) valueArr_read, nullRead); case TangoConst.Tango_DEV_STATE: case TangoConst.Tango_DEV_LONG: case TangoConst.Tango_DEV_ULONG: - return new NullableData<int[], boolean[]>(lvalueArr_read, nullRead); + return new NullableData<int[], boolean[]>((int[]) valueArr_read, nullRead); case TangoConst.Tango_DEV_SHORT: case TangoConst.Tango_DEV_USHORT: - return new NullableData<short[], boolean[]>(svalueArr_read, nullRead); + return new NullableData<short[], boolean[]>((short[]) valueArr_read, nullRead); case TangoConst.Tango_DEV_FLOAT: - return new NullableData<float[], boolean[]>(fvalueArr_read, nullRead); + return new NullableData<float[], boolean[]>((float[]) valueArr_read, nullRead); case TangoConst.Tango_DEV_STRING: - return new NullableData<String[], boolean[]>(stvalueArr_read, nullRead); + return new NullableData<String[], boolean[]>((String[]) valueArr_read, nullRead); case TangoConst.Tango_DEV_DOUBLE: default: - return new NullableData<double[], boolean[]>(dvalueArr_read, nullRead); + return new NullableData<double[], boolean[]>((double[]) valueArr_read, nullRead); } } } @@ -2955,14 +2086,14 @@ public class DataBaseAPI { StringTokenizer readTokenizer = null; int rowSize = 0, colSize = 0; - readTokenizer = new StringTokenizer(value, SnapConst.CLOB_SEPARATOR_IMAGE_ROWS); + readTokenizer = new StringTokenizer(value, GlobalConst.CLOB_SEPARATOR_IMAGE_ROWS); rowSize = readTokenizer.countTokens(); if (readTokenizer != null) { valArray = new Object[rowSize]; int i = 0; while (readTokenizer.hasMoreTokens()) { - valArray[i++] = readTokenizer.nextToken().trim().split(SnapConst.CLOB_SEPARATOR_IMAGE_COLS); + valArray[i++] = readTokenizer.nextToken().trim().split(GlobalConst.CLOB_SEPARATOR_IMAGE_COLS); } if (rowSize > 0) { colSize = ((String[]) valArray[0]).length; @@ -3131,10 +2262,10 @@ public class DataBaseAPI { */ public void registerAttribute(final SnapAttributeHeavy snapAttributeHeavy) throws SnapshotingException { Connection conn = null; - if (db_type == ConfigConst.BD_MYSQL) { + if (params.getDbType() == DataBaseType.MYSQL) { PreparedStatement preparedStatement = null; - final String tableName = getDbSchema() + "." + SnapConst.TABS[0]; + final String tableName = getDbSchema() + "." + SnapConst.AST; // Create and execute the SQL query string // Build the query string @@ -3155,7 +2286,7 @@ public class DataBaseAPI { StringBuilder valueConcat = new StringBuilder(); try { - conn = getConnection(); + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); preparedStatement.setDate(1, new java.sql.Date(snapAttributeHeavy.getRegistration_time().getTime())); @@ -3199,14 +2330,14 @@ public class DataBaseAPI { closeStatement(preparedStatement); closeConnection(conn); } - } else if (db_type == ConfigConst.BD_ORACLE) { + } else if (params.getDbType() == DataBaseType.ORACLE) { CallableStatement callableStatement = null; final String procName = "RSA"; final String query = "{call " + getDbSchema() + "." + procName + "(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)}"; StringBuilder valueConcat = new StringBuilder(); try { - conn = getConnection(); + conn = connector.getConnection(); callableStatement = conn.prepareCall(query); // number of // parameters : // 16 @@ -3274,13 +2405,13 @@ public class DataBaseAPI { // Create and execute the SQL query string String query = ""; - final String table_name = getDbSchema() + "." + SnapConst.TABS[0]; + final String table_name = getDbSchema() + "." + SnapConst.AST; String select_field_spec = ""; // String clause_1 = ConfigConst.fullName + "= ?"; - final String clause_1 = SnapConst.TAB_DEF[2] + "= " + "'" + att_name.trim() + "'"; - if (db_type == ConfigConst.BD_MYSQL) { + final String clause_1 = SnapConst.fullName + "= " + "'" + att_name.trim() + "'"; + if (params.getDbType() == DataBaseType.MYSQL) { select_field_spec = " * "; - } else if (db_type == ConfigConst.BD_ORACLE) { + } else if (params.getDbType() == DataBaseType.ORACLE) { for (int i = 0; i < SnapConst.TAB_DEF.length - 1; i++) { select_field_spec = select_field_spec + "to_char(" + SnapConst.TAB_DEF[i] + ")" + ", "; } @@ -3288,7 +2419,7 @@ public class DataBaseAPI { } query = "SELECT " + select_field_spec + " FROM " + table_name + " WHERE " + clause_1; try { - conn = getConnection(); + conn = connector.getConnection(); statement = conn.createStatement(); rset = statement.executeQuery(query); // Gets the result of the query @@ -3332,8 +2463,8 @@ public class DataBaseAPI { // Create and execute the SQL query string String query = ""; - final String table_name = getDbSchema() + "." + SnapConst.TABS[0]; - final String clause_1 = SnapConst.TAB_DEF[2] + " = " + "'" + att_name.trim() + "'"; + final String table_name = getDbSchema() + "." + SnapConst.AST; + final String clause_1 = SnapConst.fullName + " = " + "'" + att_name.trim() + "'"; final String select_field_spec = " * "; @@ -3344,7 +2475,7 @@ public class DataBaseAPI { } try { - conn = getConnection(); + conn = connector.getConnection(); statement = conn.createStatement(); rset = statement.executeQuery(query); @@ -3399,13 +2530,13 @@ public class DataBaseAPI { */ public int create_context(final SnapContext snapContext) throws SnapshotingException { int contextID = snapContext.getId(); - final String tableName = getDbSchema() + "." + SnapConst.TABS[1]; + final String tableName = getDbSchema() + "." + SnapConst.CONTEXT; final java.util.List<Integer> contextIDList = new ArrayList<Integer>(); PreparedStatement prest = null; Connection conn = null; - final String queryCurrentContext = "select " + SnapConst.TAB_CONTEXT[0] + " from " + tableName; + final String queryCurrentContext = "select " + SnapConst.ID_CONTEXT + " from " + tableName; try { - conn = getConnection(); + conn = connector.getConnection(); // check if context exists prest = conn.prepareStatement(queryCurrentContext); final ResultSet rs = prest.executeQuery(); @@ -3418,9 +2549,9 @@ public class DataBaseAPI { if (contextIDList.contains(contextID)) { // update snap.context SET name=?, author=?, reason=?, // description=? where id =?; - final String updateQuery = "UPDATE " + tableName + " SET " + SnapConst.TAB_CONTEXT[2] + "= ?, " + final String updateQuery = "UPDATE " + tableName + " SET " + SnapConst.name + "= ?, " + SnapConst.TAB_CONTEXT[3] + "= ?, " + SnapConst.TAB_CONTEXT[4] + "= ?, " - + SnapConst.TAB_CONTEXT[5] + "= ? WHERE " + SnapConst.TAB_CONTEXT[0] + "= ?"; + + SnapConst.TAB_CONTEXT[5] + "= ? WHERE " + SnapConst.ID_CONTEXT + "= ?"; try { preparedStatement = conn.prepareStatement(updateQuery); @@ -3445,10 +2576,10 @@ public class DataBaseAPI { } } else { // context does not exists, create it - if (db_type == ConfigConst.BD_MYSQL) { + if (params.getDbType() == DataBaseType.MYSQL) { // Create and execute the SQL query string // Build the query string - final String insert_fields = SnapConst.TAB_CONTEXT[1] + ", " + SnapConst.TAB_CONTEXT[2] + ", " + final String insert_fields = SnapConst.TAB_CONTEXT[1] + ", " + SnapConst.name + ", " + SnapConst.TAB_CONTEXT[3] + ", " + SnapConst.TAB_CONTEXT[4] + ", " + SnapConst.TAB_CONTEXT[5]; final String insert_values = "?,?,?,?,?"; @@ -3477,7 +2608,7 @@ public class DataBaseAPI { } finally { closeStatement(preparedStatement); } - } else if (db_type == ConfigConst.BD_ORACLE) { + } else if (params.getDbType() == DataBaseType.ORACLE) { CallableStatement callableStatement = null; final String procName = "register_context"; final String query = "{? = call " + getDbSchema() + "." + procName + "(?, ?, ?, ?, ?)}"; @@ -3527,34 +2658,22 @@ public class DataBaseAPI { final List<SnapAttributeHeavy> result = new ArrayList<SnapAttributeHeavy>(); // Create and execute the SQL query string - final String ast = getDbSchema() + "." + SnapConst.TABS[0]; - final String context = getDbSchema() + "." + SnapConst.TABS[1]; - final String list = getDbSchema() + "." + SnapConst.TABS[2]; + final String ast = getDbSchema() + "." + SnapConst.AST; + final String context = getDbSchema() + "." + SnapConst.CONTEXT; + final String list = getDbSchema() + "." + SnapConst.LIST; final String tables = ast + ", " + context + ", " + list; - final String selectFields = SnapConst.TAB_DEF[0] + ", " + // ID - ast + "." + SnapConst.TAB_DEF[1] + ", " + // time - SnapConst.TAB_DEF[2] + ", " + // full_name - SnapConst.TAB_DEF[3] + ", " + // device - SnapConst.TAB_DEF[4] + ", " + // domain - SnapConst.TAB_DEF[5] + ", " + // family - SnapConst.TAB_DEF[6] + ", " + // member - SnapConst.TAB_DEF[7] + ", " + // att_name - SnapConst.TAB_DEF[8] + ", " + // data_type - SnapConst.TAB_DEF[9] + ", " + // data_format - SnapConst.TAB_DEF[10] + ", " + // writable - SnapConst.TAB_DEF[11] + ", " + // max_dim_x - SnapConst.TAB_DEF[12] + ", " + // max_dim_y - SnapConst.TAB_DEF[13] + ", " + // levelg - SnapConst.TAB_DEF[14] + ", " + // facility - SnapConst.TAB_DEF[15] + ", " + // archivable - SnapConst.TAB_DEF[16]; // substitute + final String selectFields = SnapConst.ID + ", " + ast + "." + SnapConst.time + ", " + SnapConst.fullName + ", " + + SnapConst.device + ", " + SnapConst.domain + ", " + SnapConst.family + ", " + SnapConst.member + ", " + + SnapConst.attName + ", " + SnapConst.dataType + ", " + SnapConst.dataFormat + ", " + + SnapConst.writable + ", " + SnapConst.max_dim_x + ", " + SnapConst.max_dim_y + ", " + SnapConst.levelg + + ", " + SnapConst.facility + ", " + SnapConst.archivable + ", " + SnapConst.substitute; // final String selectFields = "*"; - final String clause1 = SnapConst.TABS[0] + "." + SnapConst.TAB_DEF[0] + " = " + SnapConst.TABS[2] + "." + final String clause1 = SnapConst.AST + "." + SnapConst.ID + " = " + SnapConst.LIST + "." + SnapConst.TAB_LIST[1]; - final String clause2 = SnapConst.TABS[2] + "." + SnapConst.TAB_LIST[0] + " = " + SnapConst.TABS[1] + "." - + SnapConst.TAB_CONTEXT[0]; - final String clause3 = SnapConst.TABS[1] + "." + SnapConst.TAB_CONTEXT[0] + " = ?"; + final String clause2 = SnapConst.LIST + "." + SnapConst.TAB_LIST[0] + " = " + SnapConst.CONTEXT + "." + + SnapConst.ID_CONTEXT; + final String clause3 = SnapConst.CONTEXT + "." + SnapConst.ID_CONTEXT + " = ?"; // the SQL request is : select DISTINCT full_name from snap.ast where // ast.id = list.id_att and list.id_context = context.id_context and // context.name = 'nom'; @@ -3571,7 +2690,7 @@ public class DataBaseAPI { ResultSet rset = null; Connection conn = null; try { - conn = getConnection(); + conn = connector.getConnection(); statement = conn.prepareStatement(query); statement.setInt(1, contextID); rset = statement.executeQuery(); @@ -3621,12 +2740,12 @@ public class DataBaseAPI { */ public SnapAttributeExtract[] getAttributeConfig(final String... attributeNames) throws SnapshotingException { final SnapAttributeExtract[] result = new SnapAttributeExtract[attributeNames.length]; - final String selectFields = SnapConst.TAB_DEF[2] + ", " + // full_name - SnapConst.TAB_DEF[0] + ", " + // attribute_id - SnapConst.TAB_DEF[8] + ", " + // data_type - SnapConst.TAB_DEF[9] + ", " + // data_format - SnapConst.TAB_DEF[10]; // writable - final String astTableName = getDbSchema() + "." + SnapConst.TABS[0]; + final String selectFields = SnapConst.fullName + ", " + // full_name + SnapConst.ID + ", " + // attribute_id + SnapConst.dataType + ", " + // data_type + SnapConst.dataFormat + ", " + // data_format + SnapConst.writable; // writable + final String astTableName = getDbSchema() + "." + SnapConst.AST; // SELECT ID, data_type, data_format, writable FROM snap.ast WHERE // full_name = 'attributeName' String query = "SELECT " + selectFields + " FROM " + astTableName + " WHERE "; @@ -3634,24 +2753,24 @@ public class DataBaseAPI { if (i > 0 && i < attributeNames.length) { query = query + " OR "; } - query = query + SnapConst.TAB_DEF[2] + " = '" + attributeNames[i] + "'"; + query = query + SnapConst.fullName + " = '" + attributeNames[i] + "'"; } PreparedStatement preparedStatement = null; ResultSet rset = null; Connection conn = null; Map<String, SnapAttributeLight> extractMap = new HashMap<String, SnapAttributeLight>(); try { - conn = getConnection(); + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); rset = preparedStatement.executeQuery(); // Gets the result of the query while (rset.next()) { final SnapAttributeLight snapAttributeLight = new SnapAttributeLight(); - snapAttributeLight.setAttributeCompleteName(rset.getString(SnapConst.TAB_DEF[2])); - snapAttributeLight.setAttributeId(rset.getInt(SnapConst.TAB_DEF[0])); - snapAttributeLight.setDataType(rset.getInt(SnapConst.TAB_DEF[8])); - snapAttributeLight.setDataFormat(rset.getInt(SnapConst.TAB_DEF[9])); - snapAttributeLight.setWritable(rset.getInt(SnapConst.TAB_DEF[10])); + snapAttributeLight.setAttributeCompleteName(rset.getString(SnapConst.fullName)); + snapAttributeLight.setAttributeId(rset.getInt(SnapConst.ID)); + snapAttributeLight.setDataType(rset.getInt(SnapConst.dataType)); + snapAttributeLight.setDataFormat(rset.getInt(SnapConst.dataFormat)); + snapAttributeLight.setWritable(rset.getInt(SnapConst.writable)); extractMap.put(snapAttributeLight.getAttributeCompleteName(), snapAttributeLight); } if (extractMap.size() != attributeNames.length) { @@ -3709,20 +2828,20 @@ public class DataBaseAPI { // Create and execute the SQL query string String query = ""; - final String table_name_1 = getDbSchema() + "." + SnapConst.TABS[0]; - final String table_name_2 = getDbSchema() + "." + SnapConst.TABS[1]; - final String table_name_3 = getDbSchema() + "." + SnapConst.TABS[2]; + final String table_name_1 = getDbSchema() + "." + SnapConst.AST; + final String table_name_2 = getDbSchema() + "." + SnapConst.CONTEXT; + final String table_name_3 = getDbSchema() + "." + SnapConst.LIST; final String tables = table_name_1 + ", " + table_name_2 + ", " + table_name_3; - final String select_fields = SnapConst.TAB_DEF[2] + ", " + // full_name - SnapConst.TAB_DEF[0] + ", " + // attribute_id - SnapConst.TAB_DEF[8] + ", " + // data_type - SnapConst.TAB_DEF[9] + ", " + // data_format - SnapConst.TAB_DEF[10]; // writable - final String clause_1 = SnapConst.TABS[0] + "." + SnapConst.TAB_DEF[0] + " = " + SnapConst.TABS[2] + "." + final String select_fields = SnapConst.fullName + ", " + // full_name + SnapConst.ID + ", " + // attribute_id + SnapConst.dataType + ", " + // data_type + SnapConst.dataFormat + ", " + // data_format + SnapConst.writable; // writable + final String clause_1 = SnapConst.AST + "." + SnapConst.ID + " = " + SnapConst.LIST + "." + SnapConst.TAB_LIST[1]; - final String clause_2 = SnapConst.TABS[2] + "." + SnapConst.TAB_LIST[0] + " = " + SnapConst.TABS[1] + "." - + SnapConst.TAB_CONTEXT[0]; - final String clause_3 = SnapConst.TABS[1] + "." + SnapConst.TAB_CONTEXT[0] + " = ?"; + final String clause_2 = SnapConst.LIST + "." + SnapConst.TAB_LIST[0] + " = " + SnapConst.CONTEXT + "." + + SnapConst.ID_CONTEXT; + final String clause_3 = SnapConst.CONTEXT + "." + SnapConst.ID_CONTEXT + " = ?"; // the SQL request is : select DISTINCT full_name from snap.ast where // ast.id = list.id_att and list.id_context = context.id_context and // context.name = 'nom'; @@ -3730,7 +2849,7 @@ public class DataBaseAPI { + " AND " + clause_3; try { - conn = getConnection(); + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); preparedStatement.setInt(1, id_context); @@ -3738,11 +2857,11 @@ public class DataBaseAPI { // Gets the result of the query while (rset.next()) { final SnapAttributeLight snapAttributeLight = new SnapAttributeLight(); - snapAttributeLight.setAttributeCompleteName(rset.getString(SnapConst.TAB_DEF[2])); - snapAttributeLight.setAttributeId(rset.getInt(SnapConst.TAB_DEF[0])); - snapAttributeLight.setDataType(rset.getInt(SnapConst.TAB_DEF[8])); - snapAttributeLight.setDataFormat(rset.getInt(SnapConst.TAB_DEF[9])); - snapAttributeLight.setWritable(rset.getInt(SnapConst.TAB_DEF[10])); + snapAttributeLight.setAttributeCompleteName(rset.getString(SnapConst.fullName)); + snapAttributeLight.setAttributeId(rset.getInt(SnapConst.ID)); + snapAttributeLight.setDataType(rset.getInt(SnapConst.dataType)); + snapAttributeLight.setDataFormat(rset.getInt(SnapConst.dataFormat)); + snapAttributeLight.setWritable(rset.getInt(SnapConst.writable)); final SnapAttributeExtract attr = new SnapAttributeExtract(snapAttributeLight); // set default value attr.setValue(null, null); @@ -3772,7 +2891,7 @@ public class DataBaseAPI { final int id_context = snapContext.getId(); final List<SnapAttributeLight> attList = snapContext.getAttributeList(); PreparedStatement preparedStatement = null; - final String tableName = getDbSchema() + "." + SnapConst.TABS[2]; + final String tableName = getDbSchema() + "." + SnapConst.LIST; String query; final String insert_fields = SnapConst.TAB_LIST[0] + ", " + SnapConst.TAB_LIST[1]; @@ -3782,7 +2901,7 @@ public class DataBaseAPI { final String selectQuery = "select " + SnapConst.TAB_LIST[1] + " from " + tableName + " where " + SnapConst.TAB_LIST[0] + " = " + id_context; try { - conn = getConnection(); + conn = connector.getConnection(); prest = conn.prepareStatement(selectQuery); final ResultSet rs = prest.executeQuery(); final List<Integer> attributeIDList = new ArrayList<Integer>(); @@ -3840,9 +2959,9 @@ public class DataBaseAPI { */ public Snapshot createNewSnap(final int contextID, final Timestamp timestamp) throws SnapshotingException { Snapshot snapShot = new Snapshot(); - if (db_type == ConfigConst.BD_MYSQL) { + if (params.getDbType() == DataBaseType.MYSQL) { snapShot = createNewSnapMySQL(contextID, timestamp); - } else if (db_type == ConfigConst.BD_ORACLE) { + } else if (params.getDbType() == DataBaseType.ORACLE) { snapShot = createNewSnapOracle(contextID, timestamp); } return snapShot; @@ -3920,7 +3039,7 @@ public class DataBaseAPI { Connection conn = null; try { - conn = getConnection(); + conn = connector.getConnection(); cstmt_register_snapshot = conn.prepareCall(query); cstmt_register_snapshot.registerOutParameter(1, Types.INTEGER); cstmt_register_snapshot.setInt(2, contextID); @@ -3960,15 +3079,15 @@ public class DataBaseAPI { */ private void updateSnapContextID(final int id_snap, final int initial_context_value) throws SnapshotingException { PreparedStatement preparedStatement = null; - final String table = getDbSchema() + "." + SnapConst.TABS[3]; + final String table = getDbSchema() + "." + SnapConst.SNAPSHOT; final String setField = SnapConst.TAB_SNAP[1]; - final String refField = SnapConst.TAB_SNAP[0]; + final String refField = SnapConst.ID_SNAP; final String query = "UPDATE " + table + " SET " + setField + "=? " + "WHERE " + refField + "=?"; Connection conn = null; try { - conn = getConnection(); + conn = connector.getConnection(); // preparedStatement = dbconn.prepareStatement(query); preparedStatement = conn.prepareStatement(query); @@ -3998,13 +3117,13 @@ public class DataBaseAPI { public void updateSnapComment(final int id_snap, final String new_comment) throws SnapshotingException { PreparedStatement preparedStatement = null; Connection conn = null; - final String table = getDbSchema() + "." + SnapConst.TABS[3]; - final String setField = SnapConst.TAB_SNAP[3]; - final String refField = SnapConst.TAB_SNAP[0]; + final String table = getDbSchema() + "." + SnapConst.SNAPSHOT; + final String setField = SnapConst.snap_comment; + final String refField = SnapConst.ID_SNAP; final String query = "UPDATE " + table + " SET " + setField + " = '" + new_comment + "' WHERE " + refField + " = ?"; try { - conn = getConnection(); + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); preparedStatement.setInt(1, id_snap); preparedStatement.executeUpdate(); @@ -4032,13 +3151,13 @@ public class DataBaseAPI { Connection conn = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; - final String table = getDbSchema() + "." + SnapConst.TABS[3]; - final String commentColumn = SnapConst.TAB_SNAP[3]; - final String id = SnapConst.TAB_SNAP[0]; + final String table = getDbSchema() + "." + SnapConst.SNAPSHOT; + final String commentColumn = SnapConst.snap_comment; + final String id = SnapConst.ID_SNAP; final String query = "SELECT " + commentColumn + " FROM " + table + " WHERE " + id + " = " + snapID; String comment = ""; try { - conn = getConnection(); + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); resultSet = preparedStatement.executeQuery(); if (resultSet.next()) { @@ -4071,15 +3190,15 @@ public class DataBaseAPI { */ private int getSnapID(final int id_context) throws SnapshotingException { int idSnap = -1; - final String table = getDbSchema() + "." + SnapConst.TABS[3]; - final String selectField = SnapConst.TAB_SNAP[0]; + final String table = getDbSchema() + "." + SnapConst.SNAPSHOT; + final String selectField = SnapConst.ID_SNAP; final String clause_1 = SnapConst.TAB_SNAP[1] + "=?"; final String query = "SELECT " + selectField + " FROM " + table + " WHERE " + clause_1; PreparedStatement preparedStatement = null; ResultSet rset = null; Connection conn = null; try { - conn = getConnection(); + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); preparedStatement.setInt(1, id_context); rset = preparedStatement.executeQuery(); @@ -4116,14 +3235,14 @@ public class DataBaseAPI { private Timestamp registerSnap(final int id_context) throws SnapshotingException { final java.sql.Timestamp time = new java.sql.Timestamp(new java.util.Date().getTime()); PreparedStatement preparedStatement = null; - final String table = getDbSchema() + "." + SnapConst.TABS[3]; - final String insert_fields = SnapConst.TAB_SNAP[1] + ", " + SnapConst.TAB_SNAP[2]; + final String table = getDbSchema() + "." + SnapConst.SNAPSHOT; + final String insert_fields = SnapConst.TAB_SNAP[1] + ", " +SnapConst.time; final String insert_values = "?, ?"; final String query = "INSERT INTO " + table + " (" + insert_fields + ") VALUES(" + insert_values + ")"; Connection conn = null; try { - conn = getConnection(); + conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); // preparedStatement = conn.prepareStatement(query); preparedStatement.setInt(1, id_context); @@ -4181,4 +3300,77 @@ public class DataBaseAPI { } + private Object initPrimitiveArray(int dataType, int length) { + switch (dataType) { + case TangoConst.Tango_DEV_BOOLEAN: + return new boolean[length]; + case TangoConst.Tango_DEV_CHAR: + case TangoConst.Tango_DEV_UCHAR: + return new byte[length]; + case TangoConst.Tango_DEV_STATE: + case TangoConst.Tango_DEV_LONG: + case TangoConst.Tango_DEV_ULONG: + return new int[length]; + case TangoConst.Tango_DEV_SHORT: + case TangoConst.Tango_DEV_USHORT: + return new short[length]; + case TangoConst.Tango_DEV_FLOAT: + return new float[length]; + case TangoConst.Tango_DEV_STRING: + return new String[length]; + case TangoConst.Tango_DEV_DOUBLE: + default: + return new double[length]; + } + + } + + private Object castResultSetAsPrimitive(int dataType, ResultSet resultSet, int index) throws SQLException { + switch (dataType) { + case TangoConst.Tango_DEV_STRING: + return resultSet.getString(1); + case TangoConst.Tango_DEV_UCHAR: + case TangoConst.Tango_DEV_CHAR: + return resultSet.getByte(index); + case TangoConst.Tango_DEV_LONG: + case TangoConst.Tango_DEV_ULONG: + case TangoConst.Tango_DEV_STATE: + return resultSet.getInt(index); + case TangoConst.Tango_DEV_BOOLEAN: + return resultSet.getInt(index) != 0; + case TangoConst.Tango_DEV_SHORT: + case TangoConst.Tango_DEV_USHORT: + return resultSet.getShort(index); + case TangoConst.Tango_DEV_FLOAT: + return resultSet.getFloat(index); + case TangoConst.Tango_DEV_DOUBLE: + default: + return resultSet.getDouble(index); + } + } + + private Object castResultSetAsObject(int dataType, ResultSet resultSet, int index) throws SQLException { + switch (dataType) { + case TangoConst.Tango_DEV_STRING: + return resultSet.getString(1); + case TangoConst.Tango_DEV_UCHAR: + case TangoConst.Tango_DEV_CHAR: + return Byte.valueOf(resultSet.getByte(index)); + case TangoConst.Tango_DEV_LONG: + case TangoConst.Tango_DEV_ULONG: + case TangoConst.Tango_DEV_STATE: + return Integer.valueOf(resultSet.getInt(index)); + case TangoConst.Tango_DEV_BOOLEAN: + return Boolean.valueOf(resultSet.getInt(index) != 0); + case TangoConst.Tango_DEV_SHORT: + case TangoConst.Tango_DEV_USHORT: + return Short.valueOf(resultSet.getShort(index)); + case TangoConst.Tango_DEV_FLOAT: + return Float.valueOf(resultSet.getFloat(index)); + case TangoConst.Tango_DEV_DOUBLE: + default: + return Double.valueOf(resultSet.getDouble(index)); + } + } + } diff --git a/src/main/java/fr/soleil/archiving/snap/api/extractor/tools/Tools.java b/src/main/java/fr/soleil/archiving/snap/api/extractor/tools/Tools.java index 0ab5c25..e656eb8 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/extractor/tools/Tools.java +++ b/src/main/java/fr/soleil/archiving/snap/api/extractor/tools/Tools.java @@ -9,8 +9,8 @@ import fr.esrf.Tango.DevError; import fr.esrf.Tango.DevFailed; import fr.soleil.archiving.common.api.exception.ArchivingException; import fr.soleil.archiving.common.api.utils.DateUtil; -import fr.soleil.archiving.snap.api.ConfigConst; import fr.soleil.archiving.snap.api.manager.SnapManagerApi; +import fr.soleil.database.connection.DataBaseParameters.DataBaseType; /** * A class with a few exception handling methods. @@ -35,14 +35,14 @@ public class Tools { * @return A date as a String formated for the database. */ public static String formatDate(long milliseconds) { - int type = SnapManagerApi.getSnapDbType(); + DataBaseType type = SnapManagerApi.getSnapDbType(); String date = ""; switch (type) { - case ConfigConst.BD_ORACLE: + case ORACLE: date = DateUtil.milliToString(milliseconds, DateUtil.FR_DATE_PATTERN); break; - case ConfigConst.BD_MYSQL: + case MYSQL: default: date = DateUtil.milliToString(milliseconds, DateUtil.US_DATE_PATTERN); diff --git a/src/main/java/fr/soleil/archiving/snap/api/manager/SnapManagerApi.java b/src/main/java/fr/soleil/archiving/snap/api/manager/SnapManagerApi.java index 0df77bc..fdf5b82 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/manager/SnapManagerApi.java +++ b/src/main/java/fr/soleil/archiving/snap/api/manager/SnapManagerApi.java @@ -128,6 +128,7 @@ import fr.soleil.archiving.snap.api.tools.SnapContext; import fr.soleil.archiving.snap.api.tools.Snapshot; import fr.soleil.archiving.snap.api.tools.SnapshotLight; import fr.soleil.archiving.snap.api.tools.SnapshotingException; +import fr.soleil.database.connection.DataBaseParameters.DataBaseType; import fr.soleil.lib.project.math.NumberArrayUtils; public class SnapManagerApi { @@ -210,11 +211,11 @@ public class SnapManagerApi { /** * @return the snap database type (MySQL, ORACLE)... */ - public static int getSnapDbType() { + public static DataBaseType getSnapDbType() { if (snapDataBase != null) { return snapDataBase.getDb_type(); } - return -1; + return DataBaseType.UNKNOWN; } // ============================================================ @@ -369,14 +370,12 @@ public class SnapManagerApi { LOGGER.info(SnapConnectionParameters.appendSnapConnectionInfoLog(new StringBuilder("Connection info:\n")) .toString()); - snapDataBase.connect_auto(); } public static synchronized void initSnapConnection(final String host, final String name, final String schema, final String user, final String pass, final String isRac) throws SnapshotingException { snapDataBase = new DataBaseAPI(host, name, schema, user, pass, Boolean.parseBoolean(isRac)); - snapDataBase.connect_auto(); } /** diff --git a/src/main/java/fr/soleil/archiving/snap/api/manager/SnapManagerImpl.java b/src/main/java/fr/soleil/archiving/snap/api/manager/SnapManagerImpl.java index 6df0640..baf338d 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/manager/SnapManagerImpl.java +++ b/src/main/java/fr/soleil/archiving/snap/api/manager/SnapManagerImpl.java @@ -167,7 +167,7 @@ public class SnapManagerImpl implements ISnapManager { // Gets the snapshot identifier final Condition[] condition = new Condition[1]; - condition[0] = new Condition(SnapConst.TAB_SNAP[0], SnapConst.OP_EQUALS, snapId + ""); + condition[0] = new Condition(SnapConst.ID_SNAP, SnapConst.OP_EQUALS, snapId + ""); final Criterions criterions = new Criterions(condition); final SnapshotLight[] snapShotLight = findSnapshots(criterions); @@ -202,7 +202,7 @@ public class SnapManagerImpl implements ISnapManager { // Gets the updated snapshot final Condition[] condition = new Condition[1]; final String id_snap_str = "" + id_snap; - condition[0] = new Condition(SnapConst.TAB_SNAP[0], SnapConst.OP_EQUALS, id_snap_str); + condition[0] = new Condition(SnapConst.ID_SNAP, SnapConst.OP_EQUALS, id_snap_str); final Criterions criterions = new Criterions(condition); final SnapshotLight[] updatedContexts = findSnapshots(criterions); @@ -249,7 +249,7 @@ public class SnapManagerImpl implements ISnapManager { @Override public SnapAttributeExtract[] getSnap(final int id) throws SnapshotingException { - final Condition condition = new Condition(SnapConst.TAB_SNAP[0], "=", String.valueOf(id)); + final Condition condition = new Condition(SnapConst.ID_SNAP, "=", String.valueOf(id)); final Criterions searchCriterions = new Criterions(); searchCriterions.addCondition(condition); final SnapshotLight snapshotLight = new SnapshotLight(); diff --git a/src/main/java/fr/soleil/archiving/snap/api/tools/Criterions.java b/src/main/java/fr/soleil/archiving/snap/api/tools/Criterions.java index 0f6afe8..f8a6055 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/tools/Criterions.java +++ b/src/main/java/fr/soleil/archiving/snap/api/tools/Criterions.java @@ -150,7 +150,7 @@ public class Criterions { */ public String getContextClause() throws SnapshotingException { String clause = ""; - String table = SnapConst.TABS[1]; + String table = SnapConst.CONTEXT; String[] field = SnapConst.TAB_CONTEXT; int count = 0; // Cas de l'ID_context. @@ -213,7 +213,7 @@ public class Criterions { */ public String getSnapshotClause() throws SnapshotingException { String clause = ""; - String table = SnapConst.TABS[3]; + String table = SnapConst.SNAPSHOT; String[] field = SnapConst.TAB_SNAP; int count = 0; // Cas de l'id_snap. @@ -310,7 +310,7 @@ public class Criterions { public int getIdContextContextTable() throws SnapshotingException { int id_context = -1; // value if no condition on this id. - Condition[] id_condition = getConditions(SnapConst.TAB_CONTEXT[0]); + Condition[] id_condition = getConditions(SnapConst.ID_CONTEXT); if (id_condition != null) { id_context = Integer.parseInt(id_condition[0].getValue()); } @@ -326,7 +326,7 @@ public class Criterions { public int getIdSnap() throws SnapshotingException { int id_snap = -1; // value if no condition on this id. - Condition[] id_condition = getConditions(SnapConst.TAB_SNAP[0]); + Condition[] id_condition = getConditions(SnapConst.ID_SNAP); if (id_condition != null) { id_snap = Integer.parseInt(id_condition[0].getValue()); } @@ -343,7 +343,7 @@ public class Criterions { */ public String getAttributeClause() throws SnapshotingException { String clause = ""; - String table = SnapConst.TABS[0]; + String table = SnapConst.AST; String[] field = SnapConst.TAB_DEF; int count = 0; for (int i = 4; i < 8; i++) // Parcours des champs de la table des diff --git a/src/main/java/fr/soleil/archiving/snap/api/tools/ScalarEvent.java b/src/main/java/fr/soleil/archiving/snap/api/tools/ScalarEvent.java index 494e2db..367e7e4 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/tools/ScalarEvent.java +++ b/src/main/java/fr/soleil/archiving/snap/api/tools/ScalarEvent.java @@ -6,6 +6,7 @@ import fr.esrf.Tango.AttrDataFormat; import fr.esrf.Tango.AttrWriteType; import fr.esrf.Tango.DevState; import fr.esrf.TangoDs.TangoConst; +import fr.soleil.archiving.common.api.tools.GlobalConst; //+====================================================================== // $Source: /cvsroot/tango-cs/tango/api/java/fr/soleil/TangoSnapshoting/SnapshotingTools/Tools/ScalarEvent.java,v $ @@ -281,7 +282,7 @@ public class ScalarEvent extends SnapAttribute { value = ""; int[] tab = (int[]) getValue(); for (int i = 0; i < tab.length; i++) { - value += tab[i] + SnapConst.CLOB_SEPARATOR; + value += tab[i] + GlobalConst.CLOB_SEPARATOR; } if (tab.length > 0) { value = value.substring(0, value.length() - 1); @@ -373,7 +374,7 @@ public class ScalarEvent extends SnapAttribute { value = ""; int[] tab = (int[]) getValue(); for (int i = 0; i < tab.length; i++) { - value += tab[i] + SnapConst.CLOB_SEPARATOR; + value += tab[i] + GlobalConst.CLOB_SEPARATOR; } if (tab.length > 0) { value = value.substring(0, value.length() - 1); diff --git a/src/main/java/fr/soleil/archiving/snap/api/tools/SnapAttributeExtract.java b/src/main/java/fr/soleil/archiving/snap/api/tools/SnapAttributeExtract.java index 4b4fcf6..e5af9c4 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/tools/SnapAttributeExtract.java +++ b/src/main/java/fr/soleil/archiving/snap/api/tools/SnapAttributeExtract.java @@ -89,6 +89,7 @@ import fr.esrf.Tango.AttrDataFormat; import fr.esrf.Tango.AttrWriteType; import fr.esrf.TangoApi.DeviceData; import fr.esrf.TangoDs.TangoConst; +import fr.soleil.archiving.common.api.tools.GlobalConst; public class SnapAttributeExtract extends SnapAttribute { @@ -345,7 +346,7 @@ public class SnapAttributeExtract extends SnapAttribute { break; } stringArrayWrite = toSplitWrite.substring(1, toSplitWrite.length() - 1).split( - SnapConst.CLOB_SEPARATOR); + GlobalConst.CLOB_SEPARATOR); switch (dataType) { case TangoConst.Tango_DEV_BOOLEAN: value = new boolean[stringArrayWrite.length]; @@ -407,7 +408,7 @@ public class SnapAttributeExtract extends SnapAttribute { break; } stringArrayRead = toSplitRead.substring(1, toSplitRead.length() - 1).split( - SnapConst.CLOB_SEPARATOR); + GlobalConst.CLOB_SEPARATOR); switch (dataType) { case TangoConst.Tango_DEV_BOOLEAN: value = new boolean[stringArrayRead.length]; @@ -477,9 +478,9 @@ public class SnapAttributeExtract extends SnapAttribute { break; } stringArrayRead = toSplitRead.substring(1, toSplitRead.length() - 1).split( - SnapConst.CLOB_SEPARATOR); + GlobalConst.CLOB_SEPARATOR); stringArrayWrite = toSplitWrite.substring(1, toSplitWrite.length() - 1).split( - SnapConst.CLOB_SEPARATOR); + GlobalConst.CLOB_SEPARATOR); value = new Object[2]; switch (dataType) { case TangoConst.Tango_DEV_BOOLEAN: @@ -638,7 +639,7 @@ public class SnapAttributeExtract extends SnapAttribute { final boolean[] valb = (boolean[]) getValue(); if (valb != null && valb.length > 0) { for (int i = 0; i < valb.length - 1; i++) { - value += valb[i] + SnapConst.CLOB_SEPARATOR; + value += valb[i] + GlobalConst.CLOB_SEPARATOR; } value += valb[valb.length - 1]; } @@ -647,7 +648,7 @@ public class SnapAttributeExtract extends SnapAttribute { final String[] valstr = (String[]) getValue(); if (valstr != null && valstr.length > 0) { for (int i = 0; i < valstr.length - 1; i++) { - value += valstr[i] + SnapConst.CLOB_SEPARATOR; + value += valstr[i] + GlobalConst.CLOB_SEPARATOR; } value += valstr[valstr.length - 1]; } @@ -657,7 +658,7 @@ public class SnapAttributeExtract extends SnapAttribute { final byte[] valc = (byte[]) getValue(); if (valc != null && valc.length > 0) { for (int i = 0; i < valc.length - 1; i++) { - value += valc[i] + SnapConst.CLOB_SEPARATOR; + value += valc[i] + GlobalConst.CLOB_SEPARATOR; } value += valc[valc.length - 1]; } @@ -668,7 +669,7 @@ public class SnapAttributeExtract extends SnapAttribute { final int[] vall = (int[]) getValue(); if (vall != null && vall.length > 0) { for (int i = 0; i < vall.length - 1; i++) { - value += vall[i] + SnapConst.CLOB_SEPARATOR; + value += vall[i] + GlobalConst.CLOB_SEPARATOR; } value += vall[vall.length - 1]; } @@ -678,7 +679,7 @@ public class SnapAttributeExtract extends SnapAttribute { final short[] vals = (short[]) getValue(); if (vals != null && vals.length > 0) { for (int i = 0; i < vals.length - 1; i++) { - value += vals[i] + SnapConst.CLOB_SEPARATOR; + value += vals[i] + GlobalConst.CLOB_SEPARATOR; } value += vals[vals.length - 1]; } @@ -687,7 +688,7 @@ public class SnapAttributeExtract extends SnapAttribute { final float[] valf = (float[]) getValue(); if (valf != null && valf.length > 0) { for (int i = 0; i < valf.length - 1; i++) { - value += valf[i] + SnapConst.CLOB_SEPARATOR; + value += valf[i] + GlobalConst.CLOB_SEPARATOR; } value += valf[valf.length - 1]; } @@ -696,7 +697,7 @@ public class SnapAttributeExtract extends SnapAttribute { final double[] vald = (double[]) getValue(); if (vald != null && vald.length > 0) { for (int i = 0; i < vald.length - 1; i++) { - value += vald[i] + SnapConst.CLOB_SEPARATOR; + value += vald[i] + GlobalConst.CLOB_SEPARATOR; } value += vald[vald.length - 1]; } @@ -713,7 +714,7 @@ public class SnapAttributeExtract extends SnapAttribute { final boolean[] valb = (boolean[]) temp[pos]; if (valb != null && valb.length > 0) { for (int i = 0; i < valb.length - 1; i++) { - value += valb[i] + SnapConst.CLOB_SEPARATOR; + value += valb[i] + GlobalConst.CLOB_SEPARATOR; } value += valb[valb.length - 1]; } @@ -722,7 +723,7 @@ public class SnapAttributeExtract extends SnapAttribute { final String[] valstr = (String[]) temp[pos]; if (valstr != null && valstr.length > 0) { for (int i = 0; i < valstr.length - 1; i++) { - value += valstr[i] + SnapConst.CLOB_SEPARATOR; + value += valstr[i] + GlobalConst.CLOB_SEPARATOR; } value += valstr[valstr.length - 1]; } @@ -732,7 +733,7 @@ public class SnapAttributeExtract extends SnapAttribute { final byte[] valc = (byte[]) temp[pos]; if (valc != null && valc.length > 0) { for (int i = 0; i < valc.length - 1; i++) { - value += valc[i] + SnapConst.CLOB_SEPARATOR; + value += valc[i] + GlobalConst.CLOB_SEPARATOR; } value += valc[valc.length - 1]; } @@ -743,7 +744,7 @@ public class SnapAttributeExtract extends SnapAttribute { final int[] vall = (int[]) temp[pos]; if (vall != null && vall.length > 0) { for (int i = 0; i < vall.length - 1; i++) { - value += vall[i] + SnapConst.CLOB_SEPARATOR; + value += vall[i] + GlobalConst.CLOB_SEPARATOR; } value += vall[vall.length - 1]; } @@ -753,7 +754,7 @@ public class SnapAttributeExtract extends SnapAttribute { final short[] vals = (short[]) temp[pos]; if (vals != null && vals.length > 0) { for (int i = 0; i < vals.length - 1; i++) { - value += vals[i] + SnapConst.CLOB_SEPARATOR; + value += vals[i] + GlobalConst.CLOB_SEPARATOR; } value += vals[vals.length - 1]; } @@ -762,7 +763,7 @@ public class SnapAttributeExtract extends SnapAttribute { final float[] valf = (float[]) temp[pos]; if (valf != null && valf.length > 0) { for (int i = 0; i < valf.length - 1; i++) { - value += valf[i] + SnapConst.CLOB_SEPARATOR; + value += valf[i] + GlobalConst.CLOB_SEPARATOR; } value += valf[valf.length - 1]; } @@ -771,7 +772,7 @@ public class SnapAttributeExtract extends SnapAttribute { final double[] vald = (double[]) temp[pos]; if (vald != null && vald.length > 0) { for (int i = 0; i < vald.length - 1; i++) { - value += vald[i] + SnapConst.CLOB_SEPARATOR; + value += vald[i] + GlobalConst.CLOB_SEPARATOR; } value += vald[vald.length - 1]; } @@ -789,7 +790,7 @@ public class SnapAttributeExtract extends SnapAttribute { final boolean[] valb = (boolean[]) getValue(); if (valb != null && valb.length > 0) { for (int i = 0; i < valb.length - 1; i++) { - value += valb[i] + SnapConst.CLOB_SEPARATOR; + value += valb[i] + GlobalConst.CLOB_SEPARATOR; } value += valb[valb.length - 1]; } @@ -798,7 +799,7 @@ public class SnapAttributeExtract extends SnapAttribute { final String[] valstr = (String[]) getValue(); if (valstr != null && valstr.length > 0) { for (int i = 0; i < valstr.length - 1; i++) { - value += valstr[i] + SnapConst.CLOB_SEPARATOR; + value += valstr[i] + GlobalConst.CLOB_SEPARATOR; } value += valstr[valstr.length - 1]; } @@ -808,7 +809,7 @@ public class SnapAttributeExtract extends SnapAttribute { final byte[] valc = (byte[]) getValue(); if (valc != null) { for (int i = 0; i < valc.length - 1; i++) { - value += valc[i] + SnapConst.CLOB_SEPARATOR; + value += valc[i] + GlobalConst.CLOB_SEPARATOR; } value += valc[valc.length - 1]; } @@ -818,7 +819,7 @@ public class SnapAttributeExtract extends SnapAttribute { final int[] vall = (int[]) getValue(); if (vall != null && vall.length > 0) { for (int i = 0; i < vall.length - 1; i++) { - value += vall[i] + SnapConst.CLOB_SEPARATOR; + value += vall[i] + GlobalConst.CLOB_SEPARATOR; } value += vall[vall.length - 1]; } @@ -828,7 +829,7 @@ public class SnapAttributeExtract extends SnapAttribute { final short[] vals = (short[]) getValue(); if (vals != null && vals.length > 0) { for (int i = 0; i < vals.length - 1; i++) { - value += vals[i] + SnapConst.CLOB_SEPARATOR; + value += vals[i] + GlobalConst.CLOB_SEPARATOR; } value += vals[vals.length - 1]; } @@ -837,7 +838,7 @@ public class SnapAttributeExtract extends SnapAttribute { final float[] valf = (float[]) getValue(); if (valf != null && valf.length > 0) { for (int i = 0; i < valf.length - 1; i++) { - value += valf[i] + SnapConst.CLOB_SEPARATOR; + value += valf[i] + GlobalConst.CLOB_SEPARATOR; } value += valf[valf.length - 1]; } @@ -846,7 +847,7 @@ public class SnapAttributeExtract extends SnapAttribute { final double[] vald = (double[]) getValue(); if (vald != null && vald.length > 0) { for (int i = 0; i < vald.length - 1; i++) { - value += vald[i] + SnapConst.CLOB_SEPARATOR; + value += vald[i] + GlobalConst.CLOB_SEPARATOR; } value += vald[vald.length - 1]; } @@ -863,7 +864,7 @@ public class SnapAttributeExtract extends SnapAttribute { final boolean[] valb = (boolean[]) temp[pos]; if (valb != null && valb.length > 0) { for (int i = 0; i < valb.length - 1; i++) { - value += valb[i] + SnapConst.CLOB_SEPARATOR; + value += valb[i] + GlobalConst.CLOB_SEPARATOR; } value += valb[valb.length - 1]; } @@ -872,7 +873,7 @@ public class SnapAttributeExtract extends SnapAttribute { final String[] valstr = (String[]) temp[pos]; if (valstr != null && valstr.length > 0) { for (int i = 0; i < valstr.length - 1; i++) { - value += valstr[i] + SnapConst.CLOB_SEPARATOR; + value += valstr[i] + GlobalConst.CLOB_SEPARATOR; } value += valstr[valstr.length - 1]; } @@ -882,7 +883,7 @@ public class SnapAttributeExtract extends SnapAttribute { final byte[] valc = (byte[]) temp[pos]; if (valc != null && valc.length > 0) { for (int i = 0; i < valc.length - 1; i++) { - value += valc[i] + SnapConst.CLOB_SEPARATOR; + value += valc[i] + GlobalConst.CLOB_SEPARATOR; } value += valc[valc.length - 1]; } @@ -892,7 +893,7 @@ public class SnapAttributeExtract extends SnapAttribute { final int[] vall = (int[]) temp[pos]; if (vall != null && vall.length > 0) { for (int i = 0; i < vall.length - 1; i++) { - value += vall[i] + SnapConst.CLOB_SEPARATOR; + value += vall[i] + GlobalConst.CLOB_SEPARATOR; } value += vall[vall.length - 1]; } @@ -902,7 +903,7 @@ public class SnapAttributeExtract extends SnapAttribute { final short[] vals = (short[]) temp[pos]; if (vals != null && vals.length > 0) { for (int i = 0; i < vals.length - 1; i++) { - value += vals[i] + SnapConst.CLOB_SEPARATOR; + value += vals[i] + GlobalConst.CLOB_SEPARATOR; } value += vals[vals.length - 1]; } @@ -911,7 +912,7 @@ public class SnapAttributeExtract extends SnapAttribute { final float[] valf = (float[]) temp[pos]; if (valf != null && valf.length > 0) { for (int i = 0; i < valf.length - 1; i++) { - value += valf[i] + SnapConst.CLOB_SEPARATOR; + value += valf[i] + GlobalConst.CLOB_SEPARATOR; } value += valf[valf.length - 1]; } @@ -920,7 +921,7 @@ public class SnapAttributeExtract extends SnapAttribute { final double[] vald = (double[]) temp[pos]; if (vald != null && vald.length > 0) { for (int i = 0; i < vald.length - 1; i++) { - value += vald[i] + SnapConst.CLOB_SEPARATOR; + value += vald[i] + GlobalConst.CLOB_SEPARATOR; } value += vald[vald.length - 1]; } @@ -1124,107 +1125,16 @@ public class SnapAttributeExtract extends SnapAttribute { switch (writable) { case AttrWriteType._READ: break; - case AttrWriteType._READ_WITH_WRITE: - switch (dataType) { - case TangoConst.Tango_DEV_STRING: - write_value = Array.get(getValue(), 1); - break; - case TangoConst.Tango_DEV_STATE: - write_value = Array.get(getValue(), 1); - break; - case TangoConst.Tango_DEV_UCHAR: - write_value = Array.get(getValue(), 1); - break; - case TangoConst.Tango_DEV_LONG: - write_value = Array.get(getValue(), 1); - break; - case TangoConst.Tango_DEV_ULONG: - write_value = Array.get(getValue(), 1); - break; - case TangoConst.Tango_DEV_BOOLEAN: - write_value = Array.get(getValue(), 1); - break; - case TangoConst.Tango_DEV_SHORT: - write_value = Array.get(getValue(), 1); - break; - case TangoConst.Tango_DEV_FLOAT: - write_value = Array.get(getValue(), 1); - break; - case TangoConst.Tango_DEV_DOUBLE: - write_value = Array.get(getValue(), 1); - break; - default: - write_value = Array.get(getValue(), 1); - break; - } + case AttrWriteType._READ_WRITE: + case AttrWriteType._READ_WITH_WRITE: + if (getValue() == null) { + write_value = null; + } else { + write_value = Array.get(getValue(), 1); + } break; case AttrWriteType._WRITE: - switch (dataType) { - case TangoConst.Tango_DEV_STRING: - write_value = getValue(); - break; - case TangoConst.Tango_DEV_STATE: - write_value = getValue(); - break; - case TangoConst.Tango_DEV_UCHAR: - write_value = getValue(); - break; - case TangoConst.Tango_DEV_LONG: - write_value = getValue(); - break; - case TangoConst.Tango_DEV_ULONG: - write_value = getValue(); - break; - case TangoConst.Tango_DEV_BOOLEAN: - write_value = getValue(); - break; - case TangoConst.Tango_DEV_SHORT: - write_value = getValue(); - break; - case TangoConst.Tango_DEV_FLOAT: - write_value = getValue(); - break; - case TangoConst.Tango_DEV_DOUBLE: - write_value = getValue(); - break; - default: - write_value = getValue(); - break; - } - break; - case AttrWriteType._READ_WRITE: - switch (dataType) { - case TangoConst.Tango_DEV_STRING: - write_value = Array.get(getValue(), 1); - break; - case TangoConst.Tango_DEV_STATE: - write_value = Array.get(getValue(), 1); - break; - case TangoConst.Tango_DEV_UCHAR: - write_value = Array.get(getValue(), 1); - break; - case TangoConst.Tango_DEV_LONG: - write_value = Array.get(getValue(), 1); - break; - case TangoConst.Tango_DEV_ULONG: - write_value = Array.get(getValue(), 1); - break; - case TangoConst.Tango_DEV_BOOLEAN: - write_value = Array.get(getValue(), 1); - break; - case TangoConst.Tango_DEV_SHORT: - write_value = Array.get(getValue(), 1); - break; - case TangoConst.Tango_DEV_FLOAT: - write_value = Array.get(getValue(), 1); - break; - case TangoConst.Tango_DEV_DOUBLE: - write_value = Array.get(getValue(), 1); - break; - default: - write_value = Array.get(getValue(), 1); - break; - } + write_value = getValue(); break; } break; @@ -1265,14 +1175,12 @@ public class SnapAttributeExtract extends SnapAttribute { case AttrWriteType._READ: break; case AttrWriteType._READ_WITH_WRITE: + case AttrWriteType._READ_WRITE: nullWrite = Array.get(nullElements, 1); break; case AttrWriteType._WRITE: nullWrite = nullElements; break; - case AttrWriteType._READ_WRITE: - nullWrite = Array.get(nullElements, 1); - break; } } return nullWrite; @@ -1288,109 +1196,18 @@ public class SnapAttributeExtract extends SnapAttribute { case AttrDataFormat._SCALAR: switch (writable) { case AttrWriteType._READ: - switch (dataType) { - case TangoConst.Tango_DEV_STRING: - read_value = getValue(); - break; - case TangoConst.Tango_DEV_STATE: - read_value = getValue(); - break; - case TangoConst.Tango_DEV_UCHAR: - read_value = getValue(); - break; - case TangoConst.Tango_DEV_LONG: - read_value = getValue(); - break; - case TangoConst.Tango_DEV_ULONG: - read_value = getValue(); - break; - case TangoConst.Tango_DEV_BOOLEAN: - read_value = getValue(); - break; - case TangoConst.Tango_DEV_SHORT: - read_value = getValue(); - break; - case TangoConst.Tango_DEV_FLOAT: - read_value = getValue(); - break; - case TangoConst.Tango_DEV_DOUBLE: - read_value = getValue(); - break; - default: - read_value = getValue(); - break; - } + read_value = getValue(); break; case AttrWriteType._READ_WITH_WRITE: - switch (dataType) { - case TangoConst.Tango_DEV_STRING: - read_value = Array.get(getValue(), 0); - break; - case TangoConst.Tango_DEV_STATE: - read_value = Array.get(getValue(), 0); - break; - case TangoConst.Tango_DEV_UCHAR: - read_value = Array.get(getValue(), 0); - break; - case TangoConst.Tango_DEV_LONG: - read_value = Array.get(getValue(), 0); - break; - case TangoConst.Tango_DEV_ULONG: - read_value = Array.get(getValue(), 0); - break; - case TangoConst.Tango_DEV_BOOLEAN: - read_value = Array.get(getValue(), 0); - break; - case TangoConst.Tango_DEV_SHORT: - read_value = Array.get(getValue(), 0); - break; - case TangoConst.Tango_DEV_FLOAT: - read_value = Array.get(getValue(), 0); - break; - case TangoConst.Tango_DEV_DOUBLE: - read_value = Array.get(getValue(), 0); - break; - default: - read_value = Array.get(getValue(), 0); - break; - } + case AttrWriteType._READ_WRITE: + if (getValue() == null) { + read_value = null; + } else { + read_value = Array.get(getValue(), 0); + } break; case AttrWriteType._WRITE: break; - case AttrWriteType._READ_WRITE: - switch (dataType) { - case TangoConst.Tango_DEV_STRING: - read_value = Array.get(getValue(), 0); - break; - case TangoConst.Tango_DEV_STATE: - read_value = Array.get(getValue(), 0); - break; - case TangoConst.Tango_DEV_UCHAR: - read_value = Array.get(getValue(), 0); - break; - case TangoConst.Tango_DEV_LONG: - read_value = Array.get(getValue(), 0); - break; - case TangoConst.Tango_DEV_ULONG: - read_value = Array.get(getValue(), 0); - break; - case TangoConst.Tango_DEV_BOOLEAN: - read_value = Array.get(getValue(), 0); - break; - case TangoConst.Tango_DEV_SHORT: - read_value = Array.get(getValue(), 0); - break; - case TangoConst.Tango_DEV_FLOAT: - read_value = Array.get(getValue(), 0); - break; - case TangoConst.Tango_DEV_DOUBLE: - read_value = Array.get(getValue(), 0); - break; - default: - read_value = Array.get(getValue(), 0); - break; - } - break; } break; case AttrDataFormat._SPECTRUM: @@ -1484,7 +1301,7 @@ public class SnapAttributeExtract extends SnapAttribute { break; // End of case AttrDataFormat._SCALAR case AttrDataFormat._SPECTRUM: { - final String[] stringTable = stringValue.split(SnapConst.CLOB_SEPARATOR_IMAGE_COLS); + final String[] stringTable = stringValue.split(GlobalConst.CLOB_SEPARATOR_IMAGE_COLS); Object newTable = null; switch (dataType) { case TangoConst.Tango_DEV_BOOLEAN: { @@ -1553,9 +1370,9 @@ public class SnapAttributeExtract extends SnapAttribute { case AttrDataFormat._IMAGE: { final String[][] stringMatrix = new String[dimX][dimX]; - final String[] stringTable = stringValue.split(SnapConst.CLOB_SEPARATOR_IMAGE_ROWS); + final String[] stringTable = stringValue.split(GlobalConst.CLOB_SEPARATOR_IMAGE_ROWS); for (int i = 0; i < stringTable.length; i++) { - stringMatrix[i] = stringTable[i].split(SnapConst.CLOB_SEPARATOR_IMAGE_COLS); + stringMatrix[i] = stringTable[i].split(GlobalConst.CLOB_SEPARATOR_IMAGE_COLS); } Object[] newMatrix = null; diff --git a/src/main/java/fr/soleil/archiving/snap/api/tools/SnapConst.java b/src/main/java/fr/soleil/archiving/snap/api/tools/SnapConst.java index 1f04539..120c82b 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/tools/SnapConst.java +++ b/src/main/java/fr/soleil/archiving/snap/api/tools/SnapConst.java @@ -135,15 +135,23 @@ public class SnapConst { * |||||||||||||||||||||||||||||||||||||||||||||||||||||||||| * |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| */ - public static final String[] TABS = { "ast", "context", "list", "snapshot", // 0 - // -> - // 3 - "t_im_1val", "t_im_2val", // 4 -> 5 - "t_sp_1val", "t_sp_2val", // 6 -> 7 - "t_sc_num_1val", "t_sc_num_2val", // 8 -> 9 - "t_sc_str_1val", "t_sc_str_2val" }; // 10 -> 11 + - public static final String[] TAB_DEF = { "ID", "time", "full_name", "device", // 0 + public static final String AST = "ast"; + public static final String CONTEXT = "context"; + public static final String LIST = "list"; + public static final String SNAPSHOT = "snapshot"; + public static final String T_IM_1VAL = "t_im_1val"; + public static final String T_IM_2VAL = "t_im_2val"; + public static final String T_SP_1VAL = "t_sp_1val"; + public static final String T_SP_2VAL = "t_sp_2val"; + public static final String T_SC_NUM_1VAL = "t_sc_num_1val"; + public static final String T_SC_NUM_2VAL = "t_sc_num_2val"; + public static final String T_SC_STR_1VAL = "t_sc_str_1val"; + public static final String T_SC_STR_2VAL = "t_sc_str_2val"; + + + public static final String[] TAB_DEF = { "ID", "time", "full_name", "device", // 0 // -> // 3 "domain", "family", "member", "att_name", // 4 -> 7 @@ -151,96 +159,130 @@ public class SnapConst { "max_dim_x", "max_dim_y", // 11 -> 12 "levelg", "facility", "archivable", "substitute" }; // 13 -> 16 + public static final String ID = "ID"; + public static final String time = "time"; + + public static final String fullName = "full_name"; + public static final String device = "device"; + public static final String domain = "domain"; + public static final String family = "family"; + public static final String member = "member"; + public static final String attName = "att_name"; + public static final String dataType = "data_type"; + public static final String dataFormat = "data_format"; + public static final String writable = "writable"; + + public static final String max_dim_x = "max_dim_x"; + public static final String max_dim_y = "max_dim_y"; + + public static final String levelg = "levelg"; + public static final String facility = "facility"; + public static final String archivable = "archivable"; + public static final String substitute = "substitute"; + + public static final String status = "status"; + public static final String maxtime = "maxtime"; + public static final String[] TAB_SNAP = { "id_snap", "id_context", "time", "snap_comment" }; // 0 + public static final String ID_SNAP = "id_snap"; + public static final String snap_comment = "snap_comment"; // -> // 3 /** * Array that contains the name's fields for the HDB Mode Table */ public static final String[] TAB_CONTEXT = { "ID_context", "time", "name", "author", "reason", "description" }; // 0 + public static final String ID_CONTEXT = "ID_context"; + public static final String name = "name"; + public static final String author = "author"; + public static final String reason = "reason"; + public static final String description = "description"; // -> // 5 /** * Array that contains the name's fields for the HDB Mode Table */ - public static final String[] TAB_LIST = { "id_context", "id_att" }; // 0 -> + public static final String ID_ATT = "id_att"; + public static final String[] TAB_LIST = { ID_CONTEXT, ID_ATT }; // 0 -> + // 2 /** * Array that contains the name's fields for the Scalar_Read Attribute's * Table */ - public static final String[] TAB_SC_RO_NUM = { "id_snap", "id_att", "value" }; - /** - * Array that contains the name's fields for the Scalar_Read Attribute's - * Table - */ - public static final String[] TAB_SC_RO_STR = { "id_snap", "id_att", "value" }; - /** - * Array that contains the name's fields for the Scalar_Read Attribute's - * Table - */ - public static final String[] TAB_SC_WO_NUM = { "id_snap", "id_att", "value" }; - /** - * Array that contains the name's fields for the Scalar_Read Attribute's - * Table - */ - public static final String[] TAB_SC_WO_STR = { "id_snap", "id_att", "value" }; - /** - * Array that contains the name's fields for the Scalar_ReadWrite - * Attribute's Table - */ - public static final String[] TAB_SC_RW_NUM = { "id_snap", "id_att", "read_value", "write_value" }; - /** - * Array that contains the name's fields for the Scalar_Read Attribute's - * Table - */ - public static final String[] TAB_SC_RW_STR = { "id_snap", "id_att", "read_value", "write_value" }; - /** - * Array that contains the name's fields for the Scalar_ReadWrite - * Attribute's Table - */ - // public static final String[] TAB_SP_RO_NUM = {"id_snap", "id_att", - // "value"}; - public static final String[] TAB_SP_RO_NUM = { "id_snap", "id_att", "dim_x", "value" }; - /** - * Array that contains the name's fields for the Scalar_Read Attribute's - * Table - */ - public static final String[] TAB_SP_RO_STR = { "id_snap", "id_att", "dim_x", "value" }; - /** - * Array that contains the name's fields for the Scalar_ReadWrite - * Attribute's Table - */ - public static final String[] TAB_SP_RW_NUM = { "id_snap", "id_att", "dim_x", "read_value", "write_value" }; - /** - * Array that contains the name's fields for the Scalar_Read Attribute's - * Table - */ - public static final String[] TAB_SP_RW_STR = { "id_snap", "id_att", "dim_x", "read_value", "write_value" }; - /** - * Array that contains the name's fields for the Scalar_ReadWrite - * Attribute's Table - */ - public static final String[] TAB_IM_RO_NUM = { "id_snap", "id_att", "dim_x", "dim_y", "value" }; - /** - * Array that contains the name's fields for the Scalar_Read Attribute's - * Table - */ - public static final String[] TAB_IM_RO_STR = { "id_snap", "id_att", "dim_x", "dim_y", "value" }; - /** - * Array that contains the name's fields for the Scalar_ReadWrite - * Attribute's Table - */ - public static final String[] TAB_IM_RW_NUM = { "id_snap", "id_att", "dim_x", "dim_y", "read_value", "write_value" }; - /** - * Array that contains the name's fields for the Scalar_Read Attribute's - * Table - */ - public static final String[] TAB_IM_RW_STR = { "id_snap", "id_att", "read_value", "write_value" }; + public static final String value = "value"; + public static final String read_value = "read_value"; + public static final String write_value = "write_value"; + public static final String dim_x = "dim_x"; + public static final String dim_y = "dim_y"; +// public static final String[] TAB_SC_RO_NUM = { ID_SNAP, ID_ATT, value }; +// +// /** +// * Array that contains the name's fields for the Scalar_Read Attribute's +// * Table +// */ +// public static final String[] TAB_SC_RO_STR = { ID_SNAP, ID_ATT, value }; +// /** +// * Array that contains the name's fields for the Scalar_Read Attribute's +// * Table +// */ +// public static final String[] TAB_SC_WO_NUM = { ID_SNAP, ID_ATT, value }; +// /** +// * Array that contains the name's fields for the Scalar_Read Attribute's +// * Table +// */ +// public static final String[] TAB_SC_WO_STR = { ID_SNAP, ID_ATT, value }; +// /** +// * Array that contains the name's fields for the Scalar_ReadWrite +// * Attribute's Table +// */ +// public static final String[] TAB_SC_RW_NUM = { ID_SNAP, ID_ATT, read_value, write_value }; +// /** +// * Array that contains the name's fields for the Scalar_Read Attribute's +// * Table +// */ +// public static final String[] TAB_SC_RW_STR = { ID_SNAP, ID_ATT, read_value, write_value }; +// /** +// * Array that contains the name's fields for the Scalar_ReadWrite +// * Attribute's Table +// */ +// public static final String[] TAB_SP_RO_NUM = { ID_SNAP, ID_ATT, dim_x, value }; +// /** +// * Array that contains the name's fields for the Scalar_Read Attribute's +// * Table +// */ +// public static final String[] TAB_SP_RO_STR = { ID_SNAP, ID_ATT, dim_x, value }; +// /** +// * Array that contains the name's fields for the Scalar_ReadWrite +// * Attribute's Table +// */ +// public static final String[] TAB_SP_RW_NUM = { ID_SNAP, ID_ATT, dim_x, read_value, write_value }; +// /** +// * Array that contains the name's fields for the Scalar_Read Attribute's +// * Table +// */ +// public static final String[] TAB_SP_RW_STR = { ID_SNAP, ID_ATT, dim_x, read_value, write_value }; +// /** +// * Array that contains the name's fields for the Scalar_ReadWrite +// * Attribute's Table +// */ +// public static final String[] TAB_IM_RO_NUM = { ID_SNAP, ID_ATT, dim_x, dim_y, value }; +// /** +// * Array that contains the name's fields for the Scalar_Read Attribute's +// * Table +// */ +// public static final String[] TAB_IM_RO_STR = { ID_SNAP, ID_ATT, dim_x, dim_y, value }; +// /** +// * Array that contains the name's fields for the Scalar_ReadWrite +// * Attribute's Table +// */ +// public static final String[] TAB_IM_RW_NUM = { ID_SNAP, ID_ATT, dim_x, dim_y, read_value, write_value }; +// /** +// * Array that contains the name's fields for the Scalar_Read Attribute's +// * Table +// */ +// public static final String[] TAB_IM_RW_STR = { ID_SNAP, ID_ATT, read_value, write_value }; - public static final String CLOB_SEPARATOR = ","; - public static final String CLOB_SEPARATOR_IMAGE_COLS = ","; - public static final String CLOB_SEPARATOR_IMAGE_ROWS = "~"; public static final String STORED_READ_VALUE = "STORED_READ_VALUE"; public static final String STORED_WRITE_VALUE = "STORED_WRITE_VALUE"; diff --git a/src/main/java/fr/soleil/archiving/snap/api/tools/SnapSpectrumEvent_RW.java b/src/main/java/fr/soleil/archiving/snap/api/tools/SnapSpectrumEvent_RW.java index 92300d1..ffa0425 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/tools/SnapSpectrumEvent_RW.java +++ b/src/main/java/fr/soleil/archiving/snap/api/tools/SnapSpectrumEvent_RW.java @@ -21,6 +21,8 @@ package fr.soleil.archiving.snap.api.tools; import java.sql.Timestamp; import java.util.Arrays; +import fr.soleil.archiving.common.api.tools.GlobalConst; + /** * @author SOLEIL */ @@ -73,37 +75,37 @@ public class SnapSpectrumEvent_RW extends SnapAttribute { StringBuilder valueStr = new StringBuilder(); if (value instanceof double[]) { for (int i = 0; i < ((double[]) value).length - 1; i++) { - valueStr.append(((double[]) value)[i]).append(SnapConst.CLOB_SEPARATOR); + valueStr.append(((double[]) value)[i]).append(GlobalConst.CLOB_SEPARATOR); } valueStr.append(((double[]) value)[((double[]) value).length - 1]); } else if (value instanceof byte[]) { for (int i = 0; i < ((byte[]) value).length - 1; i++) { - valueStr.append(((byte[]) value)[i]).append(SnapConst.CLOB_SEPARATOR); + valueStr.append(((byte[]) value)[i]).append(GlobalConst.CLOB_SEPARATOR); } valueStr.append(((byte[]) value)[((byte[]) value).length - 1]); } else if (value instanceof short[]) { for (int i = 0; i < ((short[]) value).length - 1; i++) { - valueStr.append(((short[]) value)[i]).append(SnapConst.CLOB_SEPARATOR); + valueStr.append(((short[]) value)[i]).append(GlobalConst.CLOB_SEPARATOR); } valueStr.append(((short[]) value)[((short[]) value).length - 1]); } else if (value instanceof int[]) { for (int i = 0; i < ((int[]) value).length - 1; i++) { - valueStr.append(((int[]) value)[i]).append(SnapConst.CLOB_SEPARATOR); + valueStr.append(((int[]) value)[i]).append(GlobalConst.CLOB_SEPARATOR); } valueStr.append(((int[]) value)[((int[]) value).length - 1]); } else if (value instanceof float[]) { for (int i = 0; i < ((float[]) value).length - 1; i++) { - valueStr.append(((float[]) value)[i]).append(SnapConst.CLOB_SEPARATOR); + valueStr.append(((float[]) value)[i]).append(GlobalConst.CLOB_SEPARATOR); } valueStr.append(((float[]) value)[((float[]) value).length - 1]); } else if (value instanceof boolean[]) { for (int i = 0; i < ((boolean[]) value).length - 1; i++) { - valueStr.append(((boolean[]) value)[i]).append(SnapConst.CLOB_SEPARATOR); + valueStr.append(((boolean[]) value)[i]).append(GlobalConst.CLOB_SEPARATOR); } valueStr.append(((boolean[]) value)[((boolean[]) value).length - 1]); } else if (value instanceof String[]) { for (int i = 0; i < ((String[]) value).length - 1; i++) { - valueStr.append(((String[]) value)[i]).append(SnapConst.CLOB_SEPARATOR); + valueStr.append(((String[]) value)[i]).append(GlobalConst.CLOB_SEPARATOR); } valueStr.append(((String[]) value)[((String[]) value).length - 1]); } else { @@ -344,7 +346,7 @@ public class SnapSpectrumEvent_RW extends SnapAttribute { for (int j = 0; j < val.length; j++) { valueStr.append(val[j]); if (j < val.length - 1) { - valueStr.append(SnapConst.CLOB_SEPARATOR); + valueStr.append(GlobalConst.CLOB_SEPARATOR); } } @@ -365,7 +367,7 @@ public class SnapSpectrumEvent_RW extends SnapAttribute { for (int j = 0; j < val.length; j++) { valueStr.append(val[j]); if (j < val.length - 1) { - valueStr.append(SnapConst.CLOB_SEPARATOR); + valueStr.append(GlobalConst.CLOB_SEPARATOR); } } @@ -386,7 +388,7 @@ public class SnapSpectrumEvent_RW extends SnapAttribute { for (int j = 0; j < val.length; j++) { valueStr.append(val[j]); if (j < val.length - 1) { - valueStr.append(SnapConst.CLOB_SEPARATOR); + valueStr.append(GlobalConst.CLOB_SEPARATOR); } } @@ -407,7 +409,7 @@ public class SnapSpectrumEvent_RW extends SnapAttribute { for (int j = 0; j < val.length; j++) { valueStr.append(val[j]); if (j < val.length - 1) { - valueStr.append(SnapConst.CLOB_SEPARATOR); + valueStr.append(GlobalConst.CLOB_SEPARATOR); } } @@ -428,7 +430,7 @@ public class SnapSpectrumEvent_RW extends SnapAttribute { for (int j = 0; j < val.length; j++) { valueStr.append(val[j]); if (j < val.length - 1) { - valueStr.append(SnapConst.CLOB_SEPARATOR); + valueStr.append(GlobalConst.CLOB_SEPARATOR); } } @@ -449,7 +451,7 @@ public class SnapSpectrumEvent_RW extends SnapAttribute { for (int j = 0; j < val.length; j++) { valueStr.append(val[j]); if (j < val.length - 1) { - valueStr.append(SnapConst.CLOB_SEPARATOR); + valueStr.append(GlobalConst.CLOB_SEPARATOR); } } @@ -470,7 +472,7 @@ public class SnapSpectrumEvent_RW extends SnapAttribute { for (int j = 0; j < val.length; j++) { valueStr.append(val[j]); if (j < val.length - 1) { - valueStr.append(SnapConst.CLOB_SEPARATOR); + valueStr.append(GlobalConst.CLOB_SEPARATOR); } } diff --git a/src/test/java/fr/soleil/archiving/snap/api/DataBaseAPITest.java b/src/test/java/fr/soleil/archiving/snap/api/DataBaseAPITest.java new file mode 100644 index 0000000..de28f26 --- /dev/null +++ b/src/test/java/fr/soleil/archiving/snap/api/DataBaseAPITest.java @@ -0,0 +1,159 @@ +package fr.soleil.archiving.snap.api; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Before; +import org.junit.Test; + +import fr.esrf.Tango.AttrDataFormat; +import fr.esrf.Tango.AttrWriteType; +import fr.esrf.TangoDs.TangoConst; +import fr.soleil.archiving.snap.api.tools.SnapAttributeExtract; +import fr.soleil.archiving.snap.api.tools.SnapContext; +import fr.soleil.archiving.snap.api.tools.SnapshotLight; +import fr.soleil.archiving.snap.api.tools.SnapshotingException; + +public class DataBaseAPITest { + DataBaseAPI dbApi; + + @Before + public void initDataBaseAPI() { + dbApi = new DataBaseAPI("195.221.4.203", "TEST11SE", "snap", "snap", "snap", false); + } + + @Test + public void getAttIDTest() throws SnapshotingException { + assertFalse(dbApi.isRegistered("")); + assertTrue(dbApi.isRegistered("steph/transverse/recordingmanager/fileCounter")); + int id = dbApi.getAttID("steph/transverse/recordingmanager/fileCounter"); + assertEquals(239, id); + } + + @Test + public void getMaxContextIDTest() throws SnapshotingException { + assertTrue(dbApi.getMaxContextID() > 0); + } + + @Test + public void getAllContextTest() throws SnapshotingException { + List<SnapContext> result = dbApi.getAllContext(); + assertNotNull(result); + assertFalse(result.isEmpty()); + } + + @Test + public void getContextTest() throws SnapshotingException { + List<SnapContext> result = dbApi.getContext(" WHERE id_context = ? ", 12); + assertNotNull(result); + assertTrue(result.isEmpty()); + + result = dbApi.getContext(" WHERE id_context = ? ", 76); + assertNotNull(result); + assertFalse(result.isEmpty()); + assertEquals(1, result.size()); + + result = dbApi.getContext(" WHERE name LIKE 'test%' ", -1); + assertNotNull(result); + assertFalse(result.isEmpty()); + assertEquals(5, result.size()); + + result = dbApi.getContext("", -1); + assertNotNull(result); + assertFalse(result.isEmpty()); + assertEquals(6, result.size()); + } + + @Test + public void getContextAssociatedSnapshotsTest() throws SnapshotingException { + List<SnapshotLight> result = dbApi.getContextAssociatedSnapshots(-1); + assertTrue(result.isEmpty()); + + result = dbApi.getContextAssociatedSnapshots(76); + assertFalse(result.isEmpty()); + int expected = result.size(); + + result = dbApi.getContextAssociatedSnapshots("", -1, -1); + assertFalse(result.isEmpty()); + assertEquals(31, result.size()); + + result = dbApi.getContextAssociatedSnapshots(" WHERE ID_CONTEXT=? ", 76, -1); + assertFalse(result.isEmpty()); + assertEquals(expected, result.size()); + + result = dbApi.getContextAssociatedSnapshots(" WHERE ID_SNAP=? AND ID_CONTEXT=?", 76, 228); + assertFalse(result.isEmpty()); + assertEquals(1, result.size()); + + result = dbApi.getContextAssociatedSnapshots(" WHERE ID_SNAP=? ", -1, 228); + assertFalse(result.isEmpty()); + assertEquals(1, result.size()); + } + + @Test + public void getContextIDTest() throws SnapshotingException { + int result = dbApi.getContextID(-1); + assertEquals(-1, result); + + result = dbApi.getContextID(228); + assertEquals(76, result); + } + + @Test + public void getSnapResultsTest() throws SnapshotingException { + int id_snap = 237; + final int contextID = dbApi.getContextID(id_snap); + final List<SnapAttributeExtract> theoricList = dbApi.getContextAssociatedAttributes(contextID); + final List<SnapAttributeExtract> result = new ArrayList<SnapAttributeExtract>(theoricList); + SnapAttributeExtract scRO = null; + SnapAttributeExtract scROstr = null; + SnapAttributeExtract scRW = null; + SnapAttributeExtract spRO = null; + SnapAttributeExtract spRW = null; + + for (SnapAttributeExtract item : result) { + if (item.getDataFormat() == AttrDataFormat._SCALAR) { + if (item.getWritable() == AttrWriteType._READ && item.getDataType() != TangoConst.Tango_DEV_STRING + && scRO == null + && !item.getAttributeCompleteName().equals("tango/tangotest/titan/throw_exception")) { + scRO = item; + } + if (item.getWritable() == AttrWriteType._READ && item.getDataType() == TangoConst.Tango_DEV_STRING + && scROstr == null) { + scROstr = item; + } + if (item.getWritable() == AttrWriteType._READ_WRITE && scRW == null) { + scRW = item; + } + } + if (item.getDataFormat() == AttrDataFormat._SPECTRUM) { + if (item.getWritable() == AttrWriteType._READ && spRO == null) { + spRO = item; + } + if (item.getWritable() == AttrWriteType._READ_WRITE && spRW == null) { + spRW = item; + } + } + } + assertNull(scRO.getValue()); + assertNull(scROstr.getValue()); + assertNull(scRW.getReadValue()); + assertNull(spRO.getValue()); + assertEquals("NaN", spRW.getReadValue()); + dbApi.getSnapResults(result, id_snap); + assertNotNull(scRO.getValue()); + assertNotNull(scROstr.getValue()); + assertNotNull(scRW.getReadValue()); + assertNotNull(spRO.getValue()); + assertNotEquals("NaN", spRW.getReadValue()); + } + + +} -- GitLab