3 Replies Latest reply on May 17, 2016 11:16 PM by spoorthy

    How to access the database from jive plugin?

    spoorthy

      Hi

       

      How to access the database(PostgreSQL) from jive custom plugin? could anyone give the example or steps to follow.

       

      Joey LeviPawan ShahRyan Rutan

       

      Thanks

      Spoorthy.

        • Re: How to access the database from jive plugin?
          jlevi

          Is there a reason you are still writing a plugin versus writing an add-on and using the API?  (Getting Started > Building a Jive Add-On)

           

          Add-ons are upgrade safe and can be deployed to the cloud.

            • Re: How to access the database from jive plugin?
              Scott A Johnson

              Hi Spoorthy,

               

              As Joey mentioned, writing Add-ons is more upgrade safe. If you can access the info that you need through API calls, that is the preferred approach.

               

              But as you're probably aware, some use cases fall outside the capabilities of Add-ons.


              To write your own data access object, extend the class com.jivesoftware.base.database.dao.JiveJdbcDaoSupport

               

              You can then use something like this:

               

               

              private final ParameterizedRowMapper<Thing> thingMapper = new ParameterizedRowMapper<Thing>() {
                  @Override
                  public Thing mapRow(ResultSet rs, int num) throws SQLException {
                      final Thing thing = new Thing();
                      thing.setId(rs.getLong("thingid"));
                      thing.setName(rs.getString("name"));
                      thing.setDescription(rs.getString("description"));
                      return thing;
                  }
              };
              
              public Set<Thing> getThings(){
                  List<Thing> things = getJdbcTemplate().query("SELECT thingid, name, description FROM thing_table", thingMapper);
                  return new TreeSet<Tier>(tiers);
              }
              

               

               

              Hope that helps,

              Scott