use of org.talend.designer.dbmap.model.emf.dbmap.FilterEntry in project tdi-studio-se by Talend.
the class DBMapHelper method saveDataToEmf.
public static void saveDataToEmf(DBMapData emfMapperData, ExternalDbMapData externalData) {
// input
if (externalData.getInputTables() != null && !externalData.getInputTables().isEmpty()) {
for (ExternalDbMapTable table : externalData.getInputTables()) {
final InputTable persistentTable = DbmapFactory.eINSTANCE.createInputTable();
persistentTable.setMinimized(table.isMinimized());
persistentTable.setName(table.getName());
persistentTable.setAlias(table.getAlias());
persistentTable.setJoinType(table.getJoinType());
persistentTable.setTableName(table.getTableName());
if (table.getMetadataTableEntries() != null && !table.getMetadataTableEntries().isEmpty()) {
List<DBMapperTableEntry> persistentEntities = new ArrayList<DBMapperTableEntry>();
for (ExternalDbMapEntry entity : table.getMetadataTableEntries()) {
final DBMapperTableEntry emfMapperTableEntry = DbmapFactory.eINSTANCE.createDBMapperTableEntry();
emfMapperTableEntry.setExpression(entity.getExpression());
emfMapperTableEntry.setName(entity.getName());
emfMapperTableEntry.setJoin(entity.isJoin());
emfMapperTableEntry.setOperator(entity.getOperator());
persistentEntities.add(emfMapperTableEntry);
}
persistentTable.getDBMapperTableEntries().addAll(persistentEntities);
}
emfMapperData.getInputTables().add(persistentTable);
}
}
// output
if (externalData.getOutputTables() != null && !externalData.getOutputTables().isEmpty()) {
for (ExternalDbMapTable table : externalData.getOutputTables()) {
final OutputTable persistentTable = DbmapFactory.eINSTANCE.createOutputTable();
persistentTable.setMinimized(table.isMinimized());
persistentTable.setName(table.getName());
persistentTable.setTableName(table.getTableName());
if (table.getMetadataTableEntries() != null && !table.getMetadataTableEntries().isEmpty()) {
for (ExternalDbMapEntry entity : table.getMetadataTableEntries()) {
final DBMapperTableEntry emfMapperTableEntry = DbmapFactory.eINSTANCE.createDBMapperTableEntry();
emfMapperTableEntry.setExpression(entity.getExpression());
emfMapperTableEntry.setName(entity.getName());
persistentTable.getDBMapperTableEntries().add(emfMapperTableEntry);
}
// filters
if (table.getCustomWhereConditionsEntries() != null && !table.getCustomWhereConditionsEntries().isEmpty()) {
for (ExternalDbMapEntry entity : table.getCustomWhereConditionsEntries()) {
final FilterEntry persistentEntry = DbmapFactory.eINSTANCE.createFilterEntry();
persistentEntry.setName(entity.getName());
persistentEntry.setExpression(entity.getExpression());
persistentEntry.setFilterKind(FilterTableEntry.WHERE_FILTER);
persistentTable.getFilterEntries().add(persistentEntry);
}
}
if (table.getCustomOtherConditionsEntries() != null && !table.getCustomOtherConditionsEntries().isEmpty()) {
for (ExternalDbMapEntry entity : table.getCustomOtherConditionsEntries()) {
final FilterEntry persistentEntry = DbmapFactory.eINSTANCE.createFilterEntry();
persistentEntry.setName(entity.getName());
persistentEntry.setExpression(entity.getExpression());
persistentEntry.setFilterKind(FilterTableEntry.OTHER_FILTER);
persistentTable.getFilterEntries().add(persistentEntry);
}
}
}
emfMapperData.getOutputTables().add(persistentTable);
}
}
}
use of org.talend.designer.dbmap.model.emf.dbmap.FilterEntry in project tdi-studio-se by Talend.
the class DBMapSplitTableConstraintFiltersMigrationTask method execute.
/*
* (non-Javadoc)
*
* @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
*/
@Override
public ExecutionResult execute(Item item) {
IProxyRepositoryFactory factory = CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
ProcessType processType = getProcessType(item);
boolean modified = false;
if (processType != null) {
for (Object obj : processType.getNode()) {
NodeType nodeType = (NodeType) obj;
AbstractExternalData externalData = nodeType.getNodeData();
if (externalData instanceof DBMapData) {
DBMapData mapperData = (DBMapData) externalData;
for (OutputTable pTable : mapperData.getOutputTables()) {
int i = 0;
List<FilterEntry> needSplitFilters = new ArrayList<FilterEntry>();
List<FilterEntry> newFilters = new ArrayList<FilterEntry>();
for (FilterEntry pFilter : pTable.getFilterEntries()) {
String expression = pFilter.getExpression();
if (expression != null && !expression.trim().isEmpty()) {
if (!DbGenerationManager.containWith(expression, DbMapSqlConstants.GROUP_BY_PATTERN, false) && !DbGenerationManager.containWith(expression, DbMapSqlConstants.ORDER_BY_PATTERN, false)) {
continue;
} else {
// can not split the clause directly here, because clause like this(a = b GROUP BY
// c) will be put at
// the end of where clause
needSplitFilters.add(pFilter);
}
}
}
if (!needSplitFilters.isEmpty()) {
EList<FilterEntry> entryList = pTable.getFilterEntries();
for (FilterEntry pFilter : needSplitFilters) {
String expression = pFilter.getExpression().trim();
int splitIndex = firstIndexInString(expression, DbMapSqlConstants.GROUP_BY_PATTERN);
int orderIndex = firstIndexInString(expression, DbMapSqlConstants.ORDER_BY_PATTERN);
if (splitIndex < 0 || (0 <= orderIndex && orderIndex < splitIndex)) {
splitIndex = orderIndex;
}
if (splitIndex == 0) {
// keep the order of "GROUP BY" and "ORDER BY"
pFilter.setFilterKind(FilterTableEntry.OTHER_FILTER);
entryList.remove(pFilter);
newFilters.add(pFilter);
} else {
String whereClause = expression.substring(0, splitIndex);
if (//$NON-NLS-1$
!DbGenerationManager.containWith(expression, DbMapSqlConstants.OR + "\\b", true) && !DbGenerationManager.containWith(expression, DbMapSqlConstants.AND + "\\b", true)) {
//$NON-NLS-1$
//$NON-NLS-1$
whereClause = DbMapSqlConstants.AND + " " + whereClause;
}
pFilter.setExpression(whereClause);
FilterEntry tFilter = DbmapFactory.eINSTANCE.createFilterEntry();
//$NON-NLS-1$
tFilter.setName("newFilterSplited" + ++i);
tFilter.setExpression(expression.substring(splitIndex).trim());
tFilter.setFilterKind(FilterTableEntry.OTHER_FILTER);
entryList.remove(pFilter);
entryList.add(pFilter);
newFilters.add(tFilter);
}
modified = true;
}
if (!newFilters.isEmpty()) {
pTable.getFilterEntries().addAll(newFilters);
modified = true;
}
}
}
}
}
}
try {
if (modified) {
factory.save(item, true);
return ExecutionResult.SUCCESS_WITH_ALERT;
} else {
return ExecutionResult.SUCCESS_NO_ALERT;
}
} catch (Exception e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
}
use of org.talend.designer.dbmap.model.emf.dbmap.FilterEntry in project tdi-studio-se by Talend.
the class DbMapComponent method buildExternalData.
@Override
public void buildExternalData(AbstractExternalData abstractData) {
externalData = new ExternalDbMapData();
if (abstractData instanceof DBMapData) {
DBMapData mapperData = (DBMapData) abstractData;
List<ExternalDbMapTable> externalTables = new ArrayList<ExternalDbMapTable>();
// input
for (InputTable pTable : mapperData.getInputTables()) {
ExternalDbMapTable externalTable = new ExternalDbMapTable();
externalTable.setName(pTable.getName());
externalTable.setMinimized(pTable.isMinimized());
externalTable.setAlias(pTable.getAlias());
externalTable.setJoinType(pTable.getJoinType());
externalTable.setTableName(pTable.getTableName());
List<ExternalDbMapEntry> entities = new ArrayList<ExternalDbMapEntry>();
for (DBMapperTableEntry pEntity : pTable.getDBMapperTableEntries()) {
ExternalDbMapEntry entity = new ExternalDbMapEntry();
entity.setExpression(pEntity.getExpression());
entity.setJoin(pEntity.isJoin());
entity.setName(pEntity.getName());
entity.setOperator(pEntity.getOperator());
entities.add(entity);
}
externalTable.setMetadataTableEntries(entities);
externalTables.add(externalTable);
}
externalData.setInputTables(externalTables);
// output
externalTables = new ArrayList<ExternalDbMapTable>();
for (OutputTable pTable : mapperData.getOutputTables()) {
ExternalDbMapTable externalTable = new ExternalDbMapTable();
externalTable.setName(pTable.getName());
externalTable.setMinimized(pTable.isMinimized());
externalTable.setTableName(pTable.getTableName());
List<ExternalDbMapEntry> entities = new ArrayList<ExternalDbMapEntry>();
for (DBMapperTableEntry pEntity : pTable.getDBMapperTableEntries()) {
ExternalDbMapEntry entity = new ExternalDbMapEntry();
entity.setExpression(pEntity.getExpression());
entity.setName(pEntity.getName());
entities.add(entity);
}
externalTable.setMetadataTableEntries(entities);
// filters
entities = new ArrayList<ExternalDbMapEntry>();
List<ExternalDbMapEntry> otherFilterEntities = new ArrayList<ExternalDbMapEntry>();
for (FilterEntry pFilter : pTable.getFilterEntries()) {
ExternalDbMapEntry entity = new ExternalDbMapEntry();
entity.setExpression(pFilter.getExpression());
entity.setName(pFilter.getName());
if (FilterTableEntry.OTHER_FILTER.equals(pFilter.getFilterKind())) {
otherFilterEntities.add(entity);
} else {
entities.add(entity);
}
}
externalTable.setCustomWhereConditionsEntries(entities);
externalTable.setCustomOtherConditionsEntries(otherFilterEntities);
externalTables.add(externalTable);
}
externalData.setOutputTables(externalTables);
}
this.setExternalData(externalData);
}
use of org.talend.designer.dbmap.model.emf.dbmap.FilterEntry in project tdi-studio-se by Talend.
the class OutputTableImpl method equals.
/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated not
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
OutputTableImpl other = (OutputTableImpl) obj;
EList<FilterEntry> otherFilters = other.getFilterEntries();
if (getFilterEntries().size() != otherFilters.size()) {
return false;
}
for (FilterEntry filter : getFilterEntries()) {
boolean found = false;
for (FilterEntry otherFilter : otherFilters) {
if (filter.getName().equals(otherFilter.getName())) {
found = true;
if (!filter.equals(otherFilter)) {
return false;
}
break;
}
}
if (found == false) {
return false;
}
}
return super.equals(obj);
}
Aggregations