diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/response/CollectiveResponseImpl.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/response/CollectiveResponseImpl.java index ad33099551bf71e5e96402566ccd47fdb3fc38bf..7c5e977e9a6148ecc465a7f0b853ab8def98038a 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/response/CollectiveResponseImpl.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/response/CollectiveResponseImpl.java @@ -1,40 +1,21 @@ -/* - * Synchrotron Soleil - * - * File : GroupResponse.java - * - * Project : DynamicTangoUtilities - * - * Description : - * - * Author : CLAISSE - * - * Original : 1 févr. 07 - * - * Revision: Author: - * Date: State: - * - * Log: GroupResponse.java,v - */ -/* - * Created on 1 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.response; import java.util.Collection; import java.util.Hashtable; import java.util.Map; +/** + * Implementation of CollectiveResponse + * + * @author CLAISSE + */ public class CollectiveResponseImpl implements CollectiveResponse { private final Map<String, IndividualResponse> individualResponses; private boolean hasFailed; private boolean isFailureDueToATimeout; public CollectiveResponseImpl() { - this.individualResponses = new Hashtable<String, IndividualResponse>(); + this.individualResponses = new Hashtable<>(); } @Override @@ -50,10 +31,8 @@ public class CollectiveResponseImpl implements CollectiveResponse { @Override public synchronized void addIndividualResponse(IndividualResponse individualResponse) { individualResponses.put(individualResponse.dev_name(), individualResponse); - if (individualResponse.has_failed()) { this.hasFailed = true; - if (individualResponse.has_timeout()) { this.isFailureDueToATimeout = true; } diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/response/IndividualAttributesResponseImpl.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/response/IndividualAttributesResponseImpl.java index 2f2fd57d178c6d43167fb7a0b0cbb430e5225e7e..15c73d59834c1fd74f30280bfc16b6951a963d78 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/response/IndividualAttributesResponseImpl.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/response/IndividualAttributesResponseImpl.java @@ -1,36 +1,17 @@ -/* - * Synchrotron Soleil - * - * File : IndividualAttributesResponse.java - * - * Project : DynamicTangoUtilities - * - * Description : - * - * Author : CLAISSE - * - * Original : 1 févr. 07 - * - * Revision: Author: - * Date: State: - * - * Log: IndividualAttributesResponse.java,v - */ -/* - * Created on 1 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.response; import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.DeviceAttributeWrapper; +/** + * Implementation of IndividualAttributesResponse + * + * @author CLAISSE + */ public class IndividualAttributesResponseImpl extends IndividualResponseImpl implements IndividualAttributesResponse { private DeviceAttributeWrapper[] data; - public IndividualAttributesResponseImpl(String _deviceName) { - super(_deviceName); + public IndividualAttributesResponseImpl(String deviceName) { + super(deviceName); } @Override diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/response/IndividualCommandResponse.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/response/IndividualCommandResponse.java index e0516069df782d158690820d38e45eb8f644ae0c..2f6461306cf2ef3e3d5a7a78736475d5e4c78e10 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/response/IndividualCommandResponse.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/response/IndividualCommandResponse.java @@ -1,31 +1,12 @@ -/* - * Synchrotron Soleil - * - * File : IIndividualCommandResponse.java - * - * Project : DynamicTangoUtilities - * - * Description : - * - * Author : CLAISSE - * - * Original : 1 févr. 07 - * - * Revision: Author: - * Date: State: - * - * Log: IIndividualCommandResponse.java,v - */ -/* - * Created on 1 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.response; import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.DeviceDataWrapper; +/** + * IndividualCommandResponse + * + * @author CLAISSE + */ public interface IndividualCommandResponse extends IndividualResponse { public DeviceDataWrapper get_data(); diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/response/IndividualCommandResponseImpl.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/response/IndividualCommandResponseImpl.java index fb06b66b05d36ee08ac66281f014ed9200225ae7..3d7bdcd444bfb94009d22c0b657e2314fbebb2fa 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/response/IndividualCommandResponseImpl.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/response/IndividualCommandResponseImpl.java @@ -2,22 +2,25 @@ package fr.soleil.actiongroup.collectiveaction.components.response; import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.DeviceDataWrapper; -public class IndividualCommandResponseImpl extends IndividualResponseImpl implements IndividualCommandResponse -{ +/** + * Implementation of IndividualCommandResponse + * + * @author CLAISSE + */ +public class IndividualCommandResponseImpl extends IndividualResponseImpl implements IndividualCommandResponse { private DeviceDataWrapper data; - - public IndividualCommandResponseImpl(String deviceName) - { - super ( deviceName ); + + public IndividualCommandResponseImpl(String deviceName) { + super(deviceName); } - public DeviceDataWrapper get_data() - { + @Override + public DeviceDataWrapper get_data() { return this.data; } - public void setData(DeviceDataWrapper _data) - { - this.data = _data; + @Override + public void setData(DeviceDataWrapper data) { + this.data = data; } } diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/response/IndividualResponse.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/response/IndividualResponse.java index fd4eddff96a6747528ea7276ba4a5477b52f301b..641eb33fdd1f2e50e0e2054db8902fb9168fbba0 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/response/IndividualResponse.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/response/IndividualResponse.java @@ -1,31 +1,12 @@ -/* - * Synchrotron Soleil - * - * File : dd.java - * - * Project : DynamicTangoUtilities - * - * Description : - * - * Author : CLAISSE - * - * Original : 1 févr. 07 - * - * Revision: Author: - * Date: State: - * - * Log: dd.java,v - */ -/* - * Created on 1 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.response; import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.DevErrorWrapper; +/** + * IndividualResponse + * + * @author CLAISSE + */ public interface IndividualResponse { public boolean has_failed(); @@ -35,9 +16,9 @@ public interface IndividualResponse { public boolean has_timeout(); - public void set_err_stack(DevErrorWrapper[] _err_stack); + public void set_err_stack(DevErrorWrapper[] err_stack); - public void set_failed(boolean _has_failed); + public void set_failed(boolean has_failed); - public void set_timeout(boolean _has_timeout); + public void set_timeout(boolean has_timeout); } diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/response/IndividualResponseImpl.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/response/IndividualResponseImpl.java index 82cb195cad4a6b20321e5c7759e7e29bc5a81ba1..aab65532cad44a8348e3689e84e66e97e94e1ea4 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/response/IndividualResponseImpl.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/response/IndividualResponseImpl.java @@ -1,39 +1,20 @@ -/* - * Synchrotron Soleil - * - * File : IndividualResponse.java - * - * Project : DynamicTangoUtilities - * - * Description : - * - * Author : CLAISSE - * - * Original : 1 févr. 07 - * - * Revision: Author: - * Date: State: - * - * Log: IndividualResponse.java,v - */ -/* - * Created on 1 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.response; import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.DevErrorWrapper; +/** + * Implementation of IndividualResponse + * + * @author CLAISSE + */ public class IndividualResponseImpl implements IndividualResponse { protected String deviceName; protected DevErrorWrapper[] err_stack; protected boolean has_failed; protected boolean has_timeout; - public IndividualResponseImpl(String _deviceName) { - this.deviceName = _deviceName; + public IndividualResponseImpl(String deviceName) { + this.deviceName = deviceName; } @Override @@ -57,17 +38,17 @@ public class IndividualResponseImpl implements IndividualResponse { } @Override - public void set_err_stack(DevErrorWrapper[] _err_stack) { - this.err_stack = _err_stack; + public void set_err_stack(DevErrorWrapper[] err_stack) { + this.err_stack = err_stack; } @Override - public void set_failed(boolean _has_failed) { - this.has_failed = _has_failed; + public void set_failed(boolean has_failed) { + this.has_failed = has_failed; } @Override - public void set_timeout(boolean _has_timeout) { - this.has_timeout = _has_timeout; + public void set_timeout(boolean has_timeout) { + this.has_timeout = has_timeout; } } diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleaction/atomic/ExecuteCommand.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleaction/atomic/ExecuteCommand.java index a836968c65c0a47479d0a08e3ea2c9ba27be527c..56384a6a8467c52c9e9f2d6314c17666a830318a 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleaction/atomic/ExecuteCommand.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleaction/atomic/ExecuteCommand.java @@ -1,43 +1,43 @@ package fr.soleil.actiongroup.collectiveaction.components.singleaction.atomic; + import fr.soleil.actiongroup.collectiveaction.components.singleactioncompletelistener.MinimalistActionListener; import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.ActionResult; import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.DeviceDataWrapper; import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.target.Target; /** - * Executes a void (no return) command on a device. Notifies its listener on completion. - * @author CLAISSE + * Executes a void (no return) command on a device. Notifies its listener on completion. + * + * @author CLAISSE */ -public class ExecuteCommand extends AtomicIndividualAction -{ +public class ExecuteCommand extends AtomicIndividualAction { /** * The command's name */ private String commandName; - + /** * The command's parameters */ private DeviceDataWrapper commandParameters; /** - * @param _listener The listener to notify on command execution completion - * @param _deviceToReadfrom The device to call the command on - * @param _commandName The command's name - * @param _commandParameters The command's parameters + * @param listener The listener to notify on command execution completion + * @param deviceToReadfrom The device to call the command on + * @param commandName The command's name + * @param commandParameters The command's parameters */ - public ExecuteCommand ( MinimalistActionListener _listener , Target _deviceToReadfrom , String _commandName , DeviceDataWrapper _commandParameters ) - { - super ( _listener , _deviceToReadfrom ); - this.commandName = _commandName; - this.commandParameters = _commandParameters; + public ExecuteCommand(MinimalistActionListener listener, Target deviceToReadfrom, String commandName, + DeviceDataWrapper commandParameters) { + super(listener, deviceToReadfrom); + this.commandName = commandName; + this.commandParameters = commandParameters; } @Override - protected ActionResult executeAtomicAction() throws Throwable - { - DeviceDataWrapper response = this.target.command_inout ( this.commandName , this.commandParameters ); - return new ActionResult ( response ); + protected ActionResult executeAtomicAction() throws Throwable { + DeviceDataWrapper response = this.target.command_inout(this.commandName, this.commandParameters); + return new ActionResult(response); } } \ No newline at end of file diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleaction/atomic/ExecuteStateCommand.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleaction/atomic/ExecuteStateCommand.java index 13b92baaeca22caaf3f40b03a525e3bda10cc474..95a2b54cc3cd7424db78ad8fe04d78400601d9dd 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleaction/atomic/ExecuteStateCommand.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleaction/atomic/ExecuteStateCommand.java @@ -1,21 +1,21 @@ package fr.soleil.actiongroup.collectiveaction.components.singleaction.atomic; + import fr.soleil.actiongroup.collectiveaction.components.singleactioncompletelistener.MinimalistActionListener; import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.target.Target; /** - * Executes a void (no return) command on a device. Notifies its listener on completion. - * @author CLAISSE + * Executes a void (no return) command on a device. Notifies its listener on completion. + * + * @author CLAISSE */ -public class ExecuteStateCommand extends ExecuteCommand -{ +public class ExecuteStateCommand extends ExecuteCommand { /** - * @param _listener The listener to notify on command execution completion - * @param _deviceToReadfrom The device to call the command on - * @param _commandName The command's name - * @param _commandParameters The command's parameters + * @param listener The listener to notify on command execution completion + * @param deviceToReadfrom The device to call the command on + * @param commandName The command's name + * @param commandParameters The command's parameters */ - public ExecuteStateCommand ( MinimalistActionListener _listener , Target _deviceToReadfrom ) - { - super ( _listener , _deviceToReadfrom , "State" , null); + public ExecuteStateCommand(MinimalistActionListener listener, Target deviceToReadfrom) { + super(listener, deviceToReadfrom, "State", null); } } \ No newline at end of file diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/ActionListenerDecorator.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/ActionListenerDecorator.java index ec299c2ae8cb10ac0fc8d3a5d0b8a5d8f22dcf41..b333c6fb251bfa4cdf87b1e95dc1a1459dcbfbdf 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/ActionListenerDecorator.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/ActionListenerDecorator.java @@ -1,38 +1,19 @@ -/* - * Synchrotron Soleil - * - * File : ActionResultListenerDecorator.java - * - * Project : DynamicTangoUtilities - * - * Description : - * - * Author : CLAISSE - * - * Original : 7 févr. 07 - * - * Revision: Author: - * Date: State: - * - * Log: ActionResultListenerDecorator.java,v - */ -/* - * Created on 7 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.singleactioncompletelistener; import java.util.Map; import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.ActionResult; +/** + * ActionListenerDecorator + * + * @author CLAISSE + */ public class ActionListenerDecorator implements ActionListener { private final ActionListener decorator; - public ActionListenerDecorator(ActionListener _decorator) { - this.decorator = _decorator; + public ActionListenerDecorator(ActionListener decorator) { + this.decorator = decorator; } @Override @@ -52,11 +33,11 @@ public class ActionListenerDecorator implements ActionListener { @Override public synchronized boolean hasBeenNotifiedOfFailedActions() { - return this.decorator.hasBeenNotifiedOfFailedActions(); + return decorator.hasBeenNotifiedOfFailedActions(); } @Override public synchronized Map<String, String> getMessages() { - return this.decorator.getMessages(); + return decorator.getMessages(); } } diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/Messages.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/Messages.java index de7c809c9ffb2bcc5acf71d8261e0810755c4d28..2d4be358da7817491f410df459bd2e7582fd260b 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/Messages.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/Messages.java @@ -3,13 +3,14 @@ package fr.soleil.actiongroup.collectiveaction.components.singleactioncompleteli import java.util.Map; /** - * Defines the error management interface used to share error messages between a group and its action result listener, and between the group and its client. - * @author CLAISSE + * Defines the error management interface used to share error messages between a group and its action result listener, + * and between the group and its client. + * + * @author CLAISSE */ -public interface Messages -{ +public interface Messages { /** * @return A map which keys are the failed action's target, and which values are the correseponding error messages. */ - public Map<String, String> getMessages (); + public Map<String, String> getMessages(); } diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/MinimalistActionListener.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/MinimalistActionListener.java index 6a3c280bcd6e39a6b612e454e2ca2c2e91be7977..fad2b83a393a2e5903e36dfebbed3f9056ab0f77 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/MinimalistActionListener.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/MinimalistActionListener.java @@ -2,35 +2,37 @@ package fr.soleil.actiongroup.collectiveaction.components.singleactioncompleteli import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.ActionResult; - /** * A listener, notified by each individual action thread of the result of the group operation on an individual target. - * After the information from all devices has been accumulated, it is used to get the global information. - * @author CLAISSE + * After the information from all devices has been accumulated, it is used to get the global information. + * + * @author CLAISSE */ -public interface MinimalistActionListener -{ +public interface MinimalistActionListener { /** * An individual task has been completed */ - public void actionCompleted (); - + public void actionCompleted(); + /** * An individual task has succeeded + * * @param targetName The name of the individual target * @param actionResult The task's result */ - public void actionSucceeded ( String targetName , ActionResult actionResult ); - + public void actionSucceeded(String targetName, ActionResult actionResult); + /** * An individual task has failed + * * @param targetName The name of the individual target * @param exception The exception that made the task fail */ - public void actionFailed(String targetName , ActionResult actionResult , Throwable exception ); - + public void actionFailed(String targetName, ActionResult actionResult, Throwable exception); + /** - * Returns true if at least one individual task has failed. + * Returns true if at least one individual task has failed. + * * @return True if at least one individual task has failed */ public boolean hasBeenNotifiedOfFailedActions(); diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/action/UsePluginListener.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/action/UsePluginListener.java index d97e9bcdd5e8d436adf0cbba00ea987b11139896..35b0596909ba7d998172dbca05d56c0d287ed177 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/action/UsePluginListener.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/action/UsePluginListener.java @@ -22,14 +22,14 @@ import fr.soleil.actiongroup.collectiveaction.onattributes.plugin.context.Plugin * @author CLAISSE */ public class UsePluginListener extends ActionListenerDecorator implements ActionListener { - private Logger logger = LoggerFactory.getLogger(UsePluginListener.class); + private static final Logger LOGGER = LoggerFactory.getLogger(UsePluginListener.class); private final Plugin action; private final PluginContext context; public UsePluginListener(final ActionListener _decorator, final Plugin _action, final PluginContext _context) { - super(_decorator); - action = _action; - context = _context; + super(_decorator); + action = _action; + context = _context; } /* @@ -40,18 +40,18 @@ public class UsePluginListener extends ActionListenerDecorator implements Action */ @Override public void actionSucceeded(final String targetName, final ActionResult actionResult) { - final DeviceAttributeWrapper[] attributesAnswer = actionResult.getAttributesValue(); - for (final DeviceAttributeWrapper element : attributesAnswer) { - try { - action.execute(context, targetName, element); - } catch (final Exception e) { - logger.error("error", e); - if (e instanceof DevFailed) { - logger.error("tango error {}", DevFailedUtils.toString((DevFailed) e)); - } - super.actionFailed(targetName, actionResult, e); - } - } - super.actionSucceeded(targetName, actionResult); + final DeviceAttributeWrapper[] attributesAnswer = actionResult.getAttributesValue(); + for (final DeviceAttributeWrapper element : attributesAnswer) { + try { + action.execute(context, targetName, element); + } catch (final Exception e) { + LOGGER.error("error", e); + if (e instanceof DevFailed) { + LOGGER.error("tango error {}", DevFailedUtils.toString((DevFailed) e)); + } + super.actionFailed(targetName, actionResult, e); + } + } + super.actionSucceeded(targetName, actionResult); } } diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/action/messagebuilder/ActionCompleteMessageBuilder.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/action/messagebuilder/ActionCompleteMessageBuilder.java index a5e6647ce527cc5e306a96f93c9ee30623b777f9..350cd7d3e6eb9e6678307c292f2be5f072d5f6e9 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/action/messagebuilder/ActionCompleteMessageBuilder.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/action/messagebuilder/ActionCompleteMessageBuilder.java @@ -2,15 +2,14 @@ package fr.soleil.actiongroup.collectiveaction.components.singleactioncompleteli import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.ActionResult; -public class ActionCompleteMessageBuilder extends AbstractMessageBuilder implements MessageBuilder -{ - public String getSuccessMessage ( String targetName , ActionResult actionResult ) - { +public class ActionCompleteMessageBuilder extends AbstractMessageBuilder implements MessageBuilder { + @Override + public String getSuccessMessage(String targetName, ActionResult actionResult) { return null; } - - public String getFailureMessage ( String targetName , ActionResult actionResult , Throwable e ) - { - return e.getMessage (); + + @Override + public String getFailureMessage(String targetName, ActionResult actionResult, Throwable e) { + return e.getMessage(); } } diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/action/messagebuilder/AttributePropertyUpdatedMessageBuilder.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/action/messagebuilder/AttributePropertyUpdatedMessageBuilder.java index c07fd418cb7bf84cc13cd5dc696769718a9b2579..7507554be18caa7e5a1f3de2db1f3e546df92372 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/action/messagebuilder/AttributePropertyUpdatedMessageBuilder.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/action/messagebuilder/AttributePropertyUpdatedMessageBuilder.java @@ -4,16 +4,15 @@ import java.util.Date; import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.ActionResult; -public class AttributePropertyUpdatedMessageBuilder extends AbstractMessageBuilder implements MessageBuilder -{ - public String getSuccessMessage ( String targetName , ActionResult actionResult ) - { +public class AttributePropertyUpdatedMessageBuilder extends AbstractMessageBuilder implements MessageBuilder { + @Override + public String getSuccessMessage(String targetName, ActionResult actionResult) { String message = dateFormat.format(new Date()) + " : Update property : SUCCESS"; return message; } - - public String getFailureMessage ( String targetName , ActionResult actionResult , Throwable e ) - { + + @Override + public String getFailureMessage(String targetName, ActionResult actionResult, Throwable e) { String message = dateFormat.format(new Date()) + " : Update property : FAILURE"; return message; } diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/extraction/BuildNumericListenerImpl.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/extraction/BuildNumericListenerImpl.java index d568af5d7def1c4c23ba4d40058adff8b51c5860..a69250e4b910027051a2f3faad130817c3fa97a7 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/extraction/BuildNumericListenerImpl.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/extraction/BuildNumericListenerImpl.java @@ -13,84 +13,80 @@ import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.Tools; /** * A listener for the event "the numeric attributes reading operation from a device is complete". - * If the operation succeeded, the numeric values are stored. - * @author CLAISSE + * If the operation succeeded, the numeric values are stored. + * + * @author CLAISSE */ -public class BuildNumericListenerImpl extends ActionListenerDecorator implements BuildNumericListener -{ +public class BuildNumericListenerImpl extends ActionListenerDecorator implements BuildNumericListener { /** * The object that stores the numeric values */ - private double [][] result; - + private double[][] result; + /** * Maps the devices names to their position in the result object. */ private Map<String, Integer> deviceNameToIndexMap; - + /** * The attributes qualities manager */ protected IAttributeQualityRegister attributeQualityRegister; - - public BuildNumericListenerImpl ( ActionListener _decorator , Map<String, Integer> _deviceNameToIndexMap , IAttributeQualityRegister _attributeQualityRegister ) - { - super ( _decorator ); - + + public BuildNumericListenerImpl(ActionListener _decorator, Map<String, Integer> _deviceNameToIndexMap, + IAttributeQualityRegister _attributeQualityRegister) { + super(_decorator); + this.deviceNameToIndexMap = _deviceNameToIndexMap; - this.result = new double [ _deviceNameToIndexMap.size () ][]; + this.result = new double[_deviceNameToIndexMap.size()][]; this.attributeQualityRegister = _attributeQualityRegister; } - - public void actionSucceeded ( String deviceName , ActionResult readResult ) - { - DeviceAttributeWrapper[] attributesAnswer = readResult.getAttributesValue (); - - int idx = deviceNameToIndexMap.get ( deviceName ); - double [] res = null; - - try - { - res = this.toDoubleTab ( deviceName , attributesAnswer ); - - synchronized ( this ) - { - result [ idx ] = res; + + @Override + public void actionSucceeded(String deviceName, ActionResult readResult) { + DeviceAttributeWrapper[] attributesAnswer = readResult.getAttributesValue(); + + int idx = deviceNameToIndexMap.get(deviceName); + double[] res = null; + + try { + res = this.toDoubleTab(deviceName, attributesAnswer); + + synchronized (this) { + result[idx] = res; } - - super.actionSucceeded ( deviceName , readResult ); - } - catch ( Throwable e ) - { - super.actionFailed ( deviceName , readResult , e ); + + super.actionSucceeded(deviceName, readResult); + } catch (Throwable e) { + super.actionFailed(deviceName, readResult, e); } } - + /* (non-Javadoc) * @see fr.soleil.core.CLA.listener.AbstractDeviceReaderListenerImpl#getResult() */ - public synchronized double[][] getResult() - { + @Override + public synchronized double[][] getResult() { return result; } - + /** - * Extracts the numeric values from raw numeric attributes. + * Extracts the numeric values from raw numeric attributes. * Delegates attributes quality management (or lack thereof) to mother class AbstractAttributesReadListener - * @param deviceName The device that was read from + * + * @param deviceName The device that was read from * @param deviceAttributes The result of the read operation - * @return The corresponding numeric values + * @return The corresponding numeric values * @throws DevFailed The numeric values extraction failed */ - private synchronized double[] toDoubleTab(String deviceName, DeviceAttributeWrapper [] deviceAttributes) throws DevFailedWrapper - { + private synchronized double[] toDoubleTab(String deviceName, DeviceAttributeWrapper[] deviceAttributes) + throws DevFailedWrapper { double[] ret = new double[deviceAttributes.length]; - for ( int i = 0 ; i < deviceAttributes.length ; i ++ ) - { - ret [ i ] = Tools.toDouble ( deviceAttributes [ i ].getAttribute () ); - this.registerAttributeQuality ( deviceName , deviceAttributes [ i ] ); + for (int i = 0; i < deviceAttributes.length; i++) { + ret[i] = Tools.toDouble(deviceAttributes[i].getAttribute()); + this.registerAttributeQuality(deviceName, deviceAttributes[i]); } - + return ret; } @@ -98,13 +94,12 @@ public class BuildNumericListenerImpl extends ActionListenerDecorator implements * @param deviceName The target of the attributes reading task * @param attribute A particular attribute within the attributes to read set */ - public synchronized void registerAttributeQuality ( String deviceName, DeviceAttributeWrapper attribute ) - { - this.attributeQualityRegister.registerAttributeQuality ( deviceName , attribute ); + public synchronized void registerAttributeQuality(String deviceName, DeviceAttributeWrapper attribute) { + this.attributeQualityRegister.registerAttributeQuality(deviceName, attribute); } - - public Map<String, String> getMessages() - { - return null; //TO DO? + + @Override + public Map<String, String> getMessages() { + return null; // TO DO? } } diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/extraction/FindSlowestDeviceListenerImpl.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/extraction/FindSlowestDeviceListenerImpl.java index e84d2b14f7b33ccefef76302330710e279b317d9..dc868206c78b38a883ccddab6783789a54bce4d5 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/extraction/FindSlowestDeviceListenerImpl.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/extraction/FindSlowestDeviceListenerImpl.java @@ -6,41 +6,38 @@ import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.ActionRes /** * A listener for the event "the numeric attributes reading operation from a device is complete". - * If the operation succeeded, the numeric values are stored. - * @author CLAISSE + * If the operation succeeded, the numeric values are stored. + * + * @author CLAISSE */ -public class FindSlowestDeviceListenerImpl extends ActionListenerDecorator implements FindSlowestDeviceListener -{ +public class FindSlowestDeviceListenerImpl extends ActionListenerDecorator implements FindSlowestDeviceListener { private String slowestDevice; private long slowestTime; - - public FindSlowestDeviceListenerImpl ( ActionListener _decorator ) - { - super ( _decorator ); + + public FindSlowestDeviceListenerImpl(ActionListener decorator) { + super(decorator); } - - public void actionSucceeded ( String deviceName , ActionResult readResult ) - { - long actionTime = readResult.getActionTime (); - synchronized ( this ) - { - if ( actionTime > this.slowestTime ) - { + + @Override + public void actionSucceeded(String deviceName, ActionResult readResult) { + long actionTime = readResult.getActionTime(); + synchronized (this) { + if (actionTime > this.slowestTime) { this.slowestTime = actionTime; this.slowestDevice = deviceName; } } - - super.actionSucceeded ( deviceName, readResult ); + + super.actionSucceeded(deviceName, readResult); } - - public synchronized String getSlowestDevice () - { - return this.slowestDevice; + + @Override + public synchronized String getSlowestDevice() { + return slowestDevice; } - - public synchronized long getSlowestTime () - { - return this.slowestTime; + + @Override + public synchronized long getSlowestTime() { + return slowestTime; } } diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/extraction/qualities/AttributeQualityRegister.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/extraction/qualities/AttributeQualityRegister.java index 81407dd0ae40e0ede99e2fc364946f7c4eb9c6ee..9e76893e9596a078927a0875fb6032c1d916179b 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/extraction/qualities/AttributeQualityRegister.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/extraction/qualities/AttributeQualityRegister.java @@ -1,27 +1,3 @@ -/* Synchrotron Soleil - * - * File : AttributeQualityRegister.java - * - * Project : TangoParser - * - * Description : - * - * Author : CLAISSE - * - * Original : 12 janv. 07 - * - * Revision: Author: - * Date: State: - * - * Log: AttributeQualityRegister.java,v - * - */ - /* - * Created on 12 janv. 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.singleactioncompletelistener.extraction.qualities; import java.util.Hashtable; @@ -33,68 +9,64 @@ import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.DeviceAtt /** * Manages the qualities of the read attributes. * Extracts the read attributes qualities and stores them into a Map. - * If the quality extraction fails, the attribute will be considered invalid (its quality will be AttrQuality.ATTR_INVALID) - * @author CLAISSE + * If the quality extraction fails, the attribute will be considered invalid (its quality will be + * AttrQuality.ATTR_INVALID) + * + * @author CLAISSE */ -public class AttributeQualityRegister implements IAttributeQualityRegister -{ +public class AttributeQualityRegister implements IAttributeQualityRegister { /** * An attribute complete name-->quality mapping */ protected Map<String, AttrQualityWrapper> qualities; - + /** * */ - public AttributeQualityRegister () - { - this.qualities = new Hashtable<String, AttrQualityWrapper> (); + public AttributeQualityRegister() { + this.qualities = new Hashtable<String, AttrQualityWrapper>(); } - - public void registerAttributeQuality(String deviceName, DeviceAttributeWrapper attribute) - { + + @Override + public void registerAttributeQuality(String deviceName, DeviceAttributeWrapper attribute) { AttrQualityWrapper quality = null; String attributeName = null; - - try - { - attributeName = attribute.getName (); - quality = new AttrQualityWrapper ( attribute.getQuality () ); - } - catch (Throwable e) - { - quality = new AttrQualityWrapper ( AttrQualityWrapper.ATTR_INVALID ); + + try { + attributeName = attribute.getName(); + quality = new AttrQualityWrapper(attribute.getQuality()); + } catch (Throwable e) { + quality = new AttrQualityWrapper(AttrQualityWrapper.ATTR_INVALID); } - - this.setQuality ( deviceName + "/" + attributeName , quality ); + + this.setQuality(deviceName + "/" + attributeName, quality); } - + /** * Stores the quality of the specified attribute + * * @param attributeName The attribute's complete name * @param quality The attribute's quality */ - private void setQuality ( String attributeName , AttrQualityWrapper quality ) - { - synchronized ( this ) - { - this.qualities.put ( attributeName , quality ); + private void setQuality(String attributeName, AttrQualityWrapper quality) { + synchronized (this) { + this.qualities.put(attributeName, quality); } } - + /* (non-Javadoc) * @see fr.soleil.core.groupactions.apis.listener.attributes.read.quality.IAttributeQualityReader#getQualities() */ - public synchronized Map<String, AttrQualityWrapper> getQualities() - { + @Override + public synchronized Map<String, AttrQualityWrapper> getQualities() { return qualities; } /* (non-Javadoc) * @see fr.soleil.core.groupactions.apis.listener.attributes.read.quality.IAttributeQualityReader#getQuality(java.lang.String) */ - public synchronized AttrQualityWrapper getQuality(String attributeName) - { - return qualities.get ( attributeName ); + @Override + public synchronized AttrQualityWrapper getQuality(String attributeName) { + return qualities.get(attributeName); } } diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/extraction/qualities/DoNothingAttributeQualityRegister.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/extraction/qualities/DoNothingAttributeQualityRegister.java index 61e9d3409c660265990c788bb96c5de909512e72..a1180d1ec58b1ab2d3657773cd5a4a1e276034a0 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/extraction/qualities/DoNothingAttributeQualityRegister.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/singleactioncompletelistener/extraction/qualities/DoNothingAttributeQualityRegister.java @@ -1,27 +1,3 @@ -/* Synchrotron Soleil - * - * File : aa.java - * - * Project : TangoParser - * - * Description : - * - * Author : CLAISSE - * - * Original : 12 janv. 07 - * - * Revision: Author: - * Date: State: - * - * Log: aa.java,v - * - */ - /* - * Created on 12 janv. 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.singleactioncompletelistener.extraction.qualities; import java.util.Map; @@ -30,29 +6,29 @@ import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.AttrQuali import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.DeviceAttributeWrapper; /** - * A do-nothing implementation - * @author CLAISSE + * A do-nothing implementation + * + * @author CLAISSE */ -public class DoNothingAttributeQualityRegister implements IAttributeQualityRegister -{ +public class DoNothingAttributeQualityRegister implements IAttributeQualityRegister { /* (non-Javadoc) * @see fr.soleil.core.groupactions.apis.listener.attributes.read.quality.IAttributeQualityReader#getQualities() */ - public Map<String, AttrQualityWrapper> getQualities() - { + @Override + public Map<String, AttrQualityWrapper> getQualities() { return null; } /* (non-Javadoc) * @see fr.soleil.core.groupactions.apis.listener.attributes.read.quality.IAttributeQualityReader#getQuality(java.lang.String) */ - public AttrQualityWrapper getQuality(String attributeName) - { + @Override + public AttrQualityWrapper getQuality(String attributeName) { return null; } - public void registerAttributeQuality(String deviceName, DeviceAttributeWrapper attribute) - { - + @Override + public void registerAttributeQuality(String deviceName, DeviceAttributeWrapper attribute) { + } } diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/tangowrapping/target/TargetFactory.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/tangowrapping/target/TargetFactory.java index 45e96d64de090b2787a2e4e8b8fdc9389be8b685..ae4555beff16c5e323c7a2f5cddf9bd165498c13 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/tangowrapping/target/TargetFactory.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/tangowrapping/target/TargetFactory.java @@ -1,33 +1,9 @@ -/* - * 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); } } diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/tangowrapping/target/TargetImpl.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/tangowrapping/target/TargetImpl.java index e0d3f93cf2dd39412357702b73767386fd9d271c..87778dbb202c3adbdfa4775eab3b7a5ab97f537e 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/components/tangowrapping/target/TargetImpl.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/components/tangowrapping/target/TargetImpl.java @@ -1,27 +1,3 @@ -/* - * 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,27 +49,26 @@ 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]; - for (int i = 0; i < response.length; i++) { - ret[i] = new DeviceAttributeWrapper(response[i]); + 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,13 +167,14 @@ 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]; - for (int i = 0; i < response.length; i++) { - ret[i] = new CommandInfoWrapper(response[i]); + ret = null; + } else { + ret = new CommandInfoWrapper[response.length]; + for (int i = 0; i < response.length; i++) { + ret[i] = new CommandInfoWrapper(response[i]); + } } return ret; } diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/onattributes/plugin/PersistencePlugin.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/onattributes/plugin/PersistencePlugin.java index dbefa24040aaef608ec7182501298237b604feff..886cc2ffe44a79feccba039e22738e96b178b3bb 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/onattributes/plugin/PersistencePlugin.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/onattributes/plugin/PersistencePlugin.java @@ -1,27 +1,3 @@ -/* Synchrotron Soleil - * - * File : PersistencePluginAction.java - * - * Project : TangoParser - * - * Description : - * - * Author : CLAISSE - * - * Original : 25 janv. 07 - * - * Revision: Author: - * Date: State: - * - * Log: PersistencePluginAction.java,v - * - */ - /* - * Created on 25 janv. 07 - * - * To change the template for this generated file go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ package fr.soleil.actiongroup.collectiveaction.onattributes.plugin; import fr.soleil.actiongroup.collectiveaction.components.tangowrapping.DeviceAttributeWrapper; @@ -32,26 +8,20 @@ import fr.soleil.actiongroup.collectiveaction.onattributes.plugin.persistance.Pe /** * An implementation of IPluginAction where the action consists of: - * <UL> - * <LI> extracting the attribute's type and value - * <LI> storing the attribute + * <UL> + * <LI>extracting the attribute's type and value + * <LI>storing the attribute * </UL> * The persistence management is delegated to the chosen IPersistenceManager implementation - * @author CLAISSE + * + * @author CLAISSE */ -public class PersistencePlugin implements Plugin -{ - public PersistencePlugin () - { +public class PersistencePlugin implements Plugin { - } - - public void execute ( PluginContext context, String deviceName, DeviceAttributeWrapper attribute ) throws Exception - { - AnyAttribute anyAttribute = new AnyAttribute ( deviceName , attribute ); - - PersistenceContext persistenceContext = context.getPersistenceContext (); + public void execute(PluginContext context, String deviceName, DeviceAttributeWrapper attribute) throws Exception { + AnyAttribute anyAttribute = new AnyAttribute(deviceName, attribute); + PersistenceContext persistenceContext = context.getPersistenceContext(); PersistenceManager manager = persistenceContext.getManager(); - manager.store ( anyAttribute , persistenceContext ); + manager.store(anyAttribute, persistenceContext); } } diff --git a/src/main/java/fr/soleil/actiongroup/collectiveaction/onattributes/plugin/persistance/AnyAttribute.java b/src/main/java/fr/soleil/actiongroup/collectiveaction/onattributes/plugin/persistance/AnyAttribute.java index 240cc8d55b063633a39852303a42210437d8937e..a18dca1d68f71263e35faea0d721b10e5a29a654 100644 --- a/src/main/java/fr/soleil/actiongroup/collectiveaction/onattributes/plugin/persistance/AnyAttribute.java +++ b/src/main/java/fr/soleil/actiongroup/collectiveaction/onattributes/plugin/persistance/AnyAttribute.java @@ -1,27 +1,3 @@ -/* 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>Preferences>Java>Code Generation>Code and Comments - */ package fr.soleil.actiongroup.collectiveaction.onattributes.plugin.persistance; import org.slf4j.Logger; @@ -38,8 +14,9 @@ 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 = ","; /** @@ -153,130 +130,130 @@ public class AnyAttribute { private int extractValue(final DeviceAttributeWrapper attribute) throws Exception { int _numberOfComponents = 0; switch (getType()) { - case TangoConst.Tango_DEV_BOOLEAN: - rawValueBoolean = attribute.extractBooleanArray(); - _numberOfComponents = rawValueBoolean == null ? 0 : rawValueBoolean.length; - break; - - case TangoConst.Tango_DEV_DOUBLE: - rawValueDouble = attribute.extractDoubleArray(); - _numberOfComponents = rawValueDouble == null ? 0 : rawValueDouble.length; - break; - - case TangoConst.Tango_DEV_FLOAT: - rawValueFloat = attribute.extractFloatArray(); - _numberOfComponents = rawValueFloat == null ? 0 : rawValueFloat.length; - break; - case TangoConst.Tango_DEV_LONG: - case TangoConst.Tango_DEV_INT: - rawValueInt = attribute.extractLongArray(); - _numberOfComponents = rawValueInt == null ? 0 : rawValueInt.length; - break; - case TangoConst.Tango_DEV_ULONG: - rawValueLong = attribute.extractULongArray(); - _numberOfComponents = rawValueLong == null ? 0 : rawValueLong.length; - break; - case TangoConst.Tango_DEV_LONG64: - rawValueLong = attribute.extractLong64Array(); - _numberOfComponents = rawValueLong == null ? 0 : rawValueLong.length; - break; - case TangoConst.Tango_DEV_ULONG64: - rawValueLong = attribute.extractULong64Array(); - _numberOfComponents = rawValueLong == null ? 0 : rawValueLong.length; - break; - case TangoConst.Tango_DEV_USHORT: - rawValueInt = attribute.extractUShortArray(); - _numberOfComponents = rawValueInt == null ? 0 : rawValueInt.length; - break; - case TangoConst.Tango_DEV_SHORT: - case TangoConst.Tango_DEV_CHAR: - rawValueShort = attribute.extractShortArray(); - _numberOfComponents = rawValueShort == null ? 0 : rawValueShort.length; - break; - case TangoConst.Tango_DEV_UCHAR: - rawValueShort = attribute.extractUCharArray(); - _numberOfComponents = rawValueShort == null ? 0 : rawValueShort.length; - break; - - case TangoConst.Tango_DEV_STATE: - rawValueState = attribute.extractState(); - _numberOfComponents = 1; - break; - - case TangoConst.Tango_DEV_STRING: - rawValueString = attribute.extractStringArray(); - _numberOfComponents = rawValueString == null ? 0 : rawValueString.length; - break; - default: - logger.error("NO EXTRACTION " + attribute.getName()); - } - return _numberOfComponents; - } - - private void buildPersistableValue() { - if (numberOfComponents == 0) { - return; - } - convertedStringValuesTable = new String[numberOfComponents]; - convertedNumericValuesTable = new double[numberOfComponents]; - - for (int i = 0; i < numberOfComponents; i++) { - switch (getType()) { case TangoConst.Tango_DEV_BOOLEAN: - convertedNumericValuesTable[i] = rawValueBoolean[i] ? 1 : 0; // for - // scalars - // which - // are - // stored - // as - // 0/1 - convertedStringValuesTable[i] = rawValueBoolean[i] + ""; // for - // spectrums - // which - // are - // stored - // as - // true,false,false,... + rawValueBoolean = attribute.extractBooleanArray(); + _numberOfComponents = rawValueBoolean == null ? 0 : rawValueBoolean.length; break; case TangoConst.Tango_DEV_DOUBLE: - convertedNumericValuesTable[i] = rawValueDouble[i]; - convertedStringValuesTable[i] = rawValueDouble[i] + ""; + rawValueDouble = attribute.extractDoubleArray(); + _numberOfComponents = rawValueDouble == null ? 0 : rawValueDouble.length; break; case TangoConst.Tango_DEV_FLOAT: - convertedNumericValuesTable[i] = rawValueFloat[i]; - convertedStringValuesTable[i] = rawValueFloat[i] + ""; + rawValueFloat = attribute.extractFloatArray(); + _numberOfComponents = rawValueFloat == null ? 0 : rawValueFloat.length; break; - case TangoConst.Tango_DEV_LONG: case TangoConst.Tango_DEV_INT: - case TangoConst.Tango_DEV_USHORT: - convertedNumericValuesTable[i] = rawValueInt[i]; - convertedStringValuesTable[i] = rawValueInt[i] + ""; + rawValueInt = attribute.extractLongArray(); + _numberOfComponents = rawValueInt == null ? 0 : rawValueInt.length; break; case TangoConst.Tango_DEV_ULONG: - case TangoConst.Tango_DEV_ULONG64: + rawValueLong = attribute.extractULongArray(); + _numberOfComponents = rawValueLong == null ? 0 : rawValueLong.length; + break; case TangoConst.Tango_DEV_LONG64: - convertedNumericValuesTable[i] = rawValueLong[i]; - convertedStringValuesTable[i] = rawValueLong[i] + ""; + rawValueLong = attribute.extractLong64Array(); + _numberOfComponents = rawValueLong == null ? 0 : rawValueLong.length; + break; + case TangoConst.Tango_DEV_ULONG64: + rawValueLong = attribute.extractULong64Array(); + _numberOfComponents = rawValueLong == null ? 0 : rawValueLong.length; + break; + case TangoConst.Tango_DEV_USHORT: + rawValueInt = attribute.extractUShortArray(); + _numberOfComponents = rawValueInt == null ? 0 : rawValueInt.length; break; - case TangoConst.Tango_DEV_SHORT: case TangoConst.Tango_DEV_CHAR: + rawValueShort = attribute.extractShortArray(); + _numberOfComponents = rawValueShort == null ? 0 : rawValueShort.length; + break; case TangoConst.Tango_DEV_UCHAR: - convertedNumericValuesTable[i] = rawValueShort[i]; - convertedStringValuesTable[i] = rawValueShort[i] + ""; + rawValueShort = attribute.extractUCharArray(); + _numberOfComponents = rawValueShort == null ? 0 : rawValueShort.length; break; case TangoConst.Tango_DEV_STATE: - convertedNumericValuesTable[i] = rawValueState.value(); - convertedStringValuesTable[i] = TangoConst.Tango_DevStateName[rawValueState.value()]; + rawValueState = attribute.extractState(); + _numberOfComponents = 1; break; case TangoConst.Tango_DEV_STRING: - convertedStringValuesTable[i] = rawValueString[i]; + rawValueString = attribute.extractStringArray(); + _numberOfComponents = rawValueString == null ? 0 : rawValueString.length; break; + default: + LOGGER.error("NO EXTRACTION " + attribute.getName()); + } + return _numberOfComponents; + } + + private void buildPersistableValue() { + if (numberOfComponents == 0) { + return; + } + convertedStringValuesTable = new String[numberOfComponents]; + convertedNumericValuesTable = new double[numberOfComponents]; + + for (int i = 0; i < numberOfComponents; i++) { + switch (getType()) { + case TangoConst.Tango_DEV_BOOLEAN: + convertedNumericValuesTable[i] = rawValueBoolean[i] ? 1 : 0; // for + // scalars + // which + // are + // stored + // as + // 0/1 + convertedStringValuesTable[i] = Boolean.toString(rawValueBoolean[i]); // for + // spectrums + // which + // are + // stored + // as + // true,false,false,... + break; + + case TangoConst.Tango_DEV_DOUBLE: + convertedNumericValuesTable[i] = rawValueDouble[i]; + convertedStringValuesTable[i] = Double.toString(rawValueDouble[i]); + break; + + case TangoConst.Tango_DEV_FLOAT: + convertedNumericValuesTable[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] = 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] = 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] = Short.toString(rawValueShort[i]); + break; + + case TangoConst.Tango_DEV_STATE: + convertedNumericValuesTable[i] = rawValueState.value(); + convertedStringValuesTable[i] = TangoConst.Tango_DevStateName[rawValueState.value()]; + break; + + case TangoConst.Tango_DEV_STRING: + convertedStringValuesTable[i] = rawValueString[i]; + break; } } } diff --git a/src/main/java/fr/soleil/archiving/snap/api/ConfigConst.java b/src/main/java/fr/soleil/archiving/snap/api/ConfigConst.java index 0218b053235f50bb77277f457c8daab2adfaaf66..935b68a4d29fe759ddc260e3cb79c1f3e1684450 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/ConfigConst.java +++ b/src/main/java/fr/soleil/archiving/snap/api/ConfigConst.java @@ -1,71 +1,14 @@ -// +====================================================================== -// $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"; - } 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 badafc8c2b1d63dbcf9ef718dfc96a07248997bd..ec0747b1bdcd66a4f156fb248a3519be074f7699 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/DataBaseAPI.java +++ b/src/main/java/fr/soleil/archiving/snap/api/DataBaseAPI.java @@ -1,201 +1,5 @@ -// +====================================================================== -// $Source: /cvsroot/tango-cs/tango/api/java/fr/soleil/TangoSnapshoting/SnapshotingApi/DataBaseAPI.java,v $ -// -// Project: Tango Archiving Service -// -// Description: Java source code for the class DataBaseAPI. -// (Chinkumo Jean) - Mar 4, 2003 -// -// $Author: pierrejoseph $ -// -// $Revision: 1.40 $ -// -// $Log: DataBaseAPI.java,v $ -// Revision 1.40 2007/07/19 13:54:17 pierrejoseph -// Utilisation de resultSet.getInt(1) != 0 au lieu de resultSet.getBoolean car problème face à Oracle -// -// Revision 1.39 2007/06/29 09:20:31 ounsy -// devLong represented as Integer -// -// Revision 1.38 2007/06/26 13:07:51 pierrejoseph -// dataSource usage instead of DriverManager with a MySql Database only : allows a Pool connections usage -// -// Revision 1.37 2007/04/19 13:31:50 ounsy -// corrected extract_SpectrumData_RW_MySQL and the smae for images -// -// Revision 1.36 2007/04/19 13:07:30 chinkumo -// corrected extract_SpectrumData_RO_MySQL -// -// Revision 1.35 2007/04/18 09:15:50 ounsy -// removed trace -// -// Revision 1.34 2007/04/05 10:16:03 ounsy -// corrected a Oracle bug in getAttDefinitionData -// -// Revision 1.33 2007/03/14 15:40:53 ounsy -// added statement closing in finally clauses -// -// Revision 1.32 2007/02/28 09:47:51 ounsy -// now checks the right table -// -// Revision 1.31 2007/01/11 14:37:25 ounsy -// correction of a ClassCastException -// -// Revision 1.30 2007/01/11 14:33:25 ounsy -// correction of a ClassCastException -// -// Revision 1.29 2006/10/31 16:54:24 ounsy -// milliseconds and null values management -// -// Revision 1.28 2006/06/28 12:43:58 ounsy -// image support -// -// Revision 1.27 2006/06/16 08:51:52 ounsy -// ready for images -// -// Revision 1.26 2006/05/12 09:25:19 ounsy -// CLOB_SEPARATOR in GlobalConst -// -// Revision 1.25 2006/05/04 14:33:17 ounsy -// CLOB_SEPARATOR centralized in ConfigConst -// -// Revision 1.24 2006/04/13 12:47:24 ounsy -// new spectrum types support -// -// Revision 1.23 2006/04/11 14:35:26 ounsy -// new spectrum types support -// -// Revision 1.22 2006/03/29 15:06:54 ounsy -// Improved the way cursor handles are closed -// (ResultSet and PreparedStatement objects are now close in a finally clause) -// -// Revision 1.21 2006/03/29 10:24:50 ounsy -// corrected insert_ScalarData in the case of Longs -// -// Revision 1.20 2006/03/16 15:29:08 ounsy -// String scalar support -// -// Revision 1.19 2006/03/14 13:16:48 ounsy -// removed useless logs -// -// Revision 1.18 2006/03/14 12:33:20 ounsy -// corrected the SNAP/spectrums/RW problem -// about the read and write values having the same length -// -// Revision 1.17 2006/03/07 13:45:03 ounsy -// take care of clob separator -// -// Revision 1.16 2006/03/07 10:04:04 ounsy -// take care of clob separator -// -// Revision 1.15 2006/02/28 17:05:58 chinkumo -// no message -// -// Revision 1.14 2006/02/24 12:06:10 ounsy -// replaced hard-coded "," value to CLOB_SEPARATOR -// -// Revision 1.13 2006/02/17 13:24:19 ounsy -// stable version for spectrum extraction (MySQL/Oracle split) -// -// Revision 1.12 2006/02/17 12:47:23 ounsy -// small logs modification -// -// Revision 1.11 2006/02/17 11:15:35 chinkumo -// no message -// -// Revision 1.10 2006/02/17 10:50:29 ounsy -// splitted the extract_spectrum methods MySQl/Oracle -// -// Revision 1.9 2006/02/17 09:32:35 chinkumo -// Since the structure and the name of some SNAPSHOT database's table changed, this was reported here. -// -// Revision 1.8 2006/02/15 09:04:46 ounsy -// Spectrums Management -// -// Revision 1.7 2005/11/29 17:11:17 chinkumo -// no message -// -// Revision 1.5.2.2 2005/11/15 13:34:38 chinkumo -// no message -// -// Revision 1.5.2.1 2005/09/09 08:43:53 chinkumo -// no message -// -// Revision 1.6 2005/08/29 08:08:52 chinkumo -// In the getContextAssociatedSnapshots method, the preparedStatement's argin parameters (id_context, id_snap) were swapped. -// -// Revision 1.5 2005/08/19 14:04:02 chinkumo -// no message -// -// Revision 1.4.6.1.2.2 2005/08/12 08:08:35 chinkumo -// Unused constants removed. -// -// Revision 1.4.6.1.2.1 2005/08/11 08:37:54 chinkumo -// The 'extract_ScalarData_XX' method was improved : The attributes types are better managed. -// -// 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:46 chinkumo -// crateNewSnap method was renamed into createNewSnap -// crateNewSnapMySQL method was renamed into createNewSnapMySQL -// crateNewSnapOracle method was renamed into createNewSnapOracle -// crateNewSnap method was renamed into createNewSnap -// crateNewSnap method was renamed into createNewSnap -// crateNewSnap method was renamed into createNewSnap. -// -// Revision 1.2 2005/06/14 10:12:18 chinkumo -// Branch (tangORBarchiving_1_0_1-branch_0) and HEAD merged. -// -// Revision 1.1.4.2 2005/05/11 14:41:35 chinkumo -// Some comments were corrected. -// -// Revision 1.1.4.1 2005/04/12 13:53:38 chinkumo -// The management of null values (Double.NaN) was improved. -// Some changes was made in the insertion part to improve its efficiency (String > BufferString). -// -// 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.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.AttributeHeavy; -import fr.soleil.archiving.common.api.tools.AttributeLight; -import fr.soleil.archiving.common.api.tools.GlobalConst; -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.archiving.snap.api.tools.TangoJAVAUtils; -import fr.soleil.database.connection.AbstractDataBaseConnector; -import fr.soleil.database.connection.DataBaseParameters; -import fr.soleil.database.connection.DataBaseParameters.DataBaseType; -import org.jdbi.v3.core.Handle; -import org.jdbi.v3.core.statement.Query; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.lang.reflect.Array; import java.sql.CallableStatement; import java.sql.Clob; @@ -216,6 +20,32 @@ import java.util.Random; import java.util.StringTokenizer; import java.util.stream.Collectors; +import org.jdbi.v3.core.Handle; +import org.jdbi.v3.core.statement.Query; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +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.AttributeHeavy; +import fr.soleil.archiving.common.api.tools.AttributeLight; +import fr.soleil.archiving.common.api.tools.GlobalConst; +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.archiving.snap.api.tools.TangoJAVAUtils; +import fr.soleil.database.connection.AbstractDataBaseConnector; +import fr.soleil.database.connection.DataBaseParameters; +import fr.soleil.database.connection.DataBaseParameters.DataBaseType; +import fr.soleil.lib.project.ObjectUtils; + /** * <b>Description : </b> This class hides the loading of drivers, the * connection/disconnection with the database, and more generaly, this class @@ -227,9 +57,8 @@ import java.util.stream.Collectors; public class DataBaseAPI { private static final String ERROR_EXTRACTING_SNAPSHOT_DATA = "error extracting snapshot data"; - public static boolean useLog4JDBC = System.getProperty("log4jdbc.active") == null ? false : System.getProperty( - "log4jdbc.active").equalsIgnoreCase("true"); - private final Logger logger = LoggerFactory.getLogger(DataBaseAPI.class); + public static final boolean USE_LOG4JDBC = "true".equalsIgnoreCase(System.getProperty("log4jdbc.active", "false")); + private static final Logger LOGGER = LoggerFactory.getLogger(DataBaseAPI.class); /** * Connection dbatabase type (<I>MySQL</I>, <I>Oracle</I>, ...) */ @@ -253,7 +82,7 @@ public class DataBaseAPI { * @param params Database connection parameters */ public DataBaseAPI(DataBaseParameters params) throws ArchivingException { - if (params.getHost().equals("")) { + if (params.getHost().isEmpty()) { params.setDbType(DataBaseType.H2); connector = ConnectionFactory.connect(params); } else { @@ -268,7 +97,6 @@ public class DataBaseAPI { this.params = params; } - /** * <b>Description : </b> Gets the database name * @@ -331,7 +159,7 @@ public class DataBaseAPI { * * @param arr an array of Strings * @throws NullPointerException ************************************************************* - * * *********** + * * *********** */ public int getArrayCount(final String[] arr) { int arrayCount = 0; @@ -346,19 +174,17 @@ public class DataBaseAPI { return arrayCount; } - /** * ************************************************************************ * <b>Description : </b> Closes the connection with the database * * @throws SnapshotingException ************************************************************* - * * ********* + * * ********* */ public void close(final Connection conn) { closeConnection(conn); } - /***************************************************************************** * * @@ -374,7 +200,7 @@ public class DataBaseAPI { * @param att_name The attribute's name * @return The <I>SnapDb</I>'s ID that caracterize the given attribute * @throws SnapshotingException ************************************************************* - * * ********* + * * ********* */ public int getAttID(final String att_name) throws SnapshotingException { int attributesID = 0; @@ -406,10 +232,10 @@ public class DataBaseAPI { } catch (final SQLException e) { final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE; final String reason = "Failed while executing DataBaseAPI.getAttID() method..."; - final String desc = ""; + final String desc = ObjectUtils.EMPTY_STRING; selectStringBuilder.append(" => ").append(att_name.trim()); throw new SnapshotingException(message, reason, selectStringBuilder.toString(), ErrSeverity.PANIC, desc, - "", e); + ObjectUtils.EMPTY_STRING, e); } finally { closeResultSet(rset); closeStatement(ps_get_att_id); @@ -443,7 +269,7 @@ public class DataBaseAPI { * referenced in database <I>snap</I>.<I>(mySQL only)</I> * * @return Returns the new id for the new context being referenced in - * database <I>snap</I>. + * database <I>snap</I>. * @throws SnapshotingException */ public int getMaxContextID() throws SnapshotingException { @@ -466,14 +292,16 @@ public class DataBaseAPI { final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE; final String reason = "Failed while executing DataBaseAPI.getMaxID() method..."; final String desc = "The table seem to be empty, please check it..."; - logger.error(new SnapshotingException(message, reason, ErrSeverity.WARN, desc, "").toString()); + LOGGER.error(new SnapshotingException(message, reason, ErrSeverity.WARN, desc, ObjectUtils.EMPTY_STRING) + .toString()); res = 0; } } catch (final SQLException e) { final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE; final String reason = "Failed while executing DataBaseAPI.getMaxID() method..."; - final String desc = ""; - throw new SnapshotingException(message, reason, query, ErrSeverity.PANIC, desc, "", e); + final String desc = ObjectUtils.EMPTY_STRING; + throw new SnapshotingException(message, reason, query, ErrSeverity.PANIC, desc, ObjectUtils.EMPTY_STRING, + e); } finally { closeResultSet(rset); closeStatement(stmt); @@ -483,7 +311,6 @@ public class DataBaseAPI { return res; } - /** * This method retrives from the the database, the list of all registered * contexts (or 'snap-patterns) which subscribe to the clause and/or have @@ -524,11 +351,11 @@ public class DataBaseAPI { * @return array of strings * @throws SnapshotingException * @see SnapshotLight - * ******************************************************************** - * * **** + * ******************************************************************** + * * **** */ public List<SnapshotLight> getContextAssociatedSnapshots(final String clause, final int id_context, - final int id_snap) throws SnapshotingException { + final int id_snap) throws SnapshotingException { // Create and execute the SQL query string String query; final String select_field = SnapConst.ID_SNAP + ", " + SnapConst.time + ", " + SnapConst.snap_comment; @@ -554,7 +381,6 @@ public class DataBaseAPI { } - /** * Retrieves the context identifier to wich the given snapshot identifier is * associated. @@ -588,9 +414,10 @@ public class DataBaseAPI { final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE; final String reason = "Failed while executing DataBaseAPI.getContextID() method..."; - final String desc = ""; + final String desc = ObjectUtils.EMPTY_STRING; final String queryDebug = query + " => " + snapID; - throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e); + throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, + ObjectUtils.EMPTY_STRING, e); } finally { closeResultSet(rset); closeStatement(preparedStatement); @@ -609,9 +436,9 @@ public class DataBaseAPI { ResultSet resultSet = null; // SELECT id_att, value FROM t_sc_num_1val WHERE id_snap = ? final String query = "SELECT " + SnapConst.ID_ATT + "," + SnapConst.value + " FROM " + getDbSchema() + "." - + table + " WHERE " + SnapConst.ID_SNAP + "=" + snapID + " AND " + SnapConst.ID_ATT - + " IN (" + String.join(", ", - attributes.stream().map(s -> String.valueOf(s.getAttId())).collect(Collectors.toList())) + + table + " WHERE " + SnapConst.ID_SNAP + "=" + snapID + " AND " + SnapConst.ID_ATT + " IN (" + + String.join(", ", + attributes.stream().map(s -> String.valueOf(s.getAttId())).collect(Collectors.toList())) + ")"; try { conn = connector.getConnection(); @@ -632,9 +459,8 @@ public class DataBaseAPI { } } - - private void selectRO(final List<SnapAttributeExtract> attributes, int snapID, - final String tableName) throws SnapshotingException, SQLException { + private void selectRO(final List<SnapAttributeExtract> attributes, int snapID, final String tableName) + throws SnapshotingException, SQLException { Connection conn = null; PreparedStatement preparedStatement = null; @@ -664,8 +490,7 @@ public class DataBaseAPI { 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); + NullableData<?> data = getSpectrumValue(value, null, snapAttributeExtract.getDataType(), false); snapAttributeExtract.setValue(data.getValue(), data.getNullElements()); } } @@ -676,8 +501,8 @@ public class DataBaseAPI { } } - private void selectRW(final List<SnapAttributeExtract> attributes, final int snapID, - final String tableName) throws SnapshotingException, SQLException { + private void selectRW(final List<SnapAttributeExtract> attributes, final int snapID, final String tableName) + throws SnapshotingException, SQLException { Connection conn = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null; @@ -713,8 +538,8 @@ public class DataBaseAPI { if (writeClob != null) { writeValue = writeClob.getSubString(1, (int) writeClob.length()); } - NullableData<?> data = getSpectrumValue(readValue, writeValue, - snapAttributeExtract.getDataType(), true); + NullableData<?> data = getSpectrumValue(readValue, writeValue, snapAttributeExtract.getDataType(), + true); snapAttributeExtract.setValue(data.getValue(), data.getNullElements()); snapAttributeExtract.setDimX(resultSet.getInt(4)); } @@ -738,7 +563,7 @@ public class DataBaseAPI { final String query = "SELECT " + SnapConst.ID_ATT + "," + SnapConst.read_value + "," + SnapConst.write_value + " FROM " + getDbSchema() + "." + table + " WHERE " + SnapConst.ID_SNAP + "=" + snapID + " AND " + SnapConst.ID_ATT + " IN (" + String.join(", ", - attributes.stream().map(s -> String.valueOf(s.getAttId())).collect(Collectors.toList())) + attributes.stream().map(s -> String.valueOf(s.getAttId())).collect(Collectors.toList())) + ")"; try { conn = connector.getConnection(); @@ -752,11 +577,11 @@ public class DataBaseAPI { final Object value = TangoJAVAUtils.initPrimitiveArray(snapAttributeExtract.getDataType(), 2); final boolean[] nullElements = new boolean[2]; - Array.set(value, 0, TangoJAVAUtils.castResultSetAsPrimitive(snapAttributeExtract.getDataType(), - resultSet, 2)); + Array.set(value, 0, + TangoJAVAUtils.castResultSetAsPrimitive(snapAttributeExtract.getDataType(), resultSet, 2)); nullElements[0] = resultSet.wasNull(); - Array.set(value, 1, TangoJAVAUtils.castResultSetAsPrimitive(snapAttributeExtract.getDataType(), - resultSet, 3)); + Array.set(value, 1, + TangoJAVAUtils.castResultSetAsPrimitive(snapAttributeExtract.getDataType(), resultSet, 3)); nullElements[1] = resultSet.wasNull(); snapAttributeExtract.setValue(value, nullElements); @@ -773,8 +598,8 @@ public class DataBaseAPI { * Retrieve a snapshot results' * * @param attributes the attributes to retrieve. Will contain results after - * execution - * @param snapID The snap ID + * execution + * @param snapID The snap ID * @throws SnapshotingException */ public void getSnapResults(final List<SnapAttributeExtract> attributes, final int snapID) @@ -797,56 +622,57 @@ public class DataBaseAPI { List<SnapAttributeExtract> numericScalarRW = attributes.stream() .filter(s -> s.getDataFormat() == AttrDataFormat._SCALAR && s.getDataType() != TangoConst.Tango_DEV_STRING - && (s.getWritable() == AttrWriteType._READ_WITH_WRITE || s.getWritable() == AttrWriteType._READ_WRITE)) + && (s.getWritable() == AttrWriteType._READ_WITH_WRITE + || s.getWritable() == AttrWriteType._READ_WRITE)) .collect(Collectors.toList()); List<SnapAttributeExtract> stringScalarRW = attributes.stream() .filter(s -> s.getDataFormat() == AttrDataFormat._SCALAR && s.getDataType() == TangoConst.Tango_DEV_STRING - && (s.getWritable() == AttrWriteType._READ_WITH_WRITE || s.getWritable() == AttrWriteType._READ_WRITE)) + && (s.getWritable() == AttrWriteType._READ_WITH_WRITE + || s.getWritable() == AttrWriteType._READ_WRITE)) .collect(Collectors.toList()); try { // --- Get scalar numeric read only values selectScalarRO(numericScalarRO, snapID, SnapConst.T_SC_NUM_1VAL); } catch (SQLException | SnapshotingException e) { - logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e); + LOGGER.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e); } try { // --- Get scalar numeric read write values selectScalarRW(numericScalarRW, snapID, SnapConst.T_SC_NUM_2VAL); } catch (SQLException | SnapshotingException e) { - logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e); + LOGGER.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e); } try { // --- Get scalar string read only values selectScalarRO(stringScalarRO, snapID, SnapConst.T_SC_STR_1VAL); } catch (SQLException | SnapshotingException e) { - logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e); + LOGGER.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e); } try { // --- Get scalar numeric read write values selectScalarRW(stringScalarRW, snapID, SnapConst.T_SC_STR_2VAL); } catch (SQLException | SnapshotingException e) { - logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e); + LOGGER.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e); } try { // --- Get spectrum read values selectRO(attributes, snapID, SnapConst.T_SP_1VAL); } catch (SQLException | SnapshotingException e) { - logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e); + LOGGER.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e); } try { // --- Get spectrum read write values selectRW(attributes, snapID, SnapConst.T_SP_2VAL); } catch (SQLException | SnapshotingException e) { - logger.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e); + LOGGER.error(ERROR_EXTRACTING_SNAPSHOT_DATA, e); } } - public void closeResultSet(final ResultSet resultSet) { if (resultSet == null) { return; @@ -857,7 +683,7 @@ public class DataBaseAPI { } catch (final SQLException e) { e.printStackTrace(); - logger.error("ERROR !! " + "\r\n" + "\t Origin : \t " + "DataBaseAPI.closeResultSet" + "\r\n" + LOGGER.error("ERROR !! " + "\r\n" + "\t Origin : \t " + "DataBaseAPI.closeResultSet" + "\r\n" + "\t Reason : \t " + getDbSchema().toUpperCase().trim() + "_FAILURE" + "\r\n" + "\t Description : \t " + e.getMessage()); } @@ -873,7 +699,7 @@ public class DataBaseAPI { } catch (final SQLException e) { e.printStackTrace(); - logger.error("ERROR !! " + "\r\n" + "\t Origin : \t " + "DataBaseAPI.closeStatement" + "\r\n" + LOGGER.error("ERROR !! " + "\r\n" + "\t Origin : \t " + "DataBaseAPI.closeStatement" + "\r\n" + "\t Reason : \t " + getDbSchema().toUpperCase().trim() + "_FAILURE" + "\r\n" + "\t Description : \t " + e.getMessage()); } @@ -889,23 +715,24 @@ public class DataBaseAPI { } catch (final SQLException e) { e.printStackTrace(); - logger.error("ERROR !! " + "\r\n" + "\t Origin : \t " + "DataBaseAPI.closeConnection" + "\r\n" + LOGGER.error("ERROR !! " + "\r\n" + "\t Origin : \t " + "DataBaseAPI.closeConnection" + "\r\n" + "\t Reason : \t " + getDbSchema().toUpperCase().trim() + "_FAILURE" + "\r\n" + "\t Description : \t " + e.getMessage()); } } - private NullableData<?> getSpectrumValue(final String readStr, final String writeStr, final int dataType, - final boolean returnAsReadWrite) { + final boolean returnAsReadWrite) { int readSize = 0, writeSize = 0; StringTokenizer readTokenizer; String readString = null, writeString = null; if (readStr == null) { readTokenizer = null; } else { - readString = readStr.replaceAll("\\[", "").replaceAll("\\]", ""); - if ("".equals(readString) || "null".equals(readString) || "NaN".equalsIgnoreCase(readString)) { + readString = readStr.replaceAll("\\[", ObjectUtils.EMPTY_STRING).replaceAll("\\]", + ObjectUtils.EMPTY_STRING); + if (ObjectUtils.EMPTY_STRING.equals(readString) || "null".equals(readString) + || "NaN".equalsIgnoreCase(readString)) { readTokenizer = null; } else { readTokenizer = new StringTokenizer(readString, GlobalConst.CLOB_SEPARATOR); @@ -917,8 +744,9 @@ public class DataBaseAPI { if (writeStr == null) { writeTokenizer = null; } else { - writeString = writeStr.replaceAll("\\[", "").replaceAll("\\]", ""); - if ("".equals(writeString) || "null".equals(writeString) || "NaN".equalsIgnoreCase(writeString)) { + writeString = writeStr.replaceAll("\\[", ObjectUtils.EMPTY_STRING).replaceAll("\\]", + ObjectUtils.EMPTY_STRING); + if (writeString.isEmpty() || "null".equals(writeString) || "NaN".equalsIgnoreCase(writeString)) { writeTokenizer = null; } else { writeTokenizer = new StringTokenizer(writeString, GlobalConst.CLOB_SEPARATOR); @@ -932,7 +760,6 @@ public class DataBaseAPI { Object valueArr_read = TangoJAVAUtils.initPrimitiveArray(dataType, readSize); Object valueArr_write = null; - if (returnAsReadWrite) { valueArr_write = TangoJAVAUtils.initPrimitiveArray(dataType, writeSize); } @@ -941,7 +768,7 @@ public class DataBaseAPI { nullRead = new boolean[readSize]; while (readTokenizer.hasMoreTokens()) { final String currentValRead = readTokenizer.nextToken(); - if (currentValRead == null || currentValRead.trim().equals("")) { + if (currentValRead == null || currentValRead.trim().isEmpty()) { break; } if (TangoJAVAUtils.isNullOrNaN(currentValRead)) { @@ -959,7 +786,7 @@ public class DataBaseAPI { i = 0; while (writeTokenizer.hasMoreTokens()) { final String currentValWrite = writeTokenizer.nextToken(); - if (currentValWrite == null || currentValWrite.trim().equals("")) { + if (currentValWrite == null || currentValWrite.trim().isEmpty()) { break; } if (TangoJAVAUtils.isNullOrNaN(currentValWrite)) { @@ -973,8 +800,8 @@ public class DataBaseAPI { } if (returnAsReadWrite) { - final Object[] result = new Object[]{valueArr_read, valueArr_write}; - final boolean[][] nullElements = new boolean[][]{nullRead, nullWrite}; + final Object[] result = new Object[] { valueArr_read, valueArr_write }; + final boolean[][] nullElements = new boolean[][] { nullRead, nullWrite }; return new NullableData<boolean[][]>(result, nullElements); } else { @@ -999,18 +826,18 @@ public class DataBaseAPI { */ public void registerAttribute(final AttributeHeavy snapAttributeHeavy) throws SnapshotingException { Connection conn = null; - Object[] listValues = new Object[]{snapAttributeHeavy.getAttributeCompleteName(), + Object[] listValues = new Object[] { snapAttributeHeavy.getAttributeCompleteName(), snapAttributeHeavy.getAttribute_device_name(), snapAttributeHeavy.getDomain(), snapAttributeHeavy.getFamily(), snapAttributeHeavy.getMember(), snapAttributeHeavy.getAttribute_name(), snapAttributeHeavy.getDataType(), snapAttributeHeavy.getDataFormat(), snapAttributeHeavy.getWritable(), snapAttributeHeavy.getMax_dim_x(), snapAttributeHeavy.getMax_dim_y(), snapAttributeHeavy.getLevel(), snapAttributeHeavy.getCtrl_sys(), snapAttributeHeavy.getArchivable(), - snapAttributeHeavy.getSubstitute()}; + snapAttributeHeavy.getSubstitute() }; StringBuilder valueConcat = new StringBuilder(); PreparedStatement preparedStatement = null; - String query = ""; + String query = ObjectUtils.EMPTY_STRING; if (params.getDbType() == DataBaseType.MYSQL) { final String tableName = getDbSchema() + "." + SnapConst.AST; @@ -1019,7 +846,7 @@ public class DataBaseAPI { // Build the query string String insert_fields = String.join(", ", SnapConst.TAB_DEF); - String insert_values = ""; + String insert_values = ObjectUtils.EMPTY_STRING; for (int i = 1; i < SnapConst.TAB_DEF.length - 1; i++) { insert_values = insert_values + "?" + ", "; } @@ -1065,9 +892,10 @@ public class DataBaseAPI { } catch (final SQLException e) { final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE; final String reason = "Failed while executing DataBaseAPI.registerAttribute() method..."; - final String desc = ""; + final String desc = ObjectUtils.EMPTY_STRING; final String queryDebug = query + " => " + valueConcat.toString(); - throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e); + throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, + ObjectUtils.EMPTY_STRING, e); } finally { closeStatement(preparedStatement); closeConnection(conn); @@ -1080,7 +908,7 @@ public class DataBaseAPI { * * @param snapContext the new context to register into the database for snapshots. * @return the context identifier (int) associated to the new registered - * context. + * context. * @throws SnapshotingException */ public int create_context(final SnapContext snapContext) throws SnapshotingException { @@ -1105,8 +933,8 @@ public class DataBaseAPI { if (contextIDList.contains(contextID)) { // update snap.context SET name=?, author=?, reason=?, // description=? where id =?; - final String updateQuery = "UPDATE " + tableName + " SET " + SnapConst.name + "= ?, " - + SnapConst.author + "= ?, " + SnapConst.reason + "= ?, " + SnapConst.description + "= ? WHERE " + final String updateQuery = "UPDATE " + tableName + " SET " + SnapConst.name + "= ?, " + SnapConst.author + + "= ?, " + SnapConst.reason + "= ?, " + SnapConst.description + "= ? WHERE " + SnapConst.ID_CONTEXT + "= ?"; try { @@ -1122,11 +950,12 @@ public class DataBaseAPI { } catch (final SQLException e) { final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE; final String reason = "Failed while executing DataBaseAPI.create_context() method..."; - final String desc = ""; + final String desc = ObjectUtils.EMPTY_STRING; final String queryDebug = updateQuery + " => (" + snapContext.getName() + "," + snapContext.getAuthor_name() + "," + snapContext.getReason() + "," + snapContext.getDescription() + "," + contextID + ")"; - throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e); + throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, + ObjectUtils.EMPTY_STRING, e); } finally { closeStatement(preparedStatement); } @@ -1156,11 +985,12 @@ public class DataBaseAPI { } catch (final SQLException e) { final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE; final String reason = "Failed while executing DataBaseAPI.create_context() method..."; - final String desc = ""; + final String desc = ObjectUtils.EMPTY_STRING; final String queryDebug = query + " => (" + snapContext.getCreation_date() + "," + snapContext.getName() + "," + snapContext.getAuthor_name() + "," + snapContext.getReason() + "," + snapContext.getDescription() + ")"; - throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e); + throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, + ObjectUtils.EMPTY_STRING, e); } finally { closeStatement(preparedStatement); } @@ -1184,12 +1014,13 @@ public class DataBaseAPI { } catch (final SQLException e) { final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE; final String reason = "Failed while executing DataBaseAPI.create_context() method..."; - final String desc = ""; + final String desc = ObjectUtils.EMPTY_STRING; final String queryDebug = query + " => (" + snapContext.getId() + "," + snapContext.getCreation_date() + "," + snapContext.getName() + "," + snapContext.getAuthor_name() + "," + snapContext.getReason() + "," + snapContext.getDescription() + ")"; - throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e); + throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, + ObjectUtils.EMPTY_STRING, e); } finally { closeStatement(callableStatement); } @@ -1198,8 +1029,9 @@ public class DataBaseAPI { } catch (final SQLException e1) { final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE; final String reason = "Failed while executing DataBaseAPI.create_context() method..."; - final String desc = ""; - throw new SnapshotingException(message, reason, queryCurrentContext, ErrSeverity.PANIC, desc, "", e1); + final String desc = ObjectUtils.EMPTY_STRING; + throw new SnapshotingException(message, reason, queryCurrentContext, ErrSeverity.PANIC, desc, + ObjectUtils.EMPTY_STRING, e1); } finally { closeStatement(prest); closeConnection(conn); @@ -1225,8 +1057,7 @@ public class DataBaseAPI { + ", " + SnapConst.facility + ", " + SnapConst.archivable + ", " + SnapConst.substitute; // final String selectFields = "*"; - final String clause1 = SnapConst.AST + "." + SnapConst.ID + " = " + SnapConst.LIST + "." - + SnapConst.ID_ATT; + final String clause1 = SnapConst.AST + "." + SnapConst.ID + " = " + SnapConst.LIST + "." + SnapConst.ID_ATT; final String clause2 = SnapConst.LIST + "." + SnapConst.ID_CONTEXT + " = " + SnapConst.CONTEXT + "." + SnapConst.ID_CONTEXT; final String clause3 = SnapConst.CONTEXT + "." + SnapConst.ID_CONTEXT + " = ?"; @@ -1234,7 +1065,7 @@ public class DataBaseAPI { // ast.id = list.id_att and list.id_context = context.id_context and // context.name = 'nom'; String query = "SELECT " + selectFields + " FROM " + tables - + (whereClause.equals("") ? " WHERE " : whereClause + " AND ") + clause1 + " AND " + clause2 + " AND " + + (whereClause.isEmpty() ? " WHERE " : whereClause + " AND ") + clause1 + " AND " + clause2 + " AND " + clause3; PreparedStatement statement = null; @@ -1270,9 +1101,10 @@ public class DataBaseAPI { } catch (final SQLException e) { final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE; final String reason = "Failed while executing DataBaseAPI.getAttDefinitionData() method..."; - final String desc = ""; + final String desc = ObjectUtils.EMPTY_STRING; final String queryDebug = query + " => " + contextID; - throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e); + throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, + ObjectUtils.EMPTY_STRING, e); } finally { closeResultSet(rset); closeStatement(statement); @@ -1329,8 +1161,9 @@ public class DataBaseAPI { } catch (final SQLException e) { final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE; final String reason = "Failed while executing DataBaseAPI.getContextAssociatedAttributes() method..."; - final String desc = ""; - throw new SnapshotingException(message, reason, query, ErrSeverity.PANIC, desc, "", e); + final String desc = ObjectUtils.EMPTY_STRING; + throw new SnapshotingException(message, reason, query, ErrSeverity.PANIC, desc, ObjectUtils.EMPTY_STRING, + e); } finally { closeResultSet(rset); closeStatement(preparedStatement); @@ -1376,7 +1209,7 @@ public class DataBaseAPI { Connection conn = null; // Create and execute the SQL query string - String query = ""; + String query = ObjectUtils.EMPTY_STRING; final String table_name_1 = getDbSchema() + "." + SnapConst.AST; final String table_name_2 = getDbSchema() + "." + SnapConst.CONTEXT; final String table_name_3 = getDbSchema() + "." + SnapConst.LIST; @@ -1386,8 +1219,7 @@ public class DataBaseAPI { SnapConst.dataType + ", " + // data_type SnapConst.dataFormat + ", " + // data_format SnapConst.writable; // writable - final String clause_1 = SnapConst.AST + "." + SnapConst.ID + " = " + SnapConst.LIST + "." - + SnapConst.ID_ATT; + final String clause_1 = SnapConst.AST + "." + SnapConst.ID + " = " + SnapConst.LIST + "." + SnapConst.ID_ATT; final String clause_2 = SnapConst.LIST + "." + SnapConst.ID_CONTEXT + " = " + SnapConst.CONTEXT + "." + SnapConst.ID_CONTEXT; final String clause_3 = SnapConst.CONTEXT + "." + SnapConst.ID_CONTEXT + " = ?"; @@ -1419,9 +1251,10 @@ public class DataBaseAPI { } catch (final SQLException e) { final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE; final String reason = "Failed while executing DataBaseAPI.getContextAssociatedAttributes() method..."; - final String desc = ""; + final String desc = ObjectUtils.EMPTY_STRING; final String queryDebug = query + " => " + id_context; - throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e); + throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, + ObjectUtils.EMPTY_STRING, e); } finally { closeResultSet(rset); closeStatement(preparedStatement); @@ -1470,9 +1303,10 @@ public class DataBaseAPI { } catch (final SQLException e) { final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE; final String reason = "Failed while executing DataBaseAPI.setContextAssociatedAttributes() method..."; - final String desc = ""; + final String desc = ObjectUtils.EMPTY_STRING; final String queryDebug = query + " => (" + id_context + "," + id_att + ")"; - throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e); + throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, + ObjectUtils.EMPTY_STRING, e); } finally { closeStatement(preparedStatement); } @@ -1481,8 +1315,9 @@ public class DataBaseAPI { } catch (final SQLException e) { final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE; final String reason = "Failed while executing DataBaseAPI.setContextAssociatedAttributes() method..."; - final String desc = ""; - throw new SnapshotingException(message, reason, selectQuery, ErrSeverity.PANIC, desc, "", e); + final String desc = ObjectUtils.EMPTY_STRING; + throw new SnapshotingException(message, reason, selectQuery, ErrSeverity.PANIC, desc, + ObjectUtils.EMPTY_STRING, e); } catch (final SnapshotingException e) { throw e; } finally { @@ -1495,7 +1330,7 @@ public class DataBaseAPI { * This method registers a new snapshots and retrieves its identifier * * @param contextID the context identifier to wich the new registered snapshots - * belongs to. + * belongs to. * @param timestamp the registration timestamp * @return the identifier for the new registered snapshot * @throws SnapshotingException @@ -1518,7 +1353,7 @@ public class DataBaseAPI { * This method registers a new snapshots and retrieves its identifier * * @param contextID the context identifier to wich the new registered snapshots - * belongs to. + * belongs to. * @param timestamp the registration timestamp * @return the identifier for the new registered snapshot * @throws SnapshotingException @@ -1562,7 +1397,7 @@ public class DataBaseAPI { * This method registers a new snapshots and retrieves its identifier * * @param contextID the context identifier to wich the new registered snapshots - * belongs to. + * belongs to. * @param timestamp the registration timestamp * @return the identifier for the new registered snapshot * @throws SnapshotingException @@ -1594,9 +1429,10 @@ public class DataBaseAPI { } catch (final SQLException e) { final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE; final String reason = "Failed while executing DataBaseAPI.createNewSnapOracle() method..."; - final String desc = ""; + final String desc = ObjectUtils.EMPTY_STRING; final String queryDebug = query + " => (" + Types.INTEGER + "," + contextID + "," + timestamp + ")"; - throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e); + throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, + ObjectUtils.EMPTY_STRING, e); } finally { closeStatement(cstmt_register_snapshot); closeConnection(conn); @@ -1639,9 +1475,10 @@ public class DataBaseAPI { } catch (final SQLException e) { final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE; final String reason = "Failed while executing DataBaseAPI.updateSnapContextID() method..."; - final String desc = ""; + final String desc = ObjectUtils.EMPTY_STRING; final String queryDebug = query + " => (" + initial_context_value + "," + id_snap + ")"; - throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e); + throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, + ObjectUtils.EMPTY_STRING, e); } finally { closeStatement(preparedStatement); closeConnection(conn); @@ -1670,9 +1507,10 @@ public class DataBaseAPI { } catch (final SQLException e) { final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE; final String reason = "Failed while executing DataBaseAPI.updateSnapComment() method..."; - final String desc = ""; + final String desc = ObjectUtils.EMPTY_STRING; final String queryDebug = query + " => " + id_snap; - throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e); + throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, + ObjectUtils.EMPTY_STRING, e); } finally { closeStatement(preparedStatement); closeConnection(conn); @@ -1693,7 +1531,7 @@ public class DataBaseAPI { final String table = getDbSchema() + "." + SnapConst.SNAPSHOT; final String query = "SELECT " + SnapConst.snap_comment + " FROM " + table + " WHERE " + SnapConst.ID_SNAP + " = " + snapID; - String comment = ""; + String comment = ObjectUtils.EMPTY_STRING; try { conn = connector.getConnection(); preparedStatement = conn.prepareStatement(query); @@ -1704,8 +1542,9 @@ public class DataBaseAPI { } catch (final SQLException e) { final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE; final String reason = "Failed while executing DataBaseAPI.updateSnapComment() method..."; - final String desc = ""; - throw new SnapshotingException(message, reason, query, ErrSeverity.PANIC, desc, "", e); + final String desc = ObjectUtils.EMPTY_STRING; + throw new SnapshotingException(message, reason, query, ErrSeverity.PANIC, desc, ObjectUtils.EMPTY_STRING, + e); } finally { closeStatement(preparedStatement); closeConnection(conn); @@ -1749,9 +1588,10 @@ public class DataBaseAPI { } catch (final SQLException e) { final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE; final String reason = "Failed while executing DataBaseAPI.getSnapID() method..."; - final String desc = ""; + final String desc = ObjectUtils.EMPTY_STRING; final String queryDebug = query + " => " + id_context; - throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e); + throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, + ObjectUtils.EMPTY_STRING, e); } finally { closeResultSet(rset); closeStatement(preparedStatement); @@ -1790,9 +1630,10 @@ public class DataBaseAPI { } catch (final SQLException e) { final String message = SnapConst.SNAPSHOTING_ERROR_PREFIX + " : " + SnapConst.QUERY_FAILURE; final String reason = "Failed while executing DataBaseAPI.registerSnap() method..."; - final String desc = "" + ""; + final String desc = ObjectUtils.EMPTY_STRING; final String queryDebug = query + " => (" + id_context + "," + time + ")"; - throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, "", e); + throw new SnapshotingException(message, reason, queryDebug, ErrSeverity.PANIC, desc, + ObjectUtils.EMPTY_STRING, e); } finally { closeStatement(preparedStatement); closeConnection(conn); diff --git a/src/main/java/fr/soleil/archiving/snap/api/GetSnapshotingConf.java b/src/main/java/fr/soleil/archiving/snap/api/GetSnapshotingConf.java index bf4321d4a7bfadea42dcf8202940799e99f90f8c..4cb527051ef406ce7bdae8733d0b6315090d9fdb 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/GetSnapshotingConf.java +++ b/src/main/java/fr/soleil/archiving/snap/api/GetSnapshotingConf.java @@ -1,41 +1,3 @@ -//+====================================================================== -// $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,132 +8,134 @@ 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 { - return GetConf.getHost(className); - } catch (DevFailed devFailed) { - throw new SnapshotingException(devFailed); - } + try { + return GetConf.getHost(className); + } catch (DevFailed devFailed) { + throw new SnapshotingException(devFailed); + } } /** * 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 { - return GetConf.getName(className); - } catch (DevFailed devFailed) { - throw new SnapshotingException(devFailed); - } + try { + return GetConf.getName(className); + } catch (DevFailed devFailed) { + throw new SnapshotingException(devFailed); + } } /** * 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 { - return GetConf.getSchema(className); - } catch (DevFailed devFailed) { - throw new SnapshotingException(devFailed); - } + try { + return GetConf.getSchema(className); + } catch (DevFailed devFailed) { + throw new SnapshotingException(devFailed); + } } public static String getUser(String className) throws SnapshotingException { - try { - return GetConf.getUser(className); - } catch (DevFailed devFailed) { - throw new SnapshotingException(devFailed); - } + try { + return GetConf.getUser(className); + } catch (DevFailed devFailed) { + throw new SnapshotingException(devFailed); + } } public static String getPwd(String className) throws SnapshotingException { - try { - return GetConf.getPwd(className); - } catch (DevFailed devFailed) { - throw new SnapshotingException(devFailed); - } + try { + return GetConf.getPwd(className); + } catch (DevFailed devFailed) { + throw new SnapshotingException(devFailed); + } } /** * 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 { - return GetConf.isRAC(className); - } catch (DevFailed devFailed) { - throw new SnapshotingException(devFailed); - } + try { + return GetConf.isRAC(className); + } catch (DevFailed devFailed) { + throw new SnapshotingException(devFailed); + } } /** * 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; - try { - Database dbase = ApiUtil.get_db_obj(); - int property = ConfigConst.BD_MYSQL; - DbDatum dbdatum = dbase.get_class_property(className, propname); - if (!dbdatum.is_empty()) { - property = dbdatum.extractLong(); - } - return property; - } catch (DevFailed devFailed) { - 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); - } + String propname = TYPE_PROPERTY; + try { + Database dbase = ApiUtil.get_db_obj(); + int property = ConfigConst.BD_MYSQL; + DbDatum dbdatum = dbase.get_class_property(className, propname); + if (!dbdatum.is_empty()) { + property = dbdatum.extractLong(); + } + return property; + } catch (DevFailed devFailed) { + 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, ObjectUtils.EMPTY_STRING, + devFailed); + } } /** * 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; - try { - Database dbase = ApiUtil.get_db_obj(); - boolean property = false; - propname = m_facilityProperty; - DbDatum dbdatum = dbase.get_class_property(className, propname); - if (!dbdatum.is_empty()) { - property = dbdatum.extractBoolean(); - } - return property; - } catch (DevFailed devFailed) { - 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); - } + String propname = FACILITY_PROPERTY; + try { + Database dbase = ApiUtil.get_db_obj(); + boolean property = false; + propname = FACILITY_PROPERTY; + DbDatum dbdatum = dbase.get_class_property(className, propname); + if (!dbdatum.is_empty()) { + property = dbdatum.extractBoolean(); + } + return property; + } catch (DevFailed devFailed) { + 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, ObjectUtils.EMPTY_STRING, + devFailed); + } } } diff --git a/src/main/java/fr/soleil/archiving/snap/api/SnapConnectionParameters.java b/src/main/java/fr/soleil/archiving/snap/api/SnapConnectionParameters.java index ae41817087624583e5a3590499c5fff7b53264ca..f3bcc085a0dad9a0e3db5edeb5eeb063eb72f4a5 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/SnapConnectionParameters.java +++ b/src/main/java/fr/soleil/archiving/snap/api/SnapConnectionParameters.java @@ -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; } diff --git a/src/main/java/fr/soleil/archiving/snap/api/extractor/datasources/db/RealSnapReader.java b/src/main/java/fr/soleil/archiving/snap/api/extractor/datasources/db/RealSnapReader.java index 043c8c96c8ee19778e7fc56e05714ef375dd28d7..dcbe06ee815cc0ccc1cff0930ae681a5fdef55fc 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/extractor/datasources/db/RealSnapReader.java +++ b/src/main/java/fr/soleil/archiving/snap/api/extractor/datasources/db/RealSnapReader.java @@ -1,25 +1,3 @@ -// +====================================================================== -// $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,134 +72,106 @@ 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; - } - int numberOfSnapshots = snapshots.length; - - DevVarLongStringArray ret = new DevVarLongStringArray(); - int[] lvalue = new int[numberOfSnapshots]; - java.lang.String[] svalue = new java.lang.String[numberOfSnapshots]; - for (int i = 0; i < numberOfSnapshots; i++) { - SnapshotLight currentSnapshot = snapshots[i]; - lvalue[i] = currentSnapshot.getId_snap(); - svalue[i] = currentSnapshot.getSnap_date() + " , " + currentSnapshot.getComment(); + ret = null; + } else { + int numberOfSnapshots = snapshots.length; + ret = new DevVarLongStringArray(); + int[] lvalue = new int[numberOfSnapshots]; + String[] svalue = new String[numberOfSnapshots]; + for (int i = 0; i < numberOfSnapshots; i++) { + SnapshotLight currentSnapshot = snapshots[i]; + lvalue[i] = currentSnapshot.getId_snap(); + svalue[i] = currentSnapshot.getSnap_date() + " , " + currentSnapshot.getComment(); + } + ret.lvalue = lvalue; + ret.svalue = svalue; } - 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 { - newList = manager.findSnapshots(ret); - if (ret.getConditions("first") != null) { - argout = new int[1]; - argout[0] = newList[0].getId_snap(); - } else if (ret.getConditions("last") != null) { - argout = new int[1]; - argout[0] = newList[newList.length - 1].getId_snap(); - } else { - argout = new int[newList.length]; - for (int i = 0; i < newList.length; i++) { - argout[i] = newList[i].getId_snap(); + SnapshotLight[] newList; + try { + newList = manager.findSnapshots(ret); + if (ret.getConditions("first") != null) { + argout = new int[1]; + argout[0] = newList[0].getId_snap(); + } else if (ret.getConditions("last") != null) { + argout = new int[1]; + argout[0] = newList[newList.length - 1].getId_snap(); + } else { + argout = new int[newList.length]; + for (int i = 0; i < newList.length; i++) { + argout[i] = newList[i].getId_snap(); + } } + } catch (SnapshotingException e) { + argout = null; } - } catch (SnapshotingException e) { - // TODO Auto-generated catch block - return 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,72 +237,63 @@ 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; - } - int numberOfContexts = contextTab.length; + ret = null; + } else { + int numberOfContexts = contextTab.length; - DevVarLongStringArray ret = new DevVarLongStringArray(); - int[] lvalue = new int[numberOfContexts]; - java.lang.String[] svalue = new java.lang.String[numberOfContexts]; + ret = new DevVarLongStringArray(); + int[] lvalue = new int[numberOfContexts]; + String[] svalue = new String[numberOfContexts]; - List<String> attributesList = null; - int contextId = -1; - for (int i = 0; i < numberOfContexts; i++) { - SnapContext currentContext = contextTab[i]; - contextId = currentContext.getId(); - lvalue[i] = contextId; + List<String> attributesList = null; + int contextId = -1; + for (int i = 0; i < numberOfContexts; i++) { + SnapContext currentContext = contextTab[i]; + contextId = currentContext.getId(); + lvalue[i] = contextId; - if (withAttribute) { - attributesList = getAttributeForContext(currentContext, searchCriterions); - } + if (withAttribute) { + attributesList = getAttributeForContext(currentContext, searchCriterions); + } - svalue[i] = currentContext.getName() + splitCharact + currentContext.getAuthor_name() + splitCharact - + sdf.format(currentContext.getCreation_date()) + splitCharact + currentContext.getReason() - + splitCharact + currentContext.getDescription(); - if (attributesList != null && !attributesList.isEmpty()) { - StringBuilder sb = new StringBuilder(); - for (String att : attributesList) { - sb.append(splitCharact); - 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] = 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(SPLIT_CHAR); + sb.append(att); + } + svalue[i] = svalue[i] + sb.toString(); } - svalue[i] = svalue[i] + sb.toString(); } - } - - ret.lvalue = lvalue; - ret.svalue = svalue; + 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>(); - for (AttributeHeavy att : findContextAttributes) { + attributesList = new ArrayList<>(); + for (AttributeHeavy att : findContextAttributes) { attributesList.add(att.getAttributeCompleteName()); } } @@ -384,24 +323,25 @@ 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) { for (String attributeName : attributeForContext) { - if (attributeName.contains(argin)) { + if (attributeName.contains(argin)) { mapContextList.put(id, snapContext); Collection<SnapContext> values = mapContextList.values(); - for(SnapContext snap : values){ - if(!contextList.contains(snap)){ - contextList.add(snap); - } + for (SnapContext snap : values) { + if (!contextList.contains(snap)) { + contextList.add(snap); } + } } } } @@ -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; diff --git a/src/main/java/fr/soleil/archiving/snap/api/extractor/lifecycle/DefaultLifeCycleManager.java b/src/main/java/fr/soleil/archiving/snap/api/extractor/lifecycle/DefaultLifeCycleManager.java index af120d16eefca9a8f14c11ef474a7df184f6d5f8..c7f6857092a4d57b6dbec4dc850243ab3e97c181 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/extractor/lifecycle/DefaultLifeCycleManager.java +++ b/src/main/java/fr/soleil/archiving/snap/api/extractor/lifecycle/DefaultLifeCycleManager.java @@ -1,46 +1,3 @@ -//+====================================================================== -//$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) { 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 e656eb8f512004b4ef47f28c120d86b1ddebe7fe..fa6c0fee9dad308a2392224143007b0ebd43eed3 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 @@ -1,6 +1,7 @@ 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,148 +20,134 @@ import fr.soleil.database.connection.DataBaseParameters.DataBaseType; * @author CLAISSE */ public class Tools { - final static 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); - - /** - * Returns a date as a String formated for the database. - * - * @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 = ""; - switch (type) { - case ORACLE: - date = DateUtil.milliToString(milliseconds, - DateUtil.FR_DATE_PATTERN); - break; - case MYSQL: - default: - date = DateUtil.milliToString(milliseconds, - DateUtil.US_DATE_PATTERN); - } - return date; - } - - /** - * Converts a Throwable to a DevFailed and throws it. - * - * @param exception - * The exception to convert - * @return The DevFailed representation - * @throws DevFailed - * Always thrown by definition of the method - */ - public static void throwDevFailed(Throwable exception) throws DevFailed { - DevFailed devFailed = new DevFailed(); - devFailed.initCause(exception); - throw devFailed; - } - - /** - * Extracts causes from a Throwable if it is an instance of DevFailed, and - * prints it. - * - * @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(); - } - - DevError[] errors = ((DevFailed) t).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); - } - } - } - } - - /** - * 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) { - - boolean isFr = (date.indexOf("-") != 4); - int currentLength = date.length(); - String toTheDay = "yyyy-MM-dd"; - - if (isFr) { - - } else { - if (currentLength == toTheDay.length()) { - date += " 00:00:00"; - } - if (currentLength == (toTheDay.length() + 1)) { - date += "00:00:00"; - } - if (currentLength == (toTheDay.length() + 2)) { - date += "0:00:00"; - } - if (currentLength == (toTheDay.length() + 3)) { - date += ":00:00"; - } - if (currentLength == (toTheDay.length() + 4)) { - date += "00:00"; - } - if (currentLength == (toTheDay.length() + 5)) { - date += "0:00"; - } - if (currentLength == (toTheDay.length() + 6)) { - date += ":00"; - } - if (currentLength == (toTheDay.length() + 7)) { - date += "00"; - } - if (currentLength == (toTheDay.length() + 8)) { - date += "0"; - } - } - - if (date.indexOf(".") == -1) { - date = date + (".000"); - } - - try { - if (isFr) { - genFormatFR.parse(date); - return genFormatFR.getCalendar().getTimeInMillis(); - } else { - genFormatUS.parse(date); - return genFormatUS.getCalendar().getTimeInMillis(); - } - } catch (Exception e1) { - try { - e1.printStackTrace(); - - Timestamp ts = Timestamp.valueOf(date); - return ts.getTime(); - } catch (Exception e) { - e.printStackTrace(); - return -1; - } - } - } + 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"; + 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 + * @return A date as a String formated for the database. + */ + public static String formatDate(long milliseconds) { + DataBaseType type = SnapManagerApi.getSnapDbType(); + String date = ObjectUtils.EMPTY_STRING; + switch (type) { + case ORACLE: + date = DateUtil.milliToString(milliseconds, DateUtil.FR_DATE_PATTERN); + break; + case MYSQL: + default: + date = DateUtil.milliToString(milliseconds, DateUtil.US_DATE_PATTERN); + } + return date; + } + + /** + * Converts a Throwable to a DevFailed and throws it. + * + * @param exception The exception to convert + * @return The DevFailed representation + * @throws DevFailed Always thrown by definition of the method + */ + public static void throwDevFailed(Throwable exception) throws DevFailed { + DevFailed devFailed = new DevFailed(); + devFailed.initCause(exception); + throw devFailed; + } + + /** + * Extracts causes from a Throwable if it is an instance of DevFailed, and prints it. + * + * @param t The exception to log + */ + public static void printIfDevFailed(Throwable t) { + t.printStackTrace(); + + if (t instanceof DevFailed) { + DevFailed df = (DevFailed) t; + if (df.getCause() != null) { + df.getCause().printStackTrace(); + } + + 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); + } + } + } + } + + /** + * 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 + */ + public static long stringToMilli(String date) { + long milli; + boolean isFr = (date.indexOf("-") != 4); + int currentLength = date.length(); + String toTheDay = "yyyy-MM-dd"; + if (!isFr) { + if (currentLength == toTheDay.length()) { + date += " 00:00:00"; + } + if (currentLength == (toTheDay.length() + 1)) { + date += "00:00:00"; + } + if (currentLength == (toTheDay.length() + 2)) { + date += "0:00:00"; + } + if (currentLength == (toTheDay.length() + 3)) { + date += ":00:00"; + } + if (currentLength == (toTheDay.length() + 4)) { + date += "00:00"; + } + if (currentLength == (toTheDay.length() + 5)) { + date += "0:00"; + } + if (currentLength == (toTheDay.length() + 6)) { + date += ":00"; + } + if (currentLength == (toTheDay.length() + 7)) { + date += "00"; + } + if (currentLength == (toTheDay.length() + 8)) { + date += "0"; + } + } + if (date.indexOf(".") == -1) { + date = date + (".000"); + } + try { + if (isFr) { + milli = fr.soleil.lib.project.date.DateUtil.stringToMilli(date, FR_DATE_FORMAT); + } else { + milli = fr.soleil.lib.project.date.DateUtil.stringToMilli(date, US_DATE_FORMAT); + } + } catch (Exception e1) { + try { + e1.printStackTrace(); + + Timestamp ts = Timestamp.valueOf(date); + milli = ts.getTime(); + } catch (Exception e) { + e.printStackTrace(); + milli = -1; + } + } + return milli; + } } diff --git a/src/main/java/fr/soleil/archiving/snap/api/manager/ISnapManager.java b/src/main/java/fr/soleil/archiving/snap/api/manager/ISnapManager.java index f7ef646f0c3d6c3588cc8fcdf046d5005d72f087..961210d2984f960f01a8c8498b8bde835df01ff9 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/manager/ISnapManager.java +++ b/src/main/java/fr/soleil/archiving/snap/api/manager/ISnapManager.java @@ -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; @@ -65,7 +65,7 @@ public interface ISnapManager { public SnapAttributeExtract[] findSnapshotAttributes(SnapshotLight snapshot) throws SnapshotingException; public SnapAttributeExtract[] findSnapshotAttributes(SnapshotLight snapshot, int contextID) - throws SnapshotingException; + throws SnapshotingException; public SnapContext saveContext(SnapContext context) throws SnapshotingException; @@ -75,15 +75,15 @@ public interface ISnapManager { public void setEquipmentsWithSnapshot(Snapshot snapshot) throws SnapshotingException; - public AttributeHeavy[] findContextAttributes(SnapContext context, Criterions criterions) - throws SnapshotingException; + public AttributeHeavy[] findContextAttributes(SnapContext context, Criterions criterions) + throws SnapshotingException; public SnapAttributeExtract[] getSnap(int id) throws SnapshotingException; SnapAttributeExtract[] getSnapValues(int id, String... attributeNames) throws SnapshotingException; public String setEquipmentsWithCommand(String cmd_name, String option, Snapshot snapshot) - throws SnapshotingException; + throws SnapshotingException; public int findContextId(int snapshotId) throws SnapshotingException; 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 f763e6ab2ea2022baece2ab8ca7b123c88e0550a..a96762d6d84be33398dfc246d66dd4b305d012a4 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 @@ -1,99 +1,14 @@ -// +====================================================================== -// $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, @@ -354,7 +267,7 @@ public class SnapManagerApi { } public static synchronized void initFullSnapConnection(final String host, final String name, final String schema, - final String user, final String pass, final String isRac) throws SnapshotingException { + final String user, final String pass, final String isRac) throws SnapshotingException { SnapConnectionParameters.initFromArgumentsProperties(host, name, schema, user, pass, isRac); SnapConnectionParameters.initFromSystemProperties(); @@ -378,14 +291,13 @@ public class SnapManagerApi { } - /** * This method gets informations on a given attribute and registers the * attribute into the database "Snap" * * @param att_complete_name the given attribute * @throws SnapshotingException exception throwned in case of communications problems with - * the device or database + * the device or database */ private static void register(String att_complete_name) throws SnapshotingException { if (snapDataBase == null) { @@ -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,27 +437,27 @@ 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 * * @param criterions Conditions related to the fields of the context table * @return a list of contexts which subscribe to the given conditions - * (Criterions) + * (Criterions) * @throws SnapshotingException */ public static List<SnapContext> getContext(final Criterions criterions) throws SnapshotingException { @@ -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); @@ -584,7 +496,7 @@ public class SnapManagerApi { * * @param contextID The context identifier * @return The 'SnapManagerResult.OK_SNAPLAUNCH' if success, - * 'SnapManagerResult.ERROR_SNAPLAUNCH' otherwise + * 'SnapManagerResult.ERROR_SNAPLAUNCH' otherwise */ public static int launchSnap(final int contextID) throws DevFailed { @@ -629,17 +541,17 @@ public class SnapManagerApi { * @param id_context The context identifier * @param criterions Conditions related to fields of the context table * @return a list of attributes that belong to the context identified by the - * given id_context and subscribe to the given conditions - * (criterions) + * given id_context and subscribe to the given conditions + * (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; } @@ -662,7 +574,7 @@ public class SnapManagerApi { * @throws SnapshotingException */ public static List<SnapAttributeExtract> getSnapshotAssociatedAttributes(final SnapshotLight snapshot, - int contextID) throws SnapshotingException { + int contextID) throws SnapshotingException { if (snapDataBase == null) { throw new SnapshotingException(DATA_BASE_API_NOT_INIT); } @@ -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,14 +597,13 @@ 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 * * @param criterions Conditions related to the fields of the snapshot table * @return a list of snapshots which subscribe to the given conditions - * (Criterions) + * (Criterions) * @throws SnapshotingException */ public static List<SnapshotLight> getContextAssociatedSnapshots(final Criterions criterions) @@ -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,14 +855,14 @@ 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(); DeviceData device_data = null; device_data = new DeviceData(); - String[] first_argin = new String[]{cmd_name, option, String.valueOf(snapShot.getId_snap())}; + String[] first_argin = new String[] { cmd_name, option, String.valueOf(snapShot.getId_snap()) }; String[] argin = first_argin; if (snapShot.isFiltered()) { List<SnapAttributeExtract> attributes = snapShot.getAttribute_List(); @@ -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); } } 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 ab939594e12ba7255a6a2fb5a40e286580d5a69c..422971e6e7bd2d7ddae65b2901a860cca9f98fee 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 @@ -1,68 +1,3 @@ -// +====================================================================== -// $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>Preferences>Java>Code Generation>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); @@ -238,13 +173,13 @@ public class SnapManagerImpl implements ISnapManager { } @Override - public AttributeHeavy[] findContextAttributes(final SnapContext context, final Criterions criterions) + public AttributeHeavy[] findContextAttributes(final SnapContext context, final Criterions criterions) throws SnapshotingException { // Gets the attributes which are associated to the given context and // subscribe to the given conditions - final List<AttributeHeavy> arrayList = SnapManagerApi.getContextAssociatedAttributes(context.getId(), + final List<AttributeHeavy> arrayList = SnapManagerApi.getContextAssociatedAttributes(context.getId(), criterions); - return arrayList.toArray(new AttributeHeavy[arrayList.size()]); + return arrayList.toArray(new AttributeHeavy[arrayList.size()]); } @Override diff --git a/src/main/java/fr/soleil/archiving/snap/api/persistence/SpringSnapshotPersistenceManagerImpl.java b/src/main/java/fr/soleil/archiving/snap/api/persistence/SpringSnapshotPersistenceManagerImpl.java index 9a4126a71cac8dfa9f36239e5cff9d9e3fbfe1a2..4c904f01f0c89d8a9fc6d8db953bb20c906f7fd4 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/persistence/SpringSnapshotPersistenceManagerImpl.java +++ b/src/main/java/fr/soleil/archiving/snap/api/persistence/SpringSnapshotPersistenceManagerImpl.java @@ -23,52 +23,52 @@ import fr.soleil.archiving.snap.api.persistence.spring.dto.Sp1Val; import fr.soleil.archiving.snap.api.persistence.spring.dto.Sp2Val; 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) { - beans = new ClasspathDAOBeansLoader(beansFileName, userName, password); + beans = new ClasspathDAOBeansLoader(beansFileName, userName, password); } @Override public void store(final AnyAttribute attribute, final PersistenceContext persistenceContext) throws Exception { - final SnapshotPersistenceContext context = (SnapshotPersistenceContext) persistenceContext; - logger.debug(attribute.getCompleteName() + " - values: " - + Arrays.toString(attribute.getConvertedStringValuesTable())); - switch (attribute.getFormat()) { - case AttrDataFormat._SCALAR: - if (attribute.getWritable() == AttrWriteType._READ) { - if (attribute.getType() == TangoConst.Tango_DEV_STRING) { - beans.getScStr1ValDAO().create(new ScStr1Val(attribute, context)); - } else { - beans.getScNum1ValDAO().create(new ScNum1Val(attribute, context)); - } - } else { - if (attribute.getType() == TangoConst.Tango_DEV_STRING) { - beans.getScStr2ValDAO().create(new ScStr2Val(attribute, context)); - } else { - beans.getScNum2ValDAO().create(new ScNum2Val(attribute, context)); - } - } - break; + final SnapshotPersistenceContext context = (SnapshotPersistenceContext) persistenceContext; + LOGGER.debug("storing {} with value: {}", attribute.getCompleteName(), + Arrays.toString(attribute.getConvertedStringValuesTable())); + switch (attribute.getFormat()) { + case AttrDataFormat._SCALAR: + if (attribute.getWritable() == AttrWriteType._READ) { + if (attribute.getType() == TangoConst.Tango_DEV_STRING) { + beans.getScStr1ValDAO().create(new ScStr1Val(attribute, context)); + } else { + beans.getScNum1ValDAO().create(new ScNum1Val(attribute, context)); + } + } else { + if (attribute.getType() == TangoConst.Tango_DEV_STRING) { + beans.getScStr2ValDAO().create(new ScStr2Val(attribute, context)); + } else { + beans.getScNum2ValDAO().create(new ScNum2Val(attribute, context)); + } + } + break; - case AttrDataFormat._SPECTRUM: - if (attribute.getWritable() == AttrWriteType._READ) { - beans.getSp1ValDAO().create(new Sp1Val(attribute, context)); - } else { - beans.getSp2ValDAO().create(new Sp2Val(attribute, context)); - } + case AttrDataFormat._SPECTRUM: + if (attribute.getWritable() == AttrWriteType._READ) { + beans.getSp1ValDAO().create(new Sp1Val(attribute, context)); + } else { + beans.getSp2ValDAO().create(new Sp2Val(attribute, context)); + } - break; + break; - case AttrDataFormat._IMAGE: - if (attribute.getWritable() == AttrWriteType._READ) { - beans.getIm1ValDAO().create(new Im1Val(attribute, context)); - } else { - beans.getIm2ValDAO().create(new Im2Val(attribute, context)); - } - break; - } + case AttrDataFormat._IMAGE: + if (attribute.getWritable() == AttrWriteType._READ) { + beans.getIm1ValDAO().create(new Im1Val(attribute, context)); + } else { + beans.getIm2ValDAO().create(new Im2Val(attribute, context)); + } + break; + } } /** @@ -76,11 +76,11 @@ public class SpringSnapshotPersistenceManagerImpl implements SnapshotPersistence */ @Override public String getResourceName() { - return beans.getResourceName(); - } + return beans.getResourceName(); + } - @Override - public void autowired(Object object) { - beans.getApplicationContext().getAutowireCapableBeanFactory().autowireBean(object); + @Override + public void autowired(Object object) { + beans.getApplicationContext().getAutowireCapableBeanFactory().autowireBean(object); } } diff --git a/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dao/ClasspathDAOBeansLoader.java b/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dao/ClasspathDAOBeansLoader.java index 367fc6df4c5e429ce3d8dc63364e9472ee88b875..0bd8865cd843f349490be86b09df38ab9cb39f80 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dao/ClasspathDAOBeansLoader.java +++ b/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dao/ClasspathDAOBeansLoader.java @@ -1,5 +1,11 @@ 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(); } /** diff --git a/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dto/CompositeId.java b/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dto/CompositeId.java index 98a57546a3b450a827801786a33c0608f6563ecb..9bb040ba419a411328557ecb49cc4d2c114d0c09 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dto/CompositeId.java +++ b/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dto/CompositeId.java @@ -1,27 +1,3 @@ -/* 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>Preferences>Java>Code Generation>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 diff --git a/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dto/ScNum1Val.java b/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dto/ScNum1Val.java index 91c83c7c57d77498b1f6c887e0ffc3a59ac07591..7ad0d75b0d9b1db665dc40d3539bf25a8da6d91b 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dto/ScNum1Val.java +++ b/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dto/ScNum1Val.java @@ -1,57 +1,42 @@ -/* 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>Preferences>Java>Code Generation>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; + private double value; - public ScNum1Val() { + public ScNum1Val() { - } + } - public ScNum1Val(AnyAttribute attribute, SnapshotPersistenceContext context) { - super(attribute, context); - double[] val = attribute.getConvertedNumericValuesTable(); - this.value = val[0]; - } + public ScNum1Val(AnyAttribute attribute, SnapshotPersistenceContext context) { + super(attribute, context); + double[] val = attribute.getConvertedNumericValuesTable(); + if (val == null || val.length < 1) { + value = Double.NaN; + } else { + value = val[0]; + } + } - /** - * @return the value - */ - public double getValue() { - return this.value; - } + /** + * @return the value + */ + public double getValue() { + return value; + } - /** - * @param value - * the value to set - */ - public void setValue(double value) { - this.value = value; - } + /** + * @param value + * the value to set + */ + public void setValue(double value) { + this.value = value; + } } diff --git a/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dto/ScNum2Val.java b/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dto/ScNum2Val.java index 977f93d915147b35964ad689a420406da81f8243..e2b0d71e49bcc63b18923f76b29d26134f5b667d 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dto/ScNum2Val.java +++ b/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dto/ScNum2Val.java @@ -1,27 +1,3 @@ -/* 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>Preferences>Java>Code Generation>Code and Comments - */ package fr.soleil.archiving.snap.api.persistence.spring.dto; import org.slf4j.Logger; @@ -30,56 +6,68 @@ 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 double readValue; - private double writeValue; - public ScNum2Val() { + private static final Logger LOGGER = LoggerFactory.getLogger(ScNum2Val.class); + + private double readValue; + private double writeValue; + + public ScNum2Val() { - } + } - public ScNum2Val(AnyAttribute attribute, SnapshotPersistenceContext context) { - super(attribute, context); + public ScNum2Val(AnyAttribute attribute, SnapshotPersistenceContext context) { + super(attribute, context); - double[] val = attribute.getConvertedNumericValuesTable(); - this.readValue = val[0]; - this.writeValue = val[1]; - } + double[] val = attribute.getConvertedNumericValuesTable(); + if (val == null) { + readValue = Double.NaN; + writeValue = Double.NaN; + } else { + readValue = val.length < 1 ? Double.NaN : val[0]; + writeValue = val.length < 2 ? Double.NaN : val[1]; + } + } - /** - * @return the readValue - */ - public double getReadValue() { - return this.readValue; - } + /** + * @return the readValue + */ + public double getReadValue() { + return readValue; + } - /** - * @param readValue - * the readValue to set - */ - public void setReadValue(double readValue) { - this.readValue = readValue; - } + /** + * @param readValue + * the readValue to set + */ + public void setReadValue(double readValue) { + this.readValue = readValue; + } - /** - * @return the writeValue - */ - public double getWriteValue() { - return this.writeValue; - } + /** + * @return the writeValue + */ + public double getWriteValue() { + return writeValue; + } - /** - * @param writeValue - * the writeValue to set - */ - public void setWriteValue(double writeValue) { - this.writeValue = writeValue; - } + /** + * @param writeValue + * the writeValue to set + */ + public void setWriteValue(double writeValue) { + this.writeValue = writeValue; + } - public void trace() { - super.getCompositeId().trace(); - logger.debug("ScNum2Val/readValue/" + readValue); - logger.debug("ScNum2Val/writeValue/" + writeValue); - } + public void trace() { + super.getCompositeId().trace(); + LOGGER.debug("ScNum2Val/readValue/" + readValue); + LOGGER.debug("ScNum2Val/writeValue/" + writeValue); + } } diff --git a/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dto/ScStr1Val.java b/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dto/ScStr1Val.java index 04aec963a40c8daed1a28fc1e15a87490fae23a5..3aa85b648952fefeeb7ca6c6f582f520092d179d 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dto/ScStr1Val.java +++ b/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dto/ScStr1Val.java @@ -1,58 +1,41 @@ -/* 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>Preferences>Java>Code Generation>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; - - public ScStr1Val() { - - } - - public ScStr1Val(AnyAttribute attribute, SnapshotPersistenceContext context) { - super(attribute, context); - - String[] val = attribute.getConvertedStringValuesTable(); - this.value = val[0]; - } - - /** - * @return the value - */ - public String getValue() { - return this.value; - } - - /** - * @param value - * the value to set - */ - public void setValue(String value) { - this.value = value; - } + private String value; + + public ScStr1Val() { + + } + + public ScStr1Val(AnyAttribute attribute, SnapshotPersistenceContext context) { + super(attribute, context); + String[] val = attribute.getConvertedStringValuesTable(); + if (val == null || val.length < 1) { + value = null; + } else { + value = val[0]; + } + } + + /** + * @return the value + */ + public String getValue() { + return value; + } + + /** + * @param value the value to set + */ + public void setValue(String value) { + this.value = value; + } } diff --git a/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dto/ScStr2Val.java b/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dto/ScStr2Val.java index 4dfb333f2e67e9077fe2d5ca5b917f4c80f4f96c..a425a9e502f55e167d54e330e8bd01412f9511c6 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dto/ScStr2Val.java +++ b/src/main/java/fr/soleil/archiving/snap/api/persistence/spring/dto/ScStr2Val.java @@ -1,75 +1,61 @@ -/* Synchrotron Soleil - * - * File : ScStr2Val.java - * - * Project : javaapi - * - * Description : - * - * Author : CLAISSE - * - * Original : 7 mars 07 - * - * Revision: Author: - * Date: State: - * - * Log: ScStr2Val.java,v - * - */ -/* - * Created on 7 mars 07 - * - * To change the template for this generated file go to - * Window>Preferences>Java>Code Generation>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; +/** + * 2 string values. + * + * @author CLAISSE + */ public class ScStr2Val extends Val { - private String readValue; - private String writeValue; - - public ScStr2Val() { - - } - - public ScStr2Val(AnyAttribute attribute, SnapshotPersistenceContext context) { - super(attribute, context); - - String[] val = attribute.getConvertedStringValuesTable(); - this.readValue = val[0]; - this.writeValue = val[1]; - } - - /** - * @return the readValue - */ - public String getReadValue() { - return this.readValue; - } - - /** - * @param readValue - * the readValue to set - */ - public void setReadValue(String readValue) { - this.readValue = readValue; - } - - /** - * @return the writeValue - */ - public String getWriteValue() { - return this.writeValue; - } - - /** - * @param writeValue - * the writeValue to set - */ - public void setWriteValue(String writeValue) { - this.writeValue = writeValue; - } + private String readValue; + private String writeValue; + + public ScStr2Val() { + + } + + public ScStr2Val(AnyAttribute attribute, SnapshotPersistenceContext context) { + super(attribute, context); + + String[] val = attribute.getConvertedStringValuesTable(); + if (val == null) { + readValue = null; + writeValue = null; + } else { + readValue = val.length < 1 ? null : val[0]; + writeValue = val.length < 2 ? null : val[1]; + } + } + + /** + * @return the readValue + */ + public String getReadValue() { + return readValue; + } + + /** + * @param readValue + * the readValue to set + */ + public void setReadValue(String readValue) { + this.readValue = readValue; + } + + /** + * @return the writeValue + */ + public String getWriteValue() { + return writeValue; + } + + /** + * @param writeValue + * the writeValue to set + */ + public void setWriteValue(String writeValue) { + this.writeValue = writeValue; + } } diff --git a/src/main/java/fr/soleil/archiving/snap/api/tools/Condition.java b/src/main/java/fr/soleil/archiving/snap/api/tools/Condition.java deleted file mode 100644 index de2418feacd14aaa49bf516f87000fe9dcd7ce40..0000000000000000000000000000000000000000 --- a/src/main/java/fr/soleil/archiving/snap/api/tools/Condition.java +++ /dev/null @@ -1,245 +0,0 @@ -//+====================================================================== -// $Source: /cvsroot/tango-cs/tango/api/java/fr/soleil/TangoSnapshoting/SnapshotingTools/Tools/Condition.java,v $ -// -// Project: Tango Archiving Service -// -// Description: Java source code for the class Condition. -// (Garda Laure) - 1 juil. 2005 -// -// $Author: chinkumo $ -// -// $Revision: 1.3 $ -// -// $Log: Condition.java,v $ -// 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 2005/08/02 07:18:41 chinkumo -// Comments added. -// -// Revision 1.1.4.2 2005/08/01 13:51:48 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.tools; - -import fr.esrf.Tango.ErrSeverity; - -/** - * Description : A Condition object describes a search criterion for a request - * into the database. A Condition contains : a name of a table's field an - * operator a value. - * - * @author GARDA - */ -public class Condition { - private String column; // Name of the table's field. - private String operator; // Operator of the condition. - private String value; // Value of the condition. - - /** - * This constructor takes three parameters as inputs. - * - * @param _column - * @param _operator - * @param _value - */ - public Condition(String _column, String _operator, String _value) { - this.column = _column; - this.operator = _operator; - this.value = _value; - } - - /** - * Returns the name of the table's field. - * - * @return Name of the table's field - */ - public String getColumn() { - return column; - } - - /** - * Sets the name of the table's field. - * - * @param column - * Name of the table's field - */ - public void setColumn(String column) { - this.column = column; - } - - /** - * Returns the operator of the condition. - * - * @return Operator of the condition - */ - public String getOperator() { - return operator; - } - - /** - * Sets the operator of the condition. - * - * @param operator - * Operator of the condition - */ - public void setOperator(String operator) { - this.operator = operator; - } - - /** - * Returns the value of the condition. - * - * @return Value of the condition - */ - public String getValue() { - return value; - } - - /** - * Sets the value of the condition. - * - * @param value - * Value of the condition - */ - public void setValue(String value) { - this.value = value; - } - - /** - * Returns the predicat of the SQL request for this condition. - * - * @return Predicat of the SQL request for this condition - * @throws SnapshotingException - */ - public String getPredicat() throws SnapshotingException { - String predicat = ""; - // Casts the Condition's operator and value in a SQL predicat. - if (getOperator().equals(SnapConst.OP_EQUALS)) { - predicat = " = '" + getValue() + "'"; - } else if (getOperator().equals(SnapConst.OP_LOWER_THAN_STRICT)) { - predicat = " < '" + getValue() + "'"; - } else if (getOperator().equals(SnapConst.OP_LOWER_THAN)) { - predicat = " <= '" + getValue() + "'"; - } else if (getOperator().equals(SnapConst.OP_GREATER_THAN_STRICT)) { - predicat = " > '" + getValue() + "'"; - } else if (getOperator().equals(SnapConst.OP_GREATER_THAN)) { - predicat = " >= '" + getValue() + "'"; - } else if (getOperator().equals(SnapConst.OP_CONTAINS)) { - predicat = " LIKE '%" + getValue() + "%'"; - } else if (getOperator().equals(SnapConst.OP_STARTS_WITH)) { - predicat = " LIKE '" + getValue() + "%'"; - } else if (getOperator().equals(SnapConst.OP_ENDS_WITH)) { - predicat = " LIKE '%" + getValue() + "'"; - } else { - String message = ""; - message = SnapConst.ERROR_SQL_OPERATOR; - String reason = SnapConst.ERROR_SQL_OPERATOR; - String desc = "Failed while executing DataBaseApi.getPredicat() method..."; - throw new SnapshotingException(message, reason, ErrSeverity.WARN, - desc, this.getClass().getName()); - } - return predicat; - } - - /** - * Returns the predicat of the SQL request for this condition in the case of - * an integer value. - * - * @return Predicat of the SQL request for this condition in the case of an - * integer value - * @throws SnapshotingException - */ - public String getPredicatInt() throws SnapshotingException { - String predicat = ""; - // Casts the Condition's operator and value in a SQL predicat. - if (getOperator().equals(SnapConst.OP_EQUALS)) { - predicat = " = ?"; - } else if (getOperator().equals(SnapConst.OP_LOWER_THAN_STRICT)) { - predicat = " < ?"; - } else if (getOperator().equals(SnapConst.OP_LOWER_THAN)) { - predicat = " <= ?"; - } else if (getOperator().equals(SnapConst.OP_GREATER_THAN_STRICT)) { - predicat = " > ?"; - } else if (getOperator().equals(SnapConst.OP_GREATER_THAN)) { - predicat = " >= ?"; - } - /* - * else if(getOperator().equals(ISnapManager.OP_CONTAINS)) { predicat = - * " LIKE '%" + getValue() + "%'"; } else - * if(getOperator().equals(ISnapManager.OP_STARTS_WITH)) { predicat = - * " LIKE '" + getValue() + "%'"; } else - * if(getOperator().equals(ISnapManager.OP_ENDS_WITH)) { predicat = - * " LIKE '%" + getValue() + "'"; } - */ - else { - String message = ""; - message = SnapConst.ERROR_SQL_OPERATOR; - String reason = SnapConst.ERROR_SQL_OPERATOR; - String desc = "Failed while executing DataBaseApi.getPredicatInt() method..."; - throw new SnapshotingException(message, reason, ErrSeverity.WARN, - desc, this.getClass().getName()); - } - return predicat; - } - - /** - * Returns the predicat of the SQL request for this condition in the case of - * the full name of an attribute. - * - * @return Predicat of the SQL request for this condition in the case of the - * full name of an attribute - * @throws SnapshotingException - */ - public String getPredicatFullName() throws SnapshotingException { - String predicat = ""; - // Casts the Condition's operator and value in a SQL predicat. - if (getValue().equals("*")) { - predicat = ""; - } else if (getValue().startsWith("*") && getValue().endsWith("*")) { - predicat = " LIKE '%" - + getValue().substring(1, getValue().length() - 1) + "%'"; - } else if (getValue().endsWith("*")) { - predicat = " LIKE '" - + getValue().substring(0, getValue().length() - 1) + "%'"; - } else if (getValue().startsWith("*")) { - predicat = " LIKE '%" + getValue().substring(1) + "'"; - } else if (!getValue().equals("")) { - predicat = " = '" + getValue() + "'"; - } else { - String message = ""; - message = SnapConst.ERROR_SQL_OPERATOR; - String reason = SnapConst.ERROR_SQL_OPERATOR; - String desc = "Failed while executing DataBaseApi.getPredicatFullName() method..."; - throw new SnapshotingException(message, reason, ErrSeverity.WARN, - desc, this.getClass().getName()); - } - return predicat; - } - - /** - * Returns a String which represente the object Condition. - * - * @return String which represente the object Condition - */ - public String toString() { - String condition_str = ""; - condition_str = getColumn() + " " + getOperator() + " " + getValue() - + "\r\n"; - return condition_str; - } - -} 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 deleted file mode 100644 index f8a6055e36d7dd956207e6fc36745de4762c8260..0000000000000000000000000000000000000000 --- a/src/main/java/fr/soleil/archiving/snap/api/tools/Criterions.java +++ /dev/null @@ -1,397 +0,0 @@ -//+====================================================================== -// $Source: /cvsroot/tango-cs/tango/api/java/fr/soleil/TangoSnapshoting/SnapshotingTools/Tools/Criterions.java,v $ -// -// Project: Tango Archiving Service -// -// Description: Java source code for the class Criterions. -// (Garda Laure) - 1 juil. 2005 -// -// $Author: ounsy $ -// -// $Revision: 1.8 $ -// -// $Log: Criterions.java,v $ -// Revision 1.8 2006/05/30 13:00:40 ounsy -// small bug correction -// -// Revision 1.7 2006/05/16 13:04:19 ounsy -// added a getConditionsHT() method -// -// Revision 1.6 2006/05/04 14:34:12 ounsy -// minor changes -// -// Revision 1.5 2006/03/14 12:36:47 ounsy -// removed useless logs -// -// Revision 1.4 2006/02/17 09:32:35 chinkumo -// Since the structure and the name of some SNAPSHOT database's table changed, this was reported here. -// -// 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 2005/08/02 07:18:41 chinkumo -// Comments added. -// -// Revision 1.1.4.2 2005/08/01 13:51:49 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.tools; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - -import fr.esrf.Tango.ErrSeverity; - -/** - * Description : A Criterion object describes a set of search criteria for a - * request into the database A Criterion contains : a set of Condition objects. - * - * @author GARDA - */ -public class Criterions { - private Map<String, List<Condition>> conditionsHT; // set of Condition - // objects - - /** - * Default constructor. - */ - public Criterions() { - conditionsHT = new ConcurrentHashMap<String, List<Condition>>(); - } - - /** - * This constructor takes one parameter as inputs. - * - * @param conditions - * a set of Conditions - */ - public Criterions(Condition[] conditions) { - conditionsHT = new ConcurrentHashMap<String, List<Condition>>(); - // Sets the Conditions into the Criterion. - if (conditions != null) { - int nbOfConditions = conditions.length; - for (int i = 0; i < nbOfConditions; i++) { - List<Condition> currentColumnConditionsList; - String columnName = conditions[i].getColumn(); - // The Conditions are referenced by their table's field - // (columnName). - if (conditionsHT.containsKey(columnName)) { - currentColumnConditionsList = conditionsHT.get(columnName); - } else { - currentColumnConditionsList = new ArrayList<Condition>(); - conditionsHT.put(columnName, currentColumnConditionsList); - } - - currentColumnConditionsList.add(conditions[i]); - } - } - } - - /** - * Adds a Condition into the Criterion. - * - * @param condition - * A Condition - */ - public void addCondition(Condition condition) { - if (condition != null) { - String columnName = condition.getColumn(); - List<Condition> currentColumnConditionsList; - if (!conditionsHT.containsKey(columnName)) { - currentColumnConditionsList = new ArrayList<Condition>(); - conditionsHT.put(columnName, currentColumnConditionsList); - } else { - currentColumnConditionsList = conditionsHT.get(columnName); - } - currentColumnConditionsList.add(condition); - } - } - - /** - * Returns array of all Condition objects (of this Criterion) for the given - * table's field - * - * @param columnName - * @return array of all Condition objects for the given table's field - */ - public Condition[] getConditions(String columnName) { - Condition[] ret = null; - if ((columnName != null) && (conditionsHT != null)) { - List<Condition> columnConditionsList = conditionsHT.get(columnName); - if (columnConditionsList != null) { - ret = columnConditionsList.toArray(new Condition[columnConditionsList.size()]); - } - } - return ret; - } - - /** - * Returns the SQL clause describes by the Criterion in the case of a field - * of the ContextTable. - * - * @return SQL clause describes by the Criterion in the case of a field of - * the ContextTable - * @throws SnapshotingException - */ - public String getContextClause() throws SnapshotingException { - String clause = ""; - String table = SnapConst.CONTEXT; - String[] field = SnapConst.TAB_CONTEXT; - int count = 0; - // Cas de l'ID_context. - Condition[] conditions = getConditions(field[0]); - if (conditions != null) { - // Une seule condition sur l'id_context. - if (conditions.length == 1) { - // Mise en forme du predicat de la requete SQL. - String predicat = conditions[0].getPredicatInt(); - - // Mise en forme de la requete SQL. - if (count == 0) { - clause = clause + " WHERE " + table + "." + field[0] + predicat; - count++; - } else { - clause = clause + " AND " + table + "." + field[0] + predicat; - } - } else { - String message = ""; - message = SnapConst.ERROR_SQL_OPERATOR; - String reason = SnapConst.ERROR_SQL_OPERATOR; - String desc = "Failed while executing Criterions.getSnapshotClause() method..."; - throw new SnapshotingException(message, reason, ErrSeverity.WARN, desc, this.getClass().getName()); - } - } - - // Pour les autres champs. - for (int i = 1; i < field.length; i++) // Parcours de tous les champs de - // la table des contextes, sauf - // l'ID_context. - { - conditions = getConditions(field[i]); - if (conditions != null) { - for (int j = 0; j < conditions.length; j++) { - // Mise en forme du predicat de la requete SQL. - String predicat = conditions[j].getPredicat(); - - // Mise en forme de la requete SQL. - if (count == 0) { - clause = clause + " WHERE " + table + "." + field[i] + predicat; - count++; - } else { - clause = clause + " AND " + table + "." + field[i] + predicat; - } - } - } - - } - return clause; - - } - - /** - * Returns the SQL clause describes by the Criterion in the case of a field - * of the SnapshotTable. - * - * @return SQL clause describes by the Criterion in the case of a field of - * the SnashotTable - * @throws SnapshotingException - */ - public String getSnapshotClause() throws SnapshotingException { - String clause = ""; - String table = SnapConst.SNAPSHOT; - String[] field = SnapConst.TAB_SNAP; - int count = 0; - // Cas de l'id_snap. - Condition[] conditions = getConditions(field[0]); - if (conditions != null) { - if (conditions.length == 1) { - // Mise en forme du predicat de la requete SQL. - String predicat = conditions[0].getPredicatInt(); - - // Mise en forme de la requete SQL. - if (count == 0) { - clause = clause + " WHERE " + table + "." + field[0] + predicat; - count++; - } else { - clause = clause + " AND " + table + "." + field[0] + predicat; - } - } else { - String message = ""; - message = SnapConst.ERROR_SQL_OPERATOR; - String reason = SnapConst.ERROR_SQL_OPERATOR; - String desc = "Failed while executing Criterions.getSnapshotClause() method..."; - throw new SnapshotingException(message, reason, ErrSeverity.WARN, desc, this.getClass().getName()); - } - - } - // Cas de l'ID_context. - conditions = getConditions(field[1]); - if (conditions != null) { - // Une seule condition sur l'id_context. - if (conditions.length == 1) { - // Mise en forme du predicat de la requete SQL. - String predicat = conditions[0].getPredicatInt(); - - // Mise en forme de la requete SQL. - if (count == 0) { - clause = clause + " WHERE " + table + "." + field[1] + predicat; - count++; - } else { - clause = clause + " AND " + table + "." + field[1] + predicat; - } - } else { - String message = ""; - message = SnapConst.ERROR_SQL_OPERATOR; - String reason = SnapConst.ERROR_SQL_OPERATOR; - String desc = "Failed while executing Criterions.getSnapshotClause() method..."; - throw new SnapshotingException(message, reason, ErrSeverity.WARN, desc, this.getClass().getName()); - } - - } - - for (int i = 2; i < field.length; i++) // Parcours de tous les champs de - // la table des contextes. - { - conditions = getConditions(field[i]); - if (conditions != null) { - for (int j = 0; j < conditions.length; j++) { - // Mise en forme du predicat de la requete SQL. - String predicat = conditions[j].getPredicat(); - // Mise en forme de la requete SQL. - if (count == 0) { - clause = clause + " WHERE " + table + "." + field[i] + predicat; - count++; - } else { - clause = clause + " AND " + table + "." + field[i] + predicat; - } - } - } - } - return clause; - } - - /** - * Returns the id of a context of the SnapTable. - * - * @return id of a context of the SnapTable - * @throws SnapshotingException - */ - public int getIdContextSnapTable() throws SnapshotingException { - int id_context = -1; // value if no condition on this id. - - Condition[] id_condition = getConditions(SnapConst.TAB_SNAP[1]); - if (id_condition != null) { - id_context = Integer.parseInt(id_condition[0].getValue()); - } - return id_context; - } - - /** - * Returns the id of a context. - * - * @return the id of a context - * @throws SnapshotingException - */ - public int getIdContextContextTable() throws SnapshotingException { - int id_context = -1; // value if no condition on this id. - - Condition[] id_condition = getConditions(SnapConst.ID_CONTEXT); - if (id_condition != null) { - id_context = Integer.parseInt(id_condition[0].getValue()); - } - return id_context; - } - - /** - * Returns the id of a snapshot. - * - * @return the id of a snapshot - * @throws SnapshotingException - */ - public int getIdSnap() throws SnapshotingException { - int id_snap = -1; // value if no condition on this id. - - Condition[] id_condition = getConditions(SnapConst.ID_SNAP); - if (id_condition != null) { - id_snap = Integer.parseInt(id_condition[0].getValue()); - } - return id_snap; - } - - /** - * Returns the SQL clause describes by the Criterion in the case of a field - * of the AttribteTable. - * - * @return SQL clause describes by the Criterion in the case of a field of - * the AttributeTable - * @throws SnapshotingException - */ - public String getAttributeClause() throws SnapshotingException { - String clause = ""; - 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 - // definitions. - { - Condition[] conditions = getConditions(field[i]); - if (conditions != null) { - for (int j = 0; j < conditions.length; j++) { - // Mise en forme du predicat de la requete SQL. - String predicat = conditions[j].getPredicatFullName(); - // Mise en forme de la requete SQL. - if (!predicat.equals("")) { - if (count == 0) { - clause = clause + " WHERE " + table + "." + field[i] + predicat; - count++; - } else { - clause = clause + " AND " + table + "." + field[i] + predicat; - } - } - } - } - - } - return clause; - } - - /** - * Returns a String which represente the object Criterion. - * - * @return String which represente the object Criterion - */ - @Override - public String toString() { - String criterions_str = ""; - if (conditionsHT.isEmpty()) { - criterions_str = null; - } else { - for (List<Condition> columnConditionsList : conditionsHT.values()) { - for (Condition nextCondition : columnConditionsList) { - criterions_str = criterions_str + nextCondition.toString(); - } - } - } - return criterions_str; - - } - - public Map<String, List<Condition>> getConditionsHT() { - return this.conditionsHT; - } -} diff --git a/src/main/java/fr/soleil/archiving/snap/api/tools/SnapAttribute.java b/src/main/java/fr/soleil/archiving/snap/api/tools/SnapAttribute.java index 2354556aa9e9d0297c6a4550cba7de5b4878a973..6c46d060d5656abec648362f44d37229a5ca21eb 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/tools/SnapAttribute.java +++ b/src/main/java/fr/soleil/archiving/snap/api/tools/SnapAttribute.java @@ -1,45 +1,16 @@ -//+====================================================================== -// $Source: /cvsroot/tango-cs/tango/api/java/fr/soleil/TangoSnapshoting/SnapshotingTools/Tools/SnapAttribute.java,v $ -// -// Project: Tango Archiving Service -// -// Description: Java source code for the class SnapAttribute. -// (Chinkumo Jean) - Mar 24, 2004 -// -// $Author: ounsy $ -// -// $Revision: 1.3 $ -// -// $Log: SnapAttribute.java,v $ -// Revision 1.3 2006/02/15 09:06:05 ounsy -// minor changes -// -// Revision 1.2 2005/11/29 17:11:17 chinkumo -// no message -// -// Revision 1.1.16.1 2005/11/15 13:34:38 chinkumo -// no message -// -// Revision 1.1 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.tools; import java.sql.Timestamp; +import fr.soleil.lib.project.ObjectUtils; + +/** + * A snapshot attribute. + * + * @author ounsy + */ public class SnapAttribute { - private String attributeCompleteName = ""; + private String attributeCompleteName = ObjectUtils.EMPTY_STRING; protected int dataFormat; protected int dataType; protected int writable; 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 ebbd07c05f8b21d4071c72d4c6e9bd60a38ef918..ee872fe824c76061dac4bc98356fc39e15dbb2e6 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 @@ -1,86 +1,3 @@ -// +====================================================================== -// $Source: /cvsroot/tango-cs/tango/api/java/fr/soleil/TangoSnapshoting/SnapshotingTools/Tools/SnapAttributeExtract.java,v $ -// -// Project: Tango Archiving Service -// -// Description: Java source code for the class SnapAttributeExtract. -// (Chinkumo Jean) - Nov 14, 2004 -// -// $Author: soleilarc $ -// -// $Revision: 1.15 $ -// -// $Log: SnapAttributeExtract.java,v $ -// Revision 1.15 2007/11/16 10:19:06 soleilarc -// Author: XPigeon -// Mantis bug ID: 5341 -// Comment : -// Add the new methods named getNewValue and setWriteValue. -// In the getWriteValue and getReadValue methods, modify the case for the image attribute data format. -// -// Revision 1.14 2007/06/29 09:20:31 ounsy -// devLong represented as Integer -// -// Revision 1.13 2006/10/31 16:54:24 ounsy -// milliseconds and null values management -// -// Revision 1.12 2006/05/12 09:26:20 ounsy -// CLOB_SEPARATOR in GlobalConst -// -// Revision 1.11 2006/05/04 14:35:20 ounsy -// CLOB_SEPARATOR centralized in ConfigConst -// -// Revision 1.10 2006/04/13 12:47:24 ounsy -// new spectrum types support -// -// Revision 1.9 2006/03/29 15:05:33 ounsy -// added protections against null values -// -// Revision 1.8 2006/03/14 12:36:24 ounsy -// corrected the SNAP/spectrums/RW problem -// about the read and write values having the same length -// -// Revision 1.7 2006/02/28 17:05:58 chinkumo -// no message -// -// Revision 1.6 2006/02/24 12:06:29 ounsy -// replaced hard-coded "," value to CLOB_SEPARATOR -// -// Revision 1.5 2006/02/17 09:26:46 chinkumo -// Minor change : code reformated. -// -// Revision 1.4 2006/02/15 09:06:28 ounsy -// Spectrums Management -// -// Revision 1.3 2005/11/29 17:11:17 chinkumo -// no message -// -// Revision 1.2.2.2 2005/11/15 13:34:38 chinkumo -// no message -// -// Revision 1.2.2.1 2005/09/09 08:44:53 chinkumo -// Minor changes. -// -// Revision 1.2 2005/08/19 14:04:02 chinkumo -// no message -// -// Revision 1.1.14.1 2005/08/11 08:34:58 chinkumo -// Changes was made since the 'SetEquipement' functionnality was added. -// The scalar type management was also improved. -// -// Revision 1.1 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.tools; import java.lang.reflect.Array; @@ -91,7 +8,13 @@ import fr.esrf.TangoApi.DeviceData; import fr.esrf.TangoDs.TangoConst; import fr.soleil.archiving.common.api.tools.AttributeLight; import fr.soleil.archiving.common.api.tools.GlobalConst; +import fr.soleil.lib.project.ObjectUtils; +/** + * An extracted snapshot attribute + * + * @author chinkumo + */ public class SnapAttributeExtract extends SnapAttribute { // Everything here is already available in SnapAttribute @@ -346,14 +269,15 @@ public class SnapAttributeExtract extends SnapAttribute { value = "NaN"; break; } - stringArrayWrite = toSplitWrite.substring(1, toSplitWrite.length() - 1).split( - GlobalConst.CLOB_SEPARATOR); + stringArrayWrite = toSplitWrite.substring(1, toSplitWrite.length() - 1) + .split(GlobalConst.CLOB_SEPARATOR); switch (dataType) { case TangoConst.Tango_DEV_BOOLEAN: value = new boolean[stringArrayWrite.length]; for (int i = 0; i < stringArrayWrite.length; i++) { try { - ((boolean[]) value)[i] = (((byte) Double.parseDouble(stringArrayWrite[i])) != 0); + ((boolean[]) value)[i] = (((byte) Double + .parseDouble(stringArrayWrite[i])) != 0); } catch (final NumberFormatException n) { ((boolean[]) value)[i] = "true".equalsIgnoreCase(stringArrayWrite[i]); } @@ -408,8 +332,8 @@ public class SnapAttributeExtract extends SnapAttribute { value = "NaN"; break; } - stringArrayRead = toSplitRead.substring(1, toSplitRead.length() - 1).split( - GlobalConst.CLOB_SEPARATOR); + stringArrayRead = toSplitRead.substring(1, toSplitRead.length() - 1) + .split(GlobalConst.CLOB_SEPARATOR); switch (dataType) { case TangoConst.Tango_DEV_BOOLEAN: value = new boolean[stringArrayRead.length]; @@ -478,10 +402,10 @@ public class SnapAttributeExtract extends SnapAttribute { value = "NaN"; break; } - stringArrayRead = toSplitRead.substring(1, toSplitRead.length() - 1).split( - GlobalConst.CLOB_SEPARATOR); - stringArrayWrite = toSplitWrite.substring(1, toSplitWrite.length() - 1).split( - GlobalConst.CLOB_SEPARATOR); + stringArrayRead = toSplitRead.substring(1, toSplitRead.length() - 1) + .split(GlobalConst.CLOB_SEPARATOR); + stringArrayWrite = toSplitWrite.substring(1, toSplitWrite.length() - 1) + .split(GlobalConst.CLOB_SEPARATOR); value = new Object[2]; switch (dataType) { case TangoConst.Tango_DEV_BOOLEAN: @@ -584,7 +508,7 @@ public class SnapAttributeExtract extends SnapAttribute { } - public SnapAttributeExtract(final AttributeLight snapAttributeLight) { + public SnapAttributeExtract(final AttributeLight snapAttributeLight) { super.setAttributeCompleteName(snapAttributeLight.getAttributeCompleteName()); super.setAttId(snapAttributeLight.getAttributeId()); dataFormat = snapAttributeLight.getDataFormat(); @@ -592,7 +516,6 @@ public class SnapAttributeExtract extends SnapAttribute { writable = snapAttributeLight.getWritable(); } - // Everything here is already available in SnapAttribute public String valueToString(final int pos) { final String nullvalue = "NULL"; @@ -600,13 +523,13 @@ public class SnapAttributeExtract extends SnapAttribute { if (getValue() == null) { return nullvalue; } - if (getValue() instanceof Object[]) { - final Object[] valTab = (Object[]) getValue(); - if ((writable == AttrWriteType._READ_WITH_WRITE || writable == AttrWriteType._READ_WRITE) - && valTab[pos] == null) { - return nullvalue; - } - } + if (getValue() instanceof Object[]) { + final Object[] valTab = (Object[]) getValue(); + if ((writable == AttrWriteType._READ_WITH_WRITE || writable == AttrWriteType._READ_WRITE) + && valTab[pos] == null) { + return nullvalue; + } + } switch (dataFormat) { case AttrDataFormat._SCALAR: @@ -638,18 +561,18 @@ public class SnapAttributeExtract extends SnapAttribute { switch (dataType) { case TangoConst.Tango_DEV_BOOLEAN: final boolean[] valb = (boolean[]) getValue(); - if (valb != null && valb.length > 0) { + if (valb != null && valb.length > 0) { for (int i = 0; i < valb.length - 1; i++) { - value += valb[i] + GlobalConst.CLOB_SEPARATOR; + value += valb[i] + GlobalConst.CLOB_SEPARATOR; } value += valb[valb.length - 1]; } break; case TangoConst.Tango_DEV_STRING: final String[] valstr = (String[]) getValue(); - if (valstr != null && valstr.length > 0) { + if (valstr != null && valstr.length > 0) { for (int i = 0; i < valstr.length - 1; i++) { - value += valstr[i] + GlobalConst.CLOB_SEPARATOR; + value += valstr[i] + GlobalConst.CLOB_SEPARATOR; } value += valstr[valstr.length - 1]; } @@ -657,9 +580,9 @@ public class SnapAttributeExtract extends SnapAttribute { case TangoConst.Tango_DEV_CHAR: case TangoConst.Tango_DEV_UCHAR: final byte[] valc = (byte[]) getValue(); - if (valc != null && valc.length > 0) { + if (valc != null && valc.length > 0) { for (int i = 0; i < valc.length - 1; i++) { - value += valc[i] + GlobalConst.CLOB_SEPARATOR; + value += valc[i] + GlobalConst.CLOB_SEPARATOR; } value += valc[valc.length - 1]; } @@ -668,9 +591,9 @@ public class SnapAttributeExtract extends SnapAttribute { case TangoConst.Tango_DEV_LONG: case TangoConst.Tango_DEV_ULONG: final int[] vall = (int[]) getValue(); - if (vall != null && vall.length > 0) { + if (vall != null && vall.length > 0) { for (int i = 0; i < vall.length - 1; i++) { - value += vall[i] + GlobalConst.CLOB_SEPARATOR; + value += vall[i] + GlobalConst.CLOB_SEPARATOR; } value += vall[vall.length - 1]; } @@ -678,27 +601,27 @@ public class SnapAttributeExtract extends SnapAttribute { case TangoConst.Tango_DEV_USHORT: case TangoConst.Tango_DEV_SHORT: final short[] vals = (short[]) getValue(); - if (vals != null && vals.length > 0) { + if (vals != null && vals.length > 0) { for (int i = 0; i < vals.length - 1; i++) { - value += vals[i] + GlobalConst.CLOB_SEPARATOR; + value += vals[i] + GlobalConst.CLOB_SEPARATOR; } value += vals[vals.length - 1]; } break; case TangoConst.Tango_DEV_FLOAT: final float[] valf = (float[]) getValue(); - if (valf != null && valf.length > 0) { + if (valf != null && valf.length > 0) { for (int i = 0; i < valf.length - 1; i++) { - value += valf[i] + GlobalConst.CLOB_SEPARATOR; + value += valf[i] + GlobalConst.CLOB_SEPARATOR; } value += valf[valf.length - 1]; } break; case TangoConst.Tango_DEV_DOUBLE: final double[] vald = (double[]) getValue(); - if (vald != null && vald.length > 0) { + if (vald != null && vald.length > 0) { for (int i = 0; i < vald.length - 1; i++) { - value += vald[i] + GlobalConst.CLOB_SEPARATOR; + value += vald[i] + GlobalConst.CLOB_SEPARATOR; } value += vald[vald.length - 1]; } @@ -713,18 +636,18 @@ public class SnapAttributeExtract extends SnapAttribute { switch (dataType) { case TangoConst.Tango_DEV_BOOLEAN: final boolean[] valb = (boolean[]) temp[pos]; - if (valb != null && valb.length > 0) { + if (valb != null && valb.length > 0) { for (int i = 0; i < valb.length - 1; i++) { - value += valb[i] + GlobalConst.CLOB_SEPARATOR; + value += valb[i] + GlobalConst.CLOB_SEPARATOR; } value += valb[valb.length - 1]; } break; case TangoConst.Tango_DEV_STRING: final String[] valstr = (String[]) temp[pos]; - if (valstr != null && valstr.length > 0) { + if (valstr != null && valstr.length > 0) { for (int i = 0; i < valstr.length - 1; i++) { - value += valstr[i] + GlobalConst.CLOB_SEPARATOR; + value += valstr[i] + GlobalConst.CLOB_SEPARATOR; } value += valstr[valstr.length - 1]; } @@ -732,9 +655,9 @@ public class SnapAttributeExtract extends SnapAttribute { case TangoConst.Tango_DEV_CHAR: case TangoConst.Tango_DEV_UCHAR: final byte[] valc = (byte[]) temp[pos]; - if (valc != null && valc.length > 0) { + if (valc != null && valc.length > 0) { for (int i = 0; i < valc.length - 1; i++) { - value += valc[i] + GlobalConst.CLOB_SEPARATOR; + value += valc[i] + GlobalConst.CLOB_SEPARATOR; } value += valc[valc.length - 1]; } @@ -743,9 +666,9 @@ public class SnapAttributeExtract extends SnapAttribute { case TangoConst.Tango_DEV_LONG: case TangoConst.Tango_DEV_ULONG: final int[] vall = (int[]) temp[pos]; - if (vall != null && vall.length > 0) { + if (vall != null && vall.length > 0) { for (int i = 0; i < vall.length - 1; i++) { - value += vall[i] + GlobalConst.CLOB_SEPARATOR; + value += vall[i] + GlobalConst.CLOB_SEPARATOR; } value += vall[vall.length - 1]; } @@ -753,27 +676,27 @@ public class SnapAttributeExtract extends SnapAttribute { case TangoConst.Tango_DEV_USHORT: case TangoConst.Tango_DEV_SHORT: final short[] vals = (short[]) temp[pos]; - if (vals != null && vals.length > 0) { + if (vals != null && vals.length > 0) { for (int i = 0; i < vals.length - 1; i++) { - value += vals[i] + GlobalConst.CLOB_SEPARATOR; + value += vals[i] + GlobalConst.CLOB_SEPARATOR; } value += vals[vals.length - 1]; } break; case TangoConst.Tango_DEV_FLOAT: final float[] valf = (float[]) temp[pos]; - if (valf != null && valf.length > 0) { + if (valf != null && valf.length > 0) { for (int i = 0; i < valf.length - 1; i++) { - value += valf[i] + GlobalConst.CLOB_SEPARATOR; + value += valf[i] + GlobalConst.CLOB_SEPARATOR; } value += valf[valf.length - 1]; } break; case TangoConst.Tango_DEV_DOUBLE: final double[] vald = (double[]) temp[pos]; - if (vald != null && vald.length > 0) { + if (vald != null && vald.length > 0) { for (int i = 0; i < vald.length - 1; i++) { - value += vald[i] + GlobalConst.CLOB_SEPARATOR; + value += vald[i] + GlobalConst.CLOB_SEPARATOR; } value += vald[vald.length - 1]; } @@ -789,18 +712,18 @@ public class SnapAttributeExtract extends SnapAttribute { switch (dataType) { case TangoConst.Tango_DEV_BOOLEAN: final boolean[] valb = (boolean[]) getValue(); - if (valb != null && valb.length > 0) { + if (valb != null && valb.length > 0) { for (int i = 0; i < valb.length - 1; i++) { - value += valb[i] + GlobalConst.CLOB_SEPARATOR; + value += valb[i] + GlobalConst.CLOB_SEPARATOR; } value += valb[valb.length - 1]; } break; case TangoConst.Tango_DEV_STRING: final String[] valstr = (String[]) getValue(); - if (valstr != null && valstr.length > 0) { + if (valstr != null && valstr.length > 0) { for (int i = 0; i < valstr.length - 1; i++) { - value += valstr[i] + GlobalConst.CLOB_SEPARATOR; + value += valstr[i] + GlobalConst.CLOB_SEPARATOR; } value += valstr[valstr.length - 1]; } @@ -810,7 +733,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] + GlobalConst.CLOB_SEPARATOR; + value += valc[i] + GlobalConst.CLOB_SEPARATOR; } value += valc[valc.length - 1]; } @@ -818,9 +741,9 @@ public class SnapAttributeExtract extends SnapAttribute { case TangoConst.Tango_DEV_LONG: case TangoConst.Tango_DEV_ULONG: final int[] vall = (int[]) getValue(); - if (vall != null && vall.length > 0) { + if (vall != null && vall.length > 0) { for (int i = 0; i < vall.length - 1; i++) { - value += vall[i] + GlobalConst.CLOB_SEPARATOR; + value += vall[i] + GlobalConst.CLOB_SEPARATOR; } value += vall[vall.length - 1]; } @@ -828,27 +751,27 @@ public class SnapAttributeExtract extends SnapAttribute { case TangoConst.Tango_DEV_USHORT: case TangoConst.Tango_DEV_SHORT: final short[] vals = (short[]) getValue(); - if (vals != null && vals.length > 0) { + if (vals != null && vals.length > 0) { for (int i = 0; i < vals.length - 1; i++) { - value += vals[i] + GlobalConst.CLOB_SEPARATOR; + value += vals[i] + GlobalConst.CLOB_SEPARATOR; } value += vals[vals.length - 1]; } break; case TangoConst.Tango_DEV_FLOAT: final float[] valf = (float[]) getValue(); - if (valf != null && valf.length > 0) { + if (valf != null && valf.length > 0) { for (int i = 0; i < valf.length - 1; i++) { - value += valf[i] + GlobalConst.CLOB_SEPARATOR; + value += valf[i] + GlobalConst.CLOB_SEPARATOR; } value += valf[valf.length - 1]; } break; case TangoConst.Tango_DEV_DOUBLE: final double[] vald = (double[]) getValue(); - if (vald != null && vald.length > 0) { + if (vald != null && vald.length > 0) { for (int i = 0; i < vald.length - 1; i++) { - value += vald[i] + GlobalConst.CLOB_SEPARATOR; + value += vald[i] + GlobalConst.CLOB_SEPARATOR; } value += vald[vald.length - 1]; } @@ -863,18 +786,18 @@ public class SnapAttributeExtract extends SnapAttribute { switch (dataType) { case TangoConst.Tango_DEV_BOOLEAN: final boolean[] valb = (boolean[]) temp[pos]; - if (valb != null && valb.length > 0) { + if (valb != null && valb.length > 0) { for (int i = 0; i < valb.length - 1; i++) { - value += valb[i] + GlobalConst.CLOB_SEPARATOR; + value += valb[i] + GlobalConst.CLOB_SEPARATOR; } value += valb[valb.length - 1]; } break; case TangoConst.Tango_DEV_STRING: final String[] valstr = (String[]) temp[pos]; - if (valstr != null && valstr.length > 0) { + if (valstr != null && valstr.length > 0) { for (int i = 0; i < valstr.length - 1; i++) { - value += valstr[i] + GlobalConst.CLOB_SEPARATOR; + value += valstr[i] + GlobalConst.CLOB_SEPARATOR; } value += valstr[valstr.length - 1]; } @@ -882,9 +805,9 @@ public class SnapAttributeExtract extends SnapAttribute { case TangoConst.Tango_DEV_CHAR: case TangoConst.Tango_DEV_UCHAR: final byte[] valc = (byte[]) temp[pos]; - if (valc != null && valc.length > 0) { + if (valc != null && valc.length > 0) { for (int i = 0; i < valc.length - 1; i++) { - value += valc[i] + GlobalConst.CLOB_SEPARATOR; + value += valc[i] + GlobalConst.CLOB_SEPARATOR; } value += valc[valc.length - 1]; } @@ -892,9 +815,9 @@ public class SnapAttributeExtract extends SnapAttribute { case TangoConst.Tango_DEV_LONG: case TangoConst.Tango_DEV_ULONG: final int[] vall = (int[]) temp[pos]; - if (vall != null && vall.length > 0) { + if (vall != null && vall.length > 0) { for (int i = 0; i < vall.length - 1; i++) { - value += vall[i] + GlobalConst.CLOB_SEPARATOR; + value += vall[i] + GlobalConst.CLOB_SEPARATOR; } value += vall[vall.length - 1]; } @@ -902,27 +825,27 @@ public class SnapAttributeExtract extends SnapAttribute { case TangoConst.Tango_DEV_USHORT: case TangoConst.Tango_DEV_SHORT: final short[] vals = (short[]) temp[pos]; - if (vals != null && vals.length > 0) { + if (vals != null && vals.length > 0) { for (int i = 0; i < vals.length - 1; i++) { - value += vals[i] + GlobalConst.CLOB_SEPARATOR; + value += vals[i] + GlobalConst.CLOB_SEPARATOR; } value += vals[vals.length - 1]; } break; case TangoConst.Tango_DEV_FLOAT: final float[] valf = (float[]) temp[pos]; - if (valf != null && valf.length > 0) { + if (valf != null && valf.length > 0) { for (int i = 0; i < valf.length - 1; i++) { - value += valf[i] + GlobalConst.CLOB_SEPARATOR; + value += valf[i] + GlobalConst.CLOB_SEPARATOR; } value += valf[valf.length - 1]; } break; case TangoConst.Tango_DEV_DOUBLE: final double[] vald = (double[]) temp[pos]; - if (vald != null && vald.length > 0) { + if (vald != null && vald.length > 0) { for (int i = 0; i < vald.length - 1; i++) { - value += vald[i] + GlobalConst.CLOB_SEPARATOR; + value += vald[i] + GlobalConst.CLOB_SEPARATOR; } value += vald[vald.length - 1]; } @@ -1126,16 +1049,16 @@ public class SnapAttributeExtract extends SnapAttribute { switch (writable) { case AttrWriteType._READ: break; - case AttrWriteType._READ_WRITE: - case AttrWriteType._READ_WITH_WRITE: - if (getValue() == null) { - write_value = null; - } else { - write_value = Array.get(getValue(), 1); - } + 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: - write_value = getValue(); + write_value = getValue(); break; } break; @@ -1176,7 +1099,7 @@ public class SnapAttributeExtract extends SnapAttribute { case AttrWriteType._READ: break; case AttrWriteType._READ_WITH_WRITE: - case AttrWriteType._READ_WRITE: + case AttrWriteType._READ_WRITE: nullWrite = Array.get(nullElements, 1); break; case AttrWriteType._WRITE: @@ -1197,15 +1120,15 @@ public class SnapAttributeExtract extends SnapAttribute { case AttrDataFormat._SCALAR: switch (writable) { case AttrWriteType._READ: - read_value = getValue(); + read_value = getValue(); break; case AttrWriteType._READ_WITH_WRITE: - case AttrWriteType._READ_WRITE: - if (getValue() == null) { - read_value = null; - } else { - read_value = Array.get(getValue(), 0); - } + case AttrWriteType._READ_WRITE: + if (getValue() == null) { + read_value = null; + } else { + read_value = Array.get(getValue(), 0); + } break; case AttrWriteType._WRITE: break; @@ -1302,7 +1225,7 @@ public class SnapAttributeExtract extends SnapAttribute { break; // End of case AttrDataFormat._SCALAR case AttrDataFormat._SPECTRUM: { - final String[] stringTable = stringValue.split(GlobalConst.CLOB_SEPARATOR_IMAGE_COLS); + final String[] stringTable = stringValue.split(GlobalConst.CLOB_SEPARATOR_IMAGE_COLS); Object newTable = null; switch (dataType) { case TangoConst.Tango_DEV_BOOLEAN: { @@ -1371,9 +1294,9 @@ public class SnapAttributeExtract extends SnapAttribute { case AttrDataFormat._IMAGE: { final String[][] stringMatrix = new String[dimX][dimX]; - final String[] stringTable = stringValue.split(GlobalConst.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(GlobalConst.CLOB_SEPARATOR_IMAGE_COLS); + stringMatrix[i] = stringTable[i].split(GlobalConst.CLOB_SEPARATOR_IMAGE_COLS); } Object[] newMatrix = null; @@ -1502,11 +1425,13 @@ public class SnapAttributeExtract extends SnapAttribute { @Override public String toString() { - String snapStr = ""; + String snapStr = ObjectUtils.EMPTY_STRING; final String value = (writable == AttrWriteType._READ || writable == AttrWriteType._READ_WITH_WRITE - || writable == AttrWriteType._READ_WRITE ? "read value : " + valueToString(0) : "") + || writable == AttrWriteType._READ_WRITE ? "read value : " + valueToString(0) + : ObjectUtils.EMPTY_STRING) + (writable == AttrWriteType._WRITE || writable == AttrWriteType._READ_WITH_WRITE - || writable == AttrWriteType._READ_WRITE ? "\t " + "write value : " + valueToString(1) : ""); + || writable == AttrWriteType._READ_WRITE ? "\t " + "write value : " + valueToString(1) + : ObjectUtils.EMPTY_STRING); snapStr = "attribute ID : \t" + getAttId() + "\r\n" + "attribute Name : \t" + getAttributeCompleteName() + "\r\n" + "attribute value : \t" + value + "\r\n"; return snapStr; diff --git a/src/main/java/fr/soleil/archiving/snap/api/tools/SnapAttributeMedium.java b/src/main/java/fr/soleil/archiving/snap/api/tools/SnapAttributeMedium.java index 93f64c4de0d0891e26cfd5d55abb7f2bea82f6ef..b1cdd37534ea630a59da9119b54d1ffe15fef7f4 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/tools/SnapAttributeMedium.java +++ b/src/main/java/fr/soleil/archiving/snap/api/tools/SnapAttributeMedium.java @@ -33,100 +33,103 @@ package fr.soleil.archiving.snap.api.tools; import fr.soleil.archiving.common.api.tools.AttributeLight; +import fr.soleil.lib.project.ObjectUtils; +/** + * SnapAttributeMedium + * + * @author chinkumo + */ public class SnapAttributeMedium extends AttributeLight { - private int id_snap = -1; // Identifier for this snapshot - private java.sql.Timestamp snap_date = null; // Timestamp asociated to this - - // snapshot - - public SnapAttributeMedium(String attribute_complete_name, int data_type, - int data_format, int writable, int id_context, int id_snap, - java.sql.Timestamp snap_date) { - setAttributeCompleteName(attribute_complete_name); - setDataType(data_type); - setDataFormat(data_format); - setWritable(writable); - - this.id_snap = id_snap; - this.snap_date = snap_date; - } - - public SnapAttributeMedium(AttributeLight snapAttributeLight, - int id_context, int id_snap, java.sql.Timestamp snap_date) { - setAttributeCompleteName(snapAttributeLight - .getAttributeCompleteName()); - setAttributeId(snapAttributeLight.getAttributeId()); - setDataType(snapAttributeLight.getDataType()); - setDataFormat(snapAttributeLight.getDataFormat()); - setWritable(snapAttributeLight.getWritable()); - - this.id_snap = id_snap; - this.snap_date = snap_date; - } - - public int getId_snap() { - return id_snap; - } - - public void setId_snap(int id_snap) { - this.id_snap = id_snap; - } - - public java.sql.Timestamp getSnap_date() { - return snap_date; - } - - public void setSnap_date(java.sql.Timestamp snap_date) { - this.snap_date = snap_date; - } - - public boolean equals(Object o) { - if (this == o) - return true; - if (!(o instanceof SnapAttributeMedium)) - return false; - - final SnapAttributeMedium snapAttributeMedium = (SnapAttributeMedium) o; - - if (getDataFormat() != snapAttributeMedium.getDataFormat()) - return false; - if (getDataType() != snapAttributeMedium.getDataType()) - return false; - if (getAttributeId() != snapAttributeMedium.getAttributeId()) - return false; - if (id_snap != snapAttributeMedium.id_snap) - return false; - if (getWritable() != snapAttributeMedium.getWritable()) - return false; - if (!getAttributeCompleteName().equals( - snapAttributeMedium.getAttributeCompleteName())) - return false; - if (!snap_date.equals(snapAttributeMedium.snap_date)) - return false; - - return true; - } - - public int hashCode() { - int result; - result = getAttributeCompleteName().hashCode(); - result = 29 * result + getAttributeId(); - result = 29 * result + id_snap; - result = 29 * result + snap_date.hashCode(); - return result; - } - - public String toString() { - String snapString = new String(""); - snapString = "Attribut : " + getAttributeCompleteName() + "\r\n" - + "\t" + "Attribute Id : \t" + getAttributeId() + "\r\n" - + "\t" + "data_type : \t" + getDataType() + "\r\n" + "\t" - + "data_format : \t" + getDataFormat() + "\r\n" + "\t" - + "writable : \t" + getWritable() + "\r\n" + "\t" - + "Snapshot Id : \t" + id_snap + "\r\n" + "\t" - + "SnapShot time : \t" + snap_date.toString() + "\r\n"; - return snapString; - } + private int id_snap = -1; // Identifier for this snapshot + private java.sql.Timestamp snap_date = null; // Timestamp asociated to this + + // snapshot + + public SnapAttributeMedium(String attribute_complete_name, int data_type, int data_format, int writable, + int id_context, int id_snap, java.sql.Timestamp snap_date) { + setAttributeCompleteName(attribute_complete_name); + setDataType(data_type); + setDataFormat(data_format); + setWritable(writable); + + this.id_snap = id_snap; + this.snap_date = snap_date; + } + + public SnapAttributeMedium(AttributeLight snapAttributeLight, int id_context, int id_snap, + java.sql.Timestamp snap_date) { + setAttributeCompleteName(snapAttributeLight.getAttributeCompleteName()); + setAttributeId(snapAttributeLight.getAttributeId()); + setDataType(snapAttributeLight.getDataType()); + setDataFormat(snapAttributeLight.getDataFormat()); + setWritable(snapAttributeLight.getWritable()); + + this.id_snap = id_snap; + this.snap_date = snap_date; + } + + public int getId_snap() { + return id_snap; + } + + public void setId_snap(int id_snap) { + this.id_snap = id_snap; + } + + public java.sql.Timestamp getSnap_date() { + return snap_date; + } + + public void setSnap_date(java.sql.Timestamp snap_date) { + this.snap_date = snap_date; + } + + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (!(o instanceof SnapAttributeMedium)) + return false; + + final SnapAttributeMedium snapAttributeMedium = (SnapAttributeMedium) o; + + if (getDataFormat() != snapAttributeMedium.getDataFormat()) + return false; + if (getDataType() != snapAttributeMedium.getDataType()) + return false; + if (getAttributeId() != snapAttributeMedium.getAttributeId()) + return false; + if (id_snap != snapAttributeMedium.id_snap) + return false; + if (getWritable() != snapAttributeMedium.getWritable()) + return false; + if (!getAttributeCompleteName().equals(snapAttributeMedium.getAttributeCompleteName())) + return false; + if (!snap_date.equals(snapAttributeMedium.snap_date)) + return false; + + return true; + } + + @Override + public int hashCode() { + int result; + result = getAttributeCompleteName().hashCode(); + result = 29 * result + getAttributeId(); + result = 29 * result + id_snap; + result = 29 * result + snap_date.hashCode(); + return result; + } + + @Override + public String toString() { + String snapString = ObjectUtils.EMPTY_STRING; + snapString = "Attribut : " + getAttributeCompleteName() + "\r\n" + "\t" + "Attribute Id : \t" + getAttributeId() + + "\r\n" + "\t" + "data_type : \t" + getDataType() + "\r\n" + "\t" + "data_format : \t" + + getDataFormat() + "\r\n" + "\t" + "writable : \t" + getWritable() + "\r\n" + "\t" + "Snapshot Id : \t" + + id_snap + "\r\n" + "\t" + "SnapShot time : \t" + snap_date.toString() + "\r\n"; + return snapString; + } } diff --git a/src/main/java/fr/soleil/archiving/snap/api/tools/SnapContext.java b/src/main/java/fr/soleil/archiving/snap/api/tools/SnapContext.java index 2f4c88c6500c5853ad96f41f277eba1509a90916..cd3fec202437e94b9e02c65d78313216a7ce13be 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/tools/SnapContext.java +++ b/src/main/java/fr/soleil/archiving/snap/api/tools/SnapContext.java @@ -1,38 +1,7 @@ -// +====================================================================== -// $Source: /cvsroot/tango-cs/tango/api/java/fr/soleil/TangoSnapshoting/SnapshotingTools/Tools/SnapContext.java,v $ -// -// Project: Tango Archiving Service -// -// Description: Java source code for the class SnapContext. -// (Chinkumo Jean) - Jan 22, 2004 -// -// $Author: chinkumo $ -// -// $Revision: 1.2 $ -// -// $Log: SnapContext.java,v $ -// Revision 1.2 2005/11/29 17:11:17 chinkumo -// no message -// -// Revision 1.1.16.1 2005/11/15 13:34:38 chinkumo -// no message -// -// Revision 1.1 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.tools; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.List; @@ -68,7 +37,7 @@ public class SnapContext { private Date creation_date; private String reason = ObjectUtils.EMPTY_STRING; private String description = ObjectUtils.EMPTY_STRING; - private List<AttributeLight> attributeList = new ArrayList<AttributeLight>(); + private List<AttributeLight> attributeList = new ArrayList<AttributeLight>(); /** * Default constructor Creates a new instance of SnapAttributeHeavy @@ -83,15 +52,12 @@ public class SnapContext { /** * This constructor takes several parameters as inputs. * - * @param author_name - * the context <I>author's name</I> - * @param name - * the context <I>name</I> - * @param creation_date - * the context <I>creation date</I> + * @param author_name the context <I>author's name</I> + * @param name the context <I>name</I> + * @param creation_date the context <I>creation date</I> * @see #SnapContext() * @see #SnapContext(String author_name, String name, Date creation_date) - * @see #SnapContext(String[] argin) + * @see #SnapContext(String... argin) */ public SnapContext(final String author_name, final String name, final Date creation_date) { this.author_name = author_name; @@ -102,21 +68,15 @@ public class SnapContext { /** * This constructor takes several parameters as inputs. * - * @param author_name - * the context <I>author's name</I> - * @param name - * the context <I>name</I> - * @param id - * the context <I>identifier</I> - * @param creation_date - * the context <I>creation date</I> - * @param reason - * the context <I>reason</I> - * @param description - * the context <I>description</I> + * @param author_name the context <I>author's name</I> + * @param name the context <I>name</I> + * @param id the context <I>identifier</I> + * @param creation_date the context <I>creation date</I> + * @param reason the context <I>reason</I> + * @param description the context <I>description</I> * @see #SnapContext() * @see #SnapContext(String author_name, String name, java.sql.Date creation_date) - * @see #SnapContext(String[] argin) + * @see #SnapContext(String... argin) */ public SnapContext(final String author_name, final String name, final int id, final Date creation_date, final String reason, final String description) { @@ -131,29 +91,21 @@ public class SnapContext { /** * This constructor takes several parameters as inputs. * - * @param author_name - * the context <I>author's name</I> - * @param name - * the context <I>name</I> - * @param id - * the context <I>identifier</I> - * @param creation_date - * the context <I>creation date</I> - * @param reason - * the context <I>reason</I> - * @param description - * the context <I>description</I> - * @param attributeList - * the <I>list of attributes</I> that are included in the - * context. + * @param author_name the context <I>author's name</I> + * @param name the context <I>name</I> + * @param id the context <I>identifier</I> + * @param creation_date the context <I>creation date</I> + * @param reason the context <I>reason</I> + * @param description the context <I>description</I> + * @param attributeList the <I>list of attributes</I> that are included in the context. * @see #SnapContext() * @see #SnapContext(String author_name, String name, Date creation_date) * @see #SnapContext(String author_name, String name, int id, Date creation_date, String reason, String description, * ArrayList attributeList) - * @see #SnapContext(String[] argin) + * @see #SnapContext(String... argin) */ public SnapContext(final String author_name, final String name, final int id, final Date creation_date, - final String reason, final String description, final List<AttributeLight> attributeList) { + final String reason, final String description, final List<AttributeLight> attributeList) { this.author_name = author_name; this.name = name; this.id = id; @@ -166,21 +118,23 @@ public class SnapContext { /** * This constructor builds an SnapContext from an array * - * @param argin - * an array that contains the SnapContext's author's name, name, - * identifier, creation date, reason, description and, the - * <I>list of attributes</I> that are included in the context. + * @param argin an array that contains the SnapContext's author's name, name, identifier, creation date, reason, + * description and, the <I>list of attributes</I> that are included in the context. */ - public SnapContext(final String[] argin) { + public SnapContext(final String... argin) throws SnapshotingException { + if (argin.length < 6) { + throw new SnapshotingException("argin size must be at least 6: " + Arrays.toString(argin)); + } setAuthor_name(argin[0]); setName(argin[1]); setId(Integer.parseInt(argin[2])); setCreation_date(java.sql.Date.valueOf(argin[3])); setReason(argin[4]); setDescription(argin[5]); + // Attribute list construction for (int i = 6; i < argin.length; i++) { - attributeList.add(new AttributeLight(argin[i])); + attributeList.add(new AttributeLight(argin[i])); } } @@ -303,7 +257,7 @@ public class SnapContext { * * @return the <I>list of attributes</I> that are included in the context. */ - public List<AttributeLight> getAttributeList() { + public List<AttributeLight> getAttributeList() { return attributeList; } @@ -314,7 +268,7 @@ public class SnapContext { * the <I>list of attributes</I> that are included in the * context. */ - public void setAttributeList(final List<AttributeLight> attributeList) { + public void setAttributeList(final List<AttributeLight> attributeList) { this.attributeList = attributeList; } diff --git a/src/main/java/fr/soleil/archiving/snap/api/tools/SnapTool.java b/src/main/java/fr/soleil/archiving/snap/api/tools/SnapTool.java new file mode 100644 index 0000000000000000000000000000000000000000..f4efd852317ca779616c8e06da882eaa7923ad42 --- /dev/null +++ b/src/main/java/fr/soleil/archiving/snap/api/tools/SnapTool.java @@ -0,0 +1,376 @@ +package fr.soleil.archiving.snap.api.tools; + +import fr.esrf.Tango.ErrSeverity; +import fr.soleil.archiving.common.api.tools.Condition; +import fr.soleil.archiving.common.api.tools.Criterions; +import fr.soleil.lib.project.ObjectUtils; + +public class SnapTool { + + private SnapTool() { + // hide constructor + } + + /** + * Returns the SQL clause described by a Criterion in the case of a field of the ContextTable. + * + * @param criterions The Criterion + * @return SQL clause described by the Criterion in the case of a field of the ContextTable + * @throws SnapshotingException + */ + public static String getContextClause(Criterions criterions) throws SnapshotingException { + String clause = ObjectUtils.EMPTY_STRING; + if (criterions != null) { + String table = SnapConst.CONTEXT; + String[] field = SnapConst.TAB_CONTEXT; + int count = 0; + // Cas de l'ID_context. + Condition[] conditions = criterions.getConditions(field[0]); + if (conditions != null) { + // Une seule condition sur l'id_context. + if (conditions.length == 1) { + // Mise en forme du predicat de la requete SQL. + String predicat = getPredicatInt(conditions[0]); + + // Mise en forme de la requete SQL. + if (count == 0) { + clause = clause + " WHERE " + table + "." + field[0] + predicat; + count++; + } else { + clause = clause + " AND " + table + "." + field[0] + predicat; + } + } else { + String message = ObjectUtils.EMPTY_STRING; + message = SnapConst.ERROR_SQL_OPERATOR; + String reason = SnapConst.ERROR_SQL_OPERATOR; + String desc = "Failed while executing Criterions.getSnapshotClause() method..."; + throw new SnapshotingException(message, reason, ErrSeverity.WARN, desc, + criterions.getClass().getName()); + } + } + + // Pour les autres champs. + for (int i = 1; i < field.length; i++) { + // Parcours de tous les champs de la table des contextes, sauf l'ID_context. + conditions = criterions.getConditions(field[i]); + if (conditions != null) { + for (int j = 0; j < conditions.length; j++) { + // Mise en forme du predicat de la requete SQL. + String predicat = getPredicat(conditions[j]); + + // Mise en forme de la requete SQL. + if (count == 0) { + clause = clause + " WHERE " + table + "." + field[i] + predicat; + count++; + } else { + clause = clause + " AND " + table + "." + field[i] + predicat; + } + } + } + + } + } + return clause; + } + + /** + * Returns the SQL clause described by a Criterion in the case of a field of the SnapshotTable. + * + * @param criterions The Criterion + * @return SQL clause described by the Criterion in the case of a field of the SnashotTable + * @throws SnapshotingException + */ + public static String getSnapshotClause(Criterions criterions) throws SnapshotingException { + String clause = ObjectUtils.EMPTY_STRING; + if (criterions != null) { + String table = SnapConst.SNAPSHOT; + String[] field = SnapConst.TAB_SNAP; + int count = 0; + // Cas de l'id_snap. + Condition[] conditions = criterions.getConditions(field[0]); + if (conditions != null) { + if (conditions.length == 1) { + // Mise en forme du predicat de la requete SQL. + String predicat = getPredicatInt(conditions[0]); + + // Mise en forme de la requete SQL. + if (count == 0) { + clause = clause + " WHERE " + table + "." + field[0] + predicat; + count++; + } else { + clause = clause + " AND " + table + "." + field[0] + predicat; + } + } else { + String message = ObjectUtils.EMPTY_STRING; + message = SnapConst.ERROR_SQL_OPERATOR; + String reason = SnapConst.ERROR_SQL_OPERATOR; + String desc = "Failed while executing Criterions.getSnapshotClause() method..."; + throw new SnapshotingException(message, reason, ErrSeverity.WARN, desc, + criterions.getClass().getName()); + } + + } + // Cas de l'ID_context. + conditions = criterions.getConditions(field[1]); + if (conditions != null) { + // Une seule condition sur l'id_context. + if (conditions.length == 1) { + // Mise en forme du predicat de la requete SQL. + String predicat = getPredicatInt(conditions[0]); + + // Mise en forme de la requete SQL. + if (count == 0) { + clause = clause + " WHERE " + table + "." + field[1] + predicat; + count++; + } else { + clause = clause + " AND " + table + "." + field[1] + predicat; + } + } else { + String message = ObjectUtils.EMPTY_STRING; + message = SnapConst.ERROR_SQL_OPERATOR; + String reason = SnapConst.ERROR_SQL_OPERATOR; + String desc = "Failed while executing Criterions.getSnapshotClause() method..."; + throw new SnapshotingException(message, reason, ErrSeverity.WARN, desc, + criterions.getClass().getName()); + } + + } + + for (int i = 2; i < field.length; i++) { + // Parcours de tous les champs de la table des contextes. + conditions = criterions.getConditions(field[i]); + if (conditions != null) { + for (int j = 0; j < conditions.length; j++) { + // Mise en forme du predicat de la requete SQL. + String predicat = getPredicat(conditions[j]); + // Mise en forme de la requete SQL. + if (count == 0) { + clause = clause + " WHERE " + table + "." + field[i] + predicat; + count++; + } else { + clause = clause + " AND " + table + "." + field[i] + predicat; + } + } + } + } + } + return clause; + } + + /** + * Returns the id of a context of the SnapTable. + * + * @param criterions The Criterion to recover the context + * @return id of a context of the SnapTable + * @throws SnapshotingException + */ + public static int getIdContextSnapTable(Criterions criterions) throws SnapshotingException { + int id_context = -1; // value if no condition on this id. + if (criterions != null) { + Condition[] id_condition = criterions.getConditions(SnapConst.TAB_SNAP[1]); + if (id_condition != null) { + id_context = Integer.parseInt(id_condition[0].getValue()); + } + } + return id_context; + } + + /** + * Returns the id of a context. + * + * @param criterions The Criterion to recover the context + * @return the id of a context + * @throws SnapshotingException + */ + public static int getIdContextContextTable(Criterions criterions) throws SnapshotingException { + int id_context = -1; // value if no condition on this id. + if (criterions != null) { + Condition[] id_condition = criterions.getConditions(SnapConst.ID_CONTEXT); + if (id_condition != null) { + id_context = Integer.parseInt(id_condition[0].getValue()); + } + } + return id_context; + } + + /** + * Returns the id of a snapshot. + * + * @param criterions The Criterion to recover the snapshot + * @return the id of a snapshot + * @throws SnapshotingException + */ + public static int getIdSnap(Criterions criterions) throws SnapshotingException { + int id_snap = -1; // value if no condition on this id. + if (criterions != null) { + Condition[] id_condition = criterions.getConditions(SnapConst.ID_SNAP); + if (id_condition != null) { + id_snap = Integer.parseInt(id_condition[0].getValue()); + } + } + return id_snap; + } + + /** + * Returns the SQL clause described by a Criterion in the case of a field of the AttribteTable. + * + * @param criterions The Criterion + * @return SQL clause described by the Criterion in the case of a field of the AttributeTable + * @throws SnapshotingException + */ + public static String getAttributeClause(Criterions criterions) throws SnapshotingException { + String clause = ObjectUtils.EMPTY_STRING; + if (criterions != null) { + 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 definitions. + Condition[] conditions = criterions.getConditions(field[i]); + if (conditions != null) { + for (int j = 0; j < conditions.length; j++) { + // Mise en forme du predicat de la requete SQL. + String predicat = getPredicatFullName(conditions[j]); + // Mise en forme de la requete SQL. + if (!predicat.isEmpty()) { + if (count == 0) { + clause = clause + " WHERE " + table + "." + field[i] + predicat; + count++; + } else { + clause = clause + " AND " + table + "." + field[i] + predicat; + } + } + } + } + } + } + return clause; + } + + private static String getNotNullString(String value) { + return value == null ? ObjectUtils.EMPTY_STRING : value; + } + + /** + * Returns the predicat of the SQL request for a condition. + * + * @param condition The condition + * @return Predicat of the SQL request for the condition + * @throws SnapshotingException + */ + public static String getPredicat(Condition condition) throws SnapshotingException { + String predicat = ObjectUtils.EMPTY_STRING; + if (condition != null) { + // Casts the Condition's operator and value in a SQL predicat. + String operator = getNotNullString(condition.getOperator()); + switch (operator) { + case SnapConst.OP_EQUALS: + predicat = " = '" + condition.getValue() + "'"; + break; + case SnapConst.OP_LOWER_THAN_STRICT: + predicat = " < '" + condition.getValue() + "'"; + break; + case SnapConst.OP_LOWER_THAN: + predicat = " <= '" + condition.getValue() + "'"; + break; + case SnapConst.OP_GREATER_THAN_STRICT: + predicat = " > '" + condition.getValue() + "'"; + break; + case SnapConst.OP_GREATER_THAN: + predicat = " >= '" + condition.getValue() + "'"; + break; + case SnapConst.OP_CONTAINS: + predicat = " LIKE '%" + condition.getValue() + "%'"; + break; + case SnapConst.OP_STARTS_WITH: + predicat = " LIKE '" + condition.getValue() + "%'"; + break; + case SnapConst.OP_ENDS_WITH: + predicat = " LIKE '%" + condition.getValue() + "'"; + break; + default: + String message = ObjectUtils.EMPTY_STRING; + message = SnapConst.ERROR_SQL_OPERATOR; + String reason = SnapConst.ERROR_SQL_OPERATOR; + String desc = "Failed while executing DataBaseApi.getPredicat() method..."; + throw new SnapshotingException(message, reason, ErrSeverity.WARN, desc, + condition.getClass().getName()); + } + } + return predicat; + } + + /** + * Returns the predicat of the SQL request for a condition in the case of an integer value. + * + * @param condition The condition + * @return Predicat of the SQL request for the condition in the case of an integer value + * @throws SnapshotingException + */ + public static String getPredicatInt(Condition condition) throws SnapshotingException { + String predicat = ObjectUtils.EMPTY_STRING; + if (condition != null) { + // Casts the Condition's operator and value in a SQL predicat. + String operator = getNotNullString(condition.getOperator()); + switch (operator) { + case SnapConst.OP_EQUALS: + predicat = " = ?"; + break; + case SnapConst.OP_LOWER_THAN_STRICT: + predicat = " < ?"; + break; + case SnapConst.OP_LOWER_THAN: + predicat = " <= ?"; + break; + case SnapConst.OP_GREATER_THAN_STRICT: + predicat = " > ?"; + break; + case SnapConst.OP_GREATER_THAN: + predicat = " >= ?"; + break; + default: + String message = ObjectUtils.EMPTY_STRING; + message = SnapConst.ERROR_SQL_OPERATOR; + String reason = SnapConst.ERROR_SQL_OPERATOR; + String desc = "Failed while executing DataBaseApi.getPredicatInt() method..."; + throw new SnapshotingException(message, reason, ErrSeverity.WARN, desc, + condition.getClass().getName()); + } + } + return predicat; + } + + /** + * Returns the predicat of the SQL request for a condition in the case of the full name of an attribute. + * + * @param condition The condition + * @return Predicat of the SQL request for the condition in the case of the full name of an attribute + * @throws SnapshotingException + */ + public static String getPredicatFullName(Condition condition) throws SnapshotingException { + String predicat = ObjectUtils.EMPTY_STRING; + if (condition != null) { + // Casts the Condition's operator and value in a SQL predicat. + String value = getNotNullString(condition.getValue()); + if (value.equals("*")) { + predicat = ObjectUtils.EMPTY_STRING; + } else if (value.startsWith("*") && value.endsWith("*")) { + predicat = " LIKE '%" + value.substring(1, value.length() - 1) + "%'"; + } else if (value.endsWith("*")) { + predicat = " LIKE '" + value.substring(0, value.length() - 1) + "%'"; + } else if (value.startsWith("*")) { + predicat = " LIKE '%" + value.substring(1) + "'"; + } else if (!value.isEmpty()) { + predicat = " = '" + value + "'"; + } else { + String message = ObjectUtils.EMPTY_STRING; + message = SnapConst.ERROR_SQL_OPERATOR; + String reason = SnapConst.ERROR_SQL_OPERATOR; + String desc = "Failed while executing DataBaseApi.getPredicatFullName() method..."; + throw new SnapshotingException(message, reason, ErrSeverity.WARN, desc, condition.getClass().getName()); + } + } + return predicat; + } + +} diff --git a/src/main/java/fr/soleil/archiving/snap/api/tools/Snapshot.java b/src/main/java/fr/soleil/archiving/snap/api/tools/Snapshot.java index eaa60ae404d551c478b2462c9c56a3008e859c37..b533e32a50f2934bbedd3a054a50d5d9c271dbef 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/tools/Snapshot.java +++ b/src/main/java/fr/soleil/archiving/snap/api/tools/Snapshot.java @@ -1,55 +1,3 @@ -//+====================================================================== -// $Source: /cvsroot/tango-cs/tango/api/java/fr/soleil/TangoSnapshoting/SnapshotingTools/Tools/SnapShot.java,v $ -// -// Project: Tango Archiving Service -// -// Description: Java source code for the class SnapShot. -// (Chinkumo Jean) - Mar 22, 2004 -// -// $Author: pierrejoseph $ -// -// $Revision: 1.7 $ -// -// $Log: SnapShot.java,v $ -// Revision 1.7 2007/11/23 09:22:16 pierrejoseph -// removes the connexion toward others packages -// -// Revision 1.6 2007/11/16 10:15:26 soleilarc -// Author: XPigeon -// Mantis bug ID: 5341 -// Comment : Add a new method named getPartialSnapShot. -// -// Revision 1.5 2006/02/17 09:26:46 chinkumo -// Minor change : code reformated. -// -// Revision 1.4 2006/02/15 09:07:47 ounsy -// minor changes : uncomment to debug -// -// 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:04:02 chinkumo -// no message -// -// Revision 1.1.14.1 2005/08/11 08:32:13 chinkumo -// Changes was made since the 'SetEquipement' functionnality was added. -// -// Revision 1.1 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.tools; import java.util.ArrayList; @@ -58,6 +6,7 @@ import java.util.List; import fr.esrf.Tango.AttrWriteType; import fr.esrf.Tango.DevFailed; import fr.esrf.Tango.ErrSeverity; +import fr.soleil.lib.project.ObjectUtils; /** * <p/> @@ -179,74 +128,74 @@ public class Snapshot { try { switch (option) { - case 1: - String storedValueType = argin[1]; - - if (SnapConst.STORED_READ_VALUE.equals(storedValueType)) { - for (int i = 0; i < snapAttributeExtractArray.length; i++) { - if (snapAttributeExtractArray[i].getWritable() != AttrWriteType._WRITE - && snapAttributeExtractArray[i].getWritable() != AttrWriteType._READ) { - snapAttributeExtractArray[i].setWriteValue(snapAttributeExtractArray[i].getReadValue(), - snapAttributeExtractArray[i].getNullElementsRead()); + case 1: + String storedValueType = argin[1]; + + if (SnapConst.STORED_READ_VALUE.equals(storedValueType)) { + for (int i = 0; i < snapAttributeExtractArray.length; i++) { + if (snapAttributeExtractArray[i].getWritable() != AttrWriteType._WRITE + && snapAttributeExtractArray[i].getWritable() != AttrWriteType._READ) { + snapAttributeExtractArray[i].setWriteValue(snapAttributeExtractArray[i].getReadValue(), + snapAttributeExtractArray[i].getNullElementsRead()); + } + snapShot.attribute_List.add(snapAttributeExtractArray[i]); + } - snapShot.attribute_List.add(snapAttributeExtractArray[i]); + } else if (SnapConst.STORED_WRITE_VALUE.equals(storedValueType)) { + for (int i = 0; i < snapAttributeExtractArray.length; i++) { + if (snapAttributeExtractArray[i].getWritable() != AttrWriteType._READ) { + snapShot.attribute_List.add(snapAttributeExtractArray[i]); + } + } } + break; - } else if (SnapConst.STORED_WRITE_VALUE.equals(storedValueType)) { - for (int i = 0; i < snapAttributeExtractArray.length; i++) { - if (snapAttributeExtractArray[i].getWritable() != AttrWriteType._READ) { - snapShot.attribute_List.add(snapAttributeExtractArray[i]); - } + case 2: + if (argin.length <= 2) { + throw snapExcept; } - } - break; - - case 2: - if (argin.length <= 2) { - throw snapExcept; - } - // int attributesNumberToSet = Integer.parseInt(argin[1]); - int attributesNumber = 0, - arginI = 2; - - do { - for (int snapAttrI = 0; snapAttrI < snapAttributeExtractArray.length - && attributesNumber < attributesNumberToSet && arginI < argin.length; snapAttrI++) { - - if (snapAttributeExtractArray[snapAttrI].getAttributeCompleteName().equals(argin[arginI + 1])) { - if (snapAttributeExtractArray[snapAttrI].getWritable() != AttrWriteType._READ) { - Object newValue = null; - Object nullElements = null; + // int attributesNumberToSet = Integer.parseInt(argin[1]); + int attributesNumber = 0, arginI = 2; + + do { + for (int snapAttrI = 0; snapAttrI < snapAttributeExtractArray.length + && attributesNumber < attributesNumberToSet && arginI < argin.length; snapAttrI++) { + + if (snapAttributeExtractArray[snapAttrI].getAttributeCompleteName() + .equals(argin[arginI + 1])) { + if (snapAttributeExtractArray[snapAttrI].getWritable() != AttrWriteType._READ) { + Object newValue = null; + Object nullElements = null; + + if (SnapConst.NEW_VALUE.equals(argin[arginI])) { + newValue = snapAttributeExtractArray[snapAttrI].getNewValue(argin[arginI + 2]); + } else if (SnapConst.STORED_READ_VALUE.equals(argin[arginI])) { + newValue = snapAttributeExtractArray[snapAttrI].getReadValue(); + nullElements = snapAttributeExtractArray[snapAttrI].getNullElementsRead(); + } else if (SnapConst.STORED_WRITE_VALUE.equals(argin[arginI])) { + newValue = snapAttributeExtractArray[snapAttrI].getWriteValue(); + nullElements = snapAttributeExtractArray[snapAttrI].getNullElementsWrite(); + } + + snapAttributeExtractArray[snapAttrI].setWriteValue(newValue, nullElements); + snapShot.attribute_List.add(snapAttributeExtractArray[snapAttrI]); + } + attributesNumber++; if (SnapConst.NEW_VALUE.equals(argin[arginI])) { - newValue = snapAttributeExtractArray[snapAttrI].getNewValue(argin[arginI + 2]); - } else if (SnapConst.STORED_READ_VALUE.equals(argin[arginI])) { - newValue = snapAttributeExtractArray[snapAttrI].getReadValue(); - nullElements = snapAttributeExtractArray[snapAttrI].getNullElementsRead(); - } else if (SnapConst.STORED_WRITE_VALUE.equals(argin[arginI])) { - newValue = snapAttributeExtractArray[snapAttrI].getWriteValue(); - nullElements = snapAttributeExtractArray[snapAttrI].getNullElementsWrite(); + arginI += 3; + } else { + arginI += 2; } - - snapAttributeExtractArray[snapAttrI].setWriteValue(newValue, nullElements); - snapShot.attribute_List.add(snapAttributeExtractArray[snapAttrI]); } - attributesNumber++; - if (SnapConst.NEW_VALUE.equals(argin[arginI])) { - arginI += 3; - } else { - arginI += 2; - } } + } while (attributesNumber < attributesNumberToSet && arginI < argin.length); + break; - } - } while (attributesNumber < attributesNumberToSet && arginI < argin.length); - break; - - default: - break; + default: + break; } } catch (SnapshotingException e) { @@ -390,7 +339,7 @@ public class Snapshot { @Override public String toString() { - String snapString = new String(""); + String snapString = ObjectUtils.EMPTY_STRING; snapString = "SnapShot" + "\r\n" + "Associated Context Id : \t" + id_context + "\r\n" + "Snapshot Id : \t" + id_snap + "\r\n" + "SnapShot time : \t" + snap_date.toString() + "\r\n" + "Attribute(s) : " + "\r\n"; if (attribute_List != null) { diff --git a/src/main/java/fr/soleil/archiving/snap/api/tools/SnapshotLight.java b/src/main/java/fr/soleil/archiving/snap/api/tools/SnapshotLight.java index f2cbbc42b1dea29980735a4aea7976e22ea6927b..be961682df6079ed187cb8804379582c20952d5e 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/tools/SnapshotLight.java +++ b/src/main/java/fr/soleil/archiving/snap/api/tools/SnapshotLight.java @@ -1,95 +1,70 @@ -//+====================================================================== -// $Source: /cvsroot/tango-cs/tango/api/java/fr/soleil/TangoSnapshoting/SnapshotingTools/Tools/SnapShotLight.java,v $ -// -// Project: Tango Archiving Service -// -// Description: Java source code for the class SnapShotLight. -// (Chinkumo Jean) - Nov 11, 2004 -// -// $Author: chinkumo $ -// -// $Revision: 1.2 $ -// -// $Log: SnapShotLight.java,v $ -// Revision 1.2 2005/11/29 17:11:17 chinkumo -// no message -// -// Revision 1.1.16.1 2005/11/15 13:34:38 chinkumo -// no message -// -// Revision 1.1 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.tools; +import fr.soleil.lib.project.ObjectUtils; + +/** + * SnapshotLight + * + * @author chinkumo + */ public class SnapshotLight { - private int id_snap = -1; // Identifier for this snapshot - private java.sql.Timestamp snap_date = null; // Timestamp asociated to this - // snapshot - private String comment = ""; + private int id_snap = -1; // Identifier for this snapshot + private java.sql.Timestamp snap_date = null; // Timestamp asociated to this + // snapshot + private String comment = ObjectUtils.EMPTY_STRING; - public SnapshotLight() { - } + public SnapshotLight() { + } - public SnapshotLight(int id_snap, java.sql.Timestamp snap_date, - String comment) { - this.id_snap = id_snap; - this.snap_date = snap_date; - this.comment = comment; - } + public SnapshotLight(int id_snap, java.sql.Timestamp snap_date, String comment) { + this.id_snap = id_snap; + this.snap_date = snap_date; + this.comment = comment; + } - public SnapshotLight(String[] argin) { - setId_snap(Integer.parseInt(argin[0])); - setSnap_date(java.sql.Timestamp.valueOf(argin[1])); - setComment(argin[2]); - } + public SnapshotLight(String[] argin) { + setId_snap(Integer.parseInt(argin[0])); + setSnap_date(java.sql.Timestamp.valueOf(argin[1])); + setComment(argin[2]); + } - public java.sql.Timestamp getSnap_date() { - return snap_date; - } + public java.sql.Timestamp getSnap_date() { + return snap_date; + } - public void setSnap_date(java.sql.Timestamp snap_date) { - this.snap_date = snap_date; - } + public void setSnap_date(java.sql.Timestamp snap_date) { + this.snap_date = snap_date; + } - public int getId_snap() { - return id_snap; - } + public int getId_snap() { + return id_snap; + } - public void setId_snap(int id_snap) { - this.id_snap = id_snap; - } + public void setId_snap(int id_snap) { + this.id_snap = id_snap; + } - public String getComment() { - return comment; - } + public String getComment() { + return comment; + } - public void setComment(String comment) { - this.comment = comment; - } + public void setComment(String comment) { + this.comment = comment; + } - public String[] toArray() { - String[] snapShot; - snapShot = new String[2]; - snapShot[0] = Integer.toString(id_snap); - snapShot[1] = snap_date.toString(); - snapShot[2] = comment; - return snapShot; - } + public String[] toArray() { + String[] snapShot; + snapShot = new String[2]; + snapShot[0] = Integer.toString(id_snap); + snapShot[1] = snap_date.toString(); + snapShot[2] = comment; + return snapShot; + } - public String toString() { - String snapL = "Identifier : " + id_snap + "\r\n" + "Record time : " - + snap_date + "\r\n" + "Comment : " + comment; - return snapL; - } + @Override + public String toString() { + String snapL = "Identifier : " + id_snap + "\r\n" + "Record time : " + snap_date + "\r\n" + "Comment : " + + comment; + return snapL; + } } diff --git a/src/main/java/fr/soleil/archiving/snap/api/tools/SnapshotingException.java b/src/main/java/fr/soleil/archiving/snap/api/tools/SnapshotingException.java index 8f119f55f05f4da19600579eb7b0a853a559a50c..740ec2ad6b511aa3e47c173f9eea20adea72f127 100644 --- a/src/main/java/fr/soleil/archiving/snap/api/tools/SnapshotingException.java +++ b/src/main/java/fr/soleil/archiving/snap/api/tools/SnapshotingException.java @@ -3,50 +3,13 @@ package fr.soleil.archiving.snap.api.tools; import fr.esrf.Tango.DevError; import fr.esrf.Tango.DevFailed; import fr.esrf.Tango.ErrSeverity; +import fr.soleil.lib.project.ObjectUtils; -//+====================================================================== -// $Source: /cvsroot/tango-cs/tango/api/java/fr/soleil/TangoSnapshoting/SnapshotingTools/Tools/SnapshotingException.java,v $ -// -// Project: Tango Archiving Service -// -// Description: Java source code for the class SnapshotingException. -// (chinkumo) - 24 juin 2005 -// -// $Author: soleilarc $ -// -// $Revision: 1.5 $ -// -// $Log: SnapshotingException.java,v $ -// Revision 1.5 2007/10/15 13:35:13 soleilarc -// Author: XP -// Mantis bug: 6695 -// Comment: Add a new SnapshotingException builder : public SnapshotingException(DevFailed devFailed). For the builder SnapshotingException(String message, String reason, ErrSeverity archSeverity, String desc, String origin, Exception e), put another skeleton : if () {...} else if () {...} else if () {...}. -// -// Revision 1.4 2007/10/03 16:07:18 soleilarc -// Author: XP -// Mantis bug ID: 6594 -// Comment: SnapshotingException has been completed to be able to recognize a timeout. -// -// Revision 1.3 2006/05/17 10:13:28 ounsy -// corrected a bug -// -// Revision 1.2 2005/11/29 17:11:17 chinkumo -// no message -// -// Revision 1.1.10.1 2005/11/15 13:34:38 chinkumo -// no message -// -// Revision 1.1 2005/06/28 07:41:13 chinkumo -// The SnapshotingException object defines exceptions for the Snapshoting Service. -// -// -// copyleft : Synchrotron SOLEIL -// L'Orme des Merisiers -// Saint-Aubin - BP 48 -// 91192 GIF-sur-YVETTE CEDEX -// -//-====================================================================== - +/** + * {@link Exception} concerning snapshots + * + * @author chinkumo + */ public class SnapshotingException extends Exception { private static final long serialVersionUID = 836877985535834610L; @@ -59,7 +22,7 @@ public class SnapshotingException extends Exception { public SnapshotingException() { super(); - archExcepMessage = ""; + archExcepMessage = ObjectUtils.EMPTY_STRING; devErrorTab = null; isDueToATimeOut = false; } @@ -87,10 +50,10 @@ public class SnapshotingException extends Exception { public SnapshotingException(String message, String reason, ErrSeverity archSeverity, String desc, String origin) { super(message); archExcepMessage = message; - String _reason = reason == null || reason.equals("") ? "Unknown reason" : reason; + String _reason = reason == null || reason.isEmpty() ? "Unknown reason" : reason; ErrSeverity _archSeverity = archSeverity == null ? ErrSeverity.WARN : archSeverity; - String _desc = desc == null || desc.equals("") ? "Unknown exception" : desc; - String _origin = origin == null || origin.equals("") ? "Unknown origin" : origin; + String _desc = desc == null || desc.isEmpty() ? "Unknown exception" : desc; + String _origin = origin == null || origin.isEmpty() ? "Unknown origin" : origin; DevError devError = new DevError(_reason, _archSeverity, _desc, _origin); devErrorTab = new DevError[1]; devErrorTab[0] = devError; @@ -98,7 +61,7 @@ public class SnapshotingException extends Exception { public SnapshotingException(DevFailed devFailed) { super(devFailed); - archExcepMessage = ""; + archExcepMessage = ObjectUtils.EMPTY_STRING; // The current stack is initialized DevError[] errors = devFailed.errors; @@ -130,10 +93,10 @@ public class SnapshotingException extends Exception { System.arraycopy(errors, 0, devErrorTab, 0, l); } // A new DevError object is built with the given parameters - String _reason = reason == null || reason.equals("") ? "Unknown reason" : reason; + String _reason = reason == null || reason.isEmpty() ? "Unknown reason" : reason; ErrSeverity _archSeverity = archSeverity == null ? ErrSeverity.WARN : archSeverity; - String _desc = desc == null || desc.equals("") ? "DevFailed EXCEPTION" : desc; - String _origin = origin == null || origin.equals("") ? e.getClass().getName() : origin; + String _desc = desc == null || desc.isEmpty() ? "DevFailed EXCEPTION" : desc; + String _origin = origin == null || origin.isEmpty() ? e.getClass().getName() : origin; DevError devError = new DevError(_reason, _archSeverity, _desc, _origin); // The DevError object is added at the end of the stack devErrorTab[devErrorTab.length - 1] = devError; @@ -144,13 +107,13 @@ public class SnapshotingException extends Exception { System.arraycopy(((SnapshotingException) e).devErrorTab, 0, devErrorTab, 0, ((SnapshotingException) e).devErrorTab.length); // A new DevError object is built with the given parameters - String _reason = reason == null || reason.equals("") ? "Unknown reason" : reason; + String _reason = reason == null || reason.isEmpty() ? "Unknown reason" : reason; if (query != null) { _reason += "\t\tQuery in charge : " + query; } ErrSeverity _archSeverity = archSeverity == null ? ErrSeverity.WARN : archSeverity; - String _desc = desc == null || desc.equals("") ? "Unknown exception" : desc; - String _origin = origin == null || origin.equals("") ? e.getClass().getName() : origin; + String _desc = desc == null || desc.isEmpty() ? "Unknown exception" : desc; + String _origin = origin == null || origin.isEmpty() ? e.getClass().getName() : origin; DevError devError = new DevError(_reason, _archSeverity, _desc, _origin); // The DevError object is added at the end of the stack @@ -170,10 +133,10 @@ public class SnapshotingException extends Exception { DevError devError_original = new DevError(reason_original, archSeverity_original, desc_original, origin_original); // A new DevError object is built with the given parameters - String _reason = reason == null || reason.equals("") ? "Unknown reason" : reason; + String _reason = reason == null || reason.isEmpty() ? "Unknown reason" : reason; ErrSeverity _archSeverity = archSeverity == null ? ErrSeverity.WARN : archSeverity; - String _desc = desc == null || desc.equals("") ? "Unknown exception" : desc; - String _origin = origin == null || origin.equals("") ? e.getClass().getName() : origin; + String _desc = desc == null || desc.isEmpty() ? "Unknown exception" : desc; + String _origin = origin == null || origin.isEmpty() ? e.getClass().getName() : origin; DevError devError = new DevError(_reason, _archSeverity, _desc, _origin); // The DevError objects are added at the end of the stack @@ -186,10 +149,10 @@ public class SnapshotingException extends Exception { SnapshotingException e) { archExcepMessage = message; // new SnapshotingException - String _reason = reason == null || reason.equals("") ? "Unknown reason" : reason; + String _reason = reason == null || reason.isEmpty() ? "Unknown reason" : reason; ErrSeverity _archSeverity = archSeverity == null ? ErrSeverity.WARN : archSeverity; - String _desc = desc == null || desc.equals("") ? "Unknown exception" : desc; - String _origin = origin == null || origin.equals("") ? e.getClass().getName() : origin; + String _desc = desc == null || desc.isEmpty() ? "Unknown exception" : desc; + String _origin = origin == null || origin.isEmpty() ? e.getClass().getName() : origin; DevError _devError = new DevError(_reason, _archSeverity, _desc, _origin); // The current stack is cloned DevError[] devErrorTabClone = devErrorTab; diff --git a/src/test/java/fr/soleil/archiving/snap/api/DataBaseAPITest.java b/src/test/java/fr/soleil/archiving/snap/api/DataBaseAPITest.java index 3c02dead183ddcfdbf42ddb153b9d1f661425c98..69df01e8afe18c48fc37dae00e5ef535360fe0da 100644 --- a/src/test/java/fr/soleil/archiving/snap/api/DataBaseAPITest.java +++ b/src/test/java/fr/soleil/archiving/snap/api/DataBaseAPITest.java @@ -10,145 +10,144 @@ import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.List; -import fr.soleil.archiving.common.api.exception.ArchivingException; -import fr.soleil.database.connection.DataBaseParameters; 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.common.api.exception.ArchivingException; 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; +import fr.soleil.database.connection.DataBaseParameters; +import fr.soleil.lib.project.ObjectUtils; public class DataBaseAPITest extends AbstractTest { - DataBaseAPI dbApi; - - @Before - public void initDataBaseAPI() throws ArchivingException { - DataBaseParameters parameters = new DataBaseParameters(); - parameters.setHost(""); - parameters.setName("public"); - parameters.setSchema("public"); - parameters.setUser("snap"); - parameters.setPassword("snap"); - dbApi = new DataBaseAPI(parameters); - } - - @Test - public void getAttIDTest() throws SnapshotingException { - assertFalse(dbApi.isRegistered("")); - assertTrue(dbApi.isRegistered("tango/tangotest/1/short_scalar_ro")); - int id = dbApi.getAttID("tango/tangotest/1/short_scalar_ro"); - assertEquals(245, id); - } - - @Test - public void getMaxContextIDTest() throws SnapshotingException { - assertTrue(dbApi.getMaxContextID() > 0); - } - - - @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, -1); - assertFalse(result.isEmpty()); - assertEquals(31, result.size()); - - result = dbApi.getContextAssociatedSnapshots(" WHERE ID_CONTEXT=? ", 76, -1); - assertFalse(result.isEmpty()); - assertEquals(28, 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()); - } - + DataBaseAPI dbApi; + + @Before + public void initDataBaseAPI() throws ArchivingException { + DataBaseParameters parameters = new DataBaseParameters(); + parameters.setHost(ObjectUtils.EMPTY_STRING); + parameters.setName("public"); + parameters.setSchema("public"); + parameters.setUser("snap"); + parameters.setPassword("snap"); + dbApi = new DataBaseAPI(parameters); + } + + @Test + public void getAttIDTest() throws SnapshotingException { + assertFalse(dbApi.isRegistered(ObjectUtils.EMPTY_STRING)); + assertTrue(dbApi.isRegistered("tango/tangotest/1/short_scalar_ro")); + int id = dbApi.getAttID("tango/tangotest/1/short_scalar_ro"); + assertEquals(245, id); + } + + @Test + public void getMaxContextIDTest() throws SnapshotingException { + assertTrue(dbApi.getMaxContextID() > 0); + } + + @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(ObjectUtils.EMPTY_STRING, -1); + assertNotNull(result); + assertFalse(result.isEmpty()); + assertEquals(6, result.size()); + } + + @Test + public void getContextAssociatedSnapshotsTest() throws SnapshotingException { + List<SnapshotLight> result = dbApi.getContextAssociatedSnapshots(ObjectUtils.EMPTY_STRING, -1, -1); + assertFalse(result.isEmpty()); + assertEquals(31, result.size()); + + result = dbApi.getContextAssociatedSnapshots(" WHERE ID_CONTEXT=? ", 76, -1); + assertFalse(result.isEmpty()); + assertEquals(28, 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()); + } } diff --git a/src/test/java/fr/soleil/archiving/snap/api/tools/SnapAttributesExtractTest.java b/src/test/java/fr/soleil/archiving/snap/api/tools/SnapAttributesExtractTest.java index d567dd3a9af38b8a8da29526a989cbe3ee652321..f8fea126ccea0e57309806ed1d557fa356f710e4 100644 --- a/src/test/java/fr/soleil/archiving/snap/api/tools/SnapAttributesExtractTest.java +++ b/src/test/java/fr/soleil/archiving/snap/api/tools/SnapAttributesExtractTest.java @@ -7,66 +7,68 @@ import org.junit.Test; import fr.esrf.Tango.AttrDataFormat; import fr.esrf.Tango.AttrWriteType; import fr.esrf.TangoDs.TangoConst; +import fr.soleil.lib.project.ObjectUtils; public class SnapAttributesExtractTest { - @Test - public void ScalareToStingTest() { - - testReadWrite(99, AttrDataFormat._SCALAR, "0.0", "1.0", "NULL"); - testReadWrite(TangoConst.Tango_DEV_STRING,AttrDataFormat._SCALAR, "read", "write", "NULL"); - testReadWrite(TangoConst.Tango_DEV_STATE, AttrDataFormat._SCALAR, "0", "1", "NULL"); - testReadWrite(TangoConst.Tango_DEV_UCHAR, AttrDataFormat._SCALAR, "0", "1", "NULL"); - testReadWrite(TangoConst.Tango_DEV_LONG, AttrDataFormat._SCALAR, "0", "1", "NULL"); - testReadWrite(TangoConst.Tango_DEV_ULONG, AttrDataFormat._SCALAR, "0", "1", "NULL"); - testReadWrite(TangoConst.Tango_DEV_BOOLEAN, AttrDataFormat._SCALAR, "true", "false", "NULL"); - testReadWrite(TangoConst.Tango_DEV_SHORT, AttrDataFormat._SCALAR, "0", "1", "NULL"); - testReadWrite(TangoConst.Tango_DEV_FLOAT, AttrDataFormat._SCALAR, "0.0", "1.0", "NULL"); - testReadWrite(TangoConst.Tango_DEV_DOUBLE, AttrDataFormat._SCALAR, "0.0", "1.0", "NULL"); + @Test + public void ScalareToStingTest() { - } + testReadWrite(99, AttrDataFormat._SCALAR, "0.0", "1.0", "NULL"); + testReadWrite(TangoConst.Tango_DEV_STRING, AttrDataFormat._SCALAR, "read", "write", "NULL"); + testReadWrite(TangoConst.Tango_DEV_STATE, AttrDataFormat._SCALAR, "0", "1", "NULL"); + testReadWrite(TangoConst.Tango_DEV_UCHAR, AttrDataFormat._SCALAR, "0", "1", "NULL"); + testReadWrite(TangoConst.Tango_DEV_LONG, AttrDataFormat._SCALAR, "0", "1", "NULL"); + testReadWrite(TangoConst.Tango_DEV_ULONG, AttrDataFormat._SCALAR, "0", "1", "NULL"); + testReadWrite(TangoConst.Tango_DEV_BOOLEAN, AttrDataFormat._SCALAR, "true", "false", "NULL"); + testReadWrite(TangoConst.Tango_DEV_SHORT, AttrDataFormat._SCALAR, "0", "1", "NULL"); + testReadWrite(TangoConst.Tango_DEV_FLOAT, AttrDataFormat._SCALAR, "0.0", "1.0", "NULL"); + testReadWrite(TangoConst.Tango_DEV_DOUBLE, AttrDataFormat._SCALAR, "0.0", "1.0", "NULL"); - @Test - public void SpectrumToStringTest() { - testReadWrite(TangoConst.Tango_DEV_STRING, AttrDataFormat._SPECTRUM, "[test,test]", "[test]", "[]"); - testReadWrite(TangoConst.Tango_DEV_UCHAR, AttrDataFormat._SPECTRUM, "[0]", "[1]", "[]"); - testReadWrite(TangoConst.Tango_DEV_LONG, AttrDataFormat._SPECTRUM, "[0]", "[1]", "[]"); - testReadWrite(TangoConst.Tango_DEV_ULONG, AttrDataFormat._SPECTRUM, "[0]", "[1]", "[]"); - testReadWrite(TangoConst.Tango_DEV_BOOLEAN, AttrDataFormat._SPECTRUM, "[true]", "[false]", "[]"); - testReadWrite(TangoConst.Tango_DEV_SHORT, AttrDataFormat._SPECTRUM, "[0]", "[1]", "[]"); - testReadWrite(TangoConst.Tango_DEV_FLOAT, AttrDataFormat._SPECTRUM, "[0.0]", "[1.0]", "[]"); - testReadWrite(TangoConst.Tango_DEV_DOUBLE, AttrDataFormat._SPECTRUM, "[0.0]", "[1.0]", "[]"); + } - testReadWrite(TangoConst.Tango_DEV_STRING, AttrDataFormat._SPECTRUM, "[test,test,test3]", "[test,test2]", "[]"); - testReadWrite(TangoConst.Tango_DEV_UCHAR, AttrDataFormat._SPECTRUM, "[0,1]", "[1,0]", "[]"); - testReadWrite(TangoConst.Tango_DEV_LONG, AttrDataFormat._SPECTRUM, "[0,1]", "[1,0]", "[]"); - testReadWrite(TangoConst.Tango_DEV_ULONG, AttrDataFormat._SPECTRUM, "[0,1]", "[1,0]", "[]"); - testReadWrite(TangoConst.Tango_DEV_BOOLEAN, AttrDataFormat._SPECTRUM, "[true,false]", "[false,true]", "[]"); - testReadWrite(TangoConst.Tango_DEV_SHORT, AttrDataFormat._SPECTRUM, "[0,1]", "[1,0]", "[]"); - testReadWrite(TangoConst.Tango_DEV_FLOAT, AttrDataFormat._SPECTRUM, "[0.0,1.0]", "[1.0,2.0]", "[]"); - testReadWrite(TangoConst.Tango_DEV_DOUBLE, AttrDataFormat._SPECTRUM, "[0.0,1.0]", "[1.0,2.0]", "[]"); - } + @Test + public void SpectrumToStringTest() { + testReadWrite(TangoConst.Tango_DEV_STRING, AttrDataFormat._SPECTRUM, "[test,test]", "[test]", "[]"); + testReadWrite(TangoConst.Tango_DEV_UCHAR, AttrDataFormat._SPECTRUM, "[0]", "[1]", "[]"); + testReadWrite(TangoConst.Tango_DEV_LONG, AttrDataFormat._SPECTRUM, "[0]", "[1]", "[]"); + testReadWrite(TangoConst.Tango_DEV_ULONG, AttrDataFormat._SPECTRUM, "[0]", "[1]", "[]"); + testReadWrite(TangoConst.Tango_DEV_BOOLEAN, AttrDataFormat._SPECTRUM, "[true]", "[false]", "[]"); + testReadWrite(TangoConst.Tango_DEV_SHORT, AttrDataFormat._SPECTRUM, "[0]", "[1]", "[]"); + testReadWrite(TangoConst.Tango_DEV_FLOAT, AttrDataFormat._SPECTRUM, "[0.0]", "[1.0]", "[]"); + testReadWrite(TangoConst.Tango_DEV_DOUBLE, AttrDataFormat._SPECTRUM, "[0.0]", "[1.0]", "[]"); - private void testReadWrite(int dataType,int dataFormat, String readStringValue, String writeStringValue, String emptyValue) { - String[] args = { "test", "0", "" + dataType , "" + dataFormat, - "", readStringValue, writeStringValue }; - args[4] = "" + AttrWriteType._READ; - SnapAttributeExtract sae = new SnapAttributeExtract(args); - assertEquals(readStringValue, sae.valueToString(0)); - assertEquals(emptyValue, sae.valueToString(1)); + testReadWrite(TangoConst.Tango_DEV_STRING, AttrDataFormat._SPECTRUM, "[test,test,test3]", "[test,test2]", "[]"); + testReadWrite(TangoConst.Tango_DEV_UCHAR, AttrDataFormat._SPECTRUM, "[0,1]", "[1,0]", "[]"); + testReadWrite(TangoConst.Tango_DEV_LONG, AttrDataFormat._SPECTRUM, "[0,1]", "[1,0]", "[]"); + testReadWrite(TangoConst.Tango_DEV_ULONG, AttrDataFormat._SPECTRUM, "[0,1]", "[1,0]", "[]"); + testReadWrite(TangoConst.Tango_DEV_BOOLEAN, AttrDataFormat._SPECTRUM, "[true,false]", "[false,true]", "[]"); + testReadWrite(TangoConst.Tango_DEV_SHORT, AttrDataFormat._SPECTRUM, "[0,1]", "[1,0]", "[]"); + testReadWrite(TangoConst.Tango_DEV_FLOAT, AttrDataFormat._SPECTRUM, "[0.0,1.0]", "[1.0,2.0]", "[]"); + testReadWrite(TangoConst.Tango_DEV_DOUBLE, AttrDataFormat._SPECTRUM, "[0.0,1.0]", "[1.0,2.0]", "[]"); + } - args[4] = "" + AttrWriteType._WRITE; - sae = new SnapAttributeExtract(args); - assertEquals(emptyValue, sae.valueToString(0)); - assertEquals(writeStringValue, sae.valueToString(1)); + private void testReadWrite(int dataType, int dataFormat, String readStringValue, String writeStringValue, + String emptyValue) { + String[] args = { "test", "0", ObjectUtils.EMPTY_STRING + dataType, ObjectUtils.EMPTY_STRING + dataFormat, + ObjectUtils.EMPTY_STRING, readStringValue, writeStringValue }; + args[4] = ObjectUtils.EMPTY_STRING + AttrWriteType._READ; + SnapAttributeExtract sae = new SnapAttributeExtract(args); + assertEquals(readStringValue, sae.valueToString(0)); + assertEquals(emptyValue, sae.valueToString(1)); - args[4] = "" + AttrWriteType._READ_WITH_WRITE; - sae = new SnapAttributeExtract(args); - assertEquals(readStringValue, sae.valueToString(0)); - assertEquals(writeStringValue, sae.valueToString(1)); + args[4] = ObjectUtils.EMPTY_STRING + AttrWriteType._WRITE; + sae = new SnapAttributeExtract(args); + assertEquals(emptyValue, sae.valueToString(0)); + assertEquals(writeStringValue, sae.valueToString(1)); - args[4] = "" + AttrWriteType._READ_WRITE; - sae = new SnapAttributeExtract(args); - assertEquals(readStringValue, sae.valueToString(0)); - assertEquals(writeStringValue, sae.valueToString(1)); - } + args[4] = ObjectUtils.EMPTY_STRING + AttrWriteType._READ_WITH_WRITE; + sae = new SnapAttributeExtract(args); + assertEquals(readStringValue, sae.valueToString(0)); + assertEquals(writeStringValue, sae.valueToString(1)); + + args[4] = ObjectUtils.EMPTY_STRING + AttrWriteType._READ_WRITE; + sae = new SnapAttributeExtract(args); + assertEquals(readStringValue, sae.valueToString(0)); + assertEquals(writeStringValue, sae.valueToString(1)); + } }