@Override public Collection<Column> getColumns() { Collection<Column> columns = table.getColumns(); List<Column> result = new ArrayList<Column>(columns.size()); for (Column column : columns) { result.add(new Column(column, this)); } return result; }
protected void postProcessDelete() { Delete delete = new Delete(table); String wheres = table.getColumns() .stream() .filter(col -> Model.MAIN_KEY.equals(col.getKey())) .map(col -> col.getQuotedName() + " = ?") .collect(Collectors.joining(" AND ")); delete.setWhere(wheres); deleteSqlMap.put(tableName, delete.getStatement()); }
@Override public int getTableSize(String tableName) { return sqlInfo.getDatabase().getTable(tableName).getColumns().size(); }
public Set<Column> getMissingColumns(Boolean breakAtFirstMissing) { try { Set<Column> missingColumns = new HashSet<>(); // Test whether there are new fields added in the schema that are // not present in the table schema. If so it is advised to // reinitialise the database. Set<String> columnNames = getPhysicalColumns(); // check the field names match the column names (case-insensitive) for (Column column : table.getColumns()) { // TODO: check types as well String fieldName = column.getPhysicalName(); if (!columnNames.contains(fieldName)) { log.debug(String.format("required field: %s is missing", fieldName)); missingColumns.add(column); if (breakAtFirstMissing) { return null; } } } return missingColumns; } catch (SQLException e) { log.warn("error while introspecting table: " + tableName, e); return null; } }
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); }
/** * Tables created for directories don't need a clustered column automatically defined. */ protected boolean needsClusteredColumn(Table table) { if (idType == DialectIdType.SEQUENCE) { // good enough for a clustered index // no need to add another column return false; } for (Column col : table.getColumns()) { if (col.getType().isId()) { return true; } } return false; }
Delete delete = new Delete(table); String where = null; for (Column column : table.getColumns()) { if (column.getKey().equals(Model.MAIN_KEY)) { StringBuilder buf = new StringBuilder();
List<String> whats = new LinkedList<>(); List<Column> opaqueColumns = new LinkedList<>(); for (Column column : table.getColumns()) { if (column.isOpaque()) { opaqueColumns.add(column);
List<String> whats = new LinkedList<>(); List<String> wheres = new LinkedList<>(); for (Column column : table.getColumns()) { String qname = fullQuotedName ? column.getFullQuotedName() : column.getQuotedName(); if (freeColumnsList.contains(column.getKey())) {
public SQLInfoSelect getCopyHier(boolean explicitName, boolean resetVersion) { Table table = database.getTable(Model.HIER_TABLE_NAME); Collection<Column> columns = table.getColumns(); List<String> selectWhats = new ArrayList<>(columns.size()); List<Column> selectWhatColumns = new ArrayList<>(5);
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); }
protected void postProcessRootIdSelect() { String what = null; String where = null; for (Column column : table.getColumns()) { String key = column.getKey(); String qname = column.getQuotedName(); if (key.equals(Model.MAIN_KEY)) { what = qname; selectRootIdWhatColumn = column; } else if (key.equals(Model.REPOINFO_REPONAME_KEY)) { where = qname + " = ?"; } else { throw new RuntimeException(column.toString()); } } Select select = new Select(table); select.setWhat(what); select.setFrom(table.getQuotedName()); select.setWhere(where); selectRootIdSql = select.getStatement(); }
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; }
for (Column column : table.getColumns()) { String upperName = column.getPhysicalName().toUpperCase(); Integer type = columnTypes.remove(upperName);
List<Column> columnList = new ArrayList<>(table.getColumns()); Column idColumn = null; for (Iterator<Column> i = columnList.iterator(); i.hasNext();) {
schema.addField(targetColumn, StringType.INSTANCE, null, 0, Collections.emptySet()); Insert insert = new Insert(table); for (Column column : table.getColumns()) { insert.addColumn(column);