Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • master
  • release_1_5_4
  • release_1_5_5
  • release_1_5_6
  • release_1_5_7
  • release_1_5_8
  • release_1_6_0
  • release_1_6_1
  • release_1_6_2
  • release_1_6_3
  • snapArchivingApi-1.6.4
  • snapArchivingApi-1.6.5
  • snapArchivingApi-1.6.6
  • snapArchivingApi-1.7.0
  • snapArchivingApi-1.7.1
  • snapArchivingApi-1.7.2
  • snapArchivingApi-1.7.3
  • snapArchivingApi-1.7.4
  • snapArchivingApi-1.7.5
  • snapArchivingApi-1.7.6
  • snapArchivingApi-1.7.7
  • snapArchivingApi-1.7.8
  • snapArchivingApi-1.8.0
  • snapArchivingApi-1.8.1
  • snapArchivingApi-1.8.2
  • snapArchivingApi-1.8.3
  • snapArchivingApi-1.8.4
  • trunk
28 results

Target

Select target project
  • software-control-system/tango-controls-archiving/snaparchivingapi
1 result
Select Git revision
  • master
  • release_1_5_4
  • release_1_5_5
  • release_1_5_6
  • release_1_5_7
  • release_1_5_8
  • release_1_6_0
  • release_1_6_1
  • release_1_6_2
  • release_1_6_3
  • snapArchivingApi-1.6.4
  • snapArchivingApi-1.6.5
  • snapArchivingApi-1.6.6
  • snapArchivingApi-1.7.0
  • snapArchivingApi-1.7.1
  • snapArchivingApi-1.7.2
  • snapArchivingApi-1.7.3
  • snapArchivingApi-1.7.4
  • snapArchivingApi-1.7.5
  • snapArchivingApi-1.7.6
  • snapArchivingApi-1.7.7
  • snapArchivingApi-1.7.8
  • snapArchivingApi-1.8.0
  • snapArchivingApi-1.8.1
  • snapArchivingApi-1.8.2
  • snapArchivingApi-1.8.3
  • snapArchivingApi-1.8.4
  • trunk
28 results
Show changes
Showing
with 958 additions and 1651 deletions
/*
* Synchrotron Soleil
*
* File : TargetFactory.java
*
* Project : DynamicTangoUtilities
*
* Description :
*
* Author : CLAISSE
*
* Original : 9 févr. 07
*
* Revision: Author:
* Date: State:
*
* Log: TargetFactory.java,v
*/
/*
* Created on 9 févr. 07
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package fr.soleil.actiongroup.collectiveaction.components.tangowrapping.target;
import fr.esrf.TangoApi.DeviceProxy;
public class TargetFactory {
public static Target getTarget(DeviceProxy _proxy) {
return new TargetImpl(_proxy);
public static Target getTarget(DeviceProxy proxy) {
return new TargetImpl(proxy);
}
}
/*
* Synchrotron Soleil
*
* File : Target.java
*
* Project : DynamicTangoUtilities
*
* Description :
*
* Author : CLAISSE
*
* Original : 9 févr. 07
*
* Revision: Author:
* Date: State:
*
* Log: Target.java,v
*/
/*
* Created on 9 févr. 07
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package fr.soleil.actiongroup.collectiveaction.components.tangowrapping.target;
import java.util.Arrays;
......@@ -42,13 +18,21 @@ import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.CommandIn
import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.DbDatumWrapper;
import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.DeviceAttributeWrapper;
import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.DeviceDataWrapper;
import fr.soleil.lib.project.ObjectUtils;
/**
* Target implementation
*
* @author CLAISSE
*/
public class TargetImpl implements Target {
private final Logger logger = LoggerFactory.getLogger(TargetImpl.class);
private static final Logger LOGGER = LoggerFactory.getLogger(TargetImpl.class);
private final DeviceProxy proxy;
TargetImpl(final DeviceProxy _proxy) {
proxy = _proxy;
public TargetImpl(final DeviceProxy proxy) {
this.proxy = proxy;
}
@Override
......@@ -65,28 +49,27 @@ public class TargetImpl implements Target {
} else {
response = proxy.command_inout(commandName, commandParameters.getCommandArgument());
}
return new DeviceDataWrapper(response);
}
@Override
public DeviceAttributeWrapper[] read_attribute(final String[] attributesToRead) throws DevFailed {
logger.debug("reading attributes {}", Arrays.toString(attributesToRead));
LOGGER.debug("reading attributes {}", Arrays.toString(attributesToRead));
final DeviceAttribute[] response = proxy.read_attribute(attributesToRead);
final DeviceAttributeWrapper[] wrappedResponse = wrapAttributes(response);
return wrappedResponse;
}
private DeviceAttributeWrapper[] wrapAttributes(final DeviceAttribute[] response) {
final DeviceAttributeWrapper[] ret;
if (response == null) {
return null;
}
final DeviceAttributeWrapper[] ret = new DeviceAttributeWrapper[response.length];
ret = null;
} else {
ret = new DeviceAttributeWrapper[response.length];
for (int i = 0; i < response.length; i++) {
ret[i] = new DeviceAttributeWrapper(response[i]);
}
}
return ret;
}
......@@ -103,11 +86,11 @@ public class TargetImpl implements Target {
@Override
public void put_property(final String propertyName, final DbDatumWrapper propertyValueHolder) throws DevFailed {
if (!propertyName.equals("")) {
if (propertyName.isEmpty()) {
proxy.delete_property(ObjectUtils.EMPTY_STRING);
} else {
final DbDatum propertyValue = propertyValueHolder.getDbDatum();
proxy.put_property(new DbDatum[] { propertyValue });
} else {
proxy.delete_property("");
}
}
......@@ -172,8 +155,8 @@ public class TargetImpl implements Target {
break;
default:
throw new IllegalArgumentException("WriteNumericValueListener/Unexpected attribute type/"
+ attribute.getType());
throw new IllegalArgumentException(
"WriteNumericValueListener/Unexpected attribute type/" + attribute.getType());
}
}
......@@ -184,14 +167,15 @@ public class TargetImpl implements Target {
}
private CommandInfoWrapper[] wrapCommandInfos(final CommandInfo[] response) {
final CommandInfoWrapper[] ret;
if (response == null) {
return null;
}
final CommandInfoWrapper[] ret = new CommandInfoWrapper[response.length];
ret = null;
} else {
ret = new CommandInfoWrapper[response.length];
for (int i = 0; i < response.length; i++) {
ret[i] = new CommandInfoWrapper(response[i]);
}
}
return ret;
}
}
/* Synchrotron Soleil
*
* File : AnyAttribute.java
*
* Project : TangoParser
*
* Description :
*
* Author : CLAISSE
*
* Original : 17 janv. 07
*
* Revision: Author:
* Date: State:
*
* Log: AnyAttribute.java,v
*
*/
/*
* Created on 17 janv. 07
*
* To change the template for this generated file go to
* Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
*/
package fr.soleil.actiongroup.collectiveaction.onattributes.plugin.persistance;
import org.slf4j.Logger;
......@@ -38,7 +14,8 @@ import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.TangoCons
* @author CLAISSE
*/
public class AnyAttribute {
final static Logger logger = LoggerFactory.getLogger(AnyAttribute.class);
private static final Logger LOGGER = LoggerFactory.getLogger(AnyAttribute.class);
private static final String SPECTRUM_SEPARATOR = ",";
......@@ -111,7 +88,7 @@ public class AnyAttribute {
/**
* The attribute's State value
*/
private DevState[] rawValueState;
private DevState rawValueState;
private final int numberOfComponents;
......@@ -199,8 +176,8 @@ public class AnyAttribute {
break;
case TangoConst.Tango_DEV_STATE:
rawValueState = attribute.extractDevStateArray();
_numberOfComponents = rawValueState == null ? 0 : rawValueState.length;
rawValueState = attribute.extractState();
_numberOfComponents = 1;
break;
case TangoConst.Tango_DEV_STRING:
......@@ -208,7 +185,7 @@ public class AnyAttribute {
_numberOfComponents = rawValueString == null ? 0 : rawValueString.length;
break;
default:
logger.error("NO EXTRACTION " + attribute.getName());
LOGGER.error("NO EXTRACTION " + attribute.getName());
}
return _numberOfComponents;
}
......@@ -230,7 +207,7 @@ public class AnyAttribute {
// stored
// as
// 0/1
convertedStringValuesTable[i] = rawValueBoolean[i] + ""; // for
convertedStringValuesTable[i] = Boolean.toString(rawValueBoolean[i]); // for
// spectrums
// which
// are
......@@ -241,37 +218,37 @@ public class AnyAttribute {
case TangoConst.Tango_DEV_DOUBLE:
convertedNumericValuesTable[i] = rawValueDouble[i];
convertedStringValuesTable[i] = rawValueDouble[i] + "";
convertedStringValuesTable[i] = Double.toString(rawValueDouble[i]);
break;
case TangoConst.Tango_DEV_FLOAT:
convertedNumericValuesTable[i] = rawValueFloat[i];
convertedStringValuesTable[i] = rawValueFloat[i] + "";
convertedStringValuesTable[i] = Float.toString(rawValueFloat[i]);
break;
case TangoConst.Tango_DEV_LONG:
case TangoConst.Tango_DEV_INT:
case TangoConst.Tango_DEV_USHORT:
convertedNumericValuesTable[i] = rawValueInt[i];
convertedStringValuesTable[i] = rawValueInt[i] + "";
convertedStringValuesTable[i] = Integer.toString(rawValueInt[i]);
break;
case TangoConst.Tango_DEV_ULONG:
case TangoConst.Tango_DEV_ULONG64:
case TangoConst.Tango_DEV_LONG64:
convertedNumericValuesTable[i] = rawValueLong[i];
convertedStringValuesTable[i] = rawValueLong[i] + "";
convertedStringValuesTable[i] = Long.toString(rawValueLong[i]);
break;
case TangoConst.Tango_DEV_SHORT:
case TangoConst.Tango_DEV_CHAR:
case TangoConst.Tango_DEV_UCHAR:
convertedNumericValuesTable[i] = rawValueShort[i];
convertedStringValuesTable[i] = rawValueShort[i] + "";
convertedStringValuesTable[i] = Short.toString(rawValueShort[i]);
break;
case TangoConst.Tango_DEV_STATE:
convertedNumericValuesTable[i] = rawValueState[i].value();
convertedStringValuesTable[i] = rawValueState[i].value()+"";
convertedNumericValuesTable[i] = rawValueState.value();
convertedStringValuesTable[i] = TangoConst.Tango_DevStateName[rawValueState.value()];
break;
case TangoConst.Tango_DEV_STRING:
......
// +======================================================================
// $Source: /cvsroot/tango-cs/tango/api/java/fr/soleil/TangoSnapshoting/SnapshotingApi/ConfigConst.java,v $
//
// Project: Tango Archiving Service
//
// Description: Java source code for the class ConfigConst.
// (Chinkumo Jean) - Mar 4, 2003
//
// $Author: ounsy $
//
// $Revision: 1.9 $
//
// $Log: ConfigConst.java,v $
// Revision 1.9 2007/04/05 09:55:34 ounsy
// added the default_sabeansfilename property
//
// Revision 1.8 2006/05/12 09:22:06 ounsy
// CLOB_SEPARATOR in GlobalConst
//
// Revision 1.7 2006/05/04 14:32:53 ounsy
// CLOB_SEPARATOR centralized in ConfigConst
//
// Revision 1.6 2006/02/28 17:05:58 chinkumo
// no message
//
// Revision 1.5 2006/02/17 11:15:35 chinkumo
// no message
//
// Revision 1.4 2005/11/29 17:11:17 chinkumo
// no message
//
// Revision 1.3.2.1 2005/11/15 13:34:38 chinkumo
// no message
//
// Revision 1.3 2005/08/19 14:04:02 chinkumo
// no message
//
// Revision 1.2.12.1.2.1 2005/08/12 08:08:16 chinkumo
// Unused constants removed.
//
// Revision 1.2.12.1 2005/08/01 13:49:57 chinkumo
// Several changes carried out for the support of the new graphical application (Bensikin).
//
// Revision 1.2 2005/02/04 14:50:42 chinkumo
// Table's name changed in lower cases because of troubles on UNIX platform.
//
// Revision 1.1 2005/01/26 15:35:38 chinkumo
// Ultimate synchronization before real sharing.
//
// Revision 1.1 2004/12/06 17:39:56 chinkumo
// First commit (new API architecture).
//
//
// copyleft : Synchrotron SOLEIL
// L'Orme des Merisiers
// Saint-Aubin - BP 48
// 91192 GIF-sur-YVETTE CEDEX
//
//-======================================================================
package fr.soleil.archiving.snap.api;
import java.io.File;
import fr.soleil.lib.project.ObjectUtils;
/**
* <B>File</B> : ConfigConst.java<br/>
* <B>Project</B> : Configuration java classes (hdbconfig package)<br/>
* <B>Description</B> : This file contains all the constants and functions used
* by all other classes of the package<br/>
*
* @author chinkumo, ounsy
*/
public class ConfigConst {
/*
......@@ -89,46 +32,46 @@ public class ConfigConst {
/**
* Parameter that represents the default database host
*/
public static final String default_shost = "localhost";
public static final String DEFAULT_S_HOST = "localhost";
/**
* Parameter that represents the default database names
*/
public static final String default_sbd = "snap";
public static final String DEFAULT_S_BD = "snap";
/**
* Parameter that represents the default database's schema name
*/
public static final String default_sschema = "snap"; //
public static final String DEFAULT_S_SCHEMA = "snap"; //
/**
* Parameter that represents the default database manager user id
* (operators...)
*/
public static final String default_smuser = "snap"; // "manager";
public static final String DEFAULT_SM_USER = "snap"; // "manager";
/**
* Parameter that represents the default database manager user password
*/
public static final String default_smpasswd = "snap"; // "manager";
public static final String DEFAULT_SM_PASSWD = "snap"; // "manager";
/**
* Parameter that represents the default database archiver user id
* (archivers...)
*/
public static final String default_sauser = "archiver";
public static final String DEFAULT_SA_USER = "archiver";
/**
* Parameter that represents the default database archiver user password
*/
public static final String default_sapasswd = "archiver";
public static final String DEFAULT_SA_PASSWD = "archiver";
/**
* Parameter that represents the default database archiver user password
*/
public static final String default_sabeansfilename = "beans.xml";
public static final String DEFAULT_SA_BEANS_FILE_NAME = "beans.xml";
/**
* Parameter that represents the default database browser user id
*/
public static final String default_sbuser = "browser";
public static final String DEFAULT_SB_USER = "browser";
/**
* Parameter that represents the default database browser user password (for
* the default user...)
*/
public static final String default_sbpasswd = "browser";
public static final String DEFAULT_SB_PASSWD = "browser";
// ----------------------------------- >> DataBase Type
/**
......@@ -156,36 +99,11 @@ public class ConfigConst {
/**
* Parameter that represents the PostGreSQL database driver
*/
public static final String DRIVER_POSTGRESQL = ""; // todo Give a value to
// the PostGres JDBC
// driver
// TODO Give a value to the PostGres JDBC driver
public static final String DRIVER_POSTGRESQL = ObjectUtils.EMPTY_STRING;
/**
* Port number for the connection
*/
public final static String ORACLE_PORT = "1521";
/*
* ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* ||
* ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* ||
* ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Miscellaneous global constants
* ||||||||||||||||||||||||||||||||||||||||||||
* ||||||||||||||||||||||||||||||
* ||||||||||||||||||||||||||||||||||||||||||||
* ||||||||||||||||||||||||||||||
* ||||||||||||||||||||||||||||||||||||||||||||
* ||||||||||||||||||||||||||||||
* ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/
/**
* Parameter that represents an empty String
*/
public static final String EMPTY = "";
// todo mettre en place une solution plus générique pour le "default_path"
public static String default_path = "C:" + File.separator + "tango" + File.separator + "dsnap" + File.separator
+ "snapshots";
}
//+======================================================================
// $Source: /cvsroot/tango-cs/tango/api/java/fr/soleil/TangoSnapshoting/SnapshotingApi/GetConf.java,v $
//
// Project: Tango Archiving Service
//
// Description: Java source code for the class GetConf.
// (Chinkumo Jean) - Mar 4, 2003
// $Author: ounsy $
//
// $Revision: 1.4 $
//
// $Log: GetConf.java,v $
// Revision 1.4 2006/05/04 14:33:35 ounsy
// minor changes (commented useless methods and variables)
//
// Revision 1.3 2005/11/29 17:11:17 chinkumo
// no message
//
// Revision 1.2.10.1 2005/11/15 13:34:38 chinkumo
// no message
//
// Revision 1.2 2005/06/28 09:10:16 chinkumo
// Changes made to improve the management of exceptions were reported here.
//
// Revision 1.1 2005/01/26 15:35:38 chinkumo
// Ultimate synchronization before real sharing.
//
// Revision 1.1 2004/12/06 17:39:56 chinkumo
// First commit (new API architecture).
//
//
// copyleft : Synchrotron SOLEIL
// L'Orme des Merisiers
// Saint-Aubin - BP 48
// 91192 GIF-sur-YVETTE CEDEX
//
//-======================================================================
package fr.soleil.archiving.snap.api;
import fr.esrf.Tango.DevFailed;
......@@ -46,17 +8,22 @@ import fr.esrf.TangoApi.DbDatum;
import fr.soleil.archiving.common.api.utils.GetConf;
import fr.soleil.archiving.snap.api.tools.SnapConst;
import fr.soleil.archiving.snap.api.tools.SnapshotingException;
import fr.soleil.lib.project.ObjectUtils;
/**
* Snapshot configuration
*
* @author chinkumo
*/
public class GetSnapshotingConf {
private static final String m_typeProperty = "dbType";
private static final String m_facilityProperty = "facility";
private static final String TYPE_PROPERTY = "dbType";
private static final String FACILITY_PROPERTY = "facility";
/**
* return the host property define for the given class
*
* @param className
* , the name of the class
* @param className the name of the class
*/
public static String getHost(String className) throws SnapshotingException {
try {
......@@ -69,8 +36,7 @@ public class GetSnapshotingConf {
/**
* return the name property define for the given class
*
* @param className
* , the name of the class
* @param className the name of the class
*/
public static String getName(String className) throws SnapshotingException {
try {
......@@ -83,8 +49,7 @@ public class GetSnapshotingConf {
/**
* return the name property define for the given class
*
* @param className
* , the name of the class
* @param className the name of the class
*/
public static String getSchema(String className) throws SnapshotingException {
try {
......@@ -113,8 +78,7 @@ public class GetSnapshotingConf {
/**
* return the name property define for the given class
*
* @param className
* , the name of the class
* @param className the name of the class
*/
public static String isRAC(String className) throws SnapshotingException {
try {
......@@ -127,11 +91,10 @@ public class GetSnapshotingConf {
/**
* return the name property define for the given class
*
* @param className
* , the name of the class
* @param className the name of the class
*/
public static int getType(String className) throws SnapshotingException {
String propname = m_typeProperty;
String propname = TYPE_PROPERTY;
try {
Database dbase = ApiUtil.get_db_obj();
int property = ConfigConst.BD_MYSQL;
......@@ -144,7 +107,8 @@ public class GetSnapshotingConf {
String message = SnapConst.SNAPSHOTING_ERROR_PREFIX;
String reason = SnapConst.TANGO_COMM_EXCEPTION + " or " + propname + " property missing...";
String desc = "Failed while executing GetConf.getType() method...";
throw new SnapshotingException(message, reason, ErrSeverity.WARN, desc, "", devFailed);
throw new SnapshotingException(message, reason, ErrSeverity.WARN, desc, ObjectUtils.EMPTY_STRING,
devFailed);
}
}
......@@ -152,16 +116,15 @@ public class GetSnapshotingConf {
/**
* return the facility property define for the given class
*
* @param className
* , the name of the class
* @param className the name of the class
* @throws SnapshotingException
*/
public static boolean getFacility(String className) throws SnapshotingException {
String propname = m_facilityProperty;
String propname = FACILITY_PROPERTY;
try {
Database dbase = ApiUtil.get_db_obj();
boolean property = false;
propname = m_facilityProperty;
propname = FACILITY_PROPERTY;
DbDatum dbdatum = dbase.get_class_property(className, propname);
if (!dbdatum.is_empty()) {
property = dbdatum.extractBoolean();
......@@ -171,7 +134,8 @@ public class GetSnapshotingConf {
String message = SnapConst.SNAPSHOTING_ERROR_PREFIX;
String reason = SnapConst.TANGO_COMM_EXCEPTION + " or " + propname + " property missing...";
String desc = "Failed while executing GetConf.getFacility() method...";
throw new SnapshotingException(message, reason, ErrSeverity.WARN, desc, "", devFailed);
throw new SnapshotingException(message, reason, ErrSeverity.WARN, desc, ObjectUtils.EMPTY_STRING,
devFailed);
}
}
}
......@@ -8,66 +8,66 @@ import fr.soleil.archiving.snap.api.tools.SnapshotingException;
public class SnapConnectionParameters {
private static final DbConnectionInfo snapInfoConnector = new DbConnectionInfo(
private static final DbConnectionInfo SNAP_INFO_CONNECTOR = new DbConnectionInfo(
SnapManagerApi.SNAP_MANAGER_DEVICE_CLASS);
public static String getSnapUser() {
return snapInfoConnector.getDbUser();
return SNAP_INFO_CONNECTOR.getDbUser();
}
public static void setSnapUser(String hDBUser, String origin) {
snapInfoConnector.setDbUser(hDBUser, origin);
SNAP_INFO_CONNECTOR.setDbUser(hDBUser, origin);
}
public static String getSnapPassword() {
return snapInfoConnector.getDbPassword();
return SNAP_INFO_CONNECTOR.getDbPassword();
}
public static void setSnapPassword(String hDBPassword, String origin) {
snapInfoConnector.setDbPassword(hDBPassword, origin);
SNAP_INFO_CONNECTOR.setDbPassword(hDBPassword, origin);
}
public static String getSnapHost() {
return snapInfoConnector.getDbHost();
return SNAP_INFO_CONNECTOR.getDbHost();
}
public static void setSnapHost(String hDbHost, String origin) {
snapInfoConnector.setDbHost(hDbHost, origin);
SNAP_INFO_CONNECTOR.setDbHost(hDbHost, origin);
}
public static String getSnapName() {
return snapInfoConnector.getDbName();
return SNAP_INFO_CONNECTOR.getDbName();
}
public static void setSnapName(String hDbName, String origin) {
snapInfoConnector.setDbName(hDbName, origin);
SNAP_INFO_CONNECTOR.setDbName(hDbName, origin);
}
public static String getSnapSchema() {
return snapInfoConnector.getDbSchema();
return SNAP_INFO_CONNECTOR.getDbSchema();
}
public static void setSnapSchema(String hDbSchema, String origin) {
snapInfoConnector.setDbSchema(hDbSchema, origin);
SNAP_INFO_CONNECTOR.setDbSchema(hDbSchema, origin);
}
public static boolean isSnapRac() {
return Boolean.parseBoolean(snapInfoConnector.isDbRac());
return Boolean.parseBoolean(SNAP_INFO_CONNECTOR.isDbRac());
}
public static String getSnapRac() {
return snapInfoConnector.isDbRac();
return SNAP_INFO_CONNECTOR.isDbRac();
}
public static void setSnapRac(String hDbRac, String origin) {
snapInfoConnector.setDbRac(hDbRac, origin);
SNAP_INFO_CONNECTOR.setDbRac(hDbRac, origin);
}
// Init with properties
public static void initFromDeviceProperties(final DbDevice device) throws SnapshotingException {
try {
snapInfoConnector.initFromDeviceProperties(device);
SNAP_INFO_CONNECTOR.initFromDeviceProperties(device);
} catch (final DevFailed devFailed) {
throw new SnapshotingException(devFailed);
}
......@@ -75,25 +75,25 @@ public class SnapConnectionParameters {
public static void initFromClassProperties() throws SnapshotingException {
try {
snapInfoConnector.initFromClassProperties();
SNAP_INFO_CONNECTOR.initFromClassProperties();
} catch (final DevFailed devFailed) {
throw new SnapshotingException(devFailed);
}
}
public static void initFromDefaultProperties() {
snapInfoConnector.initFromDefaultProperties(ConfigConst.default_shost, ConfigConst.default_sbd,
ConfigConst.default_sschema, ConfigConst.default_sbuser, ConfigConst.default_sbpasswd, "false");
SNAP_INFO_CONNECTOR.initFromDefaultProperties(ConfigConst.DEFAULT_S_HOST, ConfigConst.DEFAULT_S_BD,
ConfigConst.DEFAULT_S_SCHEMA, ConfigConst.DEFAULT_SB_USER, ConfigConst.DEFAULT_SB_PASSWD, "false");
}
public static void initFromSystemProperties() {
snapInfoConnector.initFromSystemProperties("SNAP_HOST", "SNAP_NAME", "SNAP_SCHEMA", "SNAP_USER", "SNAP_PASS",
SNAP_INFO_CONNECTOR.initFromSystemProperties("SNAP_HOST", "SNAP_NAME", "SNAP_SCHEMA", "SNAP_USER", "SNAP_PASS",
"SNAP_RAC");
}
public static void initFromArgumentsProperties(final String host, final String name, final String schema,
final String user, final String pass, final String isRac) {
snapInfoConnector.initFromArgumentsProperties(host, name, schema, user, pass, isRac);
SNAP_INFO_CONNECTOR.initFromArgumentsProperties(host, name, schema, user, pass, isRac);
}
/**
......@@ -141,7 +141,7 @@ public class SnapConnectionParameters {
result.append("################\n");
result.append("### Snapshot ###\n");
result.append("################\n");
snapInfoConnector.appendLoggerTrace(result);
SNAP_INFO_CONNECTOR.appendLoggerTrace(result);
result.append("\n############################");
return result;
}
......
// +======================================================================
// $Source: /cvsroot/tango-cs/tango/api/java/fr/soleil/TangoSnapshoting/SnapExtractorApi/datasources/db/RealSnapReader.java,v $
//
// Project: Tango Archiving Service
//
// Description: Java source code for the class RealSnapReader.
// (CLAISSE - 23/01/2006)
//
// $Author: chinkumo $
//
// $Revision: 1.5 $
//
// $Log: RealSnapReader.java,v $
// Revision 1.5 2008/01/08 15:32:19 chinkumo
// minor changes
//
// copyleft : Synchrotron SOLEIL
// L'Orme des Merisiers
// Saint-Aubin - BP 48
// 91192 GIF-sur-YVETTE CEDEX
//
//-======================================================================
package fr.soleil.archiving.snap.api.extractor.datasources.db;
import java.text.SimpleDateFormat;
......@@ -28,16 +6,17 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import fr.esrf.Tango.DevFailed;
import fr.esrf.Tango.DevVarLongStringArray;
import fr.soleil.archiving.common.api.tools.AttributeHeavy;
import fr.soleil.archiving.common.api.tools.Condition;
import fr.soleil.archiving.common.api.tools.Criterions;
import fr.soleil.archiving.snap.api.extractor.tools.Tools;
import fr.soleil.archiving.snap.api.manager.ISnapManager;
import fr.soleil.archiving.snap.api.manager.SnapManagerImpl;
import fr.soleil.archiving.snap.api.tools.Condition;
import fr.soleil.archiving.snap.api.tools.Criterions;
import fr.soleil.archiving.snap.api.tools.SnapAttributeExtract;
import fr.soleil.archiving.snap.api.tools.SnapConst;
import fr.soleil.archiving.snap.api.tools.SnapContext;
......@@ -47,12 +26,12 @@ import fr.soleil.archiving.snap.api.tools.SnapshotingException;
/**
* An implementation that loads data from the Snap Database
*
* @author CLAISSE
* @author chinkumo, CLAISSE
*/
public class RealSnapReader implements ISnapReader {
private ISnapManager manager;
private boolean isReady = false;
private final static String splitCharact = "|";
private static final String SPLIT_CHAR = "|";
RealSnapReader() {
super();
......@@ -61,9 +40,9 @@ public class RealSnapReader implements ISnapReader {
@Override
public synchronized void openConnection() throws DevFailed {
try {
if (!this.isReady) {
this.manager = new SnapManagerImpl();
this.isReady = true;
if (!isReady) {
manager = new SnapManagerImpl();
isReady = true;
}
} catch (Exception e) {
Tools.throwDevFailed(e);
......@@ -72,15 +51,9 @@ public class RealSnapReader implements ISnapReader {
@Override
public void closeConnection() {
this.isReady = false;
isReady = false;
}
/*
* (non-Javadoc)
*
* @see
* snapextractor.api.datasources.db.ISnapReader#getSnap(java.lang.String[])
*/
@Override
public SnapAttributeExtract[] getSnap(final int id) throws DevFailed {
try {
......@@ -99,31 +72,25 @@ public class RealSnapReader implements ISnapReader {
}
}
/*
* (non-Javadoc)
*
* @see
* snapextractor.api.datasources.db.ISnapReader#getSnapshotsForContext(int)
*/
@Override
public DevVarLongStringArray getSnapshotsForContext(final int contextId) throws DevFailed {
Criterions searchCriterions = new Criterions();
searchCriterions.addCondition(new Condition(SnapConst.TAB_SNAP[1], SnapConst.OP_EQUALS, "" + contextId));
searchCriterions
.addCondition(new Condition(SnapConst.TAB_SNAP[1], SnapConst.OP_EQUALS, Integer.toString(contextId)));
SnapshotLight[] snapshots = null;
try {
snapshots = this.manager.findSnapshots(searchCriterions);
snapshots = manager.findSnapshots(searchCriterions);
} catch (Exception e) {
Tools.throwDevFailed(e);
}
DevVarLongStringArray ret;
if (snapshots == null || snapshots.length == 0) {
return null;
}
ret = null;
} else {
int numberOfSnapshots = snapshots.length;
DevVarLongStringArray ret = new DevVarLongStringArray();
ret = new DevVarLongStringArray();
int[] lvalue = new int[numberOfSnapshots];
java.lang.String[] svalue = new java.lang.String[numberOfSnapshots];
String[] svalue = new String[numberOfSnapshots];
for (int i = 0; i < numberOfSnapshots; i++) {
SnapshotLight currentSnapshot = snapshots[i];
lvalue[i] = currentSnapshot.getId_snap();
......@@ -131,25 +98,16 @@ public class RealSnapReader implements ISnapReader {
}
ret.lvalue = lvalue;
ret.svalue = svalue;
}
return ret;
}
/*
* (non-Javadoc)
*
* @see snapextractor.api.datasources.db.ISnapReader#getSnapshotID(int)
*/
@Override
public int[] getSnapshotsID(final int ctxID, final String[] criterions) {
// ---Add your Own code to control device here ---
int[] argout = null;
Criterions ret = getInputCriterion(criterions);
if (ret == null) {
return null;
}
ret.addCondition(new Condition(SnapConst.TAB_SNAP[1], SnapConst.OP_EQUALS, "" + ctxID));
if (ret != null) {
ret.addCondition(new Condition(SnapConst.TAB_SNAP[1], SnapConst.OP_EQUALS, Integer.toString(ctxID)));
SnapshotLight[] newList;
try {
......@@ -167,66 +125,53 @@ public class RealSnapReader implements ISnapReader {
}
}
} catch (SnapshotingException e) {
// TODO Auto-generated catch block
return null;
argout = null;
}
}
// ------------------------------------------------
return argout;
}
private Criterions getInputCriterion(final String[] criterions) {
// TODO Auto-generated method stub
Criterions ret = new Criterions();
try {
Condition cond;
String criterion_type = null;
String criterion_op = null;
String criterion_value = null;
for (int i = 0; i < criterions.length; i++) {
if (criterions[i].equals("first") || criterions[i].equals("last")) {
cond = getCondition(criterions[i], criterions[i], criterions[i]);
for (String criterion : criterions) {
if (criterion.equals("first") || criterion.equals("last")) {
cond = getCondition(criterion, criterion, criterion);
ret.addCondition(cond);
} else if (criterions[i].equals("id_snap") || criterions[i].equals("comment")
|| criterions[i].equals("time")) {
criterion_type = criterions[i].substring(0, criterions[i].indexOf(" "));
criterions[i] = criterions[i].substring(criterions[i].indexOf(criterion_type)
+ criterion_type.length() + 1);
criterion_op = criterions[i].substring(0, criterions[i].indexOf(" "));
criterion_value = criterions[i].substring(
criterions[i].indexOf(criterion_op) + criterion_op.length()).trim();
} else if (criterion.equals("id_snap") || criterion.equals("comment") || criterion.equals("time")) {
criterion_type = criterion.substring(0, criterion.indexOf(" "));
criterion = criterion.substring(criterion.indexOf(criterion_type) + criterion_type.length() + 1);
criterion_op = criterion.substring(0, criterion.indexOf(" "));
criterion_value = criterion.substring(criterion.indexOf(criterion_op) + criterion_op.length())
.trim();
cond = getCondition(criterion_op, criterion_value, criterion_type);
ret.addCondition(cond);
} else {
return null;
}
ret = null;
break;
}
} // end for (String criterion : criterions)
} catch (Exception e) {
return null;
ret = null;
}
return ret;
}
// ------------------------------------------------
/**
* If both operator and threshold value are filled, builds a Condition from
* them. Otherwise returns null.
* If both operator and threshold value are filled, builds a Condition from them. Otherwise returns null.
*
* @param selectedItem
* The operator
* @param text
* The value
* @param id_field_key2
* The field's id
* @param selectedItem The operator
* @param text The value
* @param id_field_key2 The field's id
* @return The resulting Condition or null
*/
public Condition getCondition(String selectedItem, String text, String id_field_key2) {
Condition condition;
// Date Formating
if (id_field_key2.equals("time")) {
text = Tools.formatDate(Tools.stringToMilli(text));
......@@ -237,38 +182,41 @@ public class RealSnapReader implements ISnapReader {
boolean isACriterion = true;
if (selectedItem == null || selectedItem.equals("")) {
if (selectedItem == null || selectedItem.isEmpty()) {
isACriterion = false;
}
if (text == null || text.trim().equals("")) {
if (text == null || text.trim().isEmpty()) {
isACriterion = false;
}
if (isACriterion || selectedItem.equals("first") || selectedItem.equals("last")) {
return new Condition(id_field_key2, selectedItem, text.trim());
condition = new Condition(id_field_key2, selectedItem, text.trim());
} else {
condition = null;
}
return null;
return condition;
}
private String getCommentCondition(final String selectedItem) {
String res;
if (selectedItem.equalsIgnoreCase("starts")) {
return "Starts with";
res = "Starts with";
} else if (selectedItem.equalsIgnoreCase("ends")) {
return "Ends with";
res = "Ends with";
} else {
return "Contains";
res = "Contains";
}
return res;
}
private Map<Integer, SnapContext> getAllSnapContext() throws DevFailed {
Map<Integer, SnapContext> contextMap = new HashMap<Integer, SnapContext>();
Map<Integer, SnapContext> contextMap = new HashMap<>();
Criterions searchCriterions = new Criterions();
SnapContext[] contexts = null;
int contextId = -1;
try {
contexts = this.manager.findContexts(searchCriterions);
contexts = manager.findContexts(searchCriterions);
} catch (Exception e) {
Tools.throwDevFailed(e);
}
......@@ -289,23 +237,24 @@ public class RealSnapReader implements ISnapReader {
// return with attributeValue
private DevVarLongStringArray getAllContexts(boolean withAttribute) throws DevFailed {
DevVarLongStringArray ret;
Criterions searchCriterions = new Criterions();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
SnapContext[] contextTab = null;
try {
contextTab = this.manager.findContexts(searchCriterions);
contextTab = manager.findContexts(searchCriterions);
} catch (Exception e) {
Tools.throwDevFailed(e);
}
if (contextTab == null || contextTab.length == 0) {
return null;
}
ret = null;
} else {
int numberOfContexts = contextTab.length;
DevVarLongStringArray ret = new DevVarLongStringArray();
ret = new DevVarLongStringArray();
int[] lvalue = new int[numberOfContexts];
java.lang.String[] svalue = new java.lang.String[numberOfContexts];
String[] svalue = new String[numberOfContexts];
List<String> attributesList = null;
int contextId = -1;
......@@ -318,23 +267,14 @@ public class RealSnapReader implements ISnapReader {
attributesList = getAttributeForContext(currentContext, searchCriterions);
}
svalue[i] = currentContext.getName() + splitCharact + currentContext.getAuthor_name() + splitCharact
+ sdf.format(currentContext.getCreation_date()) + splitCharact + currentContext.getReason()
+ splitCharact + currentContext.getDescription();
svalue[i] = currentContext.getName() + SPLIT_CHAR + currentContext.getAuthor_name() + SPLIT_CHAR
+ sdf.format(currentContext.getCreation_date()) + SPLIT_CHAR + currentContext.getReason()
+ SPLIT_CHAR + currentContext.getDescription();
if (attributesList != null && !attributesList.isEmpty()) {
StringBuilder sb = new StringBuilder();
for (String att : attributesList) {
sb.append(splitCharact);
sb.append(SPLIT_CHAR);
sb.append(att);
/*
sb.append(att.getAttributeId());
sb.append(splitCharact);
sb.append(att.getAttributeCompleteName());
sb.append(splitCharact);
sb.append(att.getDataFormat());
sb.append(splitCharact);
sb.append(att.getDataType());
*/
}
svalue[i] = svalue[i] + sb.toString();
}
......@@ -342,18 +282,17 @@ public class RealSnapReader implements ISnapReader {
ret.lvalue = lvalue;
ret.svalue = svalue;
}
return ret;
}
private List<String> getAttributeForContext(SnapContext context, Criterions searchCriterions) {
List<String> attributesList = null;
if (context != null && this.manager != null) {
if (context != null && manager != null) {
try {
AttributeHeavy[] findContextAttributes = this.manager.findContextAttributes(context,
searchCriterions);
AttributeHeavy[] findContextAttributes = manager.findContextAttributes(context, searchCriterions);
if (findContextAttributes != null && findContextAttributes.length != 0) {
attributesList = new ArrayList<String>();
attributesList = new ArrayList<>();
for (AttributeHeavy att : findContextAttributes) {
attributesList.add(att.getAttributeCompleteName());
}
......@@ -384,12 +323,13 @@ public class RealSnapReader implements ISnapReader {
private List<SnapContext> getSnapContextListForAttribute(String argin) throws DevFailed {
Criterions criterions = new Criterions();
List<String> attributeForContext = null;
List<SnapContext> contextList = new ArrayList<SnapContext>();
Map<Integer, SnapContext> mapContextList = new HashMap<Integer, SnapContext>();
List<SnapContext> contextList = new ArrayList<>();
Map<Integer, SnapContext> mapContextList = new HashMap<>();
Map<Integer, SnapContext> allSnapContext = getAllSnapContext();
for (Integer id : allSnapContext.keySet()) {
SnapContext snapContext = allSnapContext.get(id);
for (Entry<Integer, SnapContext> entry : allSnapContext.entrySet()) {
Integer id = entry.getKey();
SnapContext snapContext = entry.getValue();
if (snapContext != null) {
attributeForContext = getAttributeForContext(snapContext, criterions);
if (attributeForContext != null) {
......@@ -426,16 +366,16 @@ public class RealSnapReader implements ISnapReader {
if (arrayList != null) {
int numberOfContexts = arrayList.length;
int[] lvalue = new int[numberOfContexts];
java.lang.String[] svalue = new java.lang.String[numberOfContexts];
String[] svalue = new String[numberOfContexts];
for (int i = 0; i < numberOfContexts; i++) {
SnapContext currentContext = arrayList[i];
contextId = currentContext.getId();
lvalue[i] = contextId;
svalue[i] = currentContext.getName() + splitCharact + currentContext.getAuthor_name()
+ splitCharact + sdf.format(currentContext.getCreation_date()) + splitCharact
+ currentContext.getReason() + splitCharact + currentContext.getDescription();
svalue[i] = currentContext.getName() + SPLIT_CHAR + currentContext.getAuthor_name() + SPLIT_CHAR
+ sdf.format(currentContext.getCreation_date()) + SPLIT_CHAR + currentContext.getReason()
+ SPLIT_CHAR + currentContext.getDescription();
}
ret.lvalue = lvalue;
ret.svalue = svalue;
......@@ -446,9 +386,8 @@ public class RealSnapReader implements ISnapReader {
@Override
public List<String> getSnapshotAttributeList() throws DevFailed {
List<String> snapshotAttributeList = new ArrayList<String>();
List<String> snapshotAttributeList = new ArrayList<>();
Map<Integer, SnapContext> allSnapContext = getAllSnapContext();
if (allSnapContext != null && !allSnapContext.isEmpty()) {
Collection<SnapContext> values = allSnapContext.values();
List<String> attributeForContext = null;
......
//+======================================================================
//$Source: /cvsroot/tango-cs/tango/api/java/fr/soleil/TangoSnapshoting/SnapExtractorApi/lifecycle/DefaultLifeCycleManager.java,v $
//
//Project: Tango Archiving Service
//
//Description: Java source code for the class DefaultLifeCycleManager.
// (Claisse Laurent) - 5 juil. 2005
//
//$Author: soleilarc $
//
//$Revision: 1.6 $
//
//$Log: DefaultLifeCycleManager.java,v $
//Revision 1.6 2007/10/15 15:03:58 soleilarc
//Author: XP
//Mantis bug ID: 6256
//Comment: Add 2 new members to this class : snapUser and snapPassword, and their setters.
//
//Revision 1.5 2007/03/14 15:45:04 ounsy
//has two new parameters user and password
//
//Revision 1.4 2006/12/06 10:14:36 ounsy
//minor changes
//
//Revision 1.3 2006/06/02 14:26:54 ounsy
//added javadoc
//
//Revision 1.2 2006/05/04 14:32:10 ounsy
//minor changes (commented useless methods and variables)
//
//Revision 1.1 2006/01/27 14:36:48 ounsy
//new APIS for snap extracting
//
//Revision 1.1.2.2 2005/09/14 15:41:32 chinkumo
//Second commit !
//
//
//copyleft : Synchrotron SOLEIL
// L'Orme des Merisiers
// Saint-Aubin - BP 48
// 91192 GIF-sur-YVETTE CEDEX
//
//-======================================================================
package fr.soleil.archiving.snap.api.extractor.lifecycle;
import org.slf4j.Logger;
......@@ -59,7 +16,7 @@ import fr.soleil.archiving.snap.api.extractor.naming.DynamicAttributeNamerFactor
* @author CLAISSE
*/
public class DefaultLifeCycleManager extends Thread implements LifeCycleManager {
final static Logger logger = LoggerFactory.getLogger(DefaultLifeCycleManager.class);
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultLifeCycleManager.class);
/**
* A reference to the device that instantiated this, if the application is
* running in device mode
......@@ -73,7 +30,7 @@ public class DefaultLifeCycleManager extends Thread implements LifeCycleManager
@Override
public synchronized void applicationWillStart() {
logger.info(".....INITIALIZING APPLICATION");
LOGGER.info(".....INITIALIZING APPLICATION");
try {
startFactories();
......@@ -85,7 +42,7 @@ public class DefaultLifeCycleManager extends Thread implements LifeCycleManager
this.warnWatcherFault();
}
logger.info(".....APPLICATION INITIALIZED");
LOGGER.info(".....APPLICATION INITIALIZED");
}
/**
......@@ -101,12 +58,12 @@ public class DefaultLifeCycleManager extends Thread implements LifeCycleManager
public synchronized void applicationWillClose() {
try {
// begin do stuff
logger.info("Application will close !");
LOGGER.info("Application will close !");
snapReader = SnapReaderFactory.getCurrentImpl();
snapReader.closeConnection();
logger.info("Application closed");
LOGGER.info("Application closed");
// end do stuff
System.exit(0);
} catch (Throwable t) {
......
package fr.soleil.archiving.snap.api.extractor.tools;
import java.sql.Timestamp;
import java.time.format.DateTimeFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -11,6 +12,7 @@ import fr.soleil.archiving.common.api.exception.ArchivingException;
import fr.soleil.archiving.common.api.utils.DateUtil;
import fr.soleil.archiving.snap.api.manager.SnapManagerApi;
import fr.soleil.database.connection.DataBaseParameters.DataBaseType;
import fr.soleil.lib.project.ObjectUtils;
/**
* A class with a few exception handling methods.
......@@ -18,34 +20,30 @@ import fr.soleil.database.connection.DataBaseParameters.DataBaseType;
* @author CLAISSE
*/
public class Tools {
final static Logger logger = LoggerFactory.getLogger(Tools.class);
private static final Logger LOGGER = LoggerFactory.getLogger(Tools.class);
public static final String FR_DATE_PATTERN = "dd-MM-yyyy HH:mm:ss.SSS";
public static final String US_DATE_PATTERN = "yyyy-MM-dd HH:mm:ss.SSS";
static final java.util.GregorianCalendar calendar = new java.util.GregorianCalendar();
static final java.text.SimpleDateFormat genFormatFR = new java.text.SimpleDateFormat(
FR_DATE_PATTERN);
static final java.text.SimpleDateFormat genFormatUS = new java.text.SimpleDateFormat(
US_DATE_PATTERN);
private static final DateTimeFormatter FR_DATE_FORMAT = fr.soleil.lib.project.date.DateUtil
.getDateTimeFormatter(FR_DATE_PATTERN);
private static final DateTimeFormatter US_DATE_FORMAT = fr.soleil.lib.project.date.DateUtil
.getDateTimeFormatter(FR_DATE_PATTERN);
/**
* Returns a date as a String formated for the database.
*
* @param milliseconds
* the date in milliseconds
* @param milliseconds the date in milliseconds
* @return A date as a String formated for the database.
*/
public static String formatDate(long milliseconds) {
DataBaseType type = SnapManagerApi.getSnapDbType();
String date = "";
String date = ObjectUtils.EMPTY_STRING;
switch (type) {
case ORACLE:
date = DateUtil.milliToString(milliseconds,
DateUtil.FR_DATE_PATTERN);
date = DateUtil.milliToString(milliseconds, DateUtil.FR_DATE_PATTERN);
break;
case MYSQL:
default:
date = DateUtil.milliToString(milliseconds,
DateUtil.US_DATE_PATTERN);
date = DateUtil.milliToString(milliseconds, DateUtil.US_DATE_PATTERN);
}
return date;
}
......@@ -53,11 +51,9 @@ public class Tools {
/**
* Converts a Throwable to a DevFailed and throws it.
*
* @param exception
* The exception to convert
* @param exception The exception to convert
* @return The DevFailed representation
* @throws DevFailed
* Always thrown by definition of the method
* @throws DevFailed Always thrown by definition of the method
*/
public static void throwDevFailed(Throwable exception) throws DevFailed {
DevFailed devFailed = new DevFailed();
......@@ -66,48 +62,43 @@ public class Tools {
}
/**
* Extracts causes from a Throwable if it is an instance of DevFailed, and
* prints it.
* Extracts causes from a Throwable if it is an instance of DevFailed, and prints it.
*
* @param t
* The exception to log
* @param t The exception to log
*/
public static void printIfDevFailed(Throwable t) {
t.printStackTrace();
if (t instanceof DevFailed) {
if (((DevFailed) t).getCause() != null) {
((DevFailed) t).getCause().printStackTrace();
DevFailed df = (DevFailed) t;
if (df.getCause() != null) {
df.getCause().printStackTrace();
}
DevError[] errors = ((DevFailed) t).errors;
DevError[] errors = df.errors;
if (errors != null && errors.length != 0) {
for (int i = 0; i < errors.length; i++) {
DevError error = errors[i];
logger.error("desc/" + error.desc + "/origin/"
+ error.origin + "/reason/" + error.reason);
LOGGER.error("desc/" + error.desc + "/origin/" + error.origin + "/reason/" + error.reason);
}
}
}
}
/**
* Cast a string format date (dd-MM-yyyy HH:mm:ss or yyyy-MM-dd HH:mm:ss)
* into long (number of milliseconds since January 1, 1970)
* Cast a string format date (dd-MM-yyyy HH:mm:ss or yyyy-MM-dd HH:mm:ss) into long (number of milliseconds since
* January 1, 1970)
*
* @param date
* @return
* @throws ArchivingException
*/
static public long stringToMilli(String date) {
public static long stringToMilli(String date) {
long milli;
boolean isFr = (date.indexOf("-") != 4);
int currentLength = date.length();
String toTheDay = "yyyy-MM-dd";
if (isFr) {
} else {
if (!isFr) {
if (currentLength == toTheDay.length()) {
date += " 00:00:00";
}
......@@ -136,30 +127,27 @@ public class Tools {
date += "0";
}
}
if (date.indexOf(".") == -1) {
date = date + (".000");
}
try {
if (isFr) {
genFormatFR.parse(date);
return genFormatFR.getCalendar().getTimeInMillis();
milli = fr.soleil.lib.project.date.DateUtil.stringToMilli(date, FR_DATE_FORMAT);
} else {
genFormatUS.parse(date);
return genFormatUS.getCalendar().getTimeInMillis();
milli = fr.soleil.lib.project.date.DateUtil.stringToMilli(date, US_DATE_FORMAT);
}
} catch (Exception e1) {
try {
e1.printStackTrace();
Timestamp ts = Timestamp.valueOf(date);
return ts.getTime();
milli = ts.getTime();
} catch (Exception e) {
e.printStackTrace();
return -1;
milli = -1;
}
}
return milli;
}
}
......@@ -43,7 +43,7 @@
package fr.soleil.archiving.snap.api.manager;
import fr.soleil.archiving.common.api.tools.AttributeHeavy;
import fr.soleil.archiving.snap.api.tools.Criterions;
import fr.soleil.archiving.common.api.tools.Criterions;
import fr.soleil.archiving.snap.api.tools.SnapAttributeExtract;
import fr.soleil.archiving.snap.api.tools.SnapContext;
import fr.soleil.archiving.snap.api.tools.Snapshot;
......
// +======================================================================
// $Source: /cvsroot/tango-cs/tango/api/java/fr/soleil/TangoSnapshoting/SnapManagerApi/SnapManagerApi.java,v $
//
// Project: Tango Archiving Service
//
// Description: Java source code for the class SnapManagerApi.
// (Chinkumo Jean) - Nov 2, 2004
// $Author: soleilarc $
//
// $Revision: 1.20 $
//
// $Log: SnapManagerApi.java,v $
// Revision 1.20 2007/10/15 13:24:49 soleilarc
// Author: XP
// Mantis bug ID: 6695
// Comment:
// In the connectSnapDatabase method, change the syntax oneString.equals("") into this one : "".equals(oneString).
// In the TriggerSetEquipments method, to use a final SnapshotingException exception, to get the list of all lift exceptions with all unreachable devices, by adding the DevFailed exceptions to its stack.
//
// Revision 1.19 2007/06/29 09:20:31 ounsy
// devLong represented as Integer
//
// Revision 1.18 2007/03/14 15:43:50 ounsy
// modified launchSnap2Archiver to no longer wait after launching a snapshot
//
// Revision 1.17 2007/01/22 10:47:13 ounsy
// added a giveup condition in launchSnap2Archiver
//
// Revision 1.16 2006/11/20 09:27:18 ounsy
// minor changes
//
// Revision 1.15 2006/10/31 16:54:24 ounsy
// milliseconds and null values management
//
// Revision 1.14 2006/10/30 14:37:21 ounsy
// minor change
//
// Revision 1.13 2006/06/28 12:43:58 ounsy
// image support
//
// Revision 1.12 2006/05/17 10:13:08 ounsy
// added the name of the attribute the command failed on for the TriggerSetEquipment method
//
// Revision 1.11 2006/05/04 14:32:38 ounsy
// minor changes (commented useless methods and variables)
//
// Revision 1.10 2006/04/13 12:46:48 ounsy
// spectrum management updated
//
// Revision 1.9 2006/04/12 15:32:59 ounsy
// added a wait loop in launchSnap2Archiver so that the snap is completely loaded
//
// Revision 1.8 2006/02/17 09:29:50 chinkumo
// Minor change : code reformated.
//
// Revision 1.7 2006/02/15 09:02:56 ounsy
// Spectrums Management
//
// Revision 1.6 2005/11/29 17:11:17 chinkumo
// no message
//
// Revision 1.5.2.1 2005/11/15 13:34:38 chinkumo
// no message
//
// Revision 1.5 2005/08/19 14:04:02 chinkumo
// no message
//
// Revision 1.4.6.1.2.1 2005/08/11 08:16:49 chinkumo
// The 'SetEquipement' command and thus functionnality was added.
//
// Revision 1.4.6.1 2005/08/01 13:49:57 chinkumo
// Several changes carried out for the support of the new graphical application (Bensikin).
//
// Revision 1.4 2005/06/28 09:10:16 chinkumo
// Changes made to improve the management of exceptions were reported here.
//
// Revision 1.3 2005/06/24 12:04:18 chinkumo
// The fr.soleil.snapArchivingApi.SnapshotingApi.DataBaseAPI.crateNewSnap method was renamed into createNewSnap.
// This change was reported here.
//
// Revision 1.2 2005/01/26 15:35:37 chinkumo
// Ultimate synchronization before real sharing.
//
// Revision 1.1 2004/12/06 17:39:56 chinkumo
// First commit (new API architecture).
//
//
// copyleft : Synchrotron SOLEIL
// L'Orme des Merisiers
// Saint-Aubin - BP 48
// 91192 GIF-sur-YVETTE CEDEX
//
//-======================================================================
package fr.soleil.archiving.snap.api.manager;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.esrf.Tango.AttrDataFormat;
import fr.esrf.Tango.AttrWriteType;
import fr.esrf.Tango.DevFailed;
......@@ -111,27 +26,26 @@ import fr.esrf.TangoDs.TangoConst;
import fr.soleil.archiving.common.api.exception.ArchivingException;
import fr.soleil.archiving.common.api.tools.AttributeHeavy;
import fr.soleil.archiving.common.api.tools.AttributeLight;
import fr.soleil.archiving.common.api.tools.Criterions;
import fr.soleil.archiving.snap.api.DataBaseAPI;
import fr.soleil.archiving.snap.api.SnapConnectionParameters;
import fr.soleil.archiving.snap.api.tools.Criterions;
import fr.soleil.archiving.snap.api.tools.SnapAttributeExtract;
import fr.soleil.archiving.snap.api.tools.SnapConst;
import fr.soleil.archiving.snap.api.tools.SnapContext;
import fr.soleil.archiving.snap.api.tools.SnapTool;
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;
import fr.soleil.database.connection.DataBaseParameters.DataBaseType;
import fr.soleil.lib.project.ObjectUtils;
import fr.soleil.lib.project.math.NumberArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
/**
* Java source code for the class SnapManagerApi
*
* @author chinkumo
*/
public class SnapManagerApi {
// Device class
......@@ -166,7 +80,7 @@ public class SnapManagerApi {
if (snapDataBase != null) {
return snapDataBase.getHost();
} else {
return "";
return ObjectUtils.EMPTY_STRING;
}
}
......@@ -177,7 +91,7 @@ public class SnapManagerApi {
if (snapDataBase != null) {
return snapDataBase.getDbName();
} else {
return "";
return ObjectUtils.EMPTY_STRING;
}
}
......@@ -188,7 +102,7 @@ public class SnapManagerApi {
if (snapDataBase != null) {
return snapDataBase.getUser();
} else {
return "";
return ObjectUtils.EMPTY_STRING;
}
}
......@@ -199,7 +113,7 @@ public class SnapManagerApi {
if (snapDataBase != null) {
return snapDataBase.getPassword();
} else {
return "";
return ObjectUtils.EMPTY_STRING;
}
}
......@@ -225,7 +139,7 @@ public class SnapManagerApi {
* @throws DevFailed
*/
private static String chooseDevice(final String deviceClass) throws DevFailed {
String device_name = "";
String device_name = ObjectUtils.EMPTY_STRING;
String[] devicesList = null;
if (SNAP_ARCHIVER_DEVICE_CLASS.equals(deviceClass)) {
initDeviceList(SNAP_ARCHIVER_DEVICE_CLASS);
......@@ -314,13 +228,12 @@ public class SnapManagerApi {
}
}
private static String[] split_att_name_3_fields(String att_name) {
String host = "";
String domain = "";
String family = "";
String member = "";
String attribut = "";
String host = ObjectUtils.EMPTY_STRING;
String domain = ObjectUtils.EMPTY_STRING;
String family = ObjectUtils.EMPTY_STRING;
String member = ObjectUtils.EMPTY_STRING;
String attribut = ObjectUtils.EMPTY_STRING;
final String[] argout = new String[5];// = {"HOST", "DOMAIN", "FAMILY",
// "MEMBER", "ATTRIBUT"};
String[] decoupe; // découpage en 5 partie : host, domain, family,
......@@ -378,7 +291,6 @@ public class SnapManagerApi {
}
/**
* This method gets informations on a given attribute and registers the
* attribute into the database "Snap"
......@@ -440,14 +352,14 @@ public class SnapManagerApi {
} catch (final DevFailed devFailed) {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.ATT_UNREACH_EXCEPTION;
final String reason = "Failed while executing SnapManagerApi.register() method...";
final String desc = "";
throw new SnapshotingException(message, reason, ErrSeverity.PANIC, desc, "", devFailed);
final String desc = ObjectUtils.EMPTY_STRING;
throw new SnapshotingException(message, reason, ErrSeverity.PANIC, desc, ObjectUtils.EMPTY_STRING,
devFailed);
} catch (final SnapshotingException e) {
throw e;
}
}
/**
* This method insure that a given attribute was registered into Snap DB
*
......@@ -512,7 +424,7 @@ public class SnapManagerApi {
try {
final String device = chooseDevice(SNAP_MANAGER_DEVICE_CLASS);
if (!device.equals("")) {
if (!device.isEmpty()) {
final DeviceProxy deviceProxy = new DeviceProxy(device);
deviceProxy.set_timeout_millis(snapContext.getAttributeList().size() * timeout);
deviceProxy.ping();
......@@ -525,20 +437,20 @@ public class SnapManagerApi {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : "
+ SnapConst.ERROR_SNAPPATTERN_CREATION;
final String reason = "Failed while executing SnapManagerApi.createContext2Manager() method...";
final String desc = "";
throw new SnapshotingException(message, reason, ErrSeverity.PANIC, desc, "");
final String desc = ObjectUtils.EMPTY_STRING;
throw new SnapshotingException(message, reason, ErrSeverity.PANIC, desc, ObjectUtils.EMPTY_STRING);
}
} catch (final DevFailed devFailed) {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.DEV_UNREACH_EXCEPTION;
final String reason = "Failed while executing SnapManagerApi.createContext2Manager() method...";
final String desc = "";
throw new SnapshotingException(message, reason, ErrSeverity.PANIC, desc, "", devFailed);
final String desc = ObjectUtils.EMPTY_STRING;
throw new SnapshotingException(message, reason, ErrSeverity.PANIC, desc, ObjectUtils.EMPTY_STRING,
devFailed);
}
return newContextID;
}
/**
* TODO LG Description : Extracts the clause SQL from the given criterions
* and gets the contexts which subscribe to thoses conditions
......@@ -553,9 +465,9 @@ public class SnapManagerApi {
throw new SnapshotingException(DATA_BASE_API_NOT_INIT);
}
// Gets the clause that corresponds to the given criterions
final String clause = criterions.getContextClause();
final String clause = SnapTool.getContextClause(criterions);
// Gets the conditions related to the context identifier
final int context_id = criterions.getIdContextContextTable();
final int context_id = SnapTool.getIdContextContextTable(criterions);
// Gets the list of the contexts which subscribe to all thoses
// conditions
return snapDataBase.getContext(clause, context_id);
......@@ -633,13 +545,13 @@ public class SnapManagerApi {
* (criterions)
* @throws SnapshotingException
*/
public static List<AttributeHeavy> getContextAssociatedAttributes(final int id_context,
final Criterions criterions) throws SnapshotingException {
public static List<AttributeHeavy> getContextAssociatedAttributes(final int id_context, final Criterions criterions)
throws SnapshotingException {
if (snapDataBase == null) {
throw new SnapshotingException(DATA_BASE_API_NOT_INIT);
}
final List<AttributeHeavy> res = snapDataBase.getContextAttributes(id_context,
criterions.getAttributeClause());
SnapTool.getAttributeClause(criterions));
return res;
}
......@@ -678,7 +590,6 @@ public class SnapManagerApi {
return result;
}
public static int getMaxID() throws SnapshotingException {
if (snapDataBase == null) {
throw new SnapshotingException(DATA_BASE_API_NOT_INIT);
......@@ -686,7 +597,6 @@ public class SnapManagerApi {
return snapDataBase.getMaxContextID();
}
/**
* TODO LG Description : Extracts the clause SQL from the given criterions
* and gets the snapshots which subscribe to thoses conditions
......@@ -702,11 +612,11 @@ public class SnapManagerApi {
throw new SnapshotingException(DATA_BASE_API_NOT_INIT);
}
// Gets the clause that corresponds to the given criterions
final String clause = criterions.getSnapshotClause();
final String clause = SnapTool.getSnapshotClause(criterions);
// Gets the conditions related to the context identifier and the
// snapshot identifier
final int id_context = criterions.getIdContextSnapTable();
final int id_snap = criterions.getIdSnap();
final int id_context = SnapTool.getIdContextSnapTable(criterions);
final int id_snap = SnapTool.getIdSnap(criterions);
// Gets the list of the snapshots which subscribe to all thoses
// conditions
return snapDataBase.getContextAssociatedSnapshots(clause, id_context, id_snap);
......@@ -791,13 +701,14 @@ public class SnapManagerApi {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.ERROR_SNAP_SET_EQUIPMENT;
final String reason = "Failed while executing SnapManagerApi.setEquipmentsWithSnapshot() method...";
final String desc = "No SnapManager available";
throw new SnapshotingException(message, reason, ErrSeverity.PANIC, desc, "");
throw new SnapshotingException(message, reason, ErrSeverity.PANIC, desc, ObjectUtils.EMPTY_STRING);
}
} catch (final DevFailed devFailed) {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.DEV_UNREACH_EXCEPTION;
final String reason = "Failed while executing SnapManagerApi.setEquipmentsWithSnapshot() method...";
final String desc = "";
throw new SnapshotingException(message, reason, ErrSeverity.PANIC, desc, "", devFailed);
final String desc = ObjectUtils.EMPTY_STRING;
throw new SnapshotingException(message, reason, ErrSeverity.PANIC, desc, ObjectUtils.EMPTY_STRING,
devFailed);
}
}
......@@ -918,10 +829,12 @@ public class SnapManagerApi {
+ nameOfFailure;
final String desc = reason;
if (snapFinalEx == null) {
snapFinalEx = new SnapshotingException(message, reason, ErrSeverity.PANIC, desc, "", devFailed);
snapFinalEx = new SnapshotingException(message, reason, ErrSeverity.PANIC, desc,
ObjectUtils.EMPTY_STRING, devFailed);
} else {
final SnapshotingException snapEx = new SnapshotingException(devFailed);
snapFinalEx.addStack(message, reason, ErrSeverity.PANIC, desc, "", snapEx);
snapFinalEx.addStack(message, reason, ErrSeverity.PANIC, desc, ObjectUtils.EMPTY_STRING,
snapEx);
}
}
}
......@@ -942,7 +855,7 @@ public class SnapManagerApi {
try {
final int timeout = 3000;
final String device = chooseDevice(SNAP_MANAGER_DEVICE_CLASS);
if (!device.equals("")) {
if (!device.equals(ObjectUtils.EMPTY_STRING)) {
final DeviceProxy deviceProxy = new DeviceProxy(device);
deviceProxy.set_timeout_millis(snapShot.getAttribute_List().size() * timeout);
deviceProxy.ping();
......@@ -961,7 +874,7 @@ public class SnapManagerApi {
}
for (int i = 0; i < attributes.size(); ++i) {
SnapAttributeExtract attr = attributes.get(i);
argin[i + 3] = (attr != null) ? attr.getAttributeCompleteName() : "";
argin[i + 3] = (attr != null) ? attr.getAttributeCompleteName() : ObjectUtils.EMPTY_STRING;
}
}
attributes = null;
......@@ -973,14 +886,15 @@ public class SnapManagerApi {
} else {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.ERROR_SNAP_SET_EQUIPMENT;
final String reason = "Failed while executing SnapManagerApi.setEquipmentWithCommand() method...";
final String desc = "";
throw new SnapshotingException(message, reason, ErrSeverity.PANIC, desc, "");
final String desc = ObjectUtils.EMPTY_STRING;
throw new SnapshotingException(message, reason, ErrSeverity.PANIC, desc, ObjectUtils.EMPTY_STRING);
}
} catch (final DevFailed devFailed) {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.DEV_UNREACH_EXCEPTION;
final String reason = "Failed while executing SnapManagerApi.setEquipmentWithCommand() method...";
final String desc = devFailed.getMessage();
throw new SnapshotingException(message, reason, ErrSeverity.PANIC, desc, "", devFailed);
throw new SnapshotingException(message, reason, ErrSeverity.PANIC, desc, ObjectUtils.EMPTY_STRING,
devFailed);
}
}
......
// +======================================================================
// $Source:
// /cvsroot/tango-cs/tango/api/java/fr/soleil/TangoSnapshoting/SnapManagerApi/SnapManagerImpl.java,v
// $
//
// Project: Tango Archiving Service
//
// Description: Java source code for the class SnapManagerImpl.
// (Chinkumo Jean) - 30 juin 2005
//
// $Author: chinkumo $
//
// $Revision: 1.9 $
//
// $Log: SnapManagerImpl.java,v $
// Revision 1.9 2008/01/08 15:32:19 chinkumo
// minor changes
//
// Revision 1.8 2007/11/23 09:21:55 pierrejoseph
// The getSnap method content comes from the RealSnapReader class.
//
// Revision 1.7 2007/10/03 15:53:09 soleilarc
// Author: XP
// Mantis bug ID: 6594
// Comment: In the launchSnapshot method, one redefines the catch clause with
// the DevFailed exception for a failure of launchSnap2Archiver, so as to be
// able to recognize a timeout after.
//
// Revision 1.6 2007/03/14 15:44:34 ounsy
// user and password are no longer hard-coded into this class
//
// Revision 1.5 2006/01/27 13:04:44 ounsy
// organised imports
//
// Revision 1.4 2006/01/10 10:54:05 chinkumo
// A bug were corrected in the launchSnapshot method. (Thanks to R.Girardot)
// This bug concerns filters and dates.
//
// Revision 1.3 2005/11/29 17:11:17 chinkumo
// no message
//
// Revision 1.2.2.1 2005/11/15 13:34:38 chinkumo
// no message
//
// Revision 1.2 2005/08/19 14:48:37 chinkumo
// no message
//
// Revision 1.1.4.3.2.1 2005/08/11 08:19:29 chinkumo
// The 'SetEquipement' command and thus functionnality was added.
//
// Revision 1.1.4.3 2005/08/04 08:04:04 chinkumo
// The changes made into the ISnapManager class was reported here.
// (ISnapManager's constants were removed as they were already defined in the
// TangoSnapshoting.SnapshotingTools.Tools.GlobalConst class).
//
// Revision 1.1.4.2 2005/08/01 13:51:45 chinkumo
// Classes added for the support of the new graphical application (Bensikin).
//
//
// copyleft : Synchrotron SOLEIL
// L'Orme des Merisiers
// Saint-Aubin - BP 48
// 91192 GIF-sur-YVETTE CEDEX
//
// -======================================================================
package fr.soleil.archiving.snap.api.manager;
import java.util.List;
......@@ -74,24 +9,23 @@ import org.tango.utils.DevFailedUtils;
import fr.esrf.Tango.DevFailed;
import fr.esrf.Tango.ErrSeverity;
import fr.soleil.archiving.common.api.tools.AttributeHeavy;
import fr.soleil.archiving.snap.api.tools.Condition;
import fr.soleil.archiving.snap.api.tools.Criterions;
import fr.soleil.archiving.common.api.tools.Condition;
import fr.soleil.archiving.common.api.tools.Criterions;
import fr.soleil.archiving.snap.api.tools.SnapAttributeExtract;
import fr.soleil.archiving.snap.api.tools.SnapConst;
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.lib.project.ObjectUtils;
/**
* @author GARDA
* <p/>
* To change the template for this generated type comment go to
* Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
* Java source code for the class SnapManagerImpl.
*
* @author chinkumo, GARDA
*/
public class SnapManagerImpl implements ISnapManager {
final static Logger logger = LoggerFactory.getLogger(SnapManagerImpl.class);
private static final Logger LOGGER = LoggerFactory.getLogger(SnapManagerImpl.class);
public SnapManagerImpl() {
}
......@@ -106,8 +40,8 @@ public class SnapManagerImpl implements ISnapManager {
throws SnapshotingException {
// Gets the list of attributes associated to the given snapshot
final List<SnapAttributeExtract> arrayList = SnapManagerApi
.getSnapshotAssociatedAttributes(snapshot, contextID);
final List<SnapAttributeExtract> arrayList = SnapManagerApi.getSnapshotAssociatedAttributes(snapshot,
contextID);
return arrayList.toArray(new SnapAttributeExtract[arrayList.size()]);
}
......@@ -130,8 +64,8 @@ public class SnapManagerImpl implements ISnapManager {
} catch (final SnapshotingException e) {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.ERROR_SNAPPATTERN_CREATION;
final String reason = "Failed while executing SnapManagerApi.createContext2Manager() method...";
final String desc = "";
throw new SnapshotingException(message, reason, ErrSeverity.ERR, desc, "", e);
final String desc = ObjectUtils.EMPTY_STRING;
throw new SnapshotingException(message, reason, ErrSeverity.ERR, desc, ObjectUtils.EMPTY_STRING, e);
}
return context;
......@@ -149,12 +83,13 @@ public class SnapManagerImpl implements ISnapManager {
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.ERROR_LAUNCHINGSNAP;
final String reason = "Failed while executing SnapManagerApi.launchSnap2Archiver() method...";
String desc = "No SnapArchiver Found";
final SnapshotingException snapEx = new SnapshotingException(message, reason, ErrSeverity.ERR, desc, "");
final SnapshotingException snapEx = new SnapshotingException(message, reason, ErrSeverity.ERR, desc,
ObjectUtils.EMPTY_STRING);
try {
snapEx.initCause(dFEx);
} catch (final IllegalStateException e) {
logger.error("CLA/Failed during initCause!");
LOGGER.error("CLA/Failed during initCause!");
e.printStackTrace();
// do nothing
}
......@@ -167,7 +102,7 @@ public class SnapManagerImpl implements ISnapManager {
// Gets the snapshot identifier
final Condition[] condition = new Condition[1];
condition[0] = new Condition(SnapConst.ID_SNAP, SnapConst.OP_EQUALS, snapId + "");
condition[0] = new Condition(SnapConst.ID_SNAP, SnapConst.OP_EQUALS, snapId + ObjectUtils.EMPTY_STRING);
final Criterions criterions = new Criterions(condition);
final SnapshotLight[] snapShotLight = findSnapshots(criterions);
......@@ -176,7 +111,8 @@ public class SnapManagerImpl implements ISnapManager {
final SnapshotLight snap = snapShotLight[0];
final List<SnapAttributeExtract> arrayList = SnapManagerApi.getSnapshotAssociatedAttributes(snap,
context.getId());
final String[] tableau = { "" + context.getId(), "" + snap.getId_snap(), "" + snap.getSnap_date() };
final String[] tableau = { ObjectUtils.EMPTY_STRING + context.getId(),
ObjectUtils.EMPTY_STRING + snap.getId_snap(), ObjectUtils.EMPTY_STRING + snap.getSnap_date() };
final Snapshot snapShot = new Snapshot(tableau);
snapShot.setAttribute_List(arrayList);
return snapShot;
......@@ -184,12 +120,11 @@ public class SnapManagerImpl implements ISnapManager {
// Pas de snapshot correspondant.
final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.ERROR_RET_SNAP;
final String reason = "Failed while executing SnapManagerApi.getSnapshotAssociatedAttributes() method...";
final String desc = "";
throw new SnapshotingException(message, reason, ErrSeverity.ERR, desc, "");
final String desc = ObjectUtils.EMPTY_STRING;
throw new SnapshotingException(message, reason, ErrSeverity.ERR, desc, ObjectUtils.EMPTY_STRING);
}
}
@Override
public SnapshotLight updateCommentOfSnapshot(final SnapshotLight context, final String comment)
throws SnapshotingException {
......@@ -201,7 +136,7 @@ public class SnapManagerImpl implements ISnapManager {
// Gets the updated snapshot
final Condition[] condition = new Condition[1];
final String id_snap_str = "" + id_snap;
final String id_snap_str = ObjectUtils.EMPTY_STRING + id_snap;
condition[0] = new Condition(SnapConst.ID_SNAP, SnapConst.OP_EQUALS, id_snap_str);
final Criterions criterions = new Criterions(condition);
......
package fr.soleil.archiving.snap.api.persistence;
import java.util.Arrays;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import fr.esrf.Tango.AttrDataFormat;
import fr.esrf.Tango.AttrWriteType;
import fr.esrf.TangoDs.TangoConst;
......@@ -16,13 +21,9 @@ import fr.soleil.archiving.snap.api.persistence.spring.dto.ScStr1Val;
import fr.soleil.archiving.snap.api.persistence.spring.dto.ScStr2Val;
import fr.soleil.archiving.snap.api.persistence.spring.dto.Sp1Val;
import fr.soleil.archiving.snap.api.persistence.spring.dto.Sp2Val;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Arrays;
public class SpringSnapshotPersistenceManagerImpl implements SnapshotPersistenceManager {
private final Logger logger = LoggerFactory.getLogger(SpringSnapshotPersistenceManagerImpl.class);
private static final Logger LOGGER = LoggerFactory.getLogger(SpringSnapshotPersistenceManagerImpl.class);
private final DAOBeansLoader beans;
SpringSnapshotPersistenceManagerImpl(final String beansFileName, final String userName, final String password) {
......@@ -32,7 +33,8 @@ public class SpringSnapshotPersistenceManagerImpl implements SnapshotPersistence
@Override
public void store(final AnyAttribute attribute, final PersistenceContext persistenceContext) throws Exception {
final SnapshotPersistenceContext context = (SnapshotPersistenceContext) persistenceContext;
logger.debug("storing {} with value: {}", attribute.getCompleteName(), Arrays.toString(attribute.getConvertedStringValuesTable()));
LOGGER.debug("storing {} with value: {}", attribute.getCompleteName(),
Arrays.toString(attribute.getConvertedStringValuesTable()));
switch (attribute.getFormat()) {
case AttrDataFormat._SCALAR:
if (attribute.getWritable() == AttrWriteType._READ) {
......@@ -60,12 +62,11 @@ public class SpringSnapshotPersistenceManagerImpl implements SnapshotPersistence
break;
case AttrDataFormat._IMAGE:
logger.warn("{} is an image, format not supported", attribute.getCompleteName());
/* if (attribute.getWritable() == AttrWriteType._READ) {
if (attribute.getWritable() == AttrWriteType._READ) {
beans.getIm1ValDAO().create(new Im1Val(attribute, context));
} else {
beans.getIm2ValDAO().create(new Im2Val(attribute, context));
}*/
}
break;
}
}
......
package fr.soleil.archiving.snap.api.persistence.spring.dao;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import fr.soleil.archiving.snap.api.persistence.spring.dto.Im1Val;
import fr.soleil.archiving.snap.api.persistence.spring.dto.Im2Val;
import fr.soleil.archiving.snap.api.persistence.spring.dto.ScNum1Val;
......@@ -8,14 +14,9 @@ import fr.soleil.archiving.snap.api.persistence.spring.dto.ScStr1Val;
import fr.soleil.archiving.snap.api.persistence.spring.dto.ScStr2Val;
import fr.soleil.archiving.snap.api.persistence.spring.dto.Sp1Val;
import fr.soleil.archiving.snap.api.persistence.spring.dto.Sp2Val;
import org.slf4j.ext.XLogger;
import org.slf4j.ext.XLoggerFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class ClasspathDAOBeansLoader implements DAOBeansLoader {
final static XLogger logger = XLoggerFactory.getXLogger(ClasspathDAOBeansLoader.class);
private static final XLogger LOGGER = XLoggerFactory.getXLogger(ClasspathDAOBeansLoader.class);
private static final String DEFAULT_BEANS_FILE_NAME = "beans.xml";
private final String resourceName;
private final ApplicationContext applicationContext;
......@@ -30,20 +31,20 @@ public class ClasspathDAOBeansLoader implements DAOBeansLoader {
private ValDAO<Im2Val> im2ValDAO;
public ClasspathDAOBeansLoader(String _resourceName, String userName, String password) {
logger.entry(_resourceName, userName, password);
LOGGER.entry(_resourceName, userName, password);
boolean defaultResource = _resourceName == null || _resourceName.trim().length() == 0;
this.resourceName = defaultResource ? DEFAULT_BEANS_FILE_NAME : _resourceName;
logger.info("configure hibernate resource: " + resourceName);
LOGGER.info("configure hibernate resource: " + resourceName);
System.setProperty("user", userName);
System.setProperty("password", password);
applicationContext = new ClassPathXmlApplicationContext(this.resourceName);
instantiateBeans(applicationContext);
logger.exit();
LOGGER.exit();
}
@SuppressWarnings("unchecked")
private void instantiateBeans(BeanFactory ctx) {
logger.entry(ctx);
LOGGER.entry(ctx);
scNum1ValDAO = (ValDAO<ScNum1Val>) ctx.getBean("scNum1ValDAO");
scNum2ValDAO = (ValDAO<ScNum2Val>) ctx.getBean("scNum2ValDAO");
scStr1ValDAO = (ValDAO<ScStr1Val>) ctx.getBean("scStr1ValDAO");
......@@ -52,7 +53,7 @@ public class ClasspathDAOBeansLoader implements DAOBeansLoader {
sp2ValDAO = (ValDAO<Sp2Val>) ctx.getBean("sp2ValDAO");
im1ValDAO = (ValDAO<Im1Val>) ctx.getBean("im1ValDAO");
im2ValDAO = (ValDAO<Im2Val>) ctx.getBean("im2ValDAO");
logger.exit();
LOGGER.exit();
}
/**
......
/* Synchrotron Soleil
*
* File : compositeId.java
*
* Project : javaapi
*
* Description :
*
* Author : CLAISSE
*
* Original : 9 mars 07
*
* Revision: Author:
* Date: State:
*
* Log: compositeId.java,v
*
*/
/*
* Created on 9 mars 07
*
* To change the template for this generated file go to
* Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
*/
package fr.soleil.archiving.snap.api.persistence.spring.dto;
import java.io.Serializable;
......@@ -29,11 +5,16 @@ import java.io.Serializable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* CompositeId
*
* @author CLAISSE
*/
public class CompositeId implements Serializable {
private static final long serialVersionUID = -7083548602060429550L;
final static Logger logger = LoggerFactory.getLogger(CompositeId.class);
private static final Logger LOGGER = LoggerFactory.getLogger(CompositeId.class);
private int idSnap;
private int idAtt;
......@@ -76,7 +57,7 @@ public class CompositeId implements Serializable {
* @return the idAtt
*/
public int getIdAtt() {
return this.idAtt;
return idAtt;
}
/**
......@@ -91,7 +72,7 @@ public class CompositeId implements Serializable {
* @return the idSnap
*/
public int getIdSnap() {
return this.idSnap;
return idSnap;
}
/**
......@@ -103,7 +84,7 @@ public class CompositeId implements Serializable {
}
public void trace() {
logger.debug(this + "/idSnap/" + idSnap + "/idAtt/" + idAtt);
LOGGER.debug(this + "/idSnap/" + idSnap + "/idAtt/" + idAtt);
}
@Override
......
/* Synchrotron Soleil
*
* File : ScNum1Val.java
*
* Project : javaapi
*
* Description :
*
* Author : CLAISSE
*
* Original : 7 mars 07
*
* Revision: Author:
* Date: State:
*
* Log: ScNum1Val.java,v
*
*/
/*
* Created on 7 mars 07
*
* To change the template for this generated file go to
* Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
*/
package fr.soleil.archiving.snap.api.persistence.spring.dto;
import fr.soleil.actiongroup.collectiveaction.onattributes.plugin.persistance.AnyAttribute;
import fr.soleil.archiving.snap.api.persistence.context.SnapshotPersistenceContext;
/**
* 1 numerical value
*
* @author CLAISSE
*/
public class ScNum1Val extends Val {
private double value;
......@@ -37,7 +18,7 @@ public class ScNum1Val extends Val {
public ScNum1Val(AnyAttribute attribute, SnapshotPersistenceContext context) {
super(attribute, context);
double[] val = attribute.getConvertedNumericValuesTable();
if (val == null) {
if (val == null || val.length < 1) {
value = Double.NaN;
} else {
value = val[0];
......
/* Synchrotron Soleil
*
* File : ScNum2Val.java
*
* Project : javaapi
*
* Description :
*
* Author : CLAISSE
*
* Original : 7 mars 07
*
* Revision: Author:
* Date: State:
*
* Log: ScNum2Val.java,v
*
*/
/*
* Created on 7 mars 07
*
* To change the template for this generated file go to
* Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
*/
package fr.soleil.archiving.snap.api.persistence.spring.dto;
import org.slf4j.Logger;
......@@ -30,8 +6,15 @@ import org.slf4j.LoggerFactory;
import fr.soleil.actiongroup.collectiveaction.onattributes.plugin.persistance.AnyAttribute;
import fr.soleil.archiving.snap.api.persistence.context.SnapshotPersistenceContext;
/**
* 2 numerical values
*
* @author CLAISSE
*/
public class ScNum2Val extends Val {
final static Logger logger = LoggerFactory.getLogger(ScNum2Val.class);
private static final Logger LOGGER = LoggerFactory.getLogger(ScNum2Val.class);
private double readValue;
private double writeValue;
......@@ -47,8 +30,8 @@ public class ScNum2Val extends Val {
readValue = Double.NaN;
writeValue = Double.NaN;
} else {
readValue = val[0];
writeValue = val[1];
readValue = val.length < 1 ? Double.NaN : val[0];
writeValue = val.length < 2 ? Double.NaN : val[1];
}
}
......@@ -56,7 +39,7 @@ public class ScNum2Val extends Val {
* @return the readValue
*/
public double getReadValue() {
return this.readValue;
return readValue;
}
/**
......@@ -71,7 +54,7 @@ public class ScNum2Val extends Val {
* @return the writeValue
*/
public double getWriteValue() {
return this.writeValue;
return writeValue;
}
/**
......@@ -84,7 +67,7 @@ public class ScNum2Val extends Val {
public void trace() {
super.getCompositeId().trace();
logger.debug("ScNum2Val/readValue/" + readValue);
logger.debug("ScNum2Val/writeValue/" + writeValue);
LOGGER.debug("ScNum2Val/readValue/" + readValue);
LOGGER.debug("ScNum2Val/writeValue/" + writeValue);
}
}
/* Synchrotron Soleil
*
* File : ScStr1Val.java
*
* Project : javaapi
*
* Description :
*
* Author : CLAISSE
*
* Original : 7 mars 07
*
* Revision: Author:
* Date: State:
*
* Log: ScStr1Val.java,v
*
*/
/*
* Created on 7 mars 07
*
* To change the template for this generated file go to
* Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
*/
package fr.soleil.archiving.snap.api.persistence.spring.dto;
import fr.soleil.actiongroup.collectiveaction.onattributes.plugin.persistance.AnyAttribute;
import fr.soleil.archiving.snap.api.persistence.context.SnapshotPersistenceContext;
/**
* 1 string value
*
* @author CLAISSE
*/
public class ScStr1Val extends Val {
private String value;
......@@ -37,7 +18,7 @@ public class ScStr1Val extends Val {
public ScStr1Val(AnyAttribute attribute, SnapshotPersistenceContext context) {
super(attribute, context);
String[] val = attribute.getConvertedStringValuesTable();
if (val == null) {
if (val == null || val.length < 1) {
value = null;
} else {
value = val[0];
......