Monthly Archives: November 2011

Oracle Case Insensitivity and JDBC Drivers

Natively Oracle is case sensitive which means if you executed a query for e.g.


select emp_id, emp_salary from employee where emp_name = 'amit';

it would search for the string ‘amit’ in lowercase. We can switch this to make the search behave case insensitively by setting the NLS_COMP and NLS_SORT parameters from Oracle’s globalization support which was previously called National Language Support (NLS).

Read the rest of this entry

Advertisement

Generating Delegate Methods In Java Using Intellij

If you are implementing a decorator pattern, you would have to implement one or more interfaces. If the interface has large number of methods, delegating each of them might be troublesome and error prone. Since there is no good way in java to implement delegates (implementing a proxy with an invocation handler is a workaround :)), a better option would be to take help of the IDE to be sure that the implementation is not error prone. Here is how to do it using Intellij IDE

Read the rest of this entry

Function Arguments – Clean Code

As an extension to the last post on functions, below are some points about function arguments.

Function Arguments

  • Function arguments take a lot of conceptual power while reading and understanding code.
  • They should be at the same level of abstraction as the function name. For e.g. String createTestableHtml(PageData pageData). Reading this function signature forces you to know the detail which isn’t particular important at that point in time.
  • The ideal number of arguments for a function is zero (niladic). Next comes one (monadic), followed closely by two (dyadic). Three arguments (triadic) should be avoided where possible. More than three (polyadic) requires very special justification—and then shouldn’t be used anyway.
  • Output arguments

    • Arguments are most naturally interpreted as inputs to a function.
    • Output arguments should be avoided. If your function must change the state of something, have it change the state of its owning object

    Read the rest of this entry

    Configuring Ehcache with JPA, Hibernate & Spring

    This post details on the steps required to configure ehcache as the second level hibernate cache when jpa, hibernate and spring are used in combination

    Configuring the cache

    Add the below properties to the persistence.xml configuration file

    <property name="hibernate.cache.use_second_level_cache" value="true"/>
    <property name="hibernate.cache.use_query_cache" value="true"/>
    <property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/>
    <property name="hibernate.generate_statistics" value="true"/>
    

    Read the rest of this entry

    Email Alerts With Logback

    Logback provides a support to send logged messages in an email through an SMTPAppender. The SMTPAppender accumulates logging events in one or more fixed-size buffers and sends the contents of the appropriate buffer in an email after a user-specified event occurs. By default, the email transmission is triggered by a logging event of level ERROR or higher. Moreover, by default, a single buffer is used for all events.

    A sample smtp appender configuration would look like below

    Read the rest of this entry