Oy! Since mike changed the name of the String in the Site object (must've
had a reason for it...) we can't use the Table to insert a new row, so instead we do it manually. git-svn-id: https://samskivert.googlecode.com/svn/trunk@1296 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: JDBCTableSiteIdentifier.java,v 1.5 2003/11/13 01:28:25 ray Exp $
|
// $Id: JDBCTableSiteIdentifier.java,v 1.6 2003/11/13 02:28:52 ray Exp $
|
||||||
//
|
//
|
||||||
// samskivert library - useful routines for java programs
|
// samskivert library - useful routines for java programs
|
||||||
// Copyright (C) 2001 Michael Bayne
|
// Copyright (C) 2001 Michael Bayne
|
||||||
@@ -21,8 +21,9 @@
|
|||||||
package com.samskivert.servlet;
|
package com.samskivert.servlet;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.Statement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
import java.sql.Statement;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -36,11 +37,8 @@ import com.samskivert.io.PersistenceException;
|
|||||||
|
|
||||||
import com.samskivert.jdbc.ConnectionProvider;
|
import com.samskivert.jdbc.ConnectionProvider;
|
||||||
import com.samskivert.jdbc.DatabaseLiaison;
|
import com.samskivert.jdbc.DatabaseLiaison;
|
||||||
import com.samskivert.jdbc.JORARepository;
|
|
||||||
import com.samskivert.jdbc.JDBCUtil;
|
import com.samskivert.jdbc.JDBCUtil;
|
||||||
import com.samskivert.jdbc.SimpleRepository;
|
import com.samskivert.jdbc.SimpleRepository;
|
||||||
import com.samskivert.jdbc.jora.Session;
|
|
||||||
import com.samskivert.jdbc.jora.Table;
|
|
||||||
|
|
||||||
import com.samskivert.util.ArrayUtil;
|
import com.samskivert.util.ArrayUtil;
|
||||||
import com.samskivert.util.HashIntMap;
|
import com.samskivert.util.HashIntMap;
|
||||||
@@ -145,20 +143,13 @@ public class JDBCTableSiteIdentifier implements SiteIdentifier
|
|||||||
* Used to load information from the site database.
|
* Used to load information from the site database.
|
||||||
*/
|
*/
|
||||||
protected class SiteIdentifierRepository
|
protected class SiteIdentifierRepository
|
||||||
extends JORARepository implements SimpleRepository.Operation
|
extends SimpleRepository implements SimpleRepository.Operation
|
||||||
{
|
{
|
||||||
public SiteIdentifierRepository (ConnectionProvider conprov)
|
public SiteIdentifierRepository (ConnectionProvider conprov)
|
||||||
{
|
{
|
||||||
super(conprov, SITE_IDENTIFIER_IDENT);
|
super(conprov, SITE_IDENTIFIER_IDENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// documentation inherited
|
|
||||||
protected void createTables (Session session)
|
|
||||||
{
|
|
||||||
_stable = new Table(
|
|
||||||
Site.class.getName(), "sites", session, "siteId");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void refreshSiteData ()
|
public void refreshSiteData ()
|
||||||
throws PersistenceException
|
throws PersistenceException
|
||||||
{
|
{
|
||||||
@@ -217,17 +208,25 @@ public class JDBCTableSiteIdentifier implements SiteIdentifier
|
|||||||
public Object invoke (Connection conn, DatabaseLiaison liaison)
|
public Object invoke (Connection conn, DatabaseLiaison liaison)
|
||||||
throws PersistenceException, SQLException
|
throws PersistenceException, SQLException
|
||||||
{
|
{
|
||||||
_stable.insert(site);
|
PreparedStatement stmt = null;
|
||||||
// update the userid now that it's known
|
try {
|
||||||
site.siteId = liaison.lastInsertedId(conn);
|
stmt = conn.prepareStatement(
|
||||||
// nothing to return
|
"insert into sites (stringId) VALUES (?)");
|
||||||
|
stmt.setString(1, site.siteString);
|
||||||
|
if (1 != stmt.executeUpdate()) {
|
||||||
|
throw new PersistenceException("Not inserted");
|
||||||
|
}
|
||||||
|
|
||||||
|
site.siteId = liaison.lastInsertedId(conn);
|
||||||
|
System.err.println("site id inserted was " + site.siteId);
|
||||||
|
} finally {
|
||||||
|
JDBCUtil.close(stmt);
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** A wrapper that provides access to the sites table. */
|
|
||||||
protected Table _stable;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user