Skip to content

Commit

Permalink
TEIIDDES-2985
Browse files Browse the repository at this point in the history
 * fixed issue with handling IN/OUT/RETURN values during import/export DDL
 * Set default export DDL NIS & Native type checkboxes to TRUE
 * now adding NIS option when exporting parameters
 * properly setting function = TRUE when importing CREATE FUNCTION
  • Loading branch information
blafond committed Jan 3, 2017
1 parent de9ec93 commit d12968d
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 88 deletions.
Expand Up @@ -18,6 +18,12 @@ public interface TeiidDDLConstants {
public static final String DETERMINISM = "DETERMINISM";//$NON-NLS-1$
public static final String CATEGORY = "CATEGORY";//$NON-NLS-1$
public static final String UPDATECOUNT = "UPDATECOUNT";//$NON-NLS-1$
public static final String ZERO = "ZERO"; //$NON-NLS-1$
public static final String ONE = "ONE"; //$NON-NLS-1$
public static final String ZERO_LITERAL = "0"; //$NON-NLS-1$
public static final String ONE_LITERAL = "1"; //$NON-NLS-1$
public static final String MULTIPLE = "MULTIPLE"; //$NON-NLS-1$
public static final String AUTO = "AUTO"; //$NON-NLS-1$
public static final String DISTINCT_VALUES = "DISTINCT_VALUES";//$NON-NLS-1$
public static final String NULL_VALUE_COUNT = "NULL_VALUE_COUNT";//$NON-NLS-1$
public static final String RADIX = "RADIX";//$NON-NLS-1$
Expand Down
Expand Up @@ -645,11 +645,12 @@ protected RelationalParameter createProcedureParameter(AstNode node, RelationalP
RelationalParameter prm = super.createProcedureParameter(node, procedure);

// Handle Teiid-specific properties and options
Object prop = node.getProperty(TeiidDdlLexicon.CreateProcedure.PARAMETER_TYPE);
if(prop != null) {
String direction = prop.toString();
prm.setDirection(direction);
String direction = node.getProperty(TeiidDdlLexicon.CreateProcedure.PARAMETER_TYPE).toString();
String resultFlag = node.getProperty(TeiidDdlLexicon.CreateProcedure.PARAMETER_RESULT_FLAG).toString();
if( resultFlag != null && resultFlag.equalsIgnoreCase(Boolean.TRUE.toString())) {
direction = DirectionKind.RETURN_LITERAL.toString();
}
prm.setDirection(direction);

// Find all the Option properties
List<AstNode> optionNodes = new ArrayList<AstNode>();
Expand Down Expand Up @@ -821,12 +822,17 @@ protected Map<AstNode,RelationalReference> createObject(AstNode node, Relational

} else if (is(node, TeiidDdlLexicon.CreateProcedure.PROCEDURE_STATEMENT)
|| is(node, TeiidDdlLexicon.CreateProcedure.FUNCTION_STATEMENT)) {
boolean isFunction = is(node, TeiidDdlLexicon.CreateProcedure.FUNCTION_STATEMENT);
String modelType = (String)node.getProperty(TeiidDdlLexicon.SchemaElement.TYPE);
if( modelType != null ) {
RelationalProcedure proc = null;
if( modelType.equalsIgnoreCase(ModelType.VIRTUAL_LITERAL.toString())) {
createVirtualProcedure(node, model);
proc = createVirtualProcedure(node, model);
} else {
createProcedure(node, model);
proc = createProcedure(node, model);
}
if( isFunction ) {
proc.setFunction(true);
}
}

Expand Down Expand Up @@ -1040,7 +1046,24 @@ private void processTeiidProcedureOptions(List<AstNode> optionNodes, RelationalP
// If any function properties are present, the setFuntion boolean is also set
if(!CoreStringUtil.isEmpty(optionValueStr)) {
if(optionName.equalsIgnoreCase(TeiidDDLConstants.UPDATECOUNT)) {
procedure.setUpdateCount(optionValueStr);
if( optionValueStr.equals(TeiidDDLConstants.ONE_LITERAL) ) {
procedure.setUpdateCount(TeiidDDLConstants.ONE);
} else if( optionValueStr.equals(TeiidDDLConstants.ZERO_LITERAL) ) {
procedure.setUpdateCount(TeiidDDLConstants.ZERO);
} else {
// Look for > 1 for MULTIPLE
int value = -1;
try {
value = Integer.parseInt(optionValueStr);
} catch (NumberFormatException e) {
}

if( value > 1 ) {
procedure.setUpdateCount(TeiidDDLConstants.MULTIPLE);
} else {
procedure.setUpdateCount(TeiidDDLConstants.AUTO);
}
}
nodeIter.remove();
} else if(optionName.equalsIgnoreCase(TeiidDDLConstants.CATEGORY)) {
procedure.setFunctionCategory(optionValueStr);
Expand Down
Expand Up @@ -40,6 +40,9 @@ public interface TeiidDDLConstants {
public static final String DETERMINISM = "DETERMINISM";//$NON-NLS-1$
public static final String CATEGORY = "CATEGORY";//$NON-NLS-1$
public static final String UPDATECOUNT = "UPDATECOUNT";//$NON-NLS-1$
public static final String ZERO = "0"; //$NON-NLS-1$
public static final String ONE = "1"; //$NON-NLS-1$
public static final String TWO = "2"; //$NON-NLS-1$
public static final String DISTINCT_VALUES = "DISTINCT_VALUES";//$NON-NLS-1$
public static final String NULL_VALUE_COUNT = "NULL_VALUE_COUNT";//$NON-NLS-1$
public static final String RADIX = "RADIX";//$NON-NLS-1$
Expand Down
Expand Up @@ -44,6 +44,7 @@
import org.teiid.designer.metamodels.relational.PrimaryKey;
import org.teiid.designer.metamodels.relational.Procedure;
import org.teiid.designer.metamodels.relational.ProcedureParameter;
import org.teiid.designer.metamodels.relational.ProcedureUpdateCount;
import org.teiid.designer.metamodels.relational.SearchabilityType;
import org.teiid.designer.metamodels.relational.Table;
import org.teiid.designer.metamodels.relational.UniqueConstraint;
Expand All @@ -54,6 +55,7 @@
import org.teiid.designer.metamodels.relational.util.RelationalUtil;
import org.teiid.designer.metamodels.transformation.TransformationMappingRoot;
import org.teiid.designer.relational.RelationalConstants;
import org.teiid.designer.relational.model.RelationalParameter;
import org.teiid.designer.transformation.TransformationPlugin;
import org.teiid.designer.transformation.util.TransformationHelper;
import org.teiid.designer.type.IDataTypeManagerService.DataTypeName;
Expand Down Expand Up @@ -83,7 +85,7 @@ public class TeiidModelToDdlGenerator implements TeiidDDLConstants, TeiidReserve
private ModelExtensionAssistantAggregator medAggregator = ExtensionPlugin.getInstance().getModelExtensionAssistantAggregator();

private boolean ignoreTeiidProcedures = false;
private boolean includeNIS;
private boolean includeNIS;
private boolean includeNativeType;


Expand Down Expand Up @@ -801,6 +803,14 @@ private String getColumnOptions(Column col) {
return options.toString();
}

private Map<String, String> getParameterOptions(ProcedureParameter parameter) {
Map<String, String> options = new HashMap<String, String>();
if( this.includeNIS ) {
options.put(NAMEINSOURCE, parameter.getNameInSource());
}
return options;
}

private String getOptions(EObject eobject) {
OptionsStatement options = new OptionsStatement();

Expand Down Expand Up @@ -1027,6 +1037,10 @@ private String getTableOptions(Table table) {

private Map<String, String> getOptionsForObject(EObject modelObject) throws Exception {
Map<String, String> options = new HashMap<String, String>();

if( modelObject instanceof ProcedureParameter ) {
options.putAll( getParameterOptions((ProcedureParameter)modelObject));
}

Collection<String> extensionNamespaces = medAggregator.getSupportedNamespacePrefixes(modelObject);
for( String ns : extensionNamespaces ) {
Expand Down Expand Up @@ -1190,6 +1204,15 @@ private String getProcedureOptions(Procedure procedure) {
// Functions have many additional extension properties
boolean isFunction = procedure.isFunction();
if(isFunction) {
String updateCount = procedure.getUpdateCount().toString();
if( updateCount.equals(ProcedureUpdateCount.ZERO_LITERAL.toString())) {
options.add(UPDATECOUNT, ZERO, ZERO);
} else if( updateCount.equals(ProcedureUpdateCount.ONE_LITERAL.toString())) {
options.add(UPDATECOUNT, ONE, ZERO);
} else if( updateCount.equals(ProcedureUpdateCount.MULTIPLE_LITERAL.toString())) {
options.add(UPDATECOUNT, TWO, ZERO);
}

String value = getPropertyValue(procedure, PROCEDURE_EXT_PROPERTIES.FUNCTION_CATEGORY);
options.add(FUNCTION_CATEGORY_PROP, value, null);

Expand Down Expand Up @@ -1233,6 +1256,7 @@ private String getProcedureOptions(Procedure procedure) {
}
}
} else {
options.add(UPDATECOUNT, ONE, ZERO);
// REST PROPERTIES??
String value = getRestPropertyValue(procedure, RestModelExtensionConstants.PropertyIds.URI);
if( value != null ) namespaces.add(REST_TEIID_SET_NAMESPACE);
Expand Down Expand Up @@ -1392,6 +1416,14 @@ public void setIncludeProcedures(boolean includeProcedures) {
public void setIncludeFKs(boolean includeFKs) {
this.includeFKs = includeFKs;
}

public void setIncludeNIS(boolean includeNIS) {
this.includeNIS = includeNIS;
}

public void setIncludeNativeType(boolean includeNativeType) {
this.includeNativeType = includeNativeType;
}

class OptionsStatement {
boolean hasOptions;
Expand Down
Expand Up @@ -623,6 +623,7 @@ public void modifyText( final ModifyEvent event ) {
0,
2,
options.isNameInSourceUsed());
this.useNamesInSourceCheckBox.setSelection(true);
this.useNamesInSourceCheckBox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected( final SelectionEvent event ) {
Expand All @@ -634,6 +635,7 @@ public void widgetSelected( final SelectionEvent event ) {
0,
2,
options.isNativeTypeUsed());
this.useNativeTypeCheckBox.setSelection(true);
this.useNativeTypeCheckBox.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected( final SelectionEvent event ) {
Expand Down

0 comments on commit d12968d

Please sign in to comment.