Skip to content

Commit

Permalink
TEIIDDES-2700 Enabled import/export of REST/EXCEL/SF properties for
Browse files Browse the repository at this point in the history
dynamic vdb features.
  • Loading branch information
blafond committed Dec 7, 2015
1 parent 6971fc8 commit 45a83cf
Show file tree
Hide file tree
Showing 10 changed files with 194 additions and 23 deletions.
Expand Up @@ -72,7 +72,7 @@ public class TeiidDdlImporter extends StandardImporter {
private static final String NS_TEIID_JPA = "teiid_jpa"; //$NON-NLS-1$
private static final String NS_DESIGNER_ODATA = "odata"; //$NON-NLS-1$
private static final String NS_DESIGNER_WEBSERVICE= "ws"; //$NON-NLS-1$
private static final String NS_DESIGNER_MONGO = "mongo"; //$NON-NLS-1$
private static final String NS_DESIGNER_MONGO = "mongodb"; //$NON-NLS-1$
private static final String NS_DESIGNER_SALESFORCE = "salesforce"; //$NON-NLS-1$
private static final String NS_DESIGNER_RELATIONAL = "relational"; //$NON-NLS-1$
private static final String NS_DESIGNER_ACCUMULO = "accumulo"; //$NON-NLS-1$
Expand Down
Expand Up @@ -293,7 +293,7 @@ public static String getRestMethod( Procedure procedure ) {
.getModelExtensionAssistant(NAMESPACE_PROVIDER.getNamespacePrefix());
restMethod = assistant.getPropertyValue(procedure, RestModelExtensionConstants.PropertyIds.REST_METHOD);

if (CoreStringUtil.isEmpty(restMethod.trim())) {
if (restMethod != null && CoreStringUtil.isEmpty(restMethod.trim())) {
// try old way
restMethod = (String)ANNOTATION_HELPER.getPropertyValueAnyCase(procedure,
ModelObjectAnnotationHelper.EXTENDED_PROPERTY_NAMESPACE
Expand Down
Expand Up @@ -11,7 +11,21 @@
import org.teiid.designer.extension.properties.NamespaceProvider;

/**
*
*
teiid_mongo:EMBEDDABLE - Means that data defined in this table is allowed to be included as an "embeddable" document
in any parent document. The parent document is referenced by the foreign key relationships. In this scenario,
Teiid maintains more than one copy of the data in MongoDB store, one in its own collection and also a copy in
each of the parent tables that have relationship to this table. You can even nest embeddable table inside another
embeddable table with some limitations. Use this property on table, where table can exist, encompass all its
relations on its own. For example, a "Category" table that defines a "Product"'s category is independent of Product,
which can be embeddable in "Products" table.
teiid_mongo:MERGE - Means that data of this table is merged with the defined parent table. There is only a single
copy of the data that is embedded in the parent document. Parent document is defined using the foreign key relationships.
PLEASE NOTE:
A given table can contain either the "teiid_mongo:EMBEDDABLE" property or the "teiid_mongo:MERGE" property
defining the type of nesting in MongoDB. A TABLE IS NOT ALLOWED TO HAVE BOTH PROPERTIES
*/
public interface MongoDBModelExtensionConstants {
/**
Expand Down
Expand Up @@ -37,7 +37,7 @@ public ModelExtensionAssistantAggregator( ModelExtensionRegistry registry ) {
this.registry = registry;
}

private ModelObjectExtensionAssistant getModelObjectExtensionAssistant( String namespacePrefix ) {
public ModelObjectExtensionAssistant getModelObjectExtensionAssistant( String namespacePrefix ) {
ModelExtensionAssistant assistant = this.registry.getModelExtensionAssistant(namespacePrefix);

if (assistant instanceof ModelObjectExtensionAssistant) {
Expand Down
Expand Up @@ -246,6 +246,8 @@ public void setPropertyValue(final Object modelObject,

if( isVirtual && !PropertyName.same(PropertyName.NON_PREPARED, propId)) {
super.setPropertyValue(modelObject, propId, newValue);
} else if( !isVirtual && PropertyName.same(PropertyName.NATIVE_QUERY, propId)) {
super.setPropertyValue(modelObject, propId, newValue);
}

// if setting aggregate to false remove these properties
Expand Down
Expand Up @@ -65,7 +65,16 @@ protected ModelExtensionPropertyDefinition getPropertyDefinition(final Object mo
if (propDefn != null) {
// must be procedure in a virtual model
if ((modelObject instanceof Procedure) && ModelUtil.isVirtual(modelObject)) {
if (PropertyIds.REST_METHOD.equals(propId) || PropertyIds.URI.equals(propId) || PropertyIds.CHARSET.equals(propId) || PropertyIds.HEADERS.equals(propId) || PropertyIds.DESCRIPTION.equals(propId)) {
boolean isFunction = false;
if( modelObject instanceof Procedure ) {
isFunction = ((Procedure)modelObject).isFunction();
}
if ( !isFunction &&
(PropertyIds.REST_METHOD.equals(propId) ||
PropertyIds.URI.equals(propId) ||
PropertyIds.CHARSET.equals(propId) ||
PropertyIds.HEADERS.equals(propId) ||
PropertyIds.DESCRIPTION.equals(propId))) {
return propDefn;
}
}
Expand Down
Expand Up @@ -16,6 +16,9 @@
public interface RelationalConstants {
final static String XMI_EXT = ".xmi"; //$NON-NLS-1$

final static String TEIID_REL_PREFIX = "teiid_rel"; //$NON-NLS-1$
final static String RELATIONAL_PREFIX = "relational"; //$NON-NLS-1$

/**
* Relational model object types
*/
Expand Down
Expand Up @@ -38,6 +38,7 @@ Require-Bundle: org.teiid.designer.core;bundle-version="[9.0.2,10.0.0)",
org.eclipse.emf.ecore.xmi;bundle-version="[2.10.2,3.0.0)",
org.teiid.designer.metamodels.function;bundle-version="[9.0.2,10.0.0)",
org.teiid.designer.relational;bundle-version="[9.0.2,10.0.0)",
org.teiid.designer.spi;bundle-version="[9.0.2,10.0.0)"
org.teiid.designer.spi;bundle-version="[9.0.2,10.0.0)",
org.teiid.designer.extension;bundle-version="[9.0.2,10.0.0)"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Expand Up @@ -111,4 +111,21 @@ public interface TeiidDDLConstants {
public static final String CHARSET = "CHARSET"; //$NON-NLS-1$
public static final String REST_CHARSET = "REST:CHARSET"; //$NON-NLS-1$
public static final String REST_TEIID_SET_NAMESPACE = "SET NAMESPACE 'http://teiid.org/rest' AS REST;"; //$NON-NLS-1$

public static String TEIID_SF_PREFIX = "teiid_sf"; //$NON-NLS-1$
public static String SALESFORCE_PREFIX = "salesforce"; //$NON-NLS-1$

public static String TEIID_MONGO_PREFIX = "teiid_mongo"; //$NON-NLS-1$
public static String MONGODB_PREFIX = "mongodb"; //$NON-NLS-1$"; //$NON-NLS-1$


/*
* Teiid's EXCEL extension properties
*/
public static String TEIID_EXCEL_PREFIX = "teiid_excel"; //$NON-NLS-1$
public static String EXCEL_PREFIX = "excel"; //$NON-NLS-1$"; //$NON-NLS-1$
public static String EXCEL_CELL_NUMBER = "CELL_NUMBER"; //$NON-NLS-1$"; //$NON-NLS-1$ COLUMN ONLY
public static String EXCEL_FILE = "FILE"; //$NON-NLS-1$"; //$NON-NLS-1$ TABLE
public static String EXCEL_FIRST_DATA_ROW_NUMBER = "FIRST_DATA_ROW_NUMBER"; //$NON-NLS-1$"; //$NON-NLS-1$ TABLE

}
Expand Up @@ -9,8 +9,10 @@

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.eclipse.core.runtime.IStatus;
Expand All @@ -27,6 +29,10 @@
import org.teiid.designer.core.util.ModelContents;
import org.teiid.designer.core.workspace.ModelResource;
import org.teiid.designer.core.workspace.ModelWorkspaceException;
import org.teiid.designer.extension.ExtensionPlugin;
import org.teiid.designer.extension.ModelExtensionAssistantAggregator;
import org.teiid.designer.extension.definition.ModelObjectExtensionAssistant;
import org.teiid.designer.extension.properties.ModelExtensionPropertyDefinition;
import org.teiid.designer.metamodels.relational.BaseTable;
import org.teiid.designer.metamodels.relational.Column;
import org.teiid.designer.metamodels.relational.DirectionKind;
Expand Down Expand Up @@ -54,7 +60,7 @@
/**
* Generator for converting a teiid xmi model into DDL
*/
public class TeiidModelToDdlGenerator implements TeiidDDLConstants, TeiidReservedConstants {
public class TeiidModelToDdlGenerator implements TeiidDDLConstants, TeiidReservedConstants, RelationalConstants {

private StringBuilder ddlBuffer = new StringBuilder();

Expand All @@ -69,6 +75,8 @@ public class TeiidModelToDdlGenerator implements TeiidDDLConstants, TeiidReserve
private List<IStatus> issues = new ArrayList<IStatus>();

private Set<String> namespaces = new HashSet<String>();

private ModelExtensionAssistantAggregator medAggregator = ExtensionPlugin.getInstance().getModelExtensionAssistantAggregator();

/**
* @param modelResource
Expand Down Expand Up @@ -372,6 +380,9 @@ private String procedure(Procedure procedure) {
String paramStr = getParameterDdl(param);
count++;
sb.append(paramStr);

addOptionsForEObject(param, sb);

if( count < nParams ) sb.append(COMMA + SPACE);
}

Expand All @@ -396,6 +407,8 @@ private String procedure(Procedure procedure) {
String columnStr = getColumnDdl(nextCol);
sb.append(columnStr);
if( count < nCols ) sb.append(COMMA + SPACE);

addOptionsForEObject(nextCol, sb);
}
sb.append(CLOSE_BRACKET);
} else if( returnType != null ) {
Expand Down Expand Up @@ -513,6 +526,17 @@ private String getColumnOptions(Column col) {
if( !col.getSearchability().equals(SearchabilityType.SEARCHABLE) ) {
options.add(SEARCHABLE, col.getSearchability().getLiteral(), SearchabilityType.SEARCHABLE_LITERAL.toString());
}

// Need to check with other assistants too
try {
Map<String, String> props = getOptionsForObject(col);
for( String key : props.keySet() ) {
String value = props.get(key);
options.add(key, value, null);
}
} catch (Exception e) {
issues.add(new Status(IStatus.ERROR, TransformationPlugin.PLUGIN_ID, "Error finding options for " + getName(col), e)); //$NON-NLS-1$
}

return options.toString();
}
Expand Down Expand Up @@ -639,7 +663,7 @@ private String getContraints(BaseTable table) {

private String getTableOptions(Table table) {
OptionsStatement options = new OptionsStatement();

options.add(NAMEINSOURCE, table.getNameInSource(), null);
options.add(MATERIALIZED, Boolean.toString(table.isMaterialized()), Boolean.FALSE.toString());
options.add(UPDATABLE, Boolean.toString(table.isSupportsUpdate()), Boolean.TRUE.toString());
Expand All @@ -649,7 +673,18 @@ private String getTableOptions(Table table) {
if( table.getMaterializedTable() != null ) {
options.add(MATERIALIZED_TABLE, table.getMaterializedTable().getName(), null);
}


// Need to check with other assistants too
try {
Map<String, String> props = getOptionsForObject(table);
for( String key : props.keySet() ) {
String value = props.get(key);
options.add(key, value, null);
}
} catch (Exception e) {
issues.add(new Status(IStatus.ERROR, TransformationPlugin.PLUGIN_ID, "Error finding options for " + getName(table), e)); //$NON-NLS-1$
}

String desc = getDescription(table);
if( !StringUtilities.isEmpty(desc) ) {
options.add(ANNOTATION, desc, null);
Expand All @@ -658,63 +693,142 @@ private String getTableOptions(Table table) {
return options.toString();
}

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

Collection<String> extensionNamespaces = medAggregator.getSupportedNamespacePrefixes(modelObject);
for( String ns : extensionNamespaces ) {
ModelObjectExtensionAssistant assistant = medAggregator.getModelObjectExtensionAssistant(ns);
if( assistant != null ) {
Collection<ModelExtensionPropertyDefinition> defns = assistant.getPropertyDefinitions(modelObject);

// If relational, we're handling this via getPropetyValue()...
if(ns.equals(RELATIONAL_PREFIX)) {
String propId = BASE_TABLE_EXT_PROPERTIES.NATIVE_QUERY;
String nativeQuery = assistant.getOverriddenValue(modelObject, propId);
if(!CoreStringUtil.isEmpty(nativeQuery)) {
propId = propId.replace(RELATIONAL_PREFIX, TEIID_REL_PREFIX);
options.put(propId, nativeQuery);
}
propId = BASE_TABLE_EXT_PROPERTIES.VIEW_TABLE_GLOBAL_TEMP_TABLE;
String globalTempTable = assistant.getOverriddenValue(modelObject, propId);
if(!CoreStringUtil.isEmpty(globalTempTable)) {
propId = propId.replace(RELATIONAL_PREFIX, TEIID_REL_PREFIX);
options.put(propId, globalTempTable);
}
} else if(ns.equals(SALESFORCE_PREFIX) ) {
for( ModelExtensionPropertyDefinition ext : defns) {
String propId = ext.getId();
String value = assistant.getOverriddenValue(modelObject, propId);

if( value != null ) {
propId = propId.replace(SALESFORCE_PREFIX, TEIID_SF_PREFIX);
options.put(propId, value);
}
}
} else if(ns.equals(MONGODB_PREFIX)) {
for( ModelExtensionPropertyDefinition ext : defns) {
String propId = ext.getId();
String value = assistant.getOverriddenValue(modelObject, propId);

if( value != null ) {
propId = propId.replace(MONGODB_PREFIX, TEIID_MONGO_PREFIX);
options.put(propId, value);
}
}
} else if(ns.equals(EXCEL_PREFIX)) {
for( ModelExtensionPropertyDefinition ext : defns) {
String propId = ext.getId();
String value = assistant.getOverriddenValue(modelObject, propId);

if( value != null ) {
propId = propId.replace(EXCEL_PREFIX, TEIID_EXCEL_PREFIX);
options.put(propId, value);
}
}
}

}
}

return options;

}

private void addOptionsForEObject(EObject eObj, StringBuilder sb) {
// Need to check with other assistants too
try {
OptionsStatement options = new OptionsStatement();
Map<String, String> props = getOptionsForObject(eObj);
for( String key : props.keySet() ) {
String value = props.get(key);
options.add(key, value, null);
}
if( !StringUtilities.isEmpty(options.toString())) {
sb.append(SPACE).append(options);
}
} catch (Exception e) {
issues.add(new Status(IStatus.ERROR, TransformationPlugin.PLUGIN_ID, "Error finding options for " + getName(eObj), e)); //$NON-NLS-1$
}
}

private String getProcedureOptions(Procedure procedure) {
OptionsStatement options = new OptionsStatement();

options.add(NAMEINSOURCE, procedure.getNameInSource(), null);

String nativeQuery = getPropertyValue(procedure, RelationalConstants.PROCEDURE_EXT_PROPERTIES.NATIVE_QUERY);
String nativeQuery = getPropertyValue(procedure, PROCEDURE_EXT_PROPERTIES.NATIVE_QUERY);
if(!CoreStringUtil.isEmpty(nativeQuery)) {
options.add(NATIVE_QUERY_PROP, nativeQuery, null);
}

// Physical Model only
if( !isVirtual ) {
String nonPreparedValue = getPropertyValue(procedure, RelationalConstants.PROCEDURE_EXT_PROPERTIES.NON_PREPARED);
String nonPreparedValue = getPropertyValue(procedure, PROCEDURE_EXT_PROPERTIES.NON_PREPARED);
setBooleanProperty(NON_PREPARED_PROP, nonPreparedValue, false, options);
}
// Functions have many additional extension properties
boolean isFunction = procedure.isFunction();
if(isFunction) {
String value = getPropertyValue(procedure, RelationalConstants.PROCEDURE_EXT_PROPERTIES.FUNCTION_CATEGORY);
String value = getPropertyValue(procedure, PROCEDURE_EXT_PROPERTIES.FUNCTION_CATEGORY);
options.add(FUNCTION_CATEGORY_PROP, value, null);

value = getPropertyValue(procedure, RelationalConstants.PROCEDURE_EXT_PROPERTIES.JAVA_CLASS);
value = getPropertyValue(procedure, PROCEDURE_EXT_PROPERTIES.JAVA_CLASS);
options.add(JAVA_CLASS, value, null);

value = getPropertyValue(procedure, RelationalConstants.PROCEDURE_EXT_PROPERTIES.JAVA_METHOD);
value = getPropertyValue(procedure, PROCEDURE_EXT_PROPERTIES.JAVA_METHOD);
options.add(JAVA_METHOD, value, null);

value = getPropertyValue(procedure, RelationalConstants.PROCEDURE_EXT_PROPERTIES.VARARGS);
value = getPropertyValue(procedure, PROCEDURE_EXT_PROPERTIES.VARARGS);
setBooleanProperty(VARARGS_PROP, value, false, options);


value = getPropertyValue(procedure, RelationalConstants.PROCEDURE_EXT_PROPERTIES.NULL_ON_NULL);
value = getPropertyValue(procedure, PROCEDURE_EXT_PROPERTIES.NULL_ON_NULL);
setBooleanProperty(NULL_ON_NULL_PROP, value, false, options);


value = getPropertyValue(procedure, RelationalConstants.PROCEDURE_EXT_PROPERTIES.DETERMINISTIC);
value = getPropertyValue(procedure, PROCEDURE_EXT_PROPERTIES.DETERMINISTIC);
setBooleanProperty(DETERMINISM_PROP, value, false, options);

value = getPropertyValue(procedure, RelationalConstants.PROCEDURE_EXT_PROPERTIES.AGGREGATE);
value = getPropertyValue(procedure, PROCEDURE_EXT_PROPERTIES.AGGREGATE);
if( value != null ) {
boolean booleanValue = Boolean.getBoolean(value);
if( booleanValue ) {
setBooleanProperty(AGGREGATE_PROP, value, false, options);

value = getPropertyValue(procedure, RelationalConstants.PROCEDURE_EXT_PROPERTIES.ANALYTIC);
value = getPropertyValue(procedure, PROCEDURE_EXT_PROPERTIES.ANALYTIC);
setBooleanProperty(ANALYTIC_PROP, value, false, options);

value = getPropertyValue(procedure, RelationalConstants.PROCEDURE_EXT_PROPERTIES.ALLOWS_ORDER_BY);
value = getPropertyValue(procedure, PROCEDURE_EXT_PROPERTIES.ALLOWS_ORDER_BY);
setBooleanProperty(ALLOWS_ORDER_BY_PROP, value, false, options);

value = getPropertyValue(procedure, RelationalConstants.PROCEDURE_EXT_PROPERTIES.USES_DISTINCT_ROWS);
value = getPropertyValue(procedure, PROCEDURE_EXT_PROPERTIES.USES_DISTINCT_ROWS);
setBooleanProperty(USES_DISTINCT_ROWS_PROP, value, false, options);

value = getPropertyValue(procedure, RelationalConstants.PROCEDURE_EXT_PROPERTIES.ALLOWS_DISTINCT);
value = getPropertyValue(procedure, PROCEDURE_EXT_PROPERTIES.ALLOWS_DISTINCT);
setBooleanProperty(ALLOWS_DISTINCT_PROP, value, false, options);

value = getPropertyValue(procedure, RelationalConstants.PROCEDURE_EXT_PROPERTIES.DECOMPOSABLE);
value = getPropertyValue(procedure, PROCEDURE_EXT_PROPERTIES.DECOMPOSABLE);
setBooleanProperty(DECOMPOSABLE_PROP, value, false, options);
}
}
Expand All @@ -731,6 +845,17 @@ private String getProcedureOptions(Procedure procedure) {
options.add(REST_METHOD, value, null);
}

// Need to check with other assistants too
try {
Map<String, String> props = getOptionsForObject(procedure);
for( String key : props.keySet() ) {
String value = props.get(key);
options.add(key, value, null);
}
} catch (Exception e) {
issues.add(new Status(IStatus.ERROR, TransformationPlugin.PLUGIN_ID, "Error finding options for " + getName(procedure), e)); //$NON-NLS-1$
}

return options.toString();
}

Expand Down

0 comments on commit 45a83cf

Please sign in to comment.