protected void postProcessInsert() { // insert (implicitly auto-generated sequences not included) Collection<Column> columns = table.getColumns(); List<Column> insertColumns = new ArrayList<>(columns.size()); Insert insert = new Insert(table); for (Column column : columns) { if (column.isIdentity()) { // identity column is never inserted continue; } insertColumns.add(column); insert.addColumn(column); } insertSqlMap.put(tableName, insert.getStatement()); insertColumnsMap.put(tableName, insertColumns); }
protected void postProcessCopy() { Collection<Column> columns = table.getColumns(); List<String> selectWhats = new ArrayList<>(columns.size()); Column copyIdColumn = table.getColumn(Model.MAIN_KEY); Insert insert = new Insert(table); for (Column column : columns) { if (column.isIdentity()) { // identity column is never copied continue; } insert.addColumn(column); if (column == copyIdColumn) { // explicit value selectWhats.add("?"); } else { // otherwise copy value selectWhats.add(column.getQuotedName()); } } Select select = new Select(table); select.setWhat(String.join(", ", selectWhats)); select.setFrom(table.getQuotedName()); select.setWhere(copyIdColumn.getQuotedName() + " = ?"); insert.setValues(select.getStatement()); copySqlMap.put(tableName, insert.getStatement()); copyIdColumnMap.put(tableName, copyIdColumn); }
Insert insert = new Insert(table); for (Column column : columnList) { insert.addColumn(column); insert.addIdentityColumn(idColumn); String sql = insert.getStatement();
List<String> selectWhats = new ArrayList<>(columns.size()); List<Column> selectWhatColumns = new ArrayList<>(5); Insert insert = new Insert(table); for (Column column : columns) { if (column.isIdentity()) { insert.addColumn(column); String quotedName = column.getQuotedName(); String key = column.getKey(); select.setWhat(String.join(", ", selectWhats)); select.setWhere(whereColumn.getQuotedName() + " = ?"); insert.setValues(select.getStatement()); String sql = insert.getStatement(); return new SQLInfoSelect(sql, selectWhatColumns, Collections.singletonList(whereColumn), null);
protected void postProcessClusterNodes() { Collection<Column> columns = table.getColumns(); Insert insert = new Insert(table); for (Column column : columns) { insert.addColumn(column); } createClusterNodeSql = insert.getStatement(); createClusterNodeColumns = new ArrayList<>(columns); Delete delete = new Delete(table); Column column = table.getColumn(Model.CLUSTER_NODES_NODEID_KEY); delete.setWhere(column.getQuotedName() + " = ?"); deleteClusterNodeSql = delete.getStatement(); deleteClusterNodeColumn = column; }
public void addLink(String sourceId, String targetId, SQLSession session, boolean checkExisting) { // OG: the following query should have avoided the round trips but // does not work for some reason that might be related to a bug in the // JDBC driver: // "INSERT INTO %s (%s, %s) (SELECT ?, ? FROM %s WHERE %s = ? AND %s = // ? HAVING COUNT(*) = 0)", tableName, sourceColumn, targetColumn, // tableName, sourceColumn, targetColumn // first step: check that this link does not exist yet if (checkExisting && exists(sourceId, targetId, session)) { return; } // second step: add the link // "INSERT INTO %s (%s, %s) VALUES (?, ?)", tableName, sourceColumn, targetColumn Insert insert = new Insert(table); insert.addColumn(table.getColumn(sourceColumn)); insert.addColumn(table.getColumn(targetColumn)); String insertSql = insert.getStatement(); if (session.logger.isLogEnabled()) { session.logger.logSQL(insertSql, Arrays.<Serializable> asList(sourceId, targetId)); } try (PreparedStatement ps = session.sqlConnection.prepareStatement(insertSql)) { ps.setString(1, sourceId); ps.setString(2, targetId); ps.execute(); } catch (SQLException e) { throw new DirectoryException(String.format("error adding link from %s to %s", sourceId, targetId), e); } }
schema.addField(sourceColumn, StringType.INSTANCE, null, 0, Collections.emptySet()); schema.addField(targetColumn, StringType.INSTANCE, null, 0, Collections.emptySet()); Insert insert = new Insert(table); for (Column column : table.getColumns()) { insert.addColumn(column); try (PreparedStatement ps = connection.prepareStatement(insert.getStatement())) { Consumer<Map<String, Object>> loader = new Consumer<Map<String, Object>>() { @Override