@Override protected boolean supportsGeneratedKeys(ExecutionContext context, Command command) { if (command instanceof Insert) { Insert insert = (Insert) command; if (insert.getParameterValues() != null) { return false; // bulk inserts result in an exception if keys are flaged for return } } return super.supportsGeneratedKeys(context, command); }
public void handleInsertSequences(Insert insert) throws TranslatorException { /* * If a missing auto_increment column is modeled with name in source indicating that an Oracle Sequence * then pull the Sequence name out of the name in source of the column. */ if (!(insert.getValueSource() instanceof ExpressionValueSource)) { return; } ExpressionValueSource values = (ExpressionValueSource) insert.getValueSource(); if (insert.getTable().getMetadataObject() == null) { return; } List<Column> allElements = insert.getTable().getMetadataObject().getColumns(); if (allElements.size() == values.getValues().size()) { return; } int index = 0; List<ColumnReference> elements = insert.getColumns(); for (Column element : allElements) { if (!element.isAutoIncremented()) { continue; } String name = element.getNameInSource(); int seqIndex = name.indexOf(SEQUENCE); if (seqIndex == -1) { continue; } boolean found = false; while (index < elements.size()) { if (element.equals(elements.get(index).getMetadataObject())) { found = true; break; } index++; } if (found) { continue; } String sequence = name.substring(seqIndex + SEQUENCE.length()); int delimiterIndex = sequence.indexOf(Tokens.DOT); if (delimiterIndex == -1) { throw new TranslatorException( JDBCPlugin.Event.TEIID11017, JDBCPlugin.Util.gs(JDBCPlugin.Event.TEIID11017, SEQUENCE, name)); } String sequenceGroupName = sequence.substring(0, delimiterIndex); String sequenceElementName = sequence.substring(delimiterIndex + 1); NamedTable sequenceGroup = this.getLanguageFactory().createNamedTable(sequenceGroupName, null, null); 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); } }