public void visit(Insert obj) { visitNode(obj.getTable()); visitNodes(obj.getColumns()); if (!(obj.getValueSource() instanceof QueryExpression) || visitSubcommands) { visitNode(obj.getValueSource()); } }
public Insert createInsert(NamedTable group, List<ColumnReference> columns, InsertValueSource valueSource) { return new Insert(group, columns, valueSource); }
@Override public void visit(Insert obj) { visitNode(obj.getTable()); visitNodes(obj.getColumns()); if (!(obj.getValueSource() instanceof QueryExpression) && obj.getParameterValues() == null) { visitNode(obj.getValueSource()); } else { // bulk insert values this.values = obj.getParameterValues(); } }
public void visit(Insert obj) { if (obj.isUpsert()) { buffer.append(getUpsertKeyword()).append(Tokens.SPACE); } else { buffer.append(getInsertKeyword()).append(Tokens.SPACE); } appendSourceComment(obj); buffer.append(INTO).append(Tokens.SPACE); append(obj.getTable()); buffer.append(Tokens.SPACE).append(Tokens.LPAREN); this.shortNameOnly = true; append(obj.getColumns()); this.shortNameOnly = false; buffer.append(Tokens.RPAREN); buffer.append(Tokens.SPACE); append(obj.getValueSource()); }
private void buildSingleRowInsertPayload(Insert insert, DataPayload data) throws TranslatorException { List<ColumnReference> columns = insert.getColumns(); List<Expression> values = ((ExpressionValueSource)insert.getValueSource()).getValues(); if(columns.size() != values.size()) { throw new TranslatorException(SalesForcePlugin.Util.gs(SalesForcePlugin.Event.TEIID13006)); } for(int i = 0; i < columns.size(); i++) { Column column = columns.get(i).getMetadataObject(); Object value = values.get(i); if(!(value instanceof Literal)) { throw new TranslatorException(SalesForcePlugin.Util.gs(SalesForcePlugin.Event.TEIID13007)); } Literal literalValue = (Literal)values.get(i); Object val = literalValue.getValue(); if (val instanceof Timestamp) { Calendar cal = Calendar.getInstance(); cal.setTime((Timestamp)val); val = cal; } data.addField(column.getSourceName(), val); } }
public void testGetValues() throws Exception { Insert insert = example("a.b"); //$NON-NLS-1$ assertNotNull(insert.getValueSource()); assertEquals(4, ((ExpressionValueSource)insert.getValueSource()).getValues().size()); for (Iterator i = ((ExpressionValueSource)insert.getValueSource()).getValues().iterator(); i.hasNext();) { assertTrue(i.next() instanceof Expression); } }
@Override public void visit(Insert insert) { super.visit(insert); try { loadColumnMetadata(insert.getTable()); } catch (TranslatorException ce) { exceptions.add(ce); } } }
org.teiid.language.Insert result = new org.teiid.language.Insert(translate(insert.getGroup()), translatedElements, valueSource); result.setParameterValues(parameterValues); setBatchValues(result); result.setUpsert(insert.isUpsert()); return result;
public void testGetElements() throws Exception { Insert insert = example("a.b"); //$NON-NLS-1$ assertNotNull(insert.getColumns()); assertEquals(4, insert.getColumns().size()); // verify that elements are not qualified by group String sInsertSQL = insert.toString(); assertTrue(sInsertSQL.substring(sInsertSQL.indexOf('(')).indexOf( '.') == -1 ); }
private void loadTempTable(List<ColumnReference> cols, List<Expression> params, String tableName, NamedTable table, List<? extends List<?>> vals) throws TranslatorException, SQLException { LogManager.logDetail(LogConstants.CTX_CONNECTOR, "loading temporary table", tableName, "with", vals.size(), "rows"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ ExpressionValueSource evs = new ExpressionValueSource(params); for (ColumnReference col : cols) { col.setMetadataObject(null); //we don't want to confuse the insert handling } Insert insert = new Insert(table, cols, evs); insert.setParameterValues(vals.iterator()); JDBCUpdateExecution ex = this.executionFactory.createUpdateExecution(insert, context, context.getRuntimeMetadata(), getConnection()); int size = this.executionFactory.getMaxDependentInPredicates() * this.executionFactory.getMaxInCriteriaSize() / cols.size(); ex.setMaxPreparedInsertBatchSize(Math.max(size, this.executionFactory.getMaxPreparedInsertBatchSize())); ex.setAtomic(false); ex.execute(); ex.statement.close(); this.executionFactory.loadedTemporaryTable(tableName, this.context, this.connection); }
@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); }
@Override public void execute() throws TranslatorException { Insert insert = (Insert)command; if (insert.getParameterValues() == null) { DataPayload data = new DataPayload(); data.setType(this.objectName); buildSingleRowInsertPayload(insert, data); if (insert.isUpsert()) { result = getConnection().upsert(data); } else { this.activeJob = getConnection().createBulkJob(this.objectName, insert.isUpsert()?OperationEnum.upsert:OperationEnum.insert, false); counts = new ArrayList<Integer>();
public void testExpressionsInInsert() throws Exception { Insert insert = example2("a.b"); //$NON-NLS-1$ assertNotNull(insert.getColumns()); assertEquals(1, insert.getColumns().size()); for (Iterator i = insert.getColumns().iterator(); i.hasNext();) { assertTrue(i.next() instanceof ColumnReference); } assertNotNull(insert.getValueSource()); assertEquals(1, ((ExpressionValueSource)insert.getValueSource()).getValues().size()); for (Iterator i = ((ExpressionValueSource)insert.getValueSource()).getValues().iterator(); i.hasNext();) { assertTrue(i.next() instanceof Expression); } }
private void handleInsert() throws TranslatorException { Insert insert = (Insert)command; ExpressionValueSource evs = (ExpressionValueSource)insert.getValueSource(); Row row = nextRow(); Sheet sheet = null; if (row == null) { sheet = workbook.getSheet(this.visitor.getSheetName()); } else { sheet = row.getSheet(); } int last = sheet.getLastRowNum(); Row newRow = sheet.createRow(last+1); List<Integer> cols = this.visitor.getProjectedColumns(); for (int i = 0; i < cols.size(); i++) { int index = cols.get(i); setValue(newRow, index-1, ((Literal)evs.getValues().get(i)).getValue()); } if (executionContext.getCommandContext().isReturnAutoGeneratedKeys()) { GeneratedKeys keys = executionContext.getCommandContext().returnGeneratedKeys(new String[] {ExcelMetadataProcessor.ROW_ID}, new Class<?>[] {TypeFacility.RUNTIME_TYPES.INTEGER}); keys.addKey(Arrays.asList(last+1)); } result++; writeXLSFile(); }
public void testGetGroup() throws Exception { assertNotNull(example("a.b").getTable()); //$NON-NLS-1$ }
org.teiid.language.Insert result = new org.teiid.language.Insert(translate(insert.getGroup()), translatedElements, valueSource); result.setParameterValues(parameterValues); setBatchValues(result); result.setUpsert(insert.isUpsert()); return result;
public InsertExecutionImpl(SalesForceExecutionFactory ef, Command command, SalesforceConnection salesforceConnection, RuntimeMetadata metadata, ExecutionContext context) throws TranslatorException { super(ef, command, salesforceConnection, metadata, context); Insert insert = (Insert)command; if (insert.getParameterValues() != null) { this.rowIter = insert.getParameterValues(); } InsertVisitor visitor = new InsertVisitor(getMetadata()); visitor.visit(insert); this.objectName = visitor.getTableName(); }
@Override public void visit(Insert obj) { visit(obj.getTable()); for (ColumnReference cr : obj.getColumns()) { visit(cr); createProjectedColumn(false); } if (!(obj.getValueSource() instanceof ExpressionValueSource)) { throw new AssertionError(); } for (Expression ex : ((ExpressionValueSource)obj.getValueSource()).getValues()) { if (!(ex instanceof Literal)) { throw new AssertionError(); } } }
protected List<com.sforce.async.SObject> buildBulkRowPayload(Insert insert, Iterator<? extends List<?>> it, int rowCount) throws TranslatorException { List<com.sforce.async.SObject> rows = new ArrayList<com.sforce.async.SObject>(); List<ColumnReference> columns = insert.getColumns(); int boundCount = 0; List<Expression> literalValues = ((ExpressionValueSource)insert.getValueSource()).getValues(); while (it.hasNext()) { if (boundCount >= rowCount) {
if (command instanceof Insert) { Insert insert = (Insert)command; if (insert.getValueSource() instanceof QueryExpression) { QueryExpression qe = (QueryExpression)insert.getValueSource(); if (qe.getWith() != null) { With with = qe.getWith();