Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
droettig committed Jan 12, 2010
1 parent a4818f6 commit 1b81d87
Show file tree
Hide file tree
Showing 3 changed files with 5,487 additions and 58 deletions.
76 changes: 18 additions & 58 deletions src/de/uni_tuebingen/wsi/ct/slang2/dbc/server/DBC_Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,13 @@ public synchronized Chapter loadChapter(Integer chapterID) throws Exception
/*
* TODO: Der Rückgabewert sollte nur die Chapter ID sein, da alles andere gleich bleibt. (CAVE: Vermutung)
*/
public synchronized Chapter saveChapter( Chapter chapter ) throws DBC_SaveException, SQLException
public synchronized Chapter saveChapter(Chapter chapter) throws DBC_SaveException, SQLException
{

if (chapter == null)
{
throw new NullPointerException();
}

logger.entering(DBC_Server.class.getName(), "saveChapter", chapter);

Expand Down Expand Up @@ -658,34 +661,20 @@ public synchronized Chapter saveChapter( Chapter chapter ) throws DBC_SaveExcept

Vector words = chapter.getWords();
logger.info("Speichere " + words.size() + " W\u00f6rter");
Word word;


for (int i = 0; i < words.size(); i++)
{
word = (Word) words.get(i);

stmt = null;

Word word = (Word) words.get(i);

if (word.getDB_ID() == -1)
{
// Insert word first if not exists
stmt = connection.prepareStatement("INSERT IGNORE INTO words " + "(content, language) "
+ "VALUES(?, ?)", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

byte[] content = new byte[0];
content = word.getContent().getBytes("ISO-8859-1");
int contentAsInt = 0;
for (int j = 0; j < content.length; j++) {
int n = (content[j] < 0 ? (int)content[j] + 256 : (int)content[j]) << (8 * j);
contentAsInt += n;
}
stmt.setInt(1, contentAsInt);
// stmt.setBytes(1, word.getContent().getBytes("ISO-8859-1"));
stmt.setBytes(1, word.getContent().getBytes("ISO-8859-1"));
stmt.setString(2, word.getLanguage());
stmt.executeUpdate();
res = stmt.getGeneratedKeys();

Integer.valueOf(word.getContent());

int wordId = 0;
if (res.next())
Expand All @@ -696,16 +685,7 @@ public synchronized Chapter saveChapter( Chapter chapter ) throws DBC_SaveExcept
{
stmt = connection.prepareStatement("SELECT id FROM words WHERE content = ? AND language = ?",
ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

byte[] pro1 = word.getContent().getBytes("ISO-8859-1");
int proAsInt1 = 0;
for (int j = 0; j < pro1.length; j++) {
int n = (pro1[j] < 0 ? (int)pro1[j] + 256 : (int)pro1[j]) << (8 * j);
proAsInt1 += n;
}
stmt.setInt(1, proAsInt1);

// stmt.setBytes(1, word.getContent().getBytes("ISO-8859-1"));
stmt.setBytes(1, word.getContent().getBytes("ISO-8859-1"));
stmt.setString(2, word.getLanguage());

res = stmt.executeQuery();
Expand Down Expand Up @@ -743,6 +723,8 @@ public synchronized Chapter saveChapter( Chapter chapter ) throws DBC_SaveExcept
{
logger.finer("-");
}

stmt.close();
}

Vector signs = chapter.getSigns();
Expand All @@ -751,11 +733,9 @@ public synchronized Chapter saveChapter( Chapter chapter ) throws DBC_SaveExcept

stmt = connection.prepareStatement("INSERT IGNORE INTO signs (sign) VALUES(?)");

Sign sign;

for (int i = 0; i < signs.size(); i++)
{
sign = (Sign) signs.get(i);
Sign sign = (Sign) signs.get(i);
if (sign.getDB_ID() == -1)
{
stmt.setString(1, sign.getContent());
Expand All @@ -766,11 +746,10 @@ public synchronized Chapter saveChapter( Chapter chapter ) throws DBC_SaveExcept

// setze entsprechende DB Id im Objekt
stmt = connection.prepareStatement("SELECT id FROM signs WHERE sign = ?");
sign = null;


for (int i = 0; i < signs.size(); i++)
{
sign = (Sign) signs.get(i);
Sign sign = (Sign) signs.get(i);

if (sign.getDB_ID() == -1)
{
Expand All @@ -795,11 +774,9 @@ public synchronized Chapter saveChapter( Chapter chapter ) throws DBC_SaveExcept
stmt = connection
.prepareStatement("INSERT INTO signs_in_chapter (chapter, sign, position) VALUES(?, ?, ?)");

sign = null;

for (int i = 0; i < signs.size(); i++)
{
sign = (Sign) signs.get(i);
Sign sign = (Sign) signs.get(i);

stmt.setInt(1, sign.getChapter().getDB_ID());
stmt.setInt(2, sign.getDB_ID());
Expand All @@ -814,11 +791,9 @@ public synchronized Chapter saveChapter( Chapter chapter ) throws DBC_SaveExcept

stmt = connection.prepareStatement("INSERT INTO paragraphs_in_chapter (chapter, position) VALUES (?, ?)");

Integer p;

for (int i = 0; i < paragraphs.size(); i++)
{
p = (Integer) paragraphs.get(i);
Integer p = (Integer) paragraphs.get(i);
stmt.setInt(1, chapter.getDB_ID());
stmt.setInt(2, p.intValue());
stmt.addBatch();
Expand All @@ -839,11 +814,9 @@ public synchronized Chapter saveChapter( Chapter chapter ) throws DBC_SaveExcept
stmt = connection
.prepareStatement("INSERT INTO illocution_units (chapter, start, end, kriterium) VALUES (?, ?, ?, ?)");

IllocutionUnit iu;

for (int i = 0; i < ius.size(); i++)
{
iu = (IllocutionUnit) ius.get(i);
IllocutionUnit iu = (IllocutionUnit) ius.get(i);
stmt.setInt(1, chapter.getDB_ID());
stmt.setInt(2, iu.getStartPosition());
stmt.setInt(3, iu.getEndPosition());
Expand All @@ -854,12 +827,9 @@ public synchronized Chapter saveChapter( Chapter chapter ) throws DBC_SaveExcept

stmt = connection
.prepareStatement("SELECT id FROM illocution_units WHERE chapter = ? AND start = ? AND end = ? AND kriterium = ?");

iu = null;

for (int i = 0; i < ius.size(); i++)
{
iu = (IllocutionUnit) ius.get(i);
IllocutionUnit iu = (IllocutionUnit) ius.get(i);
stmt.setInt(1, chapter.getDB_ID());
stmt.setInt(2, iu.getStartPosition());
stmt.setInt(3, iu.getEndPosition());
Expand Down Expand Up @@ -933,16 +903,6 @@ public synchronized void deleteChapter(Integer chapterID)
}
}

public synchronized void deleteBook( Integer bookID ) throws Exception
{
Statement stmt = connection.createStatement();
ResultSet res = stmt.executeQuery("SELECT * " + "FROM books WHERE id = " + bookID);
if (res.next())
{
stmt.execute("delete FROM chapters WHERE book = " + bookID);
stmt.execute("delete FROM books WHERE id = " + bookID);
}
}
/**
* Laedt alle Direkten Reden aus der Datenbank, die zu diesem Kapitel
* gespeichert wurden.
Expand Down
Loading

0 comments on commit 1b81d87

Please sign in to comment.