The plugin was about browsing existing Crowd users, create new users, attach pictures to users, make directory of cities (company is distributed to several cities), departments etc., similar to Userinfo example.
Developer documentation is quite useful while not complete... First thing I needed was to persist my dictionaries to database. After some discovering I've learned that Atlassian doesn't recommend using Hibernate (I couldn't attach mappings anyway) but provides Bandana instead (XML persistence based on XStream). It isn't going for me because I need to select, search, make relations between tables etc.. Make it all with Java classes?
Fortunatelly it is still possible to use pure SQL quieries. So these are the steps for using database in Confluence:
- declare DAO bean in atlassian-plugin.xml
- implement DAO class and derive it from HibernateObjectDao (provided by Atlassian)
- connect DAO to an action in atlassian-plugin.xml:
- use cities on the page viewcities.vm:
<spring name="citiesDao" key="citiesDao"where sessionFactory is Hibernate's session factory provided by Confluence;
class="dot.userinfo.cities.dao.HibernateCitiesDao">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</spring>
public class HibernateCitiesDao
extends HibernateObjectDao {
public CollectiongetAll() {
Listresult = new ArrayList ();
Session session = null;
try {
session = getSessionFactory().openSession();
ResultSet rs = session.connection().
prepareStatement("select * from city").executeQuery();
while (rs.next()) {
CityInfo o = new CityInfo();
fill(rs, o);
result.add(o);
}
} finally {
if (session != null) {
session.disconnect();
}
}
return result;
}
}
<action name="viewcities"Class ViewCities must have a setter (and getter if you want to use it directly in page) methods for citiesDao:
class="dot.userinfo.cities.action.ViewCities">
<external-ref name="citiesDao">citiesDao</external-ref>
<result name="success" type="velocity">
/templates/dot/userinfo/cities/viewcities.vm</result>
</action>
public void setCitiesDao(CitiesDao citiesDao) {
this.citiesDao = citiesDao;
}
public CitiesDao getCitiesDao() {
return citiesDao;
}
#set($cities = $action.citiesDao.all)
#foreach( $item in $cities.iterator())
...
#end
No comments:
Post a Comment