FieldType fieldType = field.getType();
if(!this.connectorEnv.isModelAuditFields() && isAuditField(field.getName())) {
continue;
}
String sfTypeName = fieldType.value();
Column column = null;
if(sfTypeName.equals(FieldType.STRING) || //string
sfTypeName.equals(FieldType.COMBOBOX) || //"combobox"
sfTypeName.equals(FieldType.REFERENCE) || //"reference"
sfTypeName.equals(FieldType.PHONE) || //"phone"
sfTypeName.equals(FieldType.ID) || //"id"
sfTypeName.equals(FieldType.URL) || //"url"
sfTypeName.equals(FieldType.EMAIL) || //"email"
sfTypeName.equals(FieldType.ENCRYPTEDSTRING) || //"encryptedstring"
sfTypeName.equals(FieldType.ANY_TYPE)) { //"anytype"
column = metadataFactory.addColumn(normalizedName, DataTypeManager.DefaultDataTypes.STRING, table);
column.setNativeType(sfTypeName);
if(sfTypeName.equals(FieldType.ID)) {
column.setNullType(NullType.No_Nulls);
ArrayList<String> columnNames = new ArrayList<String>();
columnNames.add(field.getName());
metadataFactory.addPrimaryKey(field.getName()+"_PK", columnNames, table);
}
}
else if(sfTypeName.equals(FieldType.PICKLIST)) { // "picklist"
column = metadataFactory.addColumn(normalizedName, DataTypeManager.DefaultDataTypes.STRING, table);
if(field.isRestrictedPicklist()) {
column.setNativeType("restrictedpicklist");
} else {
column.setNativeType(sfTypeName);
}
column.setProperty(COLUMN_PICKLIST_VALUES, getPicklistValues(field));
}
else if(sfTypeName.equals(FieldType.MULTIPICKLIST)) { //"multipicklist"
column = metadataFactory.addColumn(normalizedName, DataTypeManager.DefaultDataTypes.STRING, table);
if(field.isRestrictedPicklist()) {
column.setNativeType("restrictedmultiselectpicklist");
} else {
column.setNativeType(sfTypeName);
}
column.setProperty(COLUMN_PICKLIST_VALUES, getPicklistValues(field));
}
else if(sfTypeName.equals(FieldType.BASE_64)) { //"base64"
column = metadataFactory.addColumn(normalizedName, DataTypeManager.DefaultDataTypes.BLOB, table);
column.setNativeType(sfTypeName);
}
else if(sfTypeName.equals(FieldType.BOOLEAN)) { //"boolean"
column = metadataFactory.addColumn(normalizedName, DataTypeManager.DefaultDataTypes.BOOLEAN, table);
column.setNativeType(sfTypeName);
}
else if(sfTypeName.equals(FieldType.CURRENCY)) { //"currency"
column = metadataFactory.addColumn(normalizedName, DataTypeManager.DefaultDataTypes.DOUBLE, table);
column.setNativeType(sfTypeName);
column.setCurrency(true);
column.setScale(field.getScale());
column.setPrecision(field.getPrecision());
}
else if(sfTypeName.equals(FieldType.TEXTAREA)) { //"textarea"
column = metadataFactory.addColumn(normalizedName, DataTypeManager.DefaultDataTypes.STRING, table);
column.setNativeType(sfTypeName);
column.setSearchType(SearchType.Unsearchable);
}
else if(sfTypeName.equals(FieldType.INT)) { //"int"
column = metadataFactory.addColumn(normalizedName, DataTypeManager.DefaultDataTypes.INTEGER, table);
column.setNativeType(sfTypeName);
column.setPrecision(field.getPrecision());
}
else if(sfTypeName.equals(FieldType.DOUBLE) || //"double"
sfTypeName.equals(FieldType.PERCENT)) { //"percent"
column = metadataFactory.addColumn(normalizedName, DataTypeManager.DefaultDataTypes.DOUBLE, table);
column.setNativeType(sfTypeName);
column.setScale(field.getScale());
column.setPrecision(field.getPrecision());
}
else if(sfTypeName.equals(FieldType.DATE)) { //"date"
column = metadataFactory.addColumn(normalizedName, DataTypeManager.DefaultDataTypes.DATE, table);
column.setNativeType(sfTypeName);
}
else if(sfTypeName.equals(FieldType.DATETIME)) { //"datetime"
column = metadataFactory.addColumn(normalizedName, DataTypeManager.DefaultDataTypes.TIMESTAMP, table);
column.setNativeType(sfTypeName);
}
else if(sfTypeName.equals(FieldType.TIME)) { //"time"
column = metadataFactory.addColumn(normalizedName, DataTypeManager.DefaultDataTypes.TIME, table);
column.setNativeType(sfTypeName);
}
if(null == column) {
LogManager.logError(LogConstants.CTX_CONNECTOR, "Unknown type returned by SalesForce: " + sfTypeName);
continue;
} else {
column.setNameInSource(field.getName());
column.setLength(field.getLength());
if(field.isUpdateable()) {
column.setUpdatable(true);
hasUpdateableColumn = true;
}
column.setProperty(COLUMN_CALCULATED, String.valueOf(field.isCalculated()));
column.setProperty(COLUMN_CUSTOM, String.valueOf(field.isCustom()));
column.setProperty(COLUMN_DEFAULTED, String.valueOf(field.isDefaultedOnCreate()));
}
}
}