public static boolean saveDefinitionToFile(CSVRelationDefinition rdef, String fkDefFileName) { BufferedWriter out = null; boolean saveSuccess = false; try { out = new BufferedWriter(new FileWriter(fkDefFileName, true)); String[] columns = new String[10]; columns[IDX_FKT_SCHEMA] = rdef.getFktSchema(); columns[IDX_FKT_NAME] = rdef.getFktName(); columns[IDX_FKT_COLUMN] = rdef.getFktColumnName(); columns[IDX_PKT_SCHEMA] = rdef.getPktSchema(); columns[IDX_PKT_NAME] = rdef.getPktName(); columns[IDX_PKT_COLUMN] = rdef.getPktColumnName(); String[] split = rdef.getJoinType().split(" "); columns[IDX_JOIN_TYPE] = split[0]; columns[IDX_PK_TABLE_ALIAS] = rdef.getPktAlias(); columns[IDX_RELATION] = rdef.getPkName(); columns[IDX_REL_COMMENT] = rdef.getComment(); StringBuilder builder = new StringBuilder(); for (int i = 0; i < 10; i++) { if (null == columns[i]) { columns[i] = ""; } } builder.append(columns[0]); for (int i = 1; i < 10; i++) { builder.append(CSV_SEPARATOR); builder.append(columns[i]); } builder.append("\n"); out.write(builder.toString()); saveSuccess = true; } catch (FileNotFoundException e) { saveSuccess = false; Application.println(e, true); e.printStackTrace(); } catch (IOException e) { saveSuccess = false; Application.println(e, true); e.printStackTrace(); } finally { try { if (out != null) { out.close(); } } catch (IOException e) { e.printStackTrace(); } } return saveSuccess; }
public ManualDBMetaData(String fkDefFileName) { this.fkDefFileName = fkDefFileName; BufferedReader in = null; try { in = new BufferedReader(new FileReader(fkDefFileName)); String row = null; while ((row = in.readLine()) != null) { if (row.trim().isEmpty()) { continue; } String[] columns = row.split(CSV_SEPARATOR); String fktSchema = columns[IDX_FKT_SCHEMA]; String fktName = columns[IDX_FKT_NAME]; String fktColumn = columns[IDX_FKT_COLUMN]; String pktSchema = columns[IDX_PKT_SCHEMA]; String pktName = columns[IDX_PKT_NAME]; String pktColumn = columns[IDX_PKT_COLUMN]; String joinType = columns[IDX_JOIN_TYPE]; String pktAlias = columns[IDX_PK_TABLE_ALIAS]; String pkName = columns[IDX_RELATION]; String fkName = pkName; String comment = null; if (columns.length > 9) { comment = columns[IDX_REL_COMMENT]; } if (pktSchema.isEmpty()) { pktSchema = ""; } if (fktSchema.isEmpty()) { fktSchema = ""; } CSVRelationDefinition rdef = new CSVRelationDefinition(); rdef.setPktSchema(pktSchema); rdef.setPktName(pktName); rdef.setPktColumnName(pktColumn); rdef.setFktSchema(fktSchema); rdef.setFktName(fktName); rdef.setFktColumnName(fktColumn); rdef.setPktAlias(pktAlias); rdef.setJoinType(getSQLJoinType(joinType)); rdef.setComment(comment != null ? comment : ""); rdef.setFkName(fkName); rdef.setPkName(pkName); updateMap(rdef); } } catch (FileNotFoundException e) { Application.println(e, true); e.printStackTrace(); } catch (IOException e) { Application.println(e, true); e.printStackTrace(); } finally { try { if (in != null) { in.close(); } } catch (IOException e) { e.printStackTrace(); } } }