by Bozho | Feb 3, 2012 | Aggregated, Developer tips
Here are the slides for my presentation during the first DZone VIP meetup in Bulgaria. The presentation is short, and the slides can definitely be better, but I’m sharing it anyway. Here are the slides for my presentation during the first DZone VIP meetup in Bulgaria. The presentation is short, and the slides can definitely be better, but I’m sharing it...
by Bozho | Feb 2, 2012 | Aggregated, Developer tips
In spring MVC you can have public class Job { private String jobType; private String location; } @RequestMapping("/foo") public Strnig doSomethingWithJob(Job job) { ... } But that means “jobType” and “location” are the http parameter names, and there is no way to customize that. Which is odd, since this is meta-data, and it should be configurable by annotations. But if you need to customize them (for example, for SEO reasons), you can plug some little pieces of code and Spring MVC will let you do it. Here is my solution to the problem. It makes use of the pluggable argument-resolution mechanism. So, I add my own resolver, see if a command object is annotated with a custom annotation, and if it is – apply the @CommanParameter mapping. Note that Rossen Stoyanchev, main spring-mvc developer also suggested a solution, and while it’s a better one (less code duplication), it won’t work with <mvc:annotation-driven />. Mine works with that (thanks to the post-processor) In the end you can have: @SupportsCustomizedBinding public class Job { @CommandParameter("jt") private String jobType; @CommandParameter("loc") private String location; } In spring MVC you can have public class Job { private String jobType; private String location; } @RequestMapping("/foo") public Strnig doSomethingWithJob(Job job) { ... } But that means “jobType” and “location” are the http parameter names, and there is no way to customize that. Which is odd, since this is meta-data, and it should be configurable by annotations. But if you need to customize them (for example, for SEO reasons), you can plug some little pieces of code and Spring MVC will let you do it. Here is...
by Bozho | Jan 22, 2012 | Aggregated, Opinions
The Dilbert comics is just 2 years younger than me, which means there are thousands of strips. Most of them represent a mocked real-world situation, especially about big corporations and geeks. I have always wondered if managers read Dilbert. I bet they don’t, otherwise they’d say “oh, wait, this thing I’m doing was mocked by Scot Adams, and it is obviously idiotic”. Anyway, regular people like Dilbert could sometimes get a Dilbert attitude and send a comic strip to their managers. And the Dilbert website offers a pretty good search engine for that – just search for “deadline”, “raise”, “new colleague” and you’ll find a lot of good strips to send to your pointy-haired boss. Even if this isn’t going to change the habits of managers, let’s at least make some fun of them. So the next time your company hangs big posters with “Company values”, send this to everyone, cc management. And hope not to get fired. The Dilbert comics is just 2 years younger than me, which means there are thousands of strips. Most of them represent a mocked real-world situation, especially about big corporations and geeks. I have always wondered if managers read Dilbert. I bet they don’t, otherwise they’d say “oh, wait, this thing I’m doing was mocked by Scot Adams, and it is obviously idiotic”. Anyway, regular people like Dilbert could sometimes get a Dilbert attitude and send a comic strip to their managers. And the Dilbert website offers a pretty good search engine for that – just search for “deadline”, “raise”, “new colleague” and you’ll find a lot of good strips to send...
by Bozho | Jan 18, 2012 | Aggregated, Developer tips
Today I noticed this Hibernate stactrace: at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1185) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1261) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) This means that when calling Query#list() (same goes for the JPA variant, which simply invokes the hinbernate class), the session might be flushed. That actually makes sense, because you may have: //running transaction session.save(foo); List result = session.createQuery("from Foo").list(); This will return the newly inserted foo only if the session gets flushed. Otherwise the changes will not be reflected in the database, and you will not get your newly inserted entity. But when will the session be flushed? If we look at SessionImpl#autoFlushIfRequired(..): “detect in-memory changes, determine if the changes are to tables named in the query and, if so, complete execution the flush”. That’s clever. you need a running transaction Something that’s nice to know, so that you don’t flush the session manually in case you need fresh query results. Today I noticed this Hibernate stactrace: at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1185) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1261) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) This means that when calling Query#list() (same goes for the JPA variant, which simply invokes the hinbernate class), the session might be flushed. That actually makes sense, because you may have: //running transaction session.save(foo); List result = session.createQuery("from Foo").list(); This will return the newly inserted foo only if the session gets flushed. Otherwise the changes will not be reflected in the database, and you will not get your newly inserted entity. But when will the session be flushed? If we look at SessionImpl#autoFlushIfRequired(..): “detect in-memory changes, determine if the changes are to tables named in the query and, if so, complete execution the flush”. That’s clever. you need a running transaction Something that’s nice...
by Bozho | Jan 12, 2012 | Aggregated, Opinions
This is going to be an odd publication, that falls more into the “life tips” or “self help” category, than into “programming”. But bear with me. What is “clean software”? Software that has very few bugs, that has readable and maintainable code, that has good documentation and a lot of automated tests and metrics. How do you get clean software? Each day you fix and improve things. As I wrote a month ago – you should fix bad code as soon as it appears (or in the next sprint/iteration), and you should have code reviews to make sure everything committed is fine. You must write good unit tests, even though it might feel redundant. You must eliminate all bugs before writing new code (one of Joel’s 12 points). You should document everything that you write, so that it’s clear what it does and why. And you should have a project plan (Joel’s test, again). As a programmer you know these things, and you are aware that they make better software. And now the metaphor – the development of your life is like the development of a software system – if you conform to some best practices and principles, it will be better (obviously?). If you apply the “clean software” approach to your own existence, it is likely to improve in the long run. What do I mean: health issues – in case of any discomfort or pain, fix it immediately. Run the “automated tests and metrics” in a hospital, and find out what is it. If you fix it early, it won’t get more complicated to fix later. And...
Recent Comments