mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 23:13:10 +00:00
Centralise Thumbnail logic, and improve DB efficiency in generating thumbnail links on item lists (in testing, at least 4x better)
git-svn-id: http://scm.dspace.org/svn/repo/branches/dspace-1_5_x@2470 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
@@ -33,7 +33,7 @@
|
||||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
||||
* DAMAGE.
|
||||
*/
|
||||
package org.dspace.browse;
|
||||
package org.dspace.content;
|
||||
|
||||
import org.dspace.content.Bitstream;
|
||||
|
||||
@@ -96,5 +96,5 @@ public class Thumbnail
|
||||
this.thumb = thumb;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
22
dspace-api/src/main/java/org/dspace/content/dao/ItemDAO.java
Normal file
22
dspace-api/src/main/java/org/dspace/content/dao/ItemDAO.java
Normal file
@@ -0,0 +1,22 @@
|
||||
package org.dspace.content.dao;
|
||||
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.content.Bitstream;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
public abstract class ItemDAO
|
||||
{
|
||||
protected Context context;
|
||||
|
||||
protected ItemDAO(Context ctx)
|
||||
{
|
||||
context = ctx;
|
||||
}
|
||||
|
||||
public abstract Bitstream getPrimaryBitstream(int itemId, String bundleName) throws SQLException;
|
||||
|
||||
public abstract Bitstream getFirstBitstream(int itemId, String bundleName) throws SQLException;
|
||||
|
||||
public abstract Bitstream getNamedBitstream(int itemId, String bundleName, String fileName) throws SQLException;
|
||||
}
|
@@ -0,0 +1,24 @@
|
||||
package org.dspace.content.dao;
|
||||
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
|
||||
/**
|
||||
* Created by IntelliJ IDEA.
|
||||
* User: Graham
|
||||
* Date: 19-Dec-2007
|
||||
* Time: 13:13:51
|
||||
* To change this template use File | Settings | File Templates.
|
||||
*/
|
||||
public class ItemDAOFactory
|
||||
{
|
||||
public static ItemDAO getInstance(Context context)
|
||||
{
|
||||
if (ConfigurationManager.getProperty("db.name").equalsIgnoreCase("oracle"))
|
||||
{
|
||||
return new ItemDAOOracle(context);
|
||||
}
|
||||
|
||||
return new ItemDAOPostgres(context);
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
package org.dspace.content.dao;
|
||||
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.content.Bitstream;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class ItemDAOOracle extends ItemDAO
|
||||
{
|
||||
ItemDAOOracle(Context ctx)
|
||||
{
|
||||
super(ctx);
|
||||
}
|
||||
|
||||
public Bitstream getPrimaryBitstream(int itemId, String bundleName) throws SQLException {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
public Bitstream getFirstBitstream(int itemId, String bundleName) throws SQLException {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
public Bitstream getNamedBitstream(int itemId, String bundleName, String fileName) throws SQLException {
|
||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
}
|
@@ -0,0 +1,116 @@
|
||||
package org.dspace.content.dao;
|
||||
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.content.Bitstream;
|
||||
import org.dspace.storage.rdbms.DatabaseManager;
|
||||
import org.dspace.storage.rdbms.TableRowIterator;
|
||||
import org.dspace.storage.rdbms.TableRow;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class ItemDAOPostgres extends ItemDAO
|
||||
{
|
||||
private final String selectPrimaryBitstreamID =
|
||||
"SELECT bundle.primary_bitstream_id FROM item2bundle, bundle " +
|
||||
"WHERE item2bundle.item_id=? AND item2bundle.bundle_id=bundle.bundle_id AND bundle.name=? LIMIT 1";
|
||||
|
||||
private final String selectFirstBitstreamID =
|
||||
"SELECT bundle2bitstream.bitstream_id FROM item2bundle, bundle, bundle2bitstream " +
|
||||
"WHERE item2bundle.item_id=? AND item2bundle.bundle_id=bundle.bundle_id AND bundle.name=? " +
|
||||
"AND bundle.bundle_id=bundle2bitstream.bundle_id LIMIT 1";
|
||||
|
||||
// private final String selectFirstBitstreamID =
|
||||
// "SELECT bitstream.bitstream_id FROM item2bundle, bundle, bundle2bitstream, bitstream " +
|
||||
// "WHERE item2bundle.item_id=? AND item2bundle.bundle_id=bundle.bundle_id AND bundle.name=? " +
|
||||
// "AND bundle.bundle_id=bundle2bitstream.bundle_id AND bundle2bitstream.bitstream_id=bitstream.bitstream_id " +
|
||||
// " LIMIT 1";
|
||||
|
||||
// private final String selectFirstBitstreamID =
|
||||
// "SELECT bitstream_id FROM (" +
|
||||
// "SELECT bitstream.bitstream_id FROM item2bundle, bundle, bundle2bitstream, bitstream " +
|
||||
// "WHERE item2bundle.item_id=? AND item2bundle.bundle_id=bundle.bundle_id AND bundle.name=? " +
|
||||
// "AND bundle.bundle_id=bundle2bitstream.bundle_id AND bundle2bitstream.bitstream_id=bitstream.bitstream_id " +
|
||||
// "ORDER BY bitstream.sequence_id" +
|
||||
// ") allstreams LIMIT 1";
|
||||
|
||||
private final String selectNamedBitstreamID =
|
||||
"SELECT bitstream.bitstream_id FROM item2bundle, bundle, bundle2bitstream, bitstream " +
|
||||
"WHERE item2bundle.item_id=? AND item2bundle.bundle_id=bundle.bundle_id AND bundle.name=? " +
|
||||
"AND bundle.bundle_id=bundle2bitstream.bundle_id AND bundle2bitstream.bitstream_id=bitstream.bitstream_id " +
|
||||
"AND bitstream.name=?";
|
||||
|
||||
ItemDAOPostgres(Context ctx)
|
||||
{
|
||||
super(ctx);
|
||||
}
|
||||
|
||||
public Bitstream getPrimaryBitstream(int itemId, String bundleName) throws SQLException
|
||||
{
|
||||
TableRowIterator tri = null;
|
||||
|
||||
try
|
||||
{
|
||||
tri = DatabaseManager.query(context, selectPrimaryBitstreamID, itemId, bundleName);
|
||||
|
||||
if (tri.hasNext())
|
||||
{
|
||||
TableRow row = tri.next();
|
||||
int bid = row.getIntColumn("primary_bitstream_id");
|
||||
return Bitstream.find(context, bid);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tri != null)
|
||||
tri.close();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Bitstream getFirstBitstream(int itemId, String bundleName) throws SQLException
|
||||
{
|
||||
TableRowIterator tri = null;
|
||||
|
||||
try
|
||||
{
|
||||
tri = DatabaseManager.query(context, selectFirstBitstreamID, itemId, bundleName);
|
||||
if (tri.hasNext())
|
||||
{
|
||||
TableRow row = tri.next();
|
||||
int bid = row.getIntColumn("bitstream_id");
|
||||
return Bitstream.find(context, bid);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tri != null)
|
||||
tri.close();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Bitstream getNamedBitstream(int itemId, String bundleName, String fileName) throws SQLException
|
||||
{
|
||||
TableRowIterator tri = null;
|
||||
|
||||
try
|
||||
{
|
||||
tri = DatabaseManager.query(context, selectNamedBitstreamID, itemId, bundleName, fileName);
|
||||
if (tri.hasNext())
|
||||
{
|
||||
TableRow row = tri.next();
|
||||
int bid = row.getIntColumn("bitstream_id");
|
||||
return Bitstream.find(context, bid);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (tri != null)
|
||||
tri.close();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
@@ -0,0 +1,39 @@
|
||||
package org.dspace.content.service;
|
||||
|
||||
import org.dspace.content.dao.ItemDAO;
|
||||
import org.dspace.content.dao.ItemDAOFactory;
|
||||
import org.dspace.content.Bitstream;
|
||||
import org.dspace.content.Thumbnail;
|
||||
import org.dspace.core.Context;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class ItemService
|
||||
{
|
||||
public static Thumbnail getThumbnail(Context context, int itemId, boolean requireOriginal) throws SQLException
|
||||
{
|
||||
ItemDAO dao = ItemDAOFactory.getInstance(context);
|
||||
|
||||
Bitstream thumbBitstream = null;
|
||||
Bitstream primaryBitstream = dao.getPrimaryBitstream(itemId, "ORIGINAL");
|
||||
if (primaryBitstream != null)
|
||||
{
|
||||
if (primaryBitstream.getFormat().getMIMEType().equals("text/html"))
|
||||
return null;
|
||||
|
||||
thumbBitstream = dao.getNamedBitstream(itemId, "THUMBNAIL", primaryBitstream.getName() + ".jpg");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (requireOriginal)
|
||||
primaryBitstream = dao.getFirstBitstream(itemId, "ORIGINAL");
|
||||
|
||||
thumbBitstream = dao.getFirstBitstream(itemId, "THUMBNAIL");
|
||||
}
|
||||
|
||||
if (thumbBitstream != null)
|
||||
return new Thumbnail(thumbBitstream, primaryBitstream);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user