Sunday, March 25, 2012

run jetty on dependency resolved war in gradle



Background:
  • test classes(such as selenium tests) are in an independent module(maven project, etc.).
  • have an external dependency(mave, ivy, etc) to war file(s)
  • want to run jetty on dependent war file(s)
Gradle can start up jetty on dependency resolved war file(s).


When you want to run your tests after jetty started, set "daemon=true" and make the test task depends on your new run-war task.


Monday, March 5, 2012

run multiple jetty in gradle


Background:
I have a selenium test suite for end-to-end web testing.
Currently, it is running on jenkins box but it is taking so long to finish all the tests.
So, next step is to parallelize the selenium tests.
As a first step, I need to start multiple jetty servers using different port.

With Gradle jetty plugin, I camp up how to run the multiple jetty servers before tests.

Thursday, June 30, 2011

run same command on multiple directories


I've been working on applications that consist of multiple maven projects.
Many time, I have to type same commands on multiple project directories, such as "mvn install", "svn up", "git …", etc.


I wrote a bash script that executes given command(s) on multiple directories.

Multiple Directory Command:


Sample: (mc is the script alias I use)

  > mc svn up                            # svn up all projects
  > mc -g projA mvn install     # call "mvn install" on porjA group directories(defined in config file)
  > mc git checkout -b new_branch master  # create a new git branch to all project

  > mc git branch                      # display current git branch in all project
  > mc -g projA svn up             #  "svn up" projA directories
  > mc -g projB -c config_file du -sh  # chcek directory size of projB directories

please see more options here.

Thursday, January 28, 2010

datasource-proxy framework

--
I'm writing a framework that helps monitoring and debugging query execution from app.

[Project Home]

Features:
- log all database queries with parameter values
- log each query's elapsed time
- log statistics of all database call and total query elapsed time
- provide callback to database call
- provide statistics object

Database Call Log:
Time:10, Num:1, Query:{[insert into emp ( id, name )values (?, ?);][1, foo]}
Time:1, Num:1, Query:{[select this_.id as id0_0_, this_.name as name0_0_, this_.value as value0_0_ from emp this_ where (this_.id=? and this_.name=?)][1,bar]}

Statistics Log:
DataSource:MyDatasourceA ElapsedTime:13 Call:7 Query:7 (Select:3 Insert:2 Update:1 Delete:0 Other:1)
DataSource:MyDatasourceB ElapsedTime:1 Call:1 Query:1 (Select:1 Insert:0 Update:0 Delete:0 Other:0)

If you are interested,

    Monday, September 3, 2007

    Hibernate: Association Mappings in Annotation (JPA style)

    Unidirectional Association

    Unidirectional Association with Join Table

    Bidirectional Association

    Bidirectional Association with Join Table

    (*) hibernate document chapter

    Reference:
    - hibernate documentation
    - EJB 3.0 Spec


    Hibernate: Annotation many-to-many (join table)

    Bidirectonal many-to-many (join table) association

    Hibernate Doc (Chap 8.5.3)


    ::Relationship::
    person(many) <-> address(many)

    ::DB Schema::
    person(personId)
    address(addressId)
    personaddress(personId, addressId)

    ::Java Operation::
    person.getAddresses();
    address.getPeople();

    ::Annotation::

    @Entity
    @Table(name = "PERSON")
    public class Person {
    
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "personId")
      private int id;
    
      // mapping owner
      @ManyToMany
      @JoinTable(name = "PersonAddress",
        joinColumns = {
          @JoinColumn(name="personId", unique = true)           
        },
        inverseJoinColumns = {
          @JoinColumn(name="addressId")
        }
      )
      private Set<Address> addresses;
    }


    @Entity
    @Table(name = "ADDRESS")
    public class Address {
    
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "addressId")
      private int id;
    
      @ManyToMany(mappedBy="addresses")  // map info is in person class
      private Set<Person> people;
    }



    ::Generated SQL::
    - person.getAddresses();
    select addresses0_.personId as personId1_, addresses0_.addressId as addressId1_, address1_.addressId as addressId3_0_ from PersonAddress addresses0_ left outer join ADDRESS address1_ on addresses0_.addressId=address1_.addressId where addresses0_.personId=?

    - address.getPeople();
    select people0_.addressId as addressId1_, people0_.personId as personId1_, person1_.personId as personId2_0_ from PersonAddress people0_ left outer join PERSON person1_ on people0_.personId=person1_.personId where people0_.addressId=?

    [Association Mapping List]

    Hibernate: Annotation one-to-one (join table)

    Bidirectonal one-to-one (join table) association (very unusual)

    Hibernate Doc (Chap 8.5.2)


    ::Relationship::
    person(one)(mapping owner) <-> address(one)

    ::DB Schema::
    person(personId)
    address(addressId)
    personaddress(personId, addressId)

    ::Java Operation::
    person.getAddress();
    address.getPerson();

    ::Annotation::

    
    
    @Entity
    @Table(name = "PERSON")
    public class Person {
    
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "personId")
      private int id;
    
      @OneToOne(optional=true)
      @JoinTable(name="PersonAddress",
        joinColumns = {
          @JoinColumn(name="personId", unique = true)           
        },
        inverseJoinColumns = {
          @JoinColumn(name="addressId")
        }     
      )
      private Address address;
    }


    @Entity
    @Table(name = "ADDRESS")
    public class Address {
    
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Column(name = "addressId")
      private int id;
    
      @OneToOne(optional=true, mappedBy="address") // pointing to Person's address field
      private Person person;   
    }



    ::Generated SQL::
    - person.getAddress();
    select person0_.personId as personId2_2_, person0_1_.addressId as addressId3_2_, address1_.addressId as addressId4_0_, address1_1_.personId as personId3_0_, person2_.personId as personId2_1_, person2_1_.addressId as addressId3_1_ from PERSON person0_ left outer join PersonAddress person0_1_ on person0_.personId=person0_1_.personId left outer join ADDRESS address1_ on person0_1_.addressId=address1_.addressId left outer join PersonAddress address1_1_ on address1_.addressId=address1_1_.addressId left outer join PERSON person2_ on address1_1_.personId=person2_.personId left outer join PersonAddress person2_1_ on person2_.personId=person2_1_.personId where person0_.personId=?

    - address.getPerson();
    select address0_.addressId as addressId4_2_, address0_1_.personId as personId3_2_, person1_.personId as personId2_0_, person1_1_.addressId as addressId3_0_, address2_.addressId as addressId4_1_, address2_1_.personId as personId3_1_ from ADDRESS address0_ left outer join PersonAddress address0_1_ on address0_.addressId=address0_1_.addressId inner join PERSON person1_ on address0_1_.personId=person1_.personId left outer join PersonAddress person1_1_ on person1_.personId=person1_1_.personId left outer join ADDRESS address2_ on person1_1_.addressId=address2_.addressId left outer join PersonAddress address2_1_ on address2_.addressId=address2_1_.addressId where address0_.addressId=?

    [Association Mapping List]