Friday, November 28, 2008

Pizza Party: An Interesting Impact of a Virtual Community on a Real Community

Just three days ago I was presented to a social network totally dedicated to university students who are involved somehow with open source projects. This community is called Open Source University Meetup (OSUM). This is a SUN Microsystems initiative to stimulate the involvement of students on the open source world. This strategy might be efficient because, in parallel, SUN is also preparing the next generation of professionals to work with their set of open source products, increasing the work force available, and consequently the market for their solutions.

This community is also special for an additional reason. It was the stage of an important discovery: The power of engagement of a Java community, called CEJUG, around a common achievement. Let me tell you some details. Three days ago, Silveira Neto, a Sun Campus Ambassador, wrote a message to the CEJUG mailing list, saying that he had created a group in the OSUM social network dedicated to CEJUG members. He invited people to join and alerted that if the size of the group reached more than 100 people before the end of November, SUN would pay a pizza party to all the people in the group. Good motivation, isn't it?



Before the end of November, just one day after the invitation, the number was reached :O. Actually, in the same day almost 60 people joined the group. On the next day, still in the afternoon, the group got 101 people, which enabled it to get the pizza party for free. At the moment, the group has 122 members and growing slower now.



Definitively, the CEJUG community has an incredible power of engagement. Congratulations and Bon Appetit !

Saturday, November 22, 2008

The Beer Globalization

You know, I'm living in Belgium and Belgium is a very small country (We can put 100% of Belgium inside my state in Brazil :-) ), with 12 million people and considered in 2007 the world's 15th largest trading nation. It's amazing how a small piece of land can be so economically powerful.

Even being quite a young country (1830), Belgium has a rich culture and many specialties. Here is the land of the chocolate, french fries, crafts, comics, diamonds and, or course, BEERS! :-D Yeah!! Belgium is the brain of the biggest beer distribution system in the world and leads the market in incomes, volume of production and number of brands. The distribution system is so fantastic that for the first time, pure Belgian beer arrived in the city where I was born: Juazeiro do Norte, a small city in the south of Ceará with 200 thousand people living there, including my parents. The screen shot below can prove what I'm saying. It shows my father holding a bottle of Stella Artois in a happy Sunday conversation by Skype. :-) He bought many bottles in a local supermarket to remember the greatest moments they had in Belgium last year.



That's the Beer Globalization and I'm happy that it is happening now because when I come back one day, I will have the opportunity to remember great moments I'm having in this small, but very special country.

In the map below you can see exactly where it's possible to find Belgian beer in Brazil, which is exactly where Juazeiro do Norte is located ;-)



On the other hand, it isn't possible to find our Cachaça, a Brazilian strong drink, in Belgium :-( . Fortunately , my supervisor went to Brazil some weeks ago and brought to me two special bottles of Ypioca, the best one produced in Brazil, original from Fortaleza. According to him, "It was cheaper than milk in Belgium" :-D .

Thursday, November 20, 2008

Configuring Glassfish to Support Hibernate

This is just a short post to remember how I prepared Glassfish to use Hibernate 3 as a JPA persistence framework.

The first step is to add Hibernate libraries in #glassfish_home#/lib . Those libraries are:
  • antlr-2.7.6.jar
  • c3p0-0.9.1.jar
  • cglib-nodep-2.1.3.jar
  • commons-collections-2.1.1.jar
  • commons-logging-1.0.4.jar
  • concurrent-1.3.2.jar
  • dom4j-1.6.1.jar
  • ehcache-1.2.3.jar
  • hibernate3.jar
  • hibernate-annotations.jar
  • hibernate-commons-annotations.jar
  • hibernate-entitymanager.jar
  • hibernate-validator.jar
  • javassist.jar
  • log4j-1.2.11.jar
  • ojdbc14.jar
All these libraries are distributed with Hibernate on this web page: http://hibernate.org/6.html. There are even more libraries available, but the set above was compiled by an attempt/error approach, which was indeed a tough task. You have to restart Glassfish in order to use those new libraries.

The next step is to create a connection pool and a JDBC resource, but I will assume that you know how to do that or you have read a post like the one written by Jagadish.

Finally, you have to configure your persistence unit in order to use Hibernate. See parts of my persistence.xml file below:

‹persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"›
‹persistence-unit name="#persistence-unit-name#" transaction-type="JTA"›
‹provider›org.hibernate.ejb.HibernatePersistence‹/provider›
‹jta-data-source›#jdbc-datasource#‹/jta-data-source›
‹class>#persistence-class#‹/class›
... ‹!-- Your persistence classes --›
‹exclude-unlisted-classes›true‹/exclude-unlisted-classes>
‹properties›
‹property name="hibernate.dialect"
value="org.hibernate.dialect.Oracle10gDialect"/›
‹property name="hibernate.show_sql" value="false"/›
‹property name="hibernate.cache.provider_class"
value="org.hibernate.cache.HashtableCacheProvider"/›
‹/properties›
‹/persistence-unit›
‹/persistence›


Basically, you have to set the provider tag with "org.hibernate.ejb.HibernatePersistence" and set some properties according to specific needs. That's all!

Sunday, November 16, 2008

Accessing an Embedded Database Using JPA in a Desktop Application

The problem of developing an unusual application is that we spend most of the time thinking about the architecture. Every single additional code is a big decision, unless you are not so obsessed like me. When you are developing a traditional web application or an enterprise application the architecture definition is relatively easy because there are many references available to inspire you, like specialized books, professional blogs, speakers, frameworks ready to use, and so on. On the other hand, when you are developing something new, like an innovative framework, a device driver or a concurrent application (which is my case), architecture is your main concern, isn't it?

My open source project (Meanings4Fusion) is consuming all my thoughts on its architectural definition. At the same time, I'm working hard on its implementation because I have a deadline in early December and also because an active open source project may attract more people in a short term, as soon as our solutions become solutions for their problems too. For instance, you probably might be interested to know how to embed a database in your application in order to distribute it without any further installation and store data without the complexity of manipulating files or network connections. My experience was very frustrating because of the lack of information available about this problem, but now, taking some assumptions and attempts, it was much easier than I was expecting.

In order to have this facility I have made some choices:
  • considering JVM version 6 or superior: sorry for those who use Mac, but I prefer a free software world than a world of limited freedom. But, don't worry, Java 6 will be available for you soon, of course, as soon as Mac guys decide to finish it, because SUN can't do anything to help you in a proprietary system. Java 6 is faster and implements many cool things that we might need in the project.
  • using Java DB: it is actually Apache Derby with a new name. If you use Derby instead the final result will be the same. Even the configuration stuff is valid for both. Java DB can be used as a server or embedded, which is our case. Embedded, it executes in the same process of the application and may add some delay when you access the database for the first time, but it is just at the beginning, normalizing later.
  • using JPA (Java Persistence API): using a database nowadays is not a complex task anymore, neither to embedded databases. As I mentioned before, JPA simplifies the code to access the database keeping its elegance and focus on the main problem. I picked Toplink essentials because of its small size, but I don't like it. With more time I will change to Eclipse Link.
I'm writing a lot, but we don't have much to do. Just enjoying the opportunity to talk more with you. Basically, you have to add 3 more libraries within your project. To embed the database, add derby.jar (available at http://db.apache.org/derby/). To use JPA, add toplink-essentials.jar and toplink-essentials-agent.jar (available at http://oss.oracle.com/toplink-essentials-jpa.html). This is 40% of all you have to do.



The next step is to create the file persistence.xml in the directory META-INF, which should be packaged within your application (jar file). The content of the file is available here. At this line - property name="toplink.jdbc.url" value="jdbc:derby:meanings4fusion;create=true" - be aware of "create=true". It will automatically create a database if it doesn't exist yet. Something else important is this line - property name="toplink.ddl-generation" value="create-tables" - which specifies the automatic creation of tables according to the implemented entity classes. This step represents 20% of everything. We are almost there.

Now, you have to implement an entity class and some methods for it to persist it when necessary. An example is available here. The correspondent table for the Ontology entity (example) will be automatically generated in its first use. It is important to add as much information about the metadata as possible in the annotations of the entity class because it will generate a better database structure. A standalone application cannot use the transaction manager from a container, which obliges us to start, commit and, if needed, rollback a transaction.

So, Done. 100%.

Friday, November 7, 2008

Brazilian Music is an Emotional Wave

Lucky you, who can listen to Brazilian music and don't understand Portuguese. At the same time, unlucky you who can listen to Brazilian music and don't understand Portuguese. Yes, this is ambiguous, but totally true. I'm suspect to talk about that, but I think I have enough arguments to explain my point of view.

I have been observing people who like Brazilian music, but don't speak Portuguese. They usually have eclectic taste, listening to a variety of rhythms, from jazz to rock. On the other hand, I've never seen a rock fan dancing while listening to our beats, as well as a teenager, in love, listening to our romantic music. Therefore, for those who don't understand Portuguese, Brazilian music is a cultural experience, a Latin expression, a good music to release their sensuality, or just relax after a hard working day. Who listens to Bossa Nova or MPB knows what I mean when mentioning Latin expression and relaxation. Who listens to Samba, Lambada or Reggae knows what I mean when mentioning cultural experience and sensual expression.

So, if you don't know Portuguese, then you will probably just fell happy, sensual, fun or relaxed, but if you know... Wow! Guys, you and me actually live in an emotional wave... suuurfing on it! Yeah! The Brazilian music + lyrics has the incredible ability to describe your moment. Sometimes you can find more than one music to describe the same moment, each one by a different perspective. That's why I'm saying you are unlucky. Because it's very difficult to find something similar in other cultures. This was, indeed, a motivation to write this post, because I have read many lyrics and all I found was small sentences describing my feelings, unlike Brazilian composers, who write so well about emotions that you might imagine them almost as witnesses of what happened.

This girl above is Ivete Sangalo. She has a special ability to describe your moment when you are happy :D, when you want to be happy :), when you are sad :( and even when you want to be sad ;(. She is Bahiana (born in Bahia) and who is Brazilian knows how humble and loved she is.

Ivete is the new generation and you probably don't know her. But your eclectic taste most have already introduced you at least to one of these three guys below. Caetano Veloso, who composes music using complex Portuguese sentences and when you realize the real meaning behind the words you begin to laugh unexpectedly and start using that expression to feel that same feeling in a special moment. The second guy, Tom Jobim, has the ability to do the same as Caetano, but with simple sentences that everybody understands and uses to be explicitly clear. The last one, Roberto Carlos, I don't like him ;D. I've kept him to avoid interfering on the talented work of Batistão, a famous caricaturist in Brazil. But Roberto has his value. He is not a composer but sings very well and moves crowds there.



I have material to write a book ;), but this is just a blog and its intention is just to excite your curiosity. You are invited to listen to some Brazilian Music in my new radio on the right dedicated to Ivete Sangalo.

Wednesday, November 5, 2008

Annoying Unchecked Conversion using JPA

I'm a great user of the Java Persistence API (JPA). It just simplifies the code a lot when interacting with databases. Even with the simplification, the code keeps its readability because the API is object-oriented, very close to our mental abstraction. However, it is still very criticized because of pending features like Criteria, a better default implementation (Toplink sucks!) and a consistent implementation considering Generics. Actually, the last one is the reason of this post, which describes an insignificant but annoying experience with unchecked conversion caused by a weak support of Generics.

The code below shows a business method in a stateless session beans that returns a list of Transcription's instances created by the JPA with data retrieved from the database.
public List findTranscriptions(Segment segment) {
Query query em.createQuery("select t from Transcription t 
where t.segment = :segment");
query.setParameter("segment", segment);
return query.getResultList();
}

When we implement this method using Netbeans, no warning message appears automatically. It might not occur because the editor doesn't understand the word "Transcription" in the query as an entity class. However, the warning message below appears if we put the additional parameter -Xlint:unchecked, which tells the compiler to give more detail for unchecked conversion warnings.
<...>/AnnotationServiceBean.java:70: warning:
[unchecked] unchecked conversion
found   : java.util.List
required: java.util.List<...entity.Transcription>
.getResultList();
1 warning

According to this document, created by Sean Brydon at Sun Microsystems, the warning is generated because query.getResultList() returns a non-generic version of List, when the return type expects "List". To stop the warning, we are obliged to add the annotation @SuppressWarnings("unchecked") just before the method declaration as shown below.
@SuppressWarnings("unchecked")
public List findTranscriptions(Segment segment) {
Query query em.createQuery("select t from Transcription t 
where t.segment = :segment");
query.setParameter("segment", segment);
return query.getResultList();
}

The same document mentions that in a future version of the Java Persistence API, the javax.persistence.Query class will likely change to better support generics. This post is to stimulate them to do it faster, because for me @SuppressWarnings("unchecked") is actually a dirt in my beautiful and legible source code.

Monday, November 3, 2008

Extreme Usability Now on the Web

Since my recent posts about the Extreme Usability Era (here and here), it was just a matter of time to find a good example on the web. A friend of mine, Leonardo Ayres, sent to me a link to the Amazon Windowshop, a virtual shop with an incredible navigation feature. You can navigate using a mouse, of course, but using arrow keys to navigate left, right, top, bottom and the space bar to zoom in/out, you actually have an easier and faster way to explore products.



This website was developed in Adobe Flash. However, every good designer knows that the usability is not about technology in itself, but the way designers use it to improve the user experience. To became a good designer, first we have to be a great artist and then produce art using technology. In parallel, we have to observe people and understand their common behaviors and needs. Finally, we realize how the art should be applied through the technology to help people on their computer interaction.