25.02.2015 Views

Introducing Spring Framework

Introducing Spring Framework

Introducing Spring Framework

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 12 ■ Exposing a REST API<br />

if (null == _document)<br />

template.update(<br />

sql.get("insert"),<br />

new Object[] { id,<br />

document.getName(), document.getLocation(),<br />

document.getDescription(),<br />

document.getType().getTypeId(),<br />

document.getCreated(), document.getModified() });<br />

else{<br />

_document.setName((null==document.getName())?_document.getName():document.getName());<br />

_document.setLocation((null==document.getLocation())?_document.getLocation():document.<br />

getLocation());<br />

_document.setDescription((null==document.getDescription())?_document.<br />

getDescription():document.getDescription());<br />

_document.setType((null==document.getType())?_document.getType():document.getType());<br />

_document.setModified(new Date());<br />

template.update(<br />

sql.get("update"),<br />

new Object[] { _document.getName(),<br />

_document.getLocation(),<br />

_document.getDescription(),<br />

_document.getType().getTypeId(), new<br />

Date(),<br />

id });<br />

document = _document;<br />

}<br />

} catch (Exception ex) {<br />

ex.printStackTrace();<br />

}<br />

}<br />

return document;<br />

}<br />

public Document removeById(String id){<br />

Document document = findById(id);<br />

if(null != document){<br />

try{<br />

JdbcTemplate template = new JdbcTemplate(dataSource);<br />

int rows = template.update(sql.get("delete"), new Object[] { id});<br />

if(rows

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!