Notepad++ Plugins

XML Tools: Pretty Print

Oracle date related SQL queries

select TO_DATE(sysdate, 'dd/mm/yyyy') from dual

select TO_CHAR(sysdate, 'MM/DD/YYYY') from dual;

select sysdate from dual;

select * from myTable where DTTMCREATED BETWEEN TO_DATE('09/20/2012','mm/dd/yyyy') AND TO_DATE('09/21/2012','mm/dd/yyyy') 

/* as it's case insensitive in sql, so MM==mm
Oracle use mi to replace mm, and hh24 to represent use 24 hours format. */


Oracle: managing password

After a while, oracle user password will expire:

login in as system
select username, account_status from dba_users;
alter user HAIBO_JPMC identified by my_pass;

Philosophy of Guice

Dependencies injection + interfaces

Classes are glued together by interfaces, and implemented classes are injected in run-time.
---Compile time: interface calls interface, run time: implementation calls implementation. In between taken care by Guice.
  • we don't need implemented classes to get compiled.
  • we could change to different implemented classes on the fly.
  • No need to rewrite test client.
Guice
  • What to inject: map interface to real implementation, this is the place we'll make the change. Keep mind, bind interface to implementation is the best practice, but you could also bind any class to its sub class, as long as they are the same type or implements the same interface.
public class BillingModule extends AbstractModule
{
  @Override 
  protected void configure()
  {
    bind(TransactionLog.class).to(DatabaseTransactionLog.class);
    bind(CreditCardProcessor.class).to(PaypalCreditCardProcessor.class);
    bind(BillingService.class).to(RealBillingService.class);
  }
}
  • Where to inject: mark the location to tell Guice where to replace interface with implementation
public class RealBillingService implements BillingService 
{
  private final CreditCardProcessor processor;
  private final TransactionLog transactionLog;

  @Inject
  public RealBillingService(CreditCardProcessor processor, TransactionLog transactionLog) 
  {
    this.processor = processor;
    this.transactionLog = transactionLog;
  }
....
}
  • How to inject: Usage of Guice, create injector based on module, injector is like a map.
public static void main(String[] args) 
{
    Injector injector = Guice.createInjector(new BillingModule());
    BillingService billingService = injector.getInstance(BillingService.class);
    ...
}

Invoke Method

ResultSet rs....
int index ...

Object obj = rs.getObject(index);
obj = rs.getTimestamp(index);
//this will throws exception "oracle.sql.TIMESTAMP cannot be cast to java.sql.Timestamp"

To solve this problem:


Class clz = obj.getClass();
Method method = clz.getMethod("timestampValue", null);
obj = (Timestamp) method.invoke(obj, null);

Flex Object

setter:
var obj:Object = new Object();
obj.name="test";

getter:
var name:String = obj[name];

Why can't we just call obj.name to get the value? You could only if you could directly use the property name onto the object. You could not do like the following:

var key:String = "name";
var nameValue=obj.key; //this will not work
var nameValue2=obj.name; //this will work

The only way you could do is through []

var nameValue3=obj[key]; //this will work, and recommended

We could actually take property_name == ["property_name"].

Conversion between Java object and Flex object:

Objects are serialized using Java bean introspection rules and also include public fields. Fields that are static, transient, or nonpublic, as well as bean properties that are nonpublic or static, are excluded.

So only public-non-static fields will be transferred to Flex object.

XStream Notes


  • If the java class the XStream using is an inner class, you will find something like Outer-class in the xml,  better don't use inner class for XStream.
  • If you have a filed called "children" which is a list of object, but you don't want to show the name of "children", you want only show the list of object directly, you could doxs.addImplicitCollection(Node.class, "children"); in this way, "children" will not show up in xml file.
  • If you want one attribute name showed in side the tag, using xs.useAttributeFor(Employee.class, "name");
  • <employee>
  •     <name>Jack</name>
  •     <role>Manager</role>
  •     <department>Finance</department>
  •   </employee>
  • to 
  • <employee name="Jack">
  •     <role>Manager</role>
  •     <department>Finance</department>
  •   </employee>