Skip to content

Commit

Permalink
merge with DSpace version 5_x (based on 5.7)
Browse files Browse the repository at this point in the history
  • Loading branch information
lap82 committed Jul 17, 2017
1 parent 6add4be commit a0f88cd
Show file tree
Hide file tree
Showing 17 changed files with 237 additions and 280 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public static WorkspaceItem create(Context c, Collection coll,
if (template && (templateItem != null))
{
TemplateItemService tis = new DSpace().getSingletonService(TemplateItemService.class);
tis.applyTemplate(c, i, templateItem);
tis.applyTemplate(c, item, templateItem);
}

item.update();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public static TableRow querySingle(Context context, String query,
try
{
iterator = query(context, query, parameters);
retRow = (!iterator.hasNext()) ? null : iterator.next();
retRow = (!iterator.hasNext()) ? null : iterator.next(context);
} catch (SQLException e) {
log.error("SQL query single Error - ", e);
throw e;
Expand Down Expand Up @@ -459,7 +459,7 @@ public static TableRow querySingleTable(Context context, String table,

try
{
retRow = (!iterator.hasNext()) ? null : iterator.next();
retRow = (!iterator.hasNext()) ? null : iterator.next(context);
} catch (SQLException e) {
log.error("SQL query singleTable Error - ", e);
throw e;
Expand Down Expand Up @@ -546,7 +546,7 @@ public static TableRow create(Context context, String table) throws SQLException

{
try {
TableRow row = new TableRow(canonicalize(table), getColumnNames(table));
TableRow row = new TableRow(canonicalize(table), getColumnNames(context,table));
insert(context, row);
return row;
} catch (SQLException e) {
Expand Down Expand Up @@ -576,7 +576,7 @@ public static TableRow find(Context context, String table, int id) throws SQLExc
String ctable = canonicalize(table);

try {
return findByUnique(context, ctable, getPrimaryKeyColumn(ctable),
return findByUnique(context, ctable, getPrimaryKeyColumn(context, ctable),
Integer.valueOf(id));
} catch (SQLException e) {
log.error("SQL find Error - ", e);
Expand Down Expand Up @@ -642,7 +642,7 @@ public static int delete(Context context, String table, int id) throws SQLExcept
{
try {
String ctable = canonicalize(table);
return deleteByValue(context, ctable, getPrimaryKeyColumn(ctable),
return deleteByValue(context, ctable, getPrimaryKeyColumn(context, ctable),
Integer.valueOf(id));
} catch (SQLException e) {
log.error("SQL delete Error - ", e);
Expand Down Expand Up @@ -762,6 +762,10 @@ public static void freeConnection(Connection c)
* @return The newly created row
* @throws SQLException
*/
public static TableRow row(Context context, String table) throws SQLException
{
return new TableRow(canonicalize(table), getColumnNames(context, table));
}
public static TableRow row(String table) throws SQLException
{
return new TableRow(canonicalize(table), getColumnNames(table));
Expand Down Expand Up @@ -790,7 +794,7 @@ public static void insert(Context context, TableRow row) throws SQLException
newID = doInsertGeneric(context, row);
}

row.setColumn(getPrimaryKeyColumn(row), newID);
row.setColumn(getPrimaryKeyColumn(context, row), newID);
}

/**
Expand All @@ -813,8 +817,8 @@ public static int update(Context context, TableRow row) throws SQLException
.append(" set ");

List<ColumnInfo> columns = new ArrayList<ColumnInfo>();
ColumnInfo pk = getPrimaryKeyColumnInfo(table);
Collection<ColumnInfo> info = getColumnInfo(table);
ColumnInfo pk = getPrimaryKeyColumnInfo(context, table);
Collection<ColumnInfo> info = getColumnInfo(context, table);

String separator = "";
for (ColumnInfo col : info)
Expand Down Expand Up @@ -862,7 +866,7 @@ public static int delete(Context context, TableRow row) throws SQLException
throw new IllegalArgumentException("Row not associated with a table");
}

String pk = getPrimaryKeyColumn(row);
String pk = getPrimaryKeyColumn(context, row);

if (row.isColumnNull(pk))
{
Expand All @@ -881,9 +885,9 @@ public static int delete(Context context, TableRow row) throws SQLException
* @exception SQLException
* If a database error occurs
*/
static Collection<ColumnInfo> getColumnInfo(String table) throws SQLException
static Collection<ColumnInfo> getColumnInfo(Context context, String table) throws SQLException
{
Map<String, ColumnInfo> cinfo = getColumnInfoInternal(table);
Map<String, ColumnInfo> cinfo = getColumnInfoInternal(context, table);

return (cinfo == null) ? null : cinfo.values();
}
Expand All @@ -899,14 +903,18 @@ static Collection<ColumnInfo> getColumnInfo(String table) throws SQLException
* @exception SQLException
* If a database error occurs
*/
static ColumnInfo getColumnInfo(String table, String column)
static ColumnInfo getColumnInfo(Context context, String table, String column)
throws SQLException
{
Map<String, ColumnInfo> info = getColumnInfoInternal(table);
Map<String, ColumnInfo> info = getColumnInfoInternal(context, table);

return (info == null) ? null : info.get(column);
}

static List<String> getColumnNames(String table) throws SQLException{
return getColumnNames(null,table);
}

/**
* Return the names of all the columns of the given table.
*
Expand All @@ -917,10 +925,10 @@ static ColumnInfo getColumnInfo(String table, String column)
* @exception SQLException
* If a database error occurs
*/
static List<String> getColumnNames(String table) throws SQLException
static List<String> getColumnNames(Context context, String table) throws SQLException
{
List<String> results = new ArrayList<String>();
Collection<ColumnInfo> info = getColumnInfo(table);
Collection<ColumnInfo> info = getColumnInfo(context, table);

for (ColumnInfo col : info)
{
Expand Down Expand Up @@ -987,9 +995,21 @@ static String canonicalize(String db_object)
* @exception SQLException
* If a database error occurs
*/
static TableRow process(Context context, ResultSet results, String table) throws SQLException
{
return process(context,results, table, null);
}
static TableRow process(ResultSet results, String table) throws SQLException
{
return process(results, table, null);
return process(null,results, table, null);
}

/**
* @deprecated You should try to pass an existing database connection to this method to prevent opening a new one.
*/
@Deprecated
static TableRow process(ResultSet results, String table, List<String> pColumnNames) throws SQLException{
return process(null,results,table,pColumnNames);
}

/**
Expand All @@ -1005,14 +1025,14 @@ static TableRow process(ResultSet results, String table) throws SQLException
* @exception SQLException
* If a database error occurs
*/
static TableRow process(ResultSet results, String table, List<String> pColumnNames) throws SQLException
static TableRow process(Context context, ResultSet results, String table, List<String> pColumnNames) throws SQLException
{
ResultSetMetaData meta = results.getMetaData();
int columns = meta.getColumnCount() + 1;

// If we haven't been passed the column names try to generate them from the metadata / table
List<String> columnNames = pColumnNames != null ? pColumnNames :
((table == null) ? getColumnNames(meta) : getColumnNames(table));
((table == null) ? getColumnNames(meta) : getColumnNames(context,table));

TableRow row = new TableRow(canonicalize(table), columnNames);

Expand Down Expand Up @@ -1135,9 +1155,9 @@ static TableRow process(ResultSet results, String table, List<String> pColumnNam
* @exception SQLException
* If a database error occurs
*/
public static String getPrimaryKeyColumn(TableRow row) throws SQLException
public static String getPrimaryKeyColumn(Context context,TableRow row) throws SQLException
{
return getPrimaryKeyColumn(row.getTable());
return getPrimaryKeyColumn(context,row.getTable());
}

/**
Expand All @@ -1152,10 +1172,10 @@ public static String getPrimaryKeyColumn(TableRow row) throws SQLException
* @exception SQLException
* If a database error occurs
*/
protected static String getPrimaryKeyColumn(String table)
protected static String getPrimaryKeyColumn(Context context, String table)
throws SQLException
{
ColumnInfo info = getPrimaryKeyColumnInfo(table);
ColumnInfo info = getPrimaryKeyColumnInfo(context, table);

return (info == null) ? null : info.getName();
}
Expand All @@ -1171,9 +1191,9 @@ protected static String getPrimaryKeyColumn(String table)
* @exception SQLException
* If a database error occurs
*/
static ColumnInfo getPrimaryKeyColumnInfo(String table) throws SQLException
static ColumnInfo getPrimaryKeyColumnInfo(Context context, String table) throws SQLException
{
Collection<ColumnInfo> cinfo = getColumnInfo(canonicalize(table));
Collection<ColumnInfo> cinfo = getColumnInfo(context, canonicalize(table));

for (ColumnInfo info : cinfo)
{
Expand Down Expand Up @@ -1275,7 +1295,7 @@ private static int executeUpdate(Connection connection, String sql, Collection<C
* @exception SQLException
* If a database error occurs
*/
private static Map<String, ColumnInfo> getColumnInfoInternal(String table) throws SQLException
private static Map<String, ColumnInfo> getColumnInfoInternal(Context context, String table) throws SQLException
{
String ctable = canonicalize(table);
Map<String, ColumnInfo> results = info.get(ctable);
Expand All @@ -1285,7 +1305,7 @@ private static Map<String, ColumnInfo> getColumnInfoInternal(String table) throw
return results;
}

results = retrieveColumnInfo(ctable);
results = retrieveColumnInfo(context, ctable);
info.put(ctable, results);

return results;
Expand All @@ -1302,7 +1322,7 @@ private static Map<String, ColumnInfo> getColumnInfoInternal(String table) throw
* If there is a problem retrieving information from the
* RDBMS.
*/
private static Map<String, ColumnInfo> retrieveColumnInfo(String table) throws SQLException
private static Map<String, ColumnInfo> retrieveColumnInfo(Context context, String table) throws SQLException
{
Connection connection = null;
ResultSet pkcolumns = null;
Expand All @@ -1321,7 +1341,11 @@ private static Map<String, ColumnInfo> retrieveColumnInfo(String table) throws S
log.warn("table: " + table);
}

if (context != null && !context.getDBConnection().isClosed()) {
connection = context.getDBConnection();
} else {
connection = getConnection();
}

// Get current database schema name
String schema = DatabaseUtils.getSchemaName(connection);
Expand Down Expand Up @@ -1373,7 +1397,7 @@ private static Map<String, ColumnInfo> retrieveColumnInfo(String table) throws S
try { columns.close(); } catch (SQLException sqle) { }
}

if (connection != null)
if (connection != null && context == null) // Only close if connection is newly created in this method
{
try { connection.close(); } catch (SQLException sqle) { }
}
Expand Down Expand Up @@ -1754,10 +1778,10 @@ private static int doInsertPostgres(Context context, TableRow row) throws SQLExc
{
String table = row.getTable();

Collection<ColumnInfo> info = getColumnInfo(table);
Collection<ColumnInfo> info = getColumnInfo(context, table);
Collection<ColumnInfo> params = new ArrayList<ColumnInfo>();

String primaryKey = getPrimaryKeyColumn(table);
String primaryKey = getPrimaryKeyColumn(context, table);
String sql = insertSQL.get(table);

boolean firstColumn = true;
Expand Down Expand Up @@ -1793,7 +1817,7 @@ private static int doInsertPostgres(Context context, TableRow row) throws SQLExc
}
}

sql = insertBuilder.append(valuesBuilder.toString()).append(") RETURNING ").append(getPrimaryKeyColumn(table)).toString();
sql = insertBuilder.append(valuesBuilder.toString()).append(") RETURNING ").append(getPrimaryKeyColumn(context, table)).toString();
insertSQL.put(table, sql);
}
else
Expand Down Expand Up @@ -1908,8 +1932,8 @@ private static int doInsertGeneric(Context context, TableRow row) throws SQLExce
}

// Set the ID in the table row object
row.setColumn(getPrimaryKeyColumn(table), newID);
Collection<ColumnInfo> info = getColumnInfo(table);
row.setColumn(getPrimaryKeyColumn(context, table), newID);
Collection<ColumnInfo> info = getColumnInfo(context, table);

String sql = insertSQL.get(table);
if (sql == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ public Bitstream getBitstream(@PathParam("bitstream_id") Integer bitstreamId, @Q
writeStats(dspaceBitstream, UsageEvent.Action.VIEW, user_ip, user_agent, xforwardedfor, headers,
request, context);


bitstream = new Bitstream(dspaceBitstream, servletContext, expand, context);
bitstream = new Bitstream(dspaceBitstream, expand);
context.complete();
log.trace("Bitsream(id=" + bitstreamId + ") was successfully read.");

Expand Down Expand Up @@ -155,8 +154,7 @@ public ResourcePolicy[] getBitstreamPolicies(@PathParam("bitstream_id") Integer
org.dspace.content.Bitstream dspaceBitstream = findBitstream(context, bitstreamId, org.dspace.core.Constants.READ);
AuthorizeManager.getPolicies(context, dspaceBitstream);


policies = new Bitstream(dspaceBitstream, servletContext, "policies", context).getPolicies();
policies = new Bitstream(dspaceBitstream,"policies").getPolicies();

context.complete();
log.trace("Policies for bitstream(id=" + bitstreamId + ") was successfully read.");
Expand Down Expand Up @@ -232,8 +230,7 @@ public Bitstream[] getBitstreams(@QueryParam("expand") String expand,
if (dspaceBitstreams[i].getParentObject() != null)
{ // To eliminate bitstreams which cause exception, because of
// reading under administrator permissions

bitstreams.add(new Bitstream(dspaceBitstreams[i], servletContext, expand, context));
bitstreams.add(new Bitstream(dspaceBitstreams[i], expand));
writeStats(dspaceBitstreams[i], UsageEvent.Action.VIEW, user_ip, user_agent,
xforwardedfor, headers, request, context);
}
Expand Down
Loading

0 comments on commit a0f88cd

Please sign in to comment.