/** * @see org.teiid.query.sql.lang.Command#clone() * @since 5.5 */ public Object clone() { Create copy = new Create(); GroupSymbol copyTable = table.clone(); copy.setTable(copyTable); copy.columns = new ArrayList<Column>(columns.size()); for (Column column : columns) { Column copyColumn = new Column(); copyColumn.setName(column.getName()); copyColumn.setRuntimeType(column.getRuntimeType()); copyColumn.setAutoIncremented(column.isAutoIncremented()); copyColumn.setNullType(column.getNullType()); copy.columns.add(copyColumn); } copy.primaryKey = LanguageObject.Util.deepClone(primaryKey, ElementSymbol.class); copyMetadataState(copy); copy.setTableMetadata(this.tableMetadata); copy.on = this.on; copy.commitAction = this.commitAction; return copy; }
public Class<?> expectedType() { return this.column.getJavaType(); }
private Column addColumn(MetadataFactory mf, Table table, Column property, String newName) { Column c = mf.addColumn(newName, property.getRuntimeType(),table); c.setUpdatable(true); c.setNullType(property.getNullType()); c.setLength(property.getLength()); c.setPrecision(property.getPrecision()); c.setScale(property.getScale()); c.setDefaultValue(property.getDefaultValue()); c.setProperty("MIME-TYPE", c.getProperty("MIME-TYPE", false)); c.setProperty(BaseColumn.SPATIAL_SRID, property.getProperty(BaseColumn.SPATIAL_SRID, false)); c.setProperty("NATIVE_TYPE", property.getProperty("NATIVE_TYPE", false)); return c; }
public static void setMultiSourceElementMetadata(Column e) { e.setNullValues(0); e.setNullType(NullType.No_Nulls); e.setSearchType(SearchType.Searchable); e.setUpdatable(true); e.setLength(255); }
private String getColumnName(Column column) { String columnName = column.getName(); // Check if this is a embedded column, if it is then only // add the parent type String columnGroup = column.getProperty(ODataMetadataProcessor.COLUMN_GROUP, false); if (columnGroup != null) { columnName = columnGroup; } return columnName; }
private static void removeColumnOption(String key, Column c) { if (key.equals(DDLConstants.CASE_SENSITIVE)) { c.setCaseSensitive(false); } else if (key.equals(DDLConstants.SELECTABLE)) { c.setSelectable(true); } else if (key.equals(DDLConstants.UPDATABLE)) { c.setUpdatable(false); } else if (key.equals(DDLConstants.SIGNED)) { c.setSigned(false); } else if (key.equals(DDLConstants.CURRENCY)) { c.setSigned(false); } else if (key.equals(DDLConstants.FIXED_LENGTH)) { c.setFixedLength(false); } else if (key.equals(DDLConstants.SEARCHABLE)) { c.setSearchType(null); } else if (key.equals(DDLConstants.MIN_VALUE)) { c.setMinimumValue(null); } else if (key.equals(DDLConstants.MAX_VALUE)) { c.setMaximumValue(null); } else if (key.equals(DDLConstants.CHAR_OCTET_LENGTH)) { c.setCharOctetLength(0); } else if (key.equals(DDLConstants.NULL_VALUE_COUNT)) { c.setNullValues(-1); } else if (key.equals(DDLConstants.DISTINCT_VALUES)) { c.setDistinctValues(-1); } else if (key.equals(DDLConstants.UDT)) { c.setDatatype(null, false, c.getArrayDimensions()); c.setLength(0); c.setPrecision(0); c.setScale(0);
column.setNameInSource(quoteName(columnName)); column.setPrecision(columnSize); column.setScale(scale); //assume that null means 0 column.setLength(columnSize); column.setNativeType(typeName); column.setRadix(columns.getInt(10)); column.setNullType(NullType.values()[columns.getInt(11)]); column.setUpdatable(true); String remarks = columns.getString(12); column.setAnnotation(remarks); String defaultValue = columns.getString(13); column.setDefaultValue(defaultValue); if (defaultValue != null && type == Types.BIT && TypeFacility.RUNTIME_NAMES.BOOLEAN.equals(runtimeType)) { column.setDefaultValue(Boolean.FALSE.toString()); } else if(charIntVal==1) { column.setDefaultValue(Boolean.TRUE.toString()); trimedDefault = defaultValue.substring(1, defaultValue.length() - 1); column.setDefaultValue(trimedDefault); column.setCharOctetLength(columns.getInt(16)); if (rsColumns >= 23) { column.setAutoIncremented("YES".equalsIgnoreCase(columns.getString(23))); //$NON-NLS-1$
private void visit(Table table, Column column) { append(NEWLINE).append(TAB); if (table.getTableType() == Table.Type.TemporaryTable && column.isAutoIncremented() && column.getNullType() == NullType.No_Nulls && column.getJavaType() == DataTypeManager.DefaultDataClasses.INTEGER) { append(SQLStringVisitor.escapeSinglePart(column.getName())); append(SPACE); append(SERIAL); } else { appendColumn(column, true, !table.isVirtual() || !Boolean.valueOf(column.getProperty(MetadataValidator.UNTYPED, false))); if (column.isAutoIncremented()) { append(SPACE).append(AUTO_INCREMENT); } } appendDefault(column); // options appendColumnOptions(column); }
public static Column createElement(String name, ColumnSet<?> group, String type) { Column column = new Column(); column.setName(name); group.addColumn(column); column.setRuntimeType(type); if(type.equals(DataTypeManager.DefaultDataTypes.STRING)) { column.setSearchType(SearchType.Searchable); } else if (DataTypeManager.isNonComparable(type)){ column.setSearchType(SearchType.Unsearchable); } else { column.setSearchType(SearchType.All_Except_Like); } column.setNullType(NullType.Nullable); column.setPosition(group.getColumns().size()); //1 based indexing column.setUpdatable(true); column.setDatatype(SystemMetadata.getInstance().getRuntimeTypeMap().get(type), true, 0); if (DataTypeManager.hasLength(type) && !type.equalsIgnoreCase(DataTypeManager.DefaultDataTypes.CHAR)) { column.setLength(100); } column.setNameInSource(name); return column; }
assertEquals("e1", e1.getName()); assertEquals("integer", e1.getDatatype().getName()); assertEquals("primary key not same", e1, table.getPrimaryKey().getColumns().get(0)); assertEquals("e2", e2.getName()); assertEquals("string", e2.getDatatype().getName()); assertEquals("unique", e2, table.getUniqueKeys().get(0).getColumns().get(0)); assertEquals(NullType.Nullable, e2.getNullType()); assertEquals(10, e2.getLength()); assertEquals(0, e2.getPrecision()); assertEquals("e3", e3.getName()); assertEquals("date", e3.getDatatype().getName()); assertEquals("unique", e3, table.getUniqueKeys().get(1).getColumns().get(0)); assertEquals(NullType.No_Nulls, e3.getNullType()); assertEquals("e4", e4.getName()); assertEquals("bigdecimal", e4.getDatatype().getName()); assertEquals(false, e4.isAutoIncremented()); assertEquals(12, e4.getPrecision()); assertEquals(3, e4.getScale()); assertEquals(SearchType.Unsearchable, e4.getSearchType()); assertEquals("12.2", e4.getDefaultValue()); assertEquals("e5", e5.getName()); assertEquals("integer", e5.getDatatype().getName()); assertEquals(true, e5.isAutoIncremented()); assertEquals("uuid", e5.getUUID()); assertEquals("nis", e5.getNameInSource());
TypeFacility.getDataTypeName(getJavaDataType(attr.getJavaType())), entityTable); if (((SingularAttribute)attr).isOptional()) { column.setDefaultValue(null); column.setNameInSource(String.join(".", attrPath)); DataTypeManager.DefaultDataTypes.STRING, entityTable); if (((SingularAttribute)attr).isOptional()) { column.setDefaultValue(null); column.setNativeType(attr.getJavaType().getName()); column.setNameInSource(String.join(".", attrPath)); ArrayList<String> keys = new ArrayList<String>(); for (Column column:pk.getColumns()) { String fk = attr.getName() + "_" + column.getName(); Column c = addColumn(mf, fk, column.getDatatype().getRuntimeTypeName(), entityTable); c.setProperty(RELATION_PROPERTY, attr.getName()); c.setProperty(RELATION_KEY, column.getName()); c.setNameInSource(column.getNameInSource()); keys.add(fk);
if (baseColumn instanceof Column) { Column column = (Column)baseColumn; if (!column.isSelectable()) { addOption(options, SELECTABLE, column.isSelectable()); if (!column.isUpdatable() && column.getParent() instanceof Table && ((Table)column.getParent()).supportsUpdate()) { addOption(options, UPDATABLE, column.isUpdatable()); if (column.isCurrency()) { addOption(options, CURRENCY, column.isCurrency()); if (!column.isCaseSensitive() && column.getDatatype().isCaseSensitive()) { addOption(options, CASE_SENSITIVE, column.isCaseSensitive()); if (!column.isSigned() && column.getDatatype().isSigned()) { addOption(options, SIGNED, column.isSigned()); if (column.isFixedLength()) { addOption(options, FIXED_LENGTH, column.isFixedLength()); if (column.getCharOctetLength() != 0 && column.getLength() != column.getCharOctetLength()) { addOption(options, CHAR_OCTET_LENGTH, column.getCharOctetLength()); if (column.getSearchType() != null && (!column.getSearchType().equals(column.getDatatype().getSearchType()) || column.isSearchTypeSet())) { addOption(options, SEARCHABLE, column.getSearchType().name()); if (column.getMinimumValue() != null) { addOption(options, MIN_VALUE, column.getMinimumValue());
e2.setLength(10); e3.setNullType(NullType.No_Nulls); SQLParserUtil.setDefault(e3, new Function("current_date", new Expression[0])); e4.setPrecision(12); e4.setScale(3); e5.setAutoIncremented(true); e5.setUUID("uuid"); e5.setNameInSource("nis"); e5.setSelectable(false); e6.setDefaultValue("hello");
@Test public void testUDT() throws Exception { String ddl = "CREATE FOREIGN TABLE G1( e1 integer, e2 varchar OPTIONS (UDT 'NMTOKENS(12,13,11)'))"; Schema s = helpParse(ddl, "model").getSchema(); Map<String, Table> tableMap = s.getTables(); assertTrue("Table not found", tableMap.containsKey("G1")); Table table = tableMap.get("G1"); assertEquals("NMTOKENS", table.getColumns().get(1).getDatatype().getName()); assertEquals(12, table.getColumns().get(1).getLength()); assertEquals(13, table.getColumns().get(1).getPrecision()); assertEquals(11, table.getColumns().get(1).getScale()); }
c.setNullType(property.isNullable() ? NullType.Nullable : NullType.No_Nulls); c.setLength(property.getMaxLength()); c.setPrecision(property.getPrecision()); c.setScale(property.getScale()); c.setDefaultValue(property.getDefaultValue()); c.setProperty("MIME-TYPE", property.getMimeType()); c.setNativeType("Collection("+property.getType()+")"); } else { c.setNativeType(property.getType()); c.setNativeType("Collection("+property.getType()+")");
private void addColumns(List<Column> columns, boolean includeType) { append(LPAREN); boolean first = true; for (Column c:columns) { if (first) { first = false; } else { append(COMMA).append(SPACE); } if (includeType) { appendColumn(c, true, includeType); appendColumnOptions(c); } else if (c.getParent() instanceof KeyRecord) { //function based column append(c.getNameInSource()); } else { append(SQLStringVisitor.escapeSinglePart(c.getName())); } } append(RPAREN); }
for (int i = 0; i < columns.size(); i++) { Column column = columns.get(i); String colName = column.getName(); if (column.getNameInSource() != null) { colName = column.getNameInSource();
if (!element.isAutoIncremented()) { continue; String name = element.getNameInSource(); int seqIndex = name.indexOf(SEQUENCE); if (seqIndex == -1) { if (element.equals(elements.get(index).getMetadataObject())) { found = true; break; ColumnReference sequenceElement = this.getLanguageFactory().createColumnReference(sequenceElementName, sequenceGroup, null, element.getJavaType()); insert.getColumns().add(index, this.getLanguageFactory().createColumnReference(element.getName(), insert.getTable(), element, element.getJavaType())); values.getValues().add(index, sequenceElement);
private static void addColumnAnnotations(Column column, CsdlProperty property, CsdlSchema csdlSchema) { if (column.getAnnotation() != null) { addStringAnnotation(property, "Core.Description", column.getAnnotation()); if (column.getNameInSource() != null) { addStringAnnotation(property, "teiid.NAMEINSOURCE", column.getNameInSource()); if (!column.isSelectable()) { addBooleanAnnotation(property, "teiid.SELECTABLE", column.isSelectable()); if(column.isUpdatable()) { addBooleanAnnotation(property, "teiid.UPDATABLE", column.isUpdatable()); if (column.isCurrency()) { addBooleanAnnotation(property, "teiid.CURRENCY", column.isCurrency()); if (column.isCaseSensitive()) { addBooleanAnnotation(property, "teiid.CASE_SENSITIVE", column.isCaseSensitive()); if (column.isFixedLength()) { addBooleanAnnotation(property, "teiid.FIXED_LENGTH", column.isFixedLength()); if (!column.isSigned()) { addBooleanAnnotation(property, "teiid.SIGNED", column.isSigned()); if (column.getDistinctValues() != -1) { addIntAnnotation(property, "teiid.DISTINCT_VALUES", column.getDistinctValues()); if (column.getNullValues() != -1) {
private List<String> addLinkTableColumns(MetadataFactory mf, Table table, List<String> columnNames, Table linkTable) throws TranslatorException { if (columnNames != null) { for (String columnName:columnNames) { Column column = table.getColumnByName(columnName); if (column == null) { throw new TranslatorException(ODataPlugin.Util.gs(ODataPlugin.Event.TEIID17003, columnName, table.getName())); } column = mf.addColumn(column.getName(), column.getRuntimeType(), linkTable); column.setProperty(JOIN_COLUMN, String.valueOf(true)); } } else { columnNames = new ArrayList<String>(); for (Column column :table.getPrimaryKey().getColumns()) { columnNames.add(column.getName()); if (linkTable.getColumnByName(column.getName()) == null) { column = mf.addColumn(column.getName(), column.getRuntimeType(), linkTable); } column.setProperty(JOIN_COLUMN, String.valueOf(true)); } } return columnNames; }