List of usage examples for java.util Hashtable clear
public synchronized void clear()
From source file:edu.ku.brc.specify.conversion.GenericDBConversion.java
/** * @param rsmd/*from w w w. j ava 2 s . c om*/ * @param map * @param tableNames * @throws SQLException */ protected void buildIndexMapFromMetaData(final ResultSetMetaData rsmd, final List<String> origList, final Hashtable<String, Integer> map) throws SQLException { map.clear(); StringBuilder sb = new StringBuilder(); for (int i = 1; i <= rsmd.getColumnCount(); i++) { sb.setLength(0); String tableName = rsmd.getTableName(i); String fieldName = rsmd.getColumnName(i); if (isNotEmpty(tableName)) { sb.append(tableName); } else { for (String fullName : origList) { String[] parts = split(fullName, "."); if (parts[1].equals(fieldName)) { sb.append(parts[0]); break; } } } sb.append("."); sb.append(fieldName); // log.info("["+strBuf.toString()+"] "+i); map.put(sb.toString(), i); } }
From source file:edu.ku.brc.specify.conversion.GenericDBConversion.java
/** * @param rsmd//from w w w . j a v a2 s.co m * @param map * @param tableNames * @throws SQLException */ protected void buildIndexMapFromMetaData(final ResultSetMetaData rsmd, final Hashtable<String, Integer> map, final String[] tableNames) throws SQLException { map.clear(); // Find the missing table name by figuring our which one isn't used. Hashtable<String, Boolean> existsMap = new Hashtable<String, Boolean>(); for (String tblName : tableNames) { existsMap.put(tblName, true); log.debug("[" + tblName + "]"); } for (int i = 1; i <= rsmd.getColumnCount(); i++) { String tableName = rsmd.getTableName(i); // log.info("["+tableName+"]"); if (isNotEmpty(tableName)) { if (existsMap.get(tableName) != null) { existsMap.remove(tableName); log.info("Removing Table Name[" + tableName + "]"); } } } String missingTableName = null; if (existsMap.size() == 1) { missingTableName = existsMap.keys().nextElement(); log.info("Missing Table Name[" + missingTableName + "]"); } else if (existsMap.size() > 1) { throw new RuntimeException("ExistsMap cannot have more than one name in it!"); } else { log.info("No Missing Table Names."); } for (int i = 1; i <= rsmd.getColumnCount(); i++) { strBuf.setLength(0); String tableName = rsmd.getTableName(i); strBuf.append(isNotEmpty(tableName) ? tableName : missingTableName); strBuf.append("."); strBuf.append(rsmd.getColumnName(i)); map.put(strBuf.toString(), i); } }
From source file:base.BasePlayer.FileRead.java
public ArrayList<Gene> getExons(String chrom) { ArrayList<Gene> transcriptsTemp = new ArrayList<Gene>(); try {//from w ww .j av a2s .c om if (Main.genomehash.size() == 0 || Main.genomehash.get(Main.defaultGenome).size() == 0) { return new ArrayList<Gene>(); } if (ChromDraw.exonReader != null) { ChromDraw.exonReader.close(); } ChromDraw.exonReader = new TabixReader( Main.genomehash.get(Main.defaultGenome).get(Main.annotation).getCanonicalPath()); if (chrom == null) { return null; } TabixReader.Iterator exonIterator = null; try { if (!ChromDraw.exonReader.getChromosomes().contains(chrom)) { String[] gene = { Main.chromosomeDropdown.getSelectedItem().toString(), "1", "" + Main.drawCanvas.splits.get(0).chromEnd, Main.chromosomeDropdown.getSelectedItem().toString(), "1", "+", "-", "-", "-", "-", "-", "1", "1", "1", "" + Main.drawCanvas.splits.get(0).chromEnd, "-1,", "-" }; Gene addGene = new Gene(gene); Transcript addtrans = null; try { addtrans = new Transcript(gene); } catch (Exception e) { e.printStackTrace(); } addGene.addTranscript(addtrans); addGene.setLongest(addtrans); addtrans.setGene(addGene); transcriptsTemp.add(addGene); return transcriptsTemp; //return new ArrayList<Gene>(); } else { exonIterator = ChromDraw.exonReader.query(chrom); } } catch (Exception e) { try { if (chrom.matches("\\w+")) { exonIterator = ChromDraw.exonReader.query("M"); } } catch (Exception ex) { System.out.println(chrom); e.printStackTrace(); } } String s; String[] exonSplit; Transcript addtrans = null; Hashtable<String, Gene> genes = new Hashtable<String, Gene>(); Gene setGene; while (exonIterator != null && (s = exonIterator.next()) != null) { exonSplit = s.split("\t"); if (exonSplit[0].equals("23")) { exonSplit[0] = "X"; } else if (exonSplit[0].equals("24")) { exonSplit[0] = "Y"; } else if (exonSplit[0].equals("25")) { exonSplit[0] = "MT"; } addtrans = new Transcript(exonSplit); if (!genes.containsKey(exonSplit[6])) { Gene addgene = new Gene(exonSplit); genes.put(exonSplit[6], addgene); addgene.addTranscript(addtrans); addgene.setLongest(addtrans); addtrans.setGene(addgene); transcriptsTemp.add(addgene); } else { setGene = genes.get(exonSplit[6]); setGene.addTranscript(addtrans); addtrans.setGene(setGene); if (addtrans.getLength() > setGene.getLongest().getLength()) { setGene.setLongest(addtrans); } } } genes.clear(); ChromDraw.exonReader.close(); } catch (Exception e) { ErrorLog.addError(e.getStackTrace()); e.printStackTrace(); } return transcriptsTemp; }
From source file:edu.ku.brc.specify.conversion.GenericDBConversion.java
/** * @param tableName//from ww w . ja v a2 s.c om */ protected void convertLocalityExtraInfo(final String tableName, final boolean isGeoCoordDetail) { removeForeignKeyConstraints(newDBConn, BasicSQLUtils.myDestinationServerType); String capName = capitalize(tableName); TableWriter tblWriter = convLogger.getWriter(capName + ".html", capName); setTblWriter(tblWriter); IdHashMapper.setTblWriter(tblWriter); setDesc("Converting " + capName); List<String> localityDetailNamesTmp = getFieldNamesFromSchema(newDBConn, tableName); List<String> localityDetailNames = new ArrayList<String>(); Hashtable<String, Boolean> nameHash = new Hashtable<String, Boolean>(); for (String fieldName : localityDetailNamesTmp) { localityDetailNames.add(fieldName); nameHash.put(fieldName, true); System.out.println("[" + fieldName + "]"); } String fieldList = buildSelectFieldList(localityDetailNames, null); log.info(fieldList); IdMapperIFace locIdMapper = idMapperMgr.get("locality", "LocalityID"); IdMapperIFace agtIdMapper = idMapperMgr.get("agent", "AgentID"); Statement updateStatement = null; try { updateStatement = newDBConn.createStatement(); Hashtable<String, Boolean> usedFieldHash = new Hashtable<String, Boolean>(); Statement stmt = oldDBConn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); stmt.setFetchSize(Integer.MIN_VALUE); Integer countRows = getCount( "select count(LocalityID) from locality,geography where locality.GeographyID = geography.GeographyID"); if (countRows != null) { frame.setProcess(0, countRows); } ResultSet rs = stmt.executeQuery( "select locality.*,geography.* from locality LEFT JOIN geography on locality.GeographyID = geography.GeographyID "); StringBuilder colSQL = new StringBuilder(); StringBuilder valuesSQL = new StringBuilder(); int rows = 0; while (rs.next()) { usedFieldHash.clear(); valuesSQL.setLength(0); boolean hasData = false; ResultSetMetaData metaData = rs.getMetaData(); int cols = metaData.getColumnCount(); for (int i = 1; i <= cols; i++) { String colName = metaData.getColumnName(i); // Old Column Name if (colName.equals("GeoRefDetBy")) { colName = "AgentID"; } if ((nameHash.get(colName) == null || usedFieldHash.get(colName) != null) && !colName.startsWith("Range")) { if (rows == 0) { log.debug("Skipping[" + colName + "]"); } continue; } usedFieldHash.put(colName, true); if (rows == 0) { System.err.println("[" + colName + "]"); if (colName.equals("Range")) { if (!isGeoCoordDetail) { if (colSQL.length() > 0) colSQL.append(","); colSQL.append("RangeDesc"); } } else if (isGeoCoordDetail) { if (!colName.equals("RangeDirection")) { if (colSQL.length() > 0) colSQL.append(","); colSQL.append(colName); } } else { if (colSQL.length() > 0) colSQL.append(","); colSQL.append(colName); } } String value; if (colName.equals("LocalityID")) { Integer oldId = rs.getInt(i); Integer newId = locIdMapper.get(oldId); if (newId != null) { value = Integer.toString(newId); } else { String msg = "Couldn't map LocalityId oldId[" + rs.getInt(i) + "]"; log.error(msg); tblWriter.logError(msg); value = "NULL"; } } else if (isGeoCoordDetail && colName.equals("GeoRefDetDate")) { Integer dateInt = rs.getInt(i); value = getStrValue(dateInt, "date"); } else if (colName.startsWith("YesNo")) { Integer bool = rs.getInt(i); if (bool == null) { value = "NULL"; } else if (bool == 0) { value = "0"; } else { value = "1"; } } else if (isGeoCoordDetail && colName.equals("AgentID")) { Integer agentID = (Integer) rs.getObject(i); if (agentID != null) { Integer newID = agtIdMapper.get(agentID); if (newID != null) { value = newID.toString(); } else { String msg = "Couldn't map GeoRefDetBY (Agent) oldId[" + agentID + "]"; log.error(msg); tblWriter.logError(msg); value = "NULL"; } } else { value = "NULL"; } } else if (colName.equals("Range") || colName.equals("RangeDirection")) { if (!isGeoCoordDetail) { String range = rs.getString(i); range = escapeStringLiterals(range); if (range != null) { hasData = true; value = "'" + range + "'"; } else { value = "NULL"; } } else { value = null; } } else { Object obj = rs.getObject(i); if (obj != null && !colName.equals("TimestampCreated") && !colName.equals("TimestampModified")) { hasData = true; } /*if (obj instanceof String) { String str = (String)obj; int inx = str.indexOf('\''); if (inx > -1) { obj = escapeStringLiterals(str); } }*/ value = getStrValue(obj); } // log.debug(colName+" ["+value+"]"); if (value != null) { if (valuesSQL.length() > 0) { valuesSQL.append(","); } valuesSQL.append(value); } } if (hasData) { String insertSQL = "INSERT INTO " + tableName + " (" + colSQL.toString() + ", Version, CreatedByAgentID, ModifiedByAgentID) " + " VALUES(" + valuesSQL.toString() + ", 0, " + getCreatorAgentId(null) + "," + getModifiedByAgentId(null) + ")"; /*if (true) { log.info(insertSQL); }*/ try { updateStatement.executeUpdate(insertSQL); updateStatement.clearBatch(); } catch (Exception ex) { System.out.println("isGeoCoordDetail: " + isGeoCoordDetail); System.out.println(insertSQL); ex.printStackTrace(); } } rows++; if (rows % 500 == 0) { frame.setProcess(rows); } } rs.close(); stmt.close(); } catch (Exception ex) { ex.printStackTrace(); } finally { try { updateStatement.close(); } catch (SQLException ex) { ex.printStackTrace(); } } }