Changeset 1300
- Timestamp:
- 05/13/11 14:21:24 (13 years ago)
- Location:
- ComponentRegistry/trunk/ComponentRegistry/src
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/AbstractDescriptionDao.java
r1298 r1300 1 1 package clarin.cmdi.componentregistry.impl.database; 2 2 3 import org.slf4j.LoggerFactory; 4 import org.slf4j.Logger; 5 import java.sql.SQLException; 6 import java.sql.ResultSet; 7 import org.springframework.jdbc.core.simple.ParameterizedRowMapper; 8 import java.util.List; 3 9 import java.util.Collections; 4 10 import java.util.Map; … … 6 12 import org.springframework.jdbc.core.simple.SimpleJdbcInsert; 7 13 import clarin.cmdi.componentregistry.model.AbstractDescription; 14 import org.springframework.jdbc.core.SingleColumnRowMapper; 15 import org.springframework.jdbc.core.simple.ParameterizedSingleColumnRowMapper; 8 16 import org.springframework.jdbc.core.simple.SimpleJdbcDaoSupport; 9 17 import static clarin.cmdi.componentregistry.impl.database.ComponentDescriptionDatabase.*; … … 14 22 */ 15 23 public abstract class AbstractDescriptionDao extends SimpleJdbcDaoSupport { 24 25 private final static Logger LOG = LoggerFactory.getLogger(AbstractDescriptionDao.class); 16 26 17 27 protected abstract String getTableName(); … … 28 38 + " join " + getTableName() + " on " + TABLE_XML_CONTENT + "." + COLUMN_ID + " = " + getTableName() + ".content_id" 29 39 + " where " + getTableName() + "." + getCMDIdColumn() + " = :id"; 30 return getSimpleJdbcTemplate().queryForObject(select, String.class, cmdId); 40 41 42 List<String> result = getSimpleJdbcTemplate().query(select, new ParameterizedSingleColumnRowMapper<String>(), cmdId); 43 if (result.size() > 0) { 44 return result.get(0); 45 } else { 46 return null; 47 } 31 48 } 32 49 … … 45 62 params.put("is_public", Boolean.TRUE); 46 63 params.put("is_deleted", Boolean.FALSE); 47 params.put(getCMDIdColumn(), "clarin_" + contentId);64 params.put(getCMDIdColumn(), description.getId()); 48 65 params.put("name", description.getName()); 49 66 params.put("description", description.getDescription()); 50 67 return insertDescription.executeAndReturnKey(params); 51 68 } 69 70 protected <T extends AbstractDescription> List<T> getPublicDescriptions(final Class<T> _class) { 71 String select = "select name, description, " + getCMDIdColumn() + " from " + getTableName(); 72 73 ParameterizedRowMapper<T> rowMapper = new ParameterizedRowMapper<T>() { 74 75 @Override 76 public T mapRow(ResultSet rs, int rowNumber) throws SQLException { 77 try { 78 AbstractDescription cd = (AbstractDescription) _class.newInstance(); 79 cd.setName(rs.getString("name")); 80 cd.setDescription(rs.getString("description")); 81 cd.setId(rs.getString(getCMDIdColumn())); 82 return (T) cd; 83 } catch (InstantiationException ex) { 84 LOG.error("Error in row mapping", ex); 85 } catch (IllegalAccessException ex) { 86 LOG.error("Error in row mapping", ex); 87 } 88 return null; 89 } 90 }; 91 92 return getSimpleJdbcTemplate().query(select, rowMapper); 93 } 52 94 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentDescriptionDao.java
r1297 r1300 25 25 26 26 public List<ComponentDescription> getPublicComponentDescriptions() { 27 String select = "select name, description from " + TABLE_COMPONENT_DESCRIPTION; 28 29 ParameterizedRowMapper<ComponentDescription> rowMapper = new ParameterizedRowMapper<ComponentDescription>() { 30 31 @Override 32 public ComponentDescription mapRow(ResultSet rs, int rowNumber) throws SQLException { 33 ComponentDescription cd = new ComponentDescription(); 34 cd.setName(rs.getString("name")); 35 cd.setDescription(rs.getString("description")); 36 return cd; 37 } 38 }; 39 40 return getSimpleJdbcTemplate().query(select, rowMapper); 27 return getPublicDescriptions(ComponentDescription.class); 41 28 } 42 29 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java
r1297 r1300 2 2 3 3 import clarin.cmdi.componentregistry.ComponentRegistry; 4 import clarin.cmdi.componentregistry.ComponentRegistryUtils; 4 5 import clarin.cmdi.componentregistry.DeleteFailedException; 5 6 import clarin.cmdi.componentregistry.MDMarshaller; … … 30 31 31 32 private String user; 32 33 33 @Autowired 34 34 private ProfileDescriptionDao profileDescriptionDao; … … 41 41 * @see setUser 42 42 */ 43 public ComponentRegistryDbImpl(){ 44 43 public ComponentRegistryDbImpl() { 45 44 } 46 45 … … 83 82 @Override 84 83 public CMDComponentSpec getMDProfile(String id) { 85 throw new UnsupportedOperationException("Not supported yet.");84 return getMDComponent(id, profileDescriptionDao); 86 85 } 87 86 88 87 @Override 89 88 public CMDComponentSpec getMDComponent(String id) { 90 try { 91 String xml = componentDescriptionDao.getContent(id); 92 InputStream is = new ByteArrayInputStream(xml.getBytes()); 93 return MDMarshaller.unmarshal(CMDComponentSpec.class, is, MDMarshaller.getCMDComponentSchema()); 94 } catch (JAXBException ex) { 95 Logger.getLogger(ComponentRegistryDbImpl.class.getName()).log(Level.SEVERE, null, ex); 89 return getMDComponent(id, componentDescriptionDao); 90 } 91 92 private CMDComponentSpec getMDComponent(String id, AbstractDescriptionDao dao) { 93 String xml = dao.getContent(id); 94 if (xml != null) { 95 try { 96 InputStream is = new ByteArrayInputStream(xml.getBytes()); 97 return MDMarshaller.unmarshal(CMDComponentSpec.class, is, MDMarshaller.getCMDComponentSchema()); 98 } catch (JAXBException ex) { 99 Logger.getLogger(ComponentRegistryDbImpl.class.getName()).log(Level.SEVERE, null, ex); 100 } 96 101 } 97 102 return null; … … 99 104 100 105 @Override 101 public int register(AbstractDescription desc, CMDComponentSpec spec) { 106 public int register(AbstractDescription description, CMDComponentSpec spec) { 107 ComponentRegistryUtils.enrichSpecHeader(spec, description); 102 108 try { 103 109 OutputStream os = new ByteArrayOutputStream(); 104 110 MDMarshaller.marshal(spec, os); 105 111 String xml = os.toString(); 106 if (!desc .isProfile()) {107 componentDescriptionDao.insertComponent(desc , xml);112 if (!description.isProfile()) { 113 componentDescriptionDao.insertComponent(description, xml); 108 114 } 109 115 return 0; … … 171 177 } 172 178 173 public void setPublic() {179 public void setPublic() { 174 180 this.user = null; 175 181 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ProfileDescriptionDao.java
r1297 r1300 3 3 import clarin.cmdi.componentregistry.model.ProfileDescription; 4 4 import java.util.List; 5 import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;6 import org.springframework.jdbc.core.simple.ParameterizedRowMapper;7 5 import static clarin.cmdi.componentregistry.impl.database.ComponentDescriptionDatabase.*; 8 6 … … 23 21 } 24 22 25 List<ProfileDescription> getPublicProfileDescriptions() { 26 String select = "select name, description from profile_description"; 27 28 ParameterizedRowMapper<ProfileDescription> rowMapper = new ParameterizedBeanPropertyRowMapper<ProfileDescription>(); 29 30 return getSimpleJdbcTemplate().query(select, rowMapper); 23 public List<ProfileDescription> getPublicProfileDescriptions() { 24 return getPublicDescriptions(ProfileDescription.class); 31 25 } 32 26 } -
ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/model/AbstractDescription.java
r1087 r1300 95 95 return href; 96 96 } 97 97 98 98 public void setGroupName(String groupName) { 99 99 this.groupName = groupName; -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDatabase.java
r1298 r1300 38 38 + " is_public boolean NOT NULL," 39 39 + " is_deleted boolean DEFAULT false NOT NULL," 40 + " component_id character varying NOT NULL,"40 + " profile_id character varying NOT NULL," 41 41 + " name character varying NOT NULL," 42 42 + " description character varying NOT NULL," -
ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImplTest.java
r1298 r1300 13 13 import static org.junit.Assert.assertNull; 14 14 import static org.junit.Assert.assertNotNull; 15 import org.junit.Ignore;16 17 15 import org.springframework.beans.factory.annotation.Autowired; 18 16 import org.springframework.jdbc.core.JdbcTemplate;
Note: See TracChangeset
for help on using the changeset viewer.