Introducing Google Technology User Group (GTUG), Nigeria – The First GTUG in Africa

Google is cool. It changed the way we do things. It makes our lives easier and more effective.
But wait, does everyone in the world know that? What about Nigeria?

The Google Technology User Group, Nigeria (the first GTUG in Africa) provides an avenue for Google geeks in the country to meet, share and learn. And of course they are going to spread these great opportunities to everyone out there.

Learn more here.

nigeria-gtug

Subscribe for more posts: rss-icon2

Share this Post


facebook-share2 Facebook twitter Twitter friendfeed-share FriendFeed

What’s Being Said About Nigeria

Yesterday, Twitter launched a ‘Live-Updating Search Widget’ which lets you customize the widget with a certain search query to see real time results of tweets.

I customized the widget to return tweets with the keywords Nigeria, #nigeria or #lightupnigeria.

The #lightupnigeria hashtag is particularly interesting. It is a movement in regards the current situation of Power in the country and Nigerians are now expressing their desperate need of steady Electricity. There is a good post about it here.

The customized widget is now running on my home page. I also created a Google Gadget for the widget and I have it running on my iGoogle page. Click to add to your iGoogle page.

nigeria_tweets

Subscribe for more posts: rss-icon2

Share this Post


facebook-share2 Facebook twitter Twitter friendfeed-share FriendFeed

Dynamic Query with Generic CRUD Service – EJB 3.0/3.1

I applied Adam Bien’s Generic CRUD service which he described in his book, Real World Java EE patterns – Rethinking Best Practices, and it greatly simplified the CRUD operations for the project I am working on. He also discussed about it on his blog.

However, I have queries which vary considerably depending on some options selected by a user, so I needed to create my queries on the fly instead of having named queries which keep growing. I therefore extended the Generic CRUD service to generate dynamic queries.

In the CRUDService interface I added findByDynamicQuery():

public interface CrudService {
     //...
     <T> List<T> findByDynamicQuery(Class<T> type,
                     List<ParameterDefinition> parameters);
}
 

Class<T> type represents the entity class for the query to be made and List<ParameterDefinition> parameters is used for specifying the query parameters (more on that).

The DynamicQueryParameter

I needed to specify parameters for OR conditions as well; Map<String, Object> could not satisfy the requirement since each key can map to at most one value and some queries may define one key (field) for many values. E.g. “SELECT c FROM Candidate WHERE c.program = :prog1 OR c.program = :prog2″ (program twice).

To solve the problem I used List<ParameterDefinition> to specify the parameters. ParameterDefinition is a simple class that defines the parameter type, name and value:

public class ParameterDefinition {
   private final String name;
   private final Object value;
   private final ParameterType paramType;

   public ParameterDefinition(ParameterType paramType, String name, Object value) {
      this.name = name;
      this.value = value;
      this.paramType = paramType;
   }

   public ParameterType getParameterType() {
      return paramType;
   }
   public String getName() {
      return name;
   }

   public Object getValue() {
      return value;
   }
}

ParameterType is defined using an Enum:

public enum ParameterType {
    WITH, AND, OR
}

The dynamic version of the QueryParameter is therefore as follows:

public class DynamicQueryParameter {
   private List<ParameterDefinition> parameters = null;

   private DynamicQueryParameter(String name, Object value) {
      this.parameters = new ArrayList<ParameterDefinition>();
      addParameter(ParameterType.WITH, name, value);
   }

   public static DynamicQueryParameter with(String name, final Object value) {
      return new DynamicQueryParameter(name, value);
   }

   public DynamicQueryParameter and(String name, final Object value) {
      addParameter(ParameterType.AND, name, value);

      return this;
   }

   public DynamicQueryParameter or(String name, final Object value) {
      addParameter(ParameterType.OR, name, value);

      return this;
   }

   public List<ParameterDefinition> parameters() {
     return this.parameters;
   }

   private void addParameter(ParameterType paramType,
      String name, final Object value)
   {
      parameters.add(new ParameterDefinition(paramType, name, value));
   }
}

And finally the CrudService implementation:

@Stateless
@Local(CrudService.class)
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public class CrudServiceBean implements CrudService {
   @PersistenceContext
   private EntityManager em;

   //...

   public <T> List<T> findByDynamicQuery(Class<T> type,
       List<ParameterDefinition> parameters)
   {
      //generate query
      String queryString = generateQuery(type, parameters);

      Query query = this.em.createQuery(queryString);

      //set parameters
      int k = 1;	//parameter position
      for (ParameterDefinition param : parameters) {
           query.setParameter(k++, param.getValue());
      }

      return query.getResultList();
   }

   //helper method
   private <T> String generateQuery(Class<T> type,
      List<ParameterDefinition> parameters)
   {
      final String VAR = "obj";
      StringBuilder queryBuilder = new StringBuilder(
      String.format("SELECT %s FROM %s %s",
         VAR, type.getSimpleName(), VAR)
      );

      if (parameters.size() == 0) { //no conditions
           return queryBuilder.toString();
      }

      //WHERE clause
      Iterator<ParameterDefinition> itr = parameters.iterator();
      int k = 1;	//parameter position
      ParameterDefinition firstParam = itr.next();  //always type WITH
      queryBuilder.append(String.format(" WHERE %s.%s = ?%d",
           VAR, firstParam.getName(), k++));

      //append parameters
      for ( ; itr.hasNext(); ) {
           ParameterDefinition nextParam = itr.next();
           queryBuilder.append(String.format(
               " %s %s.%s = ?%s", nextParam.getParameterType(), VAR,
               nextParam.getName(), k++));
      }
      return queryBuilder.toString();
   }
}

The query can be constructed from a client as follows:

List<Candidate> candidate = crudServiceBean.findByDynamicQuery(Candidate.class,
      DynamicQueryParameter.
      with("id", "111").
      and("program", "SE").
      or("program", "IT").
      and("mode", "FT").
      parameters());

where Candidate is an entity bean and crudServiceBean is a reference to CrudServiceBean session bean.

As Nigerian Facebook’rs Approach 1 Million…

In the beginning of the year we predicted that 0.5 million (or more) Nigerians would be on Facebook by mid-year. Today there are 585,000 on the platform with more engagements being noticed. Google Trends show that more than 50,000 Nigerians return to Facebook daily.
The effect of the growth has started manifesting in the country: lot of groups are now formed with active participations and discussions.
A very interesting group recently is the “SUPPORT FOR SENATE BILL AGAINST CHILD DESTITUTION” formed to support Senator Tafidan Argungu and Forty others’ bill to stop child destitution in the country. There are more than 1,300 members on the group now. The group has certainly made an impact in this campaign which made Thisday publish an article about it (http://www.thisdayonline.com/nview.php?id=145272)
In the last 2 months, Facebook attracted more than 100,000 Nigerians each month. With this rate, we should expect 1.2 million users by the end of the year and about 2.5 million by 2011. Indeed with this number, it is going to be an interesting platform for politics for the next general elections. There are numerous political groups already.
However the biggest question still remains: do we expect to see positive developments in the country through the power of information sharing and collaboration Facebook offers?

nigeria-flag
facebook

In the beginning of the year we predicted that 0.5 million (or more) Nigerians  would be on Facebook by mid-year. Today there are 573,780 on the platform with more engagements being noticed. Google Trends show that more than 50,000 Nigerians return to Facebook daily.

The effect of the growth has started manifesting in the country: lot of groups are now formed with active participations and discussions.

A very interesting group recently is the “SUPPORT FOR SENATE BILL AGAINST CHILD DESTITUTION” formed to support Senator Tafidan Argungu and Forty others’ bill to stop child destitution in the country. There are more than 1,380 members on the group now. The group has certainly made an impact in this campaign which made Thisday publish an article about it.

In the last 2 months, Facebook attracted more than 100,000 Nigerians each month. With this rate, we should expect 1.2 million users by the end of the year and about 2.4 million by 2011. Indeed with this number, it is going to be an interesting platform for politics for the next general elections. There are numerous political groups already.

However the biggest question still remains: do we expect to see positive developments in the country through the power of information sharing and collaboration Facebook offers?

[Other posts on "Nigeria and Facebook"]

Subscribe for more posts: rss-icon2

Share this Post


facebook-share2 Facebook delicious-share Delicious linkedin-share LinkedIn digg-share DiggIt stumbleupon-share StumbleUpon friendfeed-share FriendFeed