Found this command to be pretty handy to list all the authors user names for a git project:
git log --format='%aN <%aE>' | awk '{arr[$0]++} END{for (i in arr){print arr[i], i;}}' | sort -rn | cut -d\ -f2-
Found it on this site: http://www.commandlinefu.com/commands/view/4519/list-all-authors-of-a-particular-git-project
Alex's Stuff
This is where I keep interesting things. At least things that are interesting to me...
Tuesday, June 11, 2013
Thursday, November 22, 2012
Fix a bad fstab file in CentOS
If you ever screw up your fstab file in CentOS the OS will refuse to boot. It will however allow you to enter the root password to try and fix the problem. This would be nice if the file system was mounted correctly because you could then edit the /etc/fstab file and be on your way. Alas, since the filesystem is not mounted correctly because you messed up the fstab file you can only open up files in read only mode. To fix this issue this little command and then edit your fstab file.
mount -n -o remount,rw /
Done! Now go grab a beer and be happy.
Wednesday, December 28, 2011
Wednesday, July 6, 2011
Using log4j to Print Hibernate SQL and Parameters
Here are some handy log4j entries to print out what hibernate is doing behind the scenes:
log4j.logger.org.hibernate.SQL=DEBUG -- This will output the SQL hibernate generates. log4j.logger.org.hibernate.type=TRACE -- This will show the bind variable values hibernate is using.
log4j.logger.org.hibernate.SQL=DEBUG -- This will output the SQL hibernate generates. log4j.logger.org.hibernate.type=TRACE -- This will show the bind variable values hibernate is using.
Thursday, June 2, 2011
Hibernate Criteria with Complex Object Restrictions
So here is the deal, you want to create a hibernate criteria statement with some restrictions. These are no ordinary restrictions though, these are properties of other properties in your class; So something like the following:
You want to load a Person object by setting a restriction on the username property of the UserInfo class. So at first you might try something like this:
What happens when you do that is hibernate throws up all over itself. Here is the way to make it work:
So all that really needs to be done is create an alias for the UserInfo entity and reference that in your restriction statement, DONE!
public class Person{
private UserInfo userInfo;
//Getters and setters omitted
}
public class UserInfo {
private String username;
}
You want to load a Person object by setting a restriction on the username property of the UserInfo class. So at first you might try something like this:
Criteria personCriteria = getCurrentSession().createCriteria(Person.class)
.add(Restrictions.ilike("userInfo.username", "someUserNameGoesHere"));
What happens when you do that is hibernate throws up all over itself. Here is the way to make it work:
Criteria countCriteria = getCurrentSession().createCriteria(Person.class)
.createAlias("userInfo", "ui")
.add(Restrictions.ilike("ui.username", "someUserNameGoesHere"));
So all that really needs to be done is create an alias for the UserInfo entity and reference that in your restriction statement, DONE!
Friday, April 29, 2011
Spring 3 @Async with Hibernate and Spring Transactions
The other day we ran into a fun little problem while trying to use the Spring 3 @Async annotation. We had the following scenario:
A web service was invoked by a client app to update some things in the database. Based on what was updated several other calls had to be made to the database to update even more data. When all was said and done this process could take upwards of 15 minutes to complete which is pretty bad considering the SLA was 10-30 seconds. The obvious problem here is this class is doing WAY too much, but that is what the user's wanted so that is how things had to be.
The call stack looked something like this
->Call in to web service from client - (a few calls happen within this service besides the call listed below)
--->Web service calls service facade to run calculations - (This method is transactional since it reads and writes to the database, this method is also called twice in the web service.)
------>Service facade calls a DAO object (backed by hibernate) many many times.
<---Return to client after an eternity.
Our solution to this was to make the slow part asynchronous with Spring 3's new, awesome @Async annotation. So we annotated the service facade with the @Async annotation and thought our super
slow process would run in the background. We put some log statements in the beginning and end of the slow process so we could be sure the method was actually executing in it's own thread after the web service
call returned, it blew up big time. After searching on Google for a while I found out that having @Async and @Transactional on the same method can cause issues from time to time. So we created another service
facade to call the old service facade. We annotated the new facade with @Async and left @Transactional on the old facade. This approach got us further but failed on the second call to the service facades.
You will notice above that the service facade is called two times from within the web service, the first call worked perfectly. The second call would fail with a org.hibernate.exception.GenericJDBCException: Cannot open connection exception when trying to access a member variable attahed to a parameter in the service facade. Once I dug into this I noticed the parameter object being passed to the service facades was actually a hibernate backed domain object which was populated inside the web service. The member
variable we were trying to access within the service facade was actually a collection of objects that was set to be lazy loaded. When this object was passed to the asyncronus service facade it was not fully
populated, just backed by hibernate. That being said when the async service tried to load up that collection of objects backed by hibernate the hibernate session the object was loaded on was killed
when the first thread exited, the web service thread, thus causing hibernate to fail. By moving the loading logic for that object into the ansync method everything started working!
A web service was invoked by a client app to update some things in the database. Based on what was updated several other calls had to be made to the database to update even more data. When all was said and done this process could take upwards of 15 minutes to complete which is pretty bad considering the SLA was 10-30 seconds. The obvious problem here is this class is doing WAY too much, but that is what the user's wanted so that is how things had to be.
The call stack looked something like this
->Call in to web service from client - (a few calls happen within this service besides the call listed below)
--->Web service calls service facade to run calculations - (This method is transactional since it reads and writes to the database, this method is also called twice in the web service.)
------>Service facade calls a DAO object (backed by hibernate) many many times.
<---Return to client after an eternity.
Our solution to this was to make the slow part asynchronous with Spring 3's new, awesome @Async annotation. So we annotated the service facade with the @Async annotation and thought our super
slow process would run in the background. We put some log statements in the beginning and end of the slow process so we could be sure the method was actually executing in it's own thread after the web service
call returned, it blew up big time. After searching on Google for a while I found out that having @Async and @Transactional on the same method can cause issues from time to time. So we created another service
facade to call the old service facade. We annotated the new facade with @Async and left @Transactional on the old facade. This approach got us further but failed on the second call to the service facades.
You will notice above that the service facade is called two times from within the web service, the first call worked perfectly. The second call would fail with a org.hibernate.exception.GenericJDBCException: Cannot open connection exception when trying to access a member variable attahed to a parameter in the service facade. Once I dug into this I noticed the parameter object being passed to the service facades was actually a hibernate backed domain object which was populated inside the web service. The member
variable we were trying to access within the service facade was actually a collection of objects that was set to be lazy loaded. When this object was passed to the asyncronus service facade it was not fully
populated, just backed by hibernate. That being said when the async service tried to load up that collection of objects backed by hibernate the hibernate session the object was loaded on was killed
when the first thread exited, the web service thread, thus causing hibernate to fail. By moving the loading logic for that object into the ansync method everything started working!
Monday, January 17, 2011
Extracting Movies Times from Google with Mule 3
Hey everyone, this is going to be a multipart series on what it takes to stand up a mule 3 service with the latest features to communicate with CityGrid web services and pull movie times from google and expose them using REST/JSON. To start with I am going to open up all the source code of the mule service then walk through each facet of the system over the next couple weeks. The system, affectionately named UDoin (more on the sweet name later) currently has the following features:
- UDoin takes in a set of latitude and longitude coordinates via a REST/JSON service and retrieves restaurants, bars/clubs, movie times/theaters within a radius of the given location.
- The coordinates are fed to CityGrid along with a few other arguments and this is where the restaurants, bars, and clubs come from. This is done using Mule's new style of multi-casting router the "All" router.
- After results come back from CityGrid movie times for the current location and time are extracted from Google using the open source HtmlParser project and put on the UDoin response.
- UDoin comes complete with JMX to monitor the system health in real time.
- UDoin uses maven for dependency management and packaging to allow for seamless integration with a CI server such as Hudson.
Subscribe to:
Posts (Atom)