Code
Mocking static method dependencies
Good article on refactoring “static cling“, have used this several times now:
@Service("securityContextRepository")
public final class SecurityContextRepositoryImpl implements SecurityContextRepository {
@Override public SecurityContext getSecurityContext() {
// Spring framework dependency that I rely on but do not wish to test directly
return SecurityContextHolder.getContext();
}
}
I can now mock the SecurityContextRepository implementation that is injected into my test cases and remove the reliance on a static method call.
Git revert a mistaken commit
You have 2 commits staged, and you want to keep the latest but revert the first. Easy when you know how:
git revert HEAD^
Oracle 11g UCP with Tomcat
Ensure you have the below tnsnames.ora file in TNS_ADMIN so as to connect to the server from client using connect string: sqlplus <username>@xyz
xyz = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP) (PORT = <port>) (HOST = <server_name>) ) (CONNECT_DATA = (SID = <SID>)) )
tomcat/conf/server.xml file:<GlobalNamingResources>
<Resource name="jdbc/<pool_jndi_name>" auth="Container" url="jdbc:oracle:thin:@<server_name>:<port>:<SID>" user="<username>" password="<password>" factory="oracle.ucp.jdbc.PoolDataSourceImpl" type="oracle.ucp.jdbc.PoolDataSource" connectionFactoryClassName="oracle.jdbc.pool.OracleDataSource" connectionPoolName="<pool_name>" connectionWaitTimeout="30" minPoolSize="5" maxPoolSize="25" inactiveConnectionTimeout="20" timeoutCheckInterval="60" validateConnectionOnBorrow="true" sqlForValidateConnection="SELECT 1 FROM DUAL" />
...ucp.jar to tomcat/libs directory.
Dozer examples
Best place to find Dozer example mapping files is in the source bundle under test/resources. Most other examples out there are pretty basic and won’t help you if you want to do something more complex…
Google Apps observations
After experimenting and persevering with Google Apps in a corporate environment I would say the following are the headline issues we have experienced:
Positives:
- Fantastic cost/effort reduction over homegrown or outsourced alternatives
- Simple setup and good online documentation and usability
Negatives:
- Lack of full product features in Google Docs versus MS Office
- Security features not entirely sufficient for a corporate environment
In general, for the cost, speed and effort with which you can set up a functioning environment I would say it’s definitely worth at least making sure you positively rule out Google Apps as an option for your corporate IT infrastructure.
The major issues we have found that might count against Google would be the inability to restrict usage to a certain IP range (i.e. the office) and poor Docs interoperability with MS Office. Until these are resolved corporate users will be slow on the uptake.
I think it’s a reasonable assumption that the products will improve rapidly – but I have found a lot of people with similar observations and no indication from Google that the security issues at least are being tackled!
Agile Management
I have recently been involved with a project that had a great development team – project manager, BA, server-side and UI developers and a QA team – all co-located and pulling merrily and effectively along together towards the same objectives.
Whilst we undertook some pretty serious refactoring efforts as the Product Owner (rightly) demanded a change of direction and focus, there were numerous issues that arose as senior managers who had little knowledge or understanding of the project – or possibly more importantly Agile – came under increasing pressure to “do something” as the timelines wore on due to the change of direction.
Kelly Waters’ post on why Agile must be adopted and understood from the top-down pretty succinctly sums up many of the challenges we faced, particularly around stakeholder management and expectations.
As I’ve mentioned before in response to a similar post by Mark Schumann, it’s a shame and a surprise to me that those who do not understand or are not involved directly in an Agile project, but are nonetheless in positions of influence and supposed control, cannot do a little more to understand what is in essence a fairly simple, and I doubt particularly uncommon, scenario.
Java Reflection & Constructor Varargs
I had a spot of trouble getting reflection to work with a Vararg constructor. Without being entirely sure, I think this is because Generics are implemented by type erasure whereby the type information is only available at compile time. At runtime i.e. when the Reflection API is invoked, the type information has been erased by the compiler. It looks as though this is the case to ensure legacy backwards compatibility.
Anyway, the trick with the code below was to double-wrap the constructor argument array ‘y’ in another Object array ‘z’, which isn’t clear at compile-time. This avoids an IllegalArgumentException: wrong number of arguments exception.
public A1C0(final List<RoomStream>... occupancyLevels) {
// constructor
}
public static void main(String[] args) throws Exception {
final List<RoomStream> a = new ArrayList<RoomStream>();
final List<RoomStream> b = new ArrayList<RoomStream>();
final Class[] x = {List[].class};
final List[] y = {a, b, d, e};
final Object[] z = {y};
final Constructor c = getClass().getConstructor(x);
final Object o = c.newInstance(z);
System.out.println(o); }
Agile Evolution
Charles Darwin: “It is not the strongest of the species that survive, nor the most intelligent, but the one most responsive to change.”
Agile Hype?
There is now a lot of “hype” around the Agile development methodology, possibly because it’s producing better results than traditional approaches, or perhaps it just makes people’s working lives more interesting and challenging?
Either way, I read an agile101 post suggesting that ‘doing’ agile is a sign of incompetence which put my hackles up as you might expect, given that I’m a keen advocate. But the article makes an extremely pertinent point which I’d like to stress – that Agile is only something you are going to ‘become’ with plenty of practice. Picking up a book is a good place to start but that’s all it is… Agile development is an intuitive mindset, not a bunch of rules you can follow and hope to immediately be good at.
It also struck me that as Agile has gathered pace there are now many different ways of wrapping lots of processes and metrics, management techniques and so on around the basic concepts. In my opinion this in many ways detracts from the fundamentals that are ultimately going to help you deliver, and feel these demands can actually make a team less agile as the post suggests.
Here’s my mantra, if I can call it that, which I try and religiously stick to whilst leading Agile software development teams:
- Focus, focus, focus – if it doesn’t make the boat go faster then save it for another day.
- Refactor, refactor, refactor – even the smartest and most experienced developers rarely get it bang-on first time around, especially given that priorities and requirements are often less than stable.
- Challenge the business sponsor and requirements – often I’ve found that requirements are over-complicated for the problem at hand. Get to the root of the issue, understand it, and then propose simpler alternatives which actually address the real issue.
- Aim for the best in every single line of code and development practice if you can – look after all the little things and the big things will take care of themselves!
Sure, there are many tips and suggestions that can help you and your team to a place where you are able to “move light, travel fast” but as a Technical Lead or Architect (as opposed to Project Manager, say) I think it’s more important to get an intuitive “feel” for what’s a true value-add.
Although you’ll probably have to compromise at times on some of the points mentioned above, they’ve been great cornerstones for me when I feel there are too many demands on my time from what I consider to be less important techniques or deliverables.
Hibernate’s @FilterJoinTable
Couldn’t find a completely articulate example or full documentation of how to add a filter to a Hibernate Many-to-Many collection association mapping, so thought I’d would post a complete example here.
It’s possible to apply the filter to the target entity table which is reasonably well documented, or at least you can have an educated guess, but also to the association table of the Many-to-Many relationship where the docs were a little less clear.
I have the following relational association table:
CREATE TABLE departure_point_resort_association (
departure_point_id VARCHAR(36) NOT NULL,
resort_id VARCHAR(36) NOT NULL,
site_id ENUM('30', '31'...) NOT NULL,
PRIMARY KEY (departure_point_id, resort_id),
CONSTRAINT assoc_departure_point_fk FOREIGN KEY (departure_point_id)
REFERENCES departure_point (id),
CONSTRAINT assoc_resort_fk FOREIGN KEY (resort_id) REFERENCES resort (id)
);
which is mapping a ski resort to potential departure points or airports. There was no real requirement to persist an actual SITE table (which would be entirely static data) and to map to it’s foreign key value, so instead am using a simple MySQL ENUM column above, and wanted to apply a filter at the application level to the collection of Resorts based on this site_id.
@Entity @Table
@FilterDef(name = "siteFilter", parameters = {
@ParamDef(name = "siteId", type = "string")
})
public final class Resort extends BasePersistentObject {
@ManyToMany(fetch = FetchType.EAGER)
@FilterJoinTable(name = "siteFilter", condition = "site_id = :siteId")
@JoinTable(name = "DEPARTURE_POINT_RESORT_ASSOCIATION",
joinColumns = {
@JoinColumn(name = "RESORT_ID")
},
inverseJoinColumns = {
@JoinColumn(name = "DEPARTURE_POINT_ID")
}
)
private Set departurePoints;
Then it’s simply a case of enabling the filter in the client (DAO or whatever your framework dictates):
session.enableFilter("siteFilter").setParameter("siteId", String.valueOf(siteId));
Agile CTO
- @dajb2 thanks ps. hope you're well & happy! drew 6 days ago
- @dajb2 cannot understand why internal it's not always 100%, regardless of bugs and rework #accountants #fail 6 days ago
- @dajb2 are you able to point me in direction of definitive definition of how CapEx is assigned to internal / external software projects? 6 days ago
- @dajb2 hey jack of all trades, how's it going? have a questions for you... 6 days ago
- @tfl exactly how does an hour to travel 10 stops classify as "minor delays" #epic #fail 6 days ago
- hey @github please bring back the smiley faces!!! ;o) 1 week ago
- watching @thecleancoders episode 10 on Open-Closed Principle http://t.co/6Ormqmsy #OO Best one yet @unclebobmartin Thanks! 2 weeks ago
- #devops #jobs #london http://t.co/OSgnfmls 3 weeks ago
- we are hiring #devops http://t.co/ykkoINVr and #qa https://t.co/Vn6TaYBx roles in #london #careers 2012-04-17
- looking for a senior systems engineer #devops #london #jobs https://t.co/04j14eVD 2012-04-11
- More updates...


