* 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();
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("Invalid name in source sequence format. Expected <element name>" + SEQUENCE + "<sequence name>.<sequence value>, but was " + name); //$NON-NLS-1$ //$NON-NLS-2$
}
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);
}
}