Saturday, December 3, 2011

mongodb is evil?

NoSQL databases were quite popular (with cloud computing and scala) at this year's devoxx and one of these databases was MongoDB. The way you define your models with json-style and the performance benefits seemed like the real power of MongoDB but the following article states that you should reconsider your choice if you choose MongoDB in something other than a toy project. See if mongoDB is evil.

Monday, November 28, 2011

flex likes surprises

Recently I got an odd error while working on flex.
While debugging, I saw that the following code seems to have a value in "container.eGrid.selectedItem" part. It's populated with an object of type MyObject.
But "e" of type MyObject is null. Seems nonsense right? I'm just setting what's in right to left.
A bit later, I saw that I mapped MyObject to a wrong java remoteclass. When I fixed this issue my "e" variable got populated.

var e:MyObject = container.eGrid.selectedItem as MyObject;

Tuesday, November 22, 2011

flex surprises again (this time with datefield)

In my "update" screen (in flex), I'm getting the actual date value from the model and showing it to the user. If the user changes this date value in the screen, no problem; it's working. But if he doesn't touch this date field then the value of it is null as far as I can see while debugging.

In my update screen this is the part I define the datefield.
< mx:DateField id="endingDateDatefield" text="{formatDate(myModel.endingDate)}" 
formatString="{FORMAT_STRING}" width="50%" height="25"/> 
                                  
Notice that formatDate() returns String.

The datefield is displayed correctly but when I try to save the new model I saw no value in debug. "parentPanel.endingDateDatefield.selectedDate" is null.
So I changed my code to:
< mx:DateField id="endingDateDatefield" selectedDate="{myModel.endingDate}" 
formatString="{FORMAT_STRING}" width="50%" height="25"/> 

Now I set the selectedDate field instead of text in DateField component which fixes the issue.

Tuesday, November 15, 2011

drop thread.sleep(), use timeunit's sleep()

Everybody has a Thread.sleep() call somewhere in his code.
sleep() method only accepts milliseconds and if you need some sleep functionality with another time granularity you have either to calculate the sum of milliseconds and put a magic number in the code
Thread.sleep(86400000L);
or a more readable way to do it
Thread.sleep(1000L * 60 * 60 * 24);
or a much more readable way;
TimeUnit.DAYS.sleep(1);
More beautiful code right?

Thursday, November 3, 2011

queryparameterexception: could not locate named parameter

While testing my hibernate query I got a strange exception;
"nested exception is org.hibernate.QueryParameterException: could not locate named parameter".
I checked that the said parameter is in the hibernate model. Furthermore I checked there's a corresponding column in the database. So the problem was not about these. Later I saw that there's a problem while I was trying to set my named parameter. My hql query was like "from TableName t where t.field=:field1" and I was trying to set the value in "field1" with
query.setBoolean("field_", value);
As "field_" does not exist I got this error.
The correct form was;
query.setBoolean("field1", value);