Skip to content
Snippets Groups Projects
Commit b97e9510 authored by Raphael GIRARDOT's avatar Raphael GIRARDOT
Browse files

- reduced the number of sql requests at extraction

- ArithmeticException avoided
parent ef812667
No related branches found
No related tags found
No related merge requests found
package fr.soleil.mambo.api.db;
import java.util.ArrayList;
import java.util.List;
import fr.soleil.archiving.common.api.exception.ArchivingException;
import fr.soleil.archiving.hdbtdb.api.DataBaseManager;
import fr.soleil.archiving.hdbtdb.api.management.attributes.adtapt.IAdtAptAttributes;
import fr.soleil.archiving.hdbtdb.api.manager.IArchivingManagerApiRef;
import fr.soleil.database.connection.AbstractDataBaseConnector;
import fr.soleil.database.connection.MySQLDataBaseConnector;
import fr.soleil.lib.project.ICancelable;
import fr.soleil.mambo.api.extract.ExtractionUtils;
import fr.soleil.mambo.api.extract.IAttributeExtractor;
import fr.soleil.mambo.api.extract.LegacyExtractorFactory;
......@@ -37,31 +42,53 @@ public abstract class ALegacyDataBaseAccess<M extends IArchivingManagerApiRef> i
}
@Override
public String[] getDomainsByCriterion(String domainCriterions) throws ArchivingException {
public String[] getAttributesByCriterion(String domainCriterions, String familyCriterions, String memberCriterions,
String attributeCriterions, ICancelable cancelable) throws ArchivingException {
String[] attributes;
DataBaseManager db = getDataBaseManager();
return db == null ? null : db.getAttribute().getDomains().getDomainsByCriterion(domainCriterions);
if ((db == null) || ((cancelable != null) && cancelable.isCanceled())) {
attributes = null;
} else {
List<String> attrList = new ArrayList<>();
String[] domains = db.getAttribute().getDomains().getDomainsByCriterion(domainCriterions);
if (domains != null) {
for (String domain : domains) {
if ((cancelable != null) && cancelable.isCanceled()) {
break;
}
@Override
public String[] getFamiliesByCriterion(String domain, String familyCriterions) throws ArchivingException {
DataBaseManager db = getDataBaseManager();
return db == null ? null : db.getAttribute().getFamilies().getFamiliesByCriterion(domain, familyCriterions);
String[] families = db.getAttribute().getFamilies().getFamiliesByCriterion(domain,
familyCriterions);
if (families != null) {
for (String family : families) {
if ((cancelable != null) && cancelable.isCanceled()) {
break;
}
@Override
public String[] getMembersByCriterion(String domain, String family, String memberCriterions)
throws ArchivingException {
DataBaseManager db = getDataBaseManager();
return db == null ? null
: db.getAttribute().getMembers().getMembersByCriterion(domain, family, memberCriterions);
String[] members = db.getAttribute().getMembers().getMembersByCriterion(domain, family,
memberCriterions);
if (members != null) {
for (String member : members) {
if ((cancelable != null) && cancelable.isCanceled()) {
break;
}
@Override
public String[] getAttributesByCriterion(String domain, String family, String member, String attributeCriterions)
throws ArchivingException {
DataBaseManager db = getDataBaseManager();
return db == null ? null
: db.getAttribute().getNames().getAttributesByCriterion(domain, family, member, attributeCriterions);
String[] attrs = db.getAttribute().getNames().getAttributesByCriterion(domain,
family, member, attributeCriterions);
if (attrs != null) {
for (String attr : attrs) {
if ((cancelable != null) && cancelable.isCanceled()) {
break;
}
attrList.add(attr);
}
}
}
}
}
}
}
}
attributes = ExtractionUtils.getCleanedValues(attrList);
}
return attributes;
}
@Override
......
package fr.soleil.mambo.api.db;
import fr.soleil.archiving.common.api.exception.ArchivingException;
import fr.soleil.lib.project.ICancelable;
import fr.soleil.mambo.api.extract.IAttributeExtractor;
// alternative for fr.soleil.archiving.hdbtdb.api.DataBaseManager, compatible with TTS too
......@@ -10,14 +11,8 @@ public interface IDataBaseAcess {
boolean hasUSDateFormat();
String[] getDomainsByCriterion(String domainCriterions) throws ArchivingException;
String[] getFamiliesByCriterion(String domain, String familyCriterions) throws ArchivingException;
String[] getMembersByCriterion(String domain, String family, String memberCriterions) throws ArchivingException;
String[] getAttributesByCriterion(String domain, String family, String member, String attributeCriterions)
throws ArchivingException;
String[] getAttributesByCriterion(String domainCriterions, String familyCriterions, String memberCriterions,
String attributeCriterions, ICancelable cancelable) throws ArchivingException;
String[] getAttributesCompleteNames() throws ArchivingException;
......@@ -31,6 +26,6 @@ public interface IDataBaseAcess {
String getFormat(String attributeName) throws ArchivingException;
public String getArchiverForAttribute(String attributeName) throws ArchivingException;
String getArchiverForAttribute(String attributeName) throws ArchivingException;
}
......@@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory;
import fr.soleil.archiving.common.api.exception.ArchivingException;
import fr.soleil.comete.tango.data.service.helper.TangoDeviceHelper;
import fr.soleil.database.connection.DataBaseParameters;
import fr.soleil.lib.project.ICancelable;
import fr.soleil.lib.project.ObjectUtils;
import fr.soleil.mambo.api.archiving.TTSArchivingManagerApi;
import fr.soleil.mambo.api.extract.ExtractionUtils;
......@@ -98,21 +99,6 @@ public class TTSDataBaseAccess implements IDataBaseAcess {
return optional == null || !optional.isPresent() ? null : optional.get();
}
protected String[] getCleanedValues(Collection<String> list) {
String[] values;
if (list == null) {
values = null;
} else {
values = list.toArray(new String[list.size()]);
try {
list.clear();
} catch (Exception e) {
// Ignore: it just means list can't be cleaned
}
}
return values;
}
protected String[] getAttributes(String ttsCriterions, boolean completeName) {
String[] result;
TangoArchivingConfigService service = getConfigService();
......@@ -137,7 +123,7 @@ public class TTSDataBaseAccess implements IDataBaseAcess {
}
}
}
result = getCleanedValues(attributes);
result = ExtractionUtils.getCleanedValues(attributes);
}
}
return result;
......@@ -155,36 +141,12 @@ public class TTSDataBaseAccess implements IDataBaseAcess {
}
@Override
public String[] getDomainsByCriterion(String domainCriterions) throws ArchivingException {
TangoArchivingConfigService service = getConfigService();
return service == null ? null
: getCleanedValues(service.getFilteredDomains(ExtractionUtils.toTTSCriterions(domainCriterions)));
}
@Override
public String[] getFamiliesByCriterion(String domain, String familyCriterions) throws ArchivingException {
TangoArchivingConfigService service = getConfigService();
return service == null ? null
: getCleanedValues(
service.getFilteredFamilies(domain, ExtractionUtils.toTTSCriterions(familyCriterions)));
}
@Override
public String[] getMembersByCriterion(String domain, String family, String memberCriterions)
throws ArchivingException {
TangoArchivingConfigService service = getConfigService();
return service == null ? null
: getCleanedValues(
service.getFilteredMembers(domain, family, ExtractionUtils.toTTSCriterions(memberCriterions)));
}
@Override
public String[] getAttributesByCriterion(String domain, String family, String member, String attributeCriterions)
throws ArchivingException {
public String[] getAttributesByCriterion(String domainCriterions, String familyCriterions, String memberCriterions,
String attributeCriterions, ICancelable cancelable) throws ArchivingException {
TangoArchivingConfigService service = getConfigService();
return service == null ? null
: getCleanedValues(service.getFilteredAttributes(domain, family, member,
ExtractionUtils.toTTSCriterions(attributeCriterions)));
: ExtractionUtils.getCleanedValues(service.getFilteredAttributes(domainCriterions, familyCriterions,
memberCriterions, ExtractionUtils.toTTSCriterions(attributeCriterions)));
}
@Override
......
......@@ -702,4 +702,19 @@ public class ExtractionUtils {
: criterions.replace(TTS_JOKER, ESCAPED_TTS_JOKER).replace(GUIUtilities.TANGO_JOKER, TTS_JOKER);
}
public static String[] getCleanedValues(Collection<String> list) {
String[] values;
if (list == null) {
values = null;
} else {
values = list.toArray(new String[list.size()]);
try {
list.clear();
} catch (Exception e) {
// Ignore: it just means list can't be cleaned
}
}
return values;
}
}
......@@ -159,7 +159,7 @@ public class ViewSpectrumStackChartDialog extends JDialog {
// Slider legend preparation
int increment;
if (timeList == null) {
if ((timeList == null) || (timeList.isEmpty())) {
increment = 0;
player.getSlider().setLabelTable(null);
} else {
......
......@@ -3,8 +3,10 @@ package fr.soleil.mambo.datasources.db.attributes;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import java.util.TreeMap;
import fr.esrf.Tango.AttrDataFormat;
import fr.esrf.Tango.DevFailed;
......@@ -58,7 +60,6 @@ public class BasicAttributeManager extends DbConnectionManager implements IAttri
@Override
public List<Domain> loadDomains(final Criterions searchCriterions, final Boolean historic,
final boolean forceReload, final ICancelable cancelable) throws ArchivingException {
final boolean loadCompletely = true;
final List<Domain> ret = new ArrayList<>();
String domainCriterions = GUIUtilities.TANGO_JOKER;
......@@ -95,53 +96,44 @@ public class BasicAttributeManager extends DbConnectionManager implements IAttri
attributeCriterions = attributeCondition.getValue();
}
}
// TODO optimize to do only 1 call, see TANGOARCH-824
if (cancelable == null || !cancelable.isCanceled()) {
final IDataBaseAcess database = getDataBaseApi(historic);
final String domainsStr[] = database.getDomainsByCriterion(domainCriterions);
for (final String currentDomainName : domainsStr) {
if (cancelable != null && cancelable.isCanceled()) {
break;
}
final Domain currentDomain = new Domain(currentDomainName);
final String[] familiesStr = database.getFamiliesByCriterion(currentDomainName, familyCriterions);
for (final String currentFamilyName : familiesStr) {
if (cancelable != null && cancelable.isCanceled()) {
break;
}
final Family currentFamily = new Family(currentFamilyName);
final String[] membersStr = database.getMembersByCriterion(currentDomainName, currentFamilyName,
memberCriterions);
for (final String currentMemberName : membersStr) {
if (cancelable != null && cancelable.isCanceled()) {
break;
}
final Member currentMember = new Member(currentMemberName);
currentFamily.addMember(currentMember);
if (loadCompletely) {
final String[] attributesStr = database.getAttributesByCriterion(currentDomainName,
currentFamilyName, currentMemberName, attributeCriterions);
for (String currentAttributeName : attributesStr) {
if (cancelable != null && cancelable.isCanceled()) {
break;
final String[] attributes = database.getAttributesByCriterion(domainCriterions, familyCriterions,
memberCriterions, attributeCriterions, cancelable);
if (attributes != null) {
Map<String, Domain> domains = new TreeMap<>();
for (String attribute : attributes) {
if (attribute != null) {
String[] splitAttr = attribute.split(TangoDeviceHelper.SLASH);
if (splitAttr.length == 4) {
String domainStr = splitAttr[0];
String domainLower = domainStr.toLowerCase();
Domain domain = domains.get(domainLower);
if (domain == null) {
domain = new Domain(domainStr);
domains.put(domainLower, domain);
}
Family family = domain.getFamily(splitAttr[1]);
if (family == null) {
family = new Family(splitAttr[1]);
domain.addFamily(family);
}
Member member = family.getMember(splitAttr[2]);
if (member == null) {
member = new Member(splitAttr[2]);
family.addMember(member);
}
currentAttributeName = parseCompleteName(currentAttributeName);
final Attribute currentAttribute = new Attribute();
currentAttribute.setName(currentAttributeName);
currentAttribute.setDomain(currentDomainName);
currentAttribute.setFamily(currentFamilyName);
currentAttribute.setMember(currentMemberName);
currentMember.addAttribute(currentAttribute);
}
currentAttribute.setName(splitAttr[3]);
currentAttribute.setDomain(splitAttr[0]);
currentAttribute.setFamily(splitAttr[1]);
currentAttribute.setMember(splitAttr[2]);
member.addAttribute(currentAttribute);
}
}
currentDomain.addFamily(currentFamily);
}
ret.add(currentDomain);
ret.addAll(domains.values());
domains.clear();
}
}
return ret;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment