/**
* <copyright> </copyright>
*
* $Id$
*/
package org.talend.dataquality.indicators.impl;
import java.util.List;
import java.util.Set;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.talend.dataquality.helpers.IndicatorHelper;
import org.talend.dataquality.indicators.DistinctCountIndicator;
import org.talend.dataquality.indicators.IndicatorsPackage;
import org.talend.dataquality.indicators.mapdb.AbstractDB;
import org.talend.dataquality.indicators.mapdb.DBSet;
import org.talend.dataquality.indicators.mapdb.StandardDBName;
import orgomg.cwm.objectmodel.core.Expression;
/**
* <!-- begin-user-doc --> An implementation of the model object '<em><b>Distinct Count Indicator</b></em>'. <!--
* end-user-doc -->
* <p>
* The following features are implemented:
* <ul>
* <li>{@link org.talend.dataquality.indicators.impl.DistinctCountIndicatorImpl#getDistinctValueCount <em>Distinct Value Count</em>}</li>
* </ul>
* </p>
*
* @generated
*/
public class DistinctCountIndicatorImpl extends IndicatorImpl implements DistinctCountIndicator {
/**
* The default value of the '{@link #getDistinctValueCount() <em>Distinct Value Count</em>}' attribute. <!--
* begin-user-doc --> <!-- end-user-doc -->
*
* @see #getDistinctValueCount()
* @generated
* @ordered
*/
protected static final Long DISTINCT_VALUE_COUNT_EDEFAULT = null;
/**
* The cached value of the '{@link #getDistinctValueCount() <em>Distinct Value Count</em>}' attribute. <!--
* begin-user-doc --> <!-- end-user-doc -->
*
* @see #getDistinctValueCount()
* @generated
* @ordered
*/
protected Long distinctValueCount = DISTINCT_VALUE_COUNT_EDEFAULT;
private Set<Object> distinctObjects = null;
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
protected DistinctCountIndicatorImpl() {
super();
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
protected EClass eStaticClass() {
return IndicatorsPackage.Literals.DISTINCT_COUNT_INDICATOR;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public Set<Object> getDistinctValues() {
// TODO: implement this method
// Ensure that you remove @generated or mark it @generated NOT
throw new UnsupportedOperationException();
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public Object eGet(int featureID, boolean resolve, boolean coreType) {
switch (featureID) {
case IndicatorsPackage.DISTINCT_COUNT_INDICATOR__DISTINCT_VALUE_COUNT:
return getDistinctValueCount();
}
return super.eGet(featureID, resolve, coreType);
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public void eSet(int featureID, Object newValue) {
switch (featureID) {
case IndicatorsPackage.DISTINCT_COUNT_INDICATOR__DISTINCT_VALUE_COUNT:
setDistinctValueCount((Long)newValue);
return;
}
super.eSet(featureID, newValue);
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public void eUnset(int featureID) {
switch (featureID) {
case IndicatorsPackage.DISTINCT_COUNT_INDICATOR__DISTINCT_VALUE_COUNT:
setDistinctValueCount(DISTINCT_VALUE_COUNT_EDEFAULT);
return;
}
super.eUnset(featureID);
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public boolean eIsSet(int featureID) {
switch (featureID) {
case IndicatorsPackage.DISTINCT_COUNT_INDICATOR__DISTINCT_VALUE_COUNT:
return DISTINCT_VALUE_COUNT_EDEFAULT == null ? distinctValueCount != null : !DISTINCT_VALUE_COUNT_EDEFAULT.equals(distinctValueCount);
}
return super.eIsSet(featureID);
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
* @generated NOT
*/
@Override
public String toString() {
StringBuffer result = new StringBuffer(this.getName());
result.append("= ");
result.append(distinctValueCount);
return result.toString();
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public Long getDistinctValueCount() {
return distinctValueCount;
}
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
* @generated
*/
@Override
public void setDistinctValueCount(Long newDistinctValueCount) {
Long oldDistinctValueCount = distinctValueCount;
distinctValueCount = newDistinctValueCount;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, IndicatorsPackage.DISTINCT_COUNT_INDICATOR__DISTINCT_VALUE_COUNT, oldDistinctValueCount, distinctValueCount));
}
/*
* (non-Javadoc)
*
* @see org.talend.dataquality.indicators.impl.IndicatorImpl#storeSqlResults(java.lang.Object[])
*
* ADDED scorreia 2008-04-30 storeSqlResults(List<Object[]> objects)
*/
@Override
public boolean storeSqlResults(List<Object[]> objects) {
if (!super.checkResults(objects, 1)) {
return false;
}
// MOD gdbu 2011-4-14 bug : 18975
this.setDistinctValueCount(IndicatorHelper.getLongFromObject(objects.get(0)[0]));
// ~18975
return true;
}
/*
* (non-Javadoc)
*
* @see org.talend.dataquality.indicators.impl.IndicatorImpl#getIntegerValue()
*
* ADDED scorreia 2008-05-12 getIntegerValue()
*/
@Override
public Long getIntegerValue() {
return this.getDistinctValueCount();
}
/*
* (non-Javadoc)
*
* @see org.talend.dataquality.indicators.impl.IndicatorImpl#handle(java.lang.Object)
*
* ADDED scorreia 2009-04-17 handle(Object data)
*/
@Override
public boolean handle(Object data) {
super.handle(data);
// MOD msjian 2011-8-24 TDQ-1679: when run with java engine, the Duplicate count should contain "null"
// if (data != null) {
if (this.distinctObjects.add(data)) {
if (checkMustStoreCurrentRow(drillDownValueCount)) {
this.mustStoreRow = true;
}
}
// }
// TDQ-1679 ~
return true;
}
@Override
public boolean finalizeComputation() {
this.setDistinctValueCount(Long.valueOf(distinctObjects.size()));
return super.finalizeComputation();
}
/*
* (non-Javadoc)
*
* @see org.talend.dataquality.indicators.impl.IndicatorImpl#reset()
*/
@Override
public boolean reset() {
this.distinctValueCount = DISTINCT_VALUE_COUNT_EDEFAULT;
if (isUsedMapDBMode()) {
if (needReconnect((DBSet<Object>) distinctObjects)) {
distinctObjects = initValueForDBSet(StandardDBName.computeProcessSet.name());
}
if (!distinctObjects.isEmpty()) {
distinctObjects.clear();
}
} else {
distinctObjects.clear();
}
return super.reset();
}
@Override
public Expression getInstantiatedExpressions(String language) {
return super.getInstantiatedExpressions(language);
}
/*
* (non-Javadoc)
*
* @see org.talend.dataquality.indicators.impl.IndicatorImpl#getMapDB(java.lang.String)
*/
@Override
public AbstractDB getMapDB(String dbName) {
// is mapDB mode
if (isUsedMapDBMode()) {
// is get computeProcess map
if (StandardDBName.computeProcess.name().equals(dbName) || StandardDBName.computeProcessSet.name().equals(dbName)) {
// current set is invalid
if (needReconnect((DBSet<Object>) distinctObjects)) {
// create new DBSet
return initValueForDBSet(StandardDBName.computeProcessSet.name());
} else {
return (DBSet<Object>) distinctObjects;
}
}
}
return super.getMapDB(dbName);
}
/*
* (non-Javadoc)
*
* @see org.talend.dataquality.indicators.mapdb.MapDBDrillDown#handleDrillDownData(java.lang.Object, java.util.List)
*/
@Override
public void handleDrillDownData(Object masterObject, List<Object> inputRowList) {
// store drill dwon data for view values
if (this.checkMustStoreCurrentRow(drillDownValueCount)) {
if (!drillDownValuesSet.contains(masterObject)) {
drillDownValueCount++;
drillDownValuesSet.add(masterObject);
}
}
}
} // DistinctCountIndicatorImpl