(Robert Tansley)

- Bitstream file sizes now stored in BIGINT column size_bytes.
  Fixes SF bug #1035366
- Queries involving booleans now have Oracle/PostgreSQL-neutral SQL syntax;
  removes some DB-dependent code from business logic layer


git-svn-id: http://scm.dspace.org/svn/repo/trunk@1374 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Robert Tansley
2005-11-17 19:02:04 +00:00
parent 8a66267869
commit 5a5c51179e
10 changed files with 55 additions and 124 deletions

View File

@@ -1,5 +1,11 @@
1.4 beta 1 1.4 beta 1
========== ==========
(Robert Tansley)
- Bitstream file sizes now stored in BIGINT column size_bytes.
Fixes SF bug #1035366
- Queries involving booleans now have Oracle/PostgreSQL-neutral SQL syntax;
removes some DB-dependent code from business logic layer
(Martin Hald, Larry Stone, Robert Tansley) (Martin Hald, Larry Stone, Robert Tansley)
- Support for multiple (flat) metadata schemas - Support for multiple (flat) metadata schemas

View File

@@ -148,7 +148,7 @@ CREATE TABLE Bitstream
bitstream_id INTEGER PRIMARY KEY, bitstream_id INTEGER PRIMARY KEY,
bitstream_format_id INTEGER REFERENCES BitstreamFormatRegistry(bitstream_format_id), bitstream_format_id INTEGER REFERENCES BitstreamFormatRegistry(bitstream_format_id),
name VARCHAR(256), name VARCHAR(256),
size INTEGER, size_bytes BIGINT,
checksum VARCHAR(64), checksum VARCHAR(64),
checksum_algorithm VARCHAR(32), checksum_algorithm VARCHAR(32),
description TEXT, description TEXT,

View File

@@ -138,3 +138,12 @@ CREATE VIEW dcvalue AS
SELECT setval('metadatafieldregistry_seq', max(metadata_field_id)) FROM metadatafieldregistry; SELECT setval('metadatafieldregistry_seq', max(metadata_field_id)) FROM metadatafieldregistry;
SELECT setval('metadatavalue_seq', max(metadata_value_id)) FROM metadatavalue; SELECT setval('metadatavalue_seq', max(metadata_value_id)) FROM metadatavalue;
SELECT setval('metadataschemaregistry_seq', max(metadata_schema_id)) FROM metadataschemaregistry; SELECT setval('metadataschemaregistry_seq', max(metadata_schema_id)) FROM metadataschemaregistry;
------------------------------------------------------
-- Bitstream table -- increase capacity of file size
-- column, and bring in line with Oracle schema
------------------------------------------------------
ALTER TABLE bitstream ADD COLUMN size_bytes BIGINT;
UPDATE bitstream SET size_bytes = size;
ALTER TABLE bitstream DROP COLUMN size;

View File

@@ -229,8 +229,13 @@ public class DIDLCrosswalk extends Crosswalk
metadata.append("\" encoding=\"base64\">"); metadata.append("\" encoding=\"base64\">");
try try
{ {
/*
byte[] buffer = new byte[bitstreams[k].getSize()]; * Assume that size of in-line bitstreams will always be
* smaller than MAXINT bytes
*/
int intSize = (int) bitstreams[k].getSize();
byte[] buffer = new byte[intSize];
//BufferedInputStream bis=new BufferedInputStream(bitstreams[k].retrieve()); //BufferedInputStream bis=new BufferedInputStream(bitstreams[k].retrieve());
Context contextl= new Context(); Context contextl= new Context();

View File

@@ -355,15 +355,9 @@ public class Bitstream extends DSpaceObject
* *
* @return the size in bytes * @return the size in bytes
*/ */
public int getSize() public long getSize()
{ {
if ("oracle".equals(ConfigurationManager.getProperty("db.name"))) return bRow.getLongColumn("size_bytes");
{
return bRow.getIntColumn("size_bytes");
}
// default is column "size" for postgres
return bRow.getIntColumn("size");
} }
/** /**

View File

@@ -305,21 +305,9 @@ public class BitstreamFormat
{ {
List formats = new ArrayList(); List formats = new ArrayList();
String myQuery = null; String myQuery = "SELECT * FROM bitstreamformatregistry WHERE internal='0' "
+ "AND short_description NOT LIKE 'Unknown' "
if ("oracle".equals(ConfigurationManager.getProperty("db.name"))) + "ORDER BY support_level DESC, short_description";
{
myQuery = "SELECT * FROM bitstreamformatregistry WHERE internal=0 "
+ "AND short_description NOT LIKE 'Unknown' "
+ "ORDER BY support_level DESC, short_description";
}
else
{
// default postgres, use boolean
myQuery = "SELECT * FROM bitstreamformatregistry WHERE internal=false "
+ "AND short_description NOT LIKE 'Unknown' "
+ "ORDER BY support_level DESC, short_description";
}
TableRowIterator tri = DatabaseManager.query(context, TableRowIterator tri = DatabaseManager.query(context,
"bitstreamformatregistry", myQuery); "bitstreamformatregistry", myQuery);

View File

@@ -308,23 +308,10 @@ public class Collection extends DSpaceObject
*/ */
public ItemIterator getItems() throws SQLException public ItemIterator getItems() throws SQLException
{ {
String myQuery = null; String myQuery = "SELECT item.* FROM item, collection2item WHERE "
+ "item.item_id=collection2item.item_id AND "
if ("oracle".equals(ConfigurationManager.getProperty("db.name"))) + "collection2item.collection_id=" + getID()
{ + " AND item.in_archive='1'";
myQuery = "SELECT item.* FROM item, collection2item WHERE "
+ "item.item_id=collection2item.item_id AND "
+ "collection2item.collection_id=" + getID()
+ " AND item.in_archive=1";
}
else
{
// default postgres, use boolean
myQuery = "SELECT item.* FROM item, collection2item WHERE "
+ "item.item_id=collection2item.item_id AND "
+ "collection2item.collection_id=" + getID()
+ " AND item.in_archive=true";
}
TableRowIterator rows = DatabaseManager.query(ourContext, "item", TableRowIterator rows = DatabaseManager.query(ourContext, "item",
myQuery); myQuery);
@@ -1144,19 +1131,15 @@ public class Collection extends DSpaceObject
{ {
Statement statement = ourContext.getDBConnection().createStatement(); Statement statement = ourContext.getDBConnection().createStatement();
final ResultSet rs; final ResultSet rs;
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
rs = statement.executeQuery( rs = statement
"SELECT count(*) FROM collection2item, item WHERE " .executeQuery("SELECT count(*) FROM collection2item, item WHERE "
+ "collection2item.collection_id = " + getID() + "collection2item.collection_id = "
+ " AND collection2item.item_id = item.item_id " + getID()
+ "AND in_archive =1 AND item.withdrawn=0"); + " AND collection2item.item_id = item.item_id "
else + "AND in_archive ='1' AND item.withdrawn='0'");
rs = statement.executeQuery(
"SELECT count(*) FROM collection2item, item WHERE " int itemcount = 0;
+ "collection2item.collection_id = " + getID()
+ " AND collection2item.item_id = item.item_id "
+ "AND in_archive ='t' AND item.withdrawn='f'");
int itemcount = 0;
rs.next(); rs.next();
itemcount = rs.getInt(1); itemcount = rs.getInt(1);

View File

@@ -266,17 +266,7 @@ public class Item extends DSpaceObject
*/ */
public static ItemIterator findAll(Context context) throws SQLException public static ItemIterator findAll(Context context) throws SQLException
{ {
String myQuery = null; String myQuery = "SELECT * FROM item WHERE in_archive='1'";
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
{
myQuery = "SELECT * FROM item WHERE in_archive=1";
}
else
{
// default postgres
myQuery = "SELECT * FROM item WHERE in_archive=true";
}
TableRowIterator rows = DatabaseManager.query(context, "item", myQuery); TableRowIterator rows = DatabaseManager.query(context, "item", myQuery);
@@ -297,19 +287,8 @@ public class Item extends DSpaceObject
public static ItemIterator findBySubmitter(Context context, EPerson eperson) public static ItemIterator findBySubmitter(Context context, EPerson eperson)
throws SQLException throws SQLException
{ {
String myQuery = null; String myQuery = "SELECT * FROM item WHERE in_archive='1' AND submitter_id="
+ eperson.getID();
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
{
myQuery = "SELECT * FROM item WHERE in_archive=1 AND submitter_id="
+ eperson.getID();
}
else
{
// default postgres
myQuery = "SELECT * FROM item WHERE in_archive=true AND submitter_id="
+ eperson.getID();
}
TableRowIterator rows = DatabaseManager.query(context, "item", myQuery); TableRowIterator rows = DatabaseManager.query(context, "item", myQuery);

View File

@@ -343,15 +343,7 @@ public class BitstreamStorageManager
fos.close(); fos.close();
is.close(); is.close();
if ("oracle".equals(ConfigurationManager.getProperty("db.name"))) bitstream.setColumn("size_bytes", file.length());
{
bitstream.setColumn("size_bytes", (int) file.length());
}
else
{
// postgres default
bitstream.setColumn("size", (int) file.length());
}
bitstream.setColumn("checksum", Utils.toHex(dis.getMessageDigest() bitstream.setColumn("checksum", Utils.toHex(dis.getMessageDigest()
.digest())); .digest()));
@@ -500,17 +492,7 @@ public class BitstreamStorageManager
} }
bitstream.setColumn("checksum_algorithm", "MD5"); bitstream.setColumn("checksum_algorithm", "MD5");
bitstream.setColumn("size_bytes", (int) file.length());
// oracle v. postgresql - 'size' (legacy) is reserved word in oracle
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
{
bitstream.setColumn("size_bytes", (int) file.length());
}
else
{
bitstream.setColumn("size", (int) file.length());
}
bitstream.setColumn("deleted", false); bitstream.setColumn("deleted", false);
DatabaseManager.update(context, bitstream); DatabaseManager.update(context, bitstream);
@@ -585,19 +567,10 @@ public class BitstreamStorageManager
*/ */
public static void delete(Context context, int id) throws SQLException public static void delete(Context context, int id) throws SQLException
{ {
if ("oracle".equals(ConfigurationManager.getProperty("db.name"))) DatabaseManager
{ .updateQuery(context,
// oracle uses 1 for true "update Bitstream set deleted = '1' where bitstream_id = "
DatabaseManager.updateQuery(context, + id);
"update Bitstream set deleted = 1 where bitstream_id = "
+ id);
}
else
{
DatabaseManager.updateQuery(context,
"update Bitstream set deleted = 't' where bitstream_id = "
+ id);
}
} }
/** /**
@@ -618,17 +591,7 @@ public class BitstreamStorageManager
{ {
context = new Context(); context = new Context();
String myQuery = null; String myQuery = "select * from Bitstream where deleted = '1'";
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
{
myQuery = "select * from Bitstream where deleted = 1";
}
else
{
// postgres
myQuery = "select * from Bitstream where deleted = 't'";
}
List storage = DatabaseManager.query(context, "Bitstream", myQuery) List storage = DatabaseManager.query(context, "Bitstream", myQuery)
.toList(); .toList();

View File

@@ -1148,6 +1148,10 @@ public class DatabaseManager
continue; continue;
} }
else if (jdbctype == Types.BIGINT)
{
statement.setLong(count, row.getLongColumn(column));
}
else if (jdbctype == Types.VARCHAR) else if (jdbctype == Types.VARCHAR)
{ {
statement.setString(count, row.getStringColumn(column)); statement.setString(count, row.getStringColumn(column));