Skip to content
Snippets Groups Projects
Commit 76527fea authored by tjc's avatar tjc
Browse files

move to using ByteBuffer

git-svn-id: svn+ssh://svn.internal.sanger.ac.uk/repos/svn/pathsoft/artemis/trunk@3775 ee4ac58c-ac51-4696-9907-e4b3aa274f04
parent fe824fd3
No related branches found
No related tags found
No related merge requests found
/* DatabaseDocument.java
*
* created: Fri Dec 18 1998
* created: 2005
*
* This file is part of Artemis
*
* Copyright (C) 1998,1999,2000 Genome Research Limited
* Copyright (C) 2005 Genome Research Limited
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
......@@ -50,8 +50,8 @@ public class DatabaseDocument extends Document
private Vector organism;
private String sqlLog = System.getProperty("user.home")+
System.getProperty("file.separator")+"art_sql_debug.log";
private StringBuffer[] gff_buffer;
private StringBuffer gff_buff;
private ByteBuffer[] gff_buffer;
private ByteBuffer gff_buff;
private String[] types = { "exon", "gene", "CDS", "transcript" };
private boolean splitGFFEntry;
......@@ -92,7 +92,7 @@ public class DatabaseDocument extends Document
}
public DatabaseDocument(String location, String feature_id,
StringBuffer gff_buff, String name)
ByteBuffer gff_buff, String name)
{
super(location);
this.feature_id = feature_id;
......@@ -192,7 +192,7 @@ public class DatabaseDocument extends Document
if(gff_buff != null)
{
instream = new ByteArrayInputStream(gff_buff.toString().getBytes());
instream = new ByteArrayInputStream(gff_buff.getBytes());
return instream;
}
......@@ -202,19 +202,27 @@ public class DatabaseDocument extends Document
System.out.println("Connected");
gff_buffer = getGFF(conn,feature_id);
String entry;
ByteBuffer entry = new ByteBuffer();
if(splitGFFEntry)
entry = gff_buffer[0] + getSequence(conn);
{
if(gff_buffer[0].size() > 0)
entry.append(gff_buffer[0]);
getSequence(conn, entry);
}
else
{
entry = new String();
for(int i=0; i<gff_buffer.length; i++)
entry = entry + gff_buffer[i];
entry = entry + getSequence(conn);
{
if(gff_buffer[i].size() > 0)
entry.append(gff_buffer[i]);
}
getSequence(conn, entry);
}
appendToLogFile(entry,sqlLog);
// if(System.getProperty("debug") != null)
// appendToLogFile(new String(entry.getBytes()),sqlLog);
instream = new ByteArrayInputStream(entry.getBytes());
conn.close();
......@@ -231,16 +239,28 @@ public class DatabaseDocument extends Document
public DatabaseDocument[] getGffDocuments(String location, String id)
{
DatabaseDocument[] new_docs = new DatabaseDocument[gff_buffer.length-1];
int nentries = 0;
for(int i=1; i<gff_buffer.length; i++)
{
if(gff_buffer[i].size() > 0)
nentries++;
}
DatabaseDocument[] new_docs = new DatabaseDocument[nentries];
nentries = 0;
for(int i=1; i<gff_buffer.length; i++)
{
if(gff_buffer[i].size() == 0)
continue;
String name;
if(i >= types.length)
name = "other";
else
name = types[i];
new_docs[i-1] = new DatabaseDocument(location, id, gff_buffer[i], name);
new_docs[nentries] = new DatabaseDocument(location, id, gff_buffer[i], name);
nentries++;
}
return new_docs;
......@@ -253,7 +273,7 @@ public class DatabaseDocument extends Document
* in the form of a GFF stream.
*
*/
private StringBuffer[] getGFF(Connection conn, String parentFeatureID)
private ByteBuffer[] getGFF(Connection conn, String parentFeatureID)
throws java.sql.SQLException
{
Statement st = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
......@@ -278,13 +298,13 @@ public class DatabaseDocument extends Document
appendToLogFile(sql,sqlLog);
ResultSet rs = st.executeQuery(sql);
StringBuffer[] buffers = new StringBuffer[types.length+1];
ByteBuffer[] buffers = new ByteBuffer[types.length+1];
for(int i=0; i<buffers.length; i++)
buffers[i] = new StringBuffer();
buffers[i] = new ByteBuffer();
String parentFeature = getFeatureName(parentFeatureID,conn);
Hashtable hstore = new Hashtable();
StringBuffer this_buff;
ByteBuffer this_buff;
while(rs.next())
{
......@@ -422,7 +442,7 @@ public class DatabaseDocument extends Document
}
public String getSequence(Connection conn) throws java.sql.SQLException
public ByteBuffer getSequence(Connection conn, ByteBuffer buff) throws java.sql.SQLException
{
Statement st = conn.createStatement();
String sql = "SELECT name, residues from feature where feature_id = '"+
......@@ -433,8 +453,14 @@ public class DatabaseDocument extends Document
ResultSet rs = st.executeQuery(sql);
rs.next();
name = rs.getString("name");
return "##FASTA\n>" + name + "\n" + rs.getString("residues");
buff.append("##FASTA\n>");
buff.append(rs.getBytes("name"));
buff.append("\n");
buff.append(rs.getBytes("residues"));
return buff;
// return "##FASTA\n>" + name + "\n" + rs.getString("residues");
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment