Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DS-1172] Add basic Spring plumbing for DAOs #22

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -27,6 +27,7 @@
import org.dspace.browse.IndexBrowse;
import org.dspace.browse.ItemCounter;
import org.dspace.browse.ItemCountException;
import org.dspace.content.service.CollectionService;
import org.dspace.core.ConfigurationManager;
import org.dspace.core.Constants;
import org.dspace.core.Context;
@@ -38,6 +39,7 @@
import org.dspace.storage.rdbms.DatabaseManager;
import org.dspace.storage.rdbms.TableRow;
import org.dspace.storage.rdbms.TableRowIterator;
import org.dspace.utils.DSpace;
import org.dspace.workflow.WorkflowItem;
import org.dspace.xmlworkflow.storedcomponents.CollectionRole;
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
@@ -103,7 +105,7 @@
* the corresponding row in the table
* @throws SQLException
*/
Collection(Context context, TableRow row) throws SQLException
public Collection(Context context, TableRow row) throws SQLException
{
ourContext = context;
collectionRow = row;
@@ -164,36 +166,8 @@
*/
public static Collection find(Context context, int id) throws SQLException
{
// First check the cache
Collection fromCache = (Collection) context.fromCache(Collection.class,
id);

if (fromCache != null)
{
return fromCache;
}

TableRow row = DatabaseManager.find(context, "collection", id);

if (row == null)
{
if (log.isDebugEnabled())
{
log.debug(LogManager.getHeader(context, "find_collection",
"not_found,collection_id=" + id));
}

return null;
}

// not null, return Collection
if (log.isDebugEnabled())
{
log.debug(LogManager.getHeader(context, "find_collection",
"collection_id=" + id));
}

return new Collection(context, row);
CollectionService collectionService = new DSpace().getSingletonService(CollectionService.class);
return collectionService.find(context, id);
}

/**
@@ -0,0 +1,25 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/

package org.dspace.content.dao;

import org.dspace.content.Collection;
import org.dspace.core.Context;
import java.sql.SQLException;

/**
* User: Robin Taylor
* Date: 16/03/12
* Time: 13:46
*/
public interface CollectionDAO {

public Collection find(Context context, int id) throws SQLException;


}
@@ -0,0 +1,55 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/

package org.dspace.content.dao;

import org.apache.log4j.Logger;
import org.dspace.content.Collection;
import org.dspace.core.Context;
import org.dspace.storage.rdbms.DatabaseManager;
import org.dspace.storage.rdbms.TableRow;

import java.sql.SQLException;

/**
* User: Robin Taylor
* Date: 16/03/12
* Time: 13:46
*/

public class LegacyCollectionDAO implements CollectionDAO {

private static Logger log = Logger.getLogger(LegacyCollectionDAO.class);


/**
* Get a collection from the database. Loads in the metadata
*
* @param context
* DSpace context object
* @param id
* ID of the collection
*
* @return the collection, or null if the ID is invalid.
* @throws SQLException
*/
public Collection find(Context context, int id) throws SQLException
{
TableRow row = DatabaseManager.find(context, "collection", id);

if (row == null)
{
return null;
}

// not null, return Collection
return new Collection(context, row);
}


}
@@ -0,0 +1,23 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/

package org.dspace.content.service;

import org.dspace.content.Collection;
import org.dspace.core.Context;
import java.sql.SQLException;

/**
* User: Robin Taylor
* Date: 31/05/12
* Time: 15:55
*/
public interface CollectionService {

public Collection find(Context context, int id) throws SQLException;
}
@@ -0,0 +1,64 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/

package org.dspace.content.service;

import org.apache.log4j.Logger;
import org.dspace.content.Collection;
import org.dspace.content.dao.CollectionDAO;
import org.dspace.core.Context;
import org.dspace.core.LogManager;
import org.dspace.utils.DSpace;

import java.sql.SQLException;
import java.util.List;

/**
* User: Robin Taylor
* Date: 31/05/12
* Time: 14:40
*/

public class CollectionServiceImpl implements CollectionService {

private CollectionDAO collectionDAO;

/** log4j category */
private static Logger log = Logger.getLogger(CollectionServiceImpl.class);


public void setCollectionDAO(CollectionDAO collectionDAO)
{
this.collectionDAO = collectionDAO;
}

public Collection find(Context context, int id) throws SQLException {
Collection collection = collectionDAO.find(context, id);

// First check the cache
Collection fromCache = (Collection) context.fromCache(Collection.class, id);

if (fromCache != null)
{
return fromCache;
}

// not null, return Collection
if (log.isDebugEnabled())
{
log.debug(LogManager.getHeader(context, "find_collection",
"collection_id=" + id));
}

// not null, return Collection
log.debug(LogManager.getHeader(context, "find_collection", "collection_id=" + id));
return collection;
}


}
@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
The contents of this file are subject to the license and copyright
detailed in the LICENSE and NOTICE files at the root of the source
tree and available online at
http://www.dspace.org/license/
-->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-autowire-candidates="*Service,*DAO,javax.sql.DataSource">

<context:annotation-config /> <!-- allows us to use spring annotations in beans -->

<bean id="org.dspace.content.service.CollectionService" class="org.dspace.content.service.CollectionServiceImpl" >
<property name="collectionDAO" ref="org.dspace.content.dao.CollectionDAO" />
</bean>

<bean id="org.dspace.content.dao.CollectionDAO" class="org.dspace.content.dao.LegacyCollectionDAO" />

</beans>
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.