Java Code Samples

How to use Minute Project

Posted in Java, Old stuff by Cristian on September 4, 2010

I just discovered a Sourceforge project : MinuteProject and it’s wiki page.

How it works and what is does ?

Simple ,based on the database model generates code for A LOT of things : Spring + Hibernate , Spring + Jpa, Spring + Ibatis, OpenXava and some other incubator targets.

In this post I will focus on Spring + Hibernate target.

What this Spring + Hibernate target generates ?

It generates full backend layer for a given database.Once having this you can focus more on the business layer so it will save you A LOT of time.

Why this project and not other  ?

Because this does a lot more  and it is completely free and extensible. Even  you can extend it if you want by opening a new target.

Do not fall in the trap the everything that is not expensive is not good ! You will hear a lot more about MinuteProject in the near future so do not hesitate to use it.

How do i start ?

Step 1)

First be sure you have Maven installed and it would not hurt if you have MySql as well (despite it is database agnostic and Oracle,HSQL,DB2,Firebird,Postgres,MySql are already tested)

Then download MinuteProject .

Step 2)

Create a database (or use an existing one).

I created a simple sales application that has : customers,products and invoices

Sql scripts are here

Step 3)

Create a config file based on a sample that you can find in demo\config dir of the MinuteProject distribution, where the only important thing you need to specify is the connection parameters to the database you just created on previous step
Name that mp-config-sales.xml.Sample is here

Step 4)

Alter one of the exiting cmd file and add at the and
“%JAVA_HOME%\bin\java” %CP% net.sf.minuteProject.application.ModelViewGenerator mp-config-sales.xml
(assuming the name of the file created on the step 3 is mp-config-sales.xml).Otherwise specify the name you provided on step 3.

Step 5)

Generate the code :)

Execute the cmd file created on step 5 and check the DEV directory created in the root of the MinuteProject distribution.

You will find there some generated code that saved not only your time ,but also your money :)

I will just show you the interface for the CustomerDao and CustomerExtDao class.

You will see the power of this project just studying this interfaces.

Optional

If you have Maven ,run the file from MinuteProject root directory target\mp-bsla\install_maven.cmd  just to install minute project into you m2 repository

After that you can run ,build , test with maven the projects that were generated and described in the steps above.

Conclusion

There will be a graphical tool for this avoiding this editing this files that I described.

If you ask me how can I characterize this project in a word , the for sure it will be : PRODUCTIVITY

In case you did not click on the links above here is just a sample of what MinuteProject generates

package mp.demo.sales.dao.face.admin;

import mp.demo.sales.domain.admin.Customers;
import java.util.List;
import net.sf.minuteProject.architecture.bsla.bean.criteria.PaginationCriteria;
import net.sf.minuteProject.architecture.bsla.dao.face.DataAccessObject;

/**
 *
 * <p>Title: CustomersDao</p>
 *
 * <p>Description: Interface of a Data access object dealing with CustomersDao
 * persistence. It offers a set of methods which allow for saving,
 * deleting and searching customers objects</p>
 *
 */
public interface CustomersDao extends DataAccessObject {

 /**
 * Inserts a Customers entity
 * @param Customers customers
 */
 public void insertCustomers(Customers customers) ;

 /**
 * Inserts a list of Customers entity
 * @param List<Customers> customerss
 */
 public void insertCustomerss(List<Customers> customerss) ;

 /**
 * Updates a Customers entity
 * @param Customers customers
 */
 public Customers updateCustomers(Customers customers) ;

 /**
 * Updates a TbParty entity with only the attributes set into TbParty.
 * The primary keys are to be set for this method to operate.
 * This is a performance friendly feature, which remove the udibiquous full load and full update when an
 * update is to be done
 * Remark: The primary keys cannot be update by this methods, nor are the attributes that must be set to null.
 * @param TbParty tbParty
 */
 public int updateNotNullOnlyCustomers(Customers customers) ;

 public int updateNotNullOnlyPrototypeCustomers(Customers customers, Customers prototypeCriteria);

 /**
 * Saves a Customers entity
 * @param Customers customers
 */
 public void saveCustomers(Customers customers);

 /**
 * Deletes a Customers entity
 * @param Customers customers
 */
 public void deleteCustomers(Customers customers) ;

 /**
 * Loads the Customers entity which is related to an instance of
 * Customers
 * @param Long id
 * @return Customers The Customers entity

 public Customers loadCustomers(Long id);
*/
 /**
 * Loads the Customers entity which is related to an instance of
 * Customers
 * @param java.lang.Integer Id
 * @return Customers The Customers entity
 */
 public Customers loadCustomers(java.lang.Integer id);    

 /**
 * Loads a list of Customers entity
 * @param List<java.lang.Integer> ids
 * @return List<Customers> The Customers entity
 */
 public List<Customers> loadCustomersListByCustomers (List<Customers> customerss);

 /**
 * Loads a list of Customers entity
 * @param List<java.lang.Integer> ids
 * @return List<Customers> The Customers entity
 */
 public List<Customers> loadCustomersListById(List<java.lang.Integer> ids);

 /**
 * Loads the Customers entity which is related to an instance of
 * Customers and its dependent one to many objects
 * @param Long id
 * @return Customers The Customers entity
 */
 public Customers loadFullFirstLevelCustomers(java.lang.Integer id);

 /**
 * Loads the Customers entity which is related to an instance of
 * Customers
 * @param Customers customers
 * @return Customers The Customers entity
 */
 public Customers loadFullFirstLevelCustomers(Customers customers);    

 /**
 * Loads the Customers entity which is related to an instance of
 * Customers and its dependent objects one to many
 * @param Long id
 * @return Customers The Customers entity
 */
 public Customers loadFullCustomers(Long id) ;

 /**
 * Searches a list of Customers entity based on a Customers containing Customers matching criteria
 * @param Customers customers
 * @return List<Customers>
 */
 public List<Customers> searchPrototypeCustomers(Customers customers) ;

 /**
 * Searches a list of Customers entity based on a list of Customers containing Customers matching criteria
 * @param List<Customers> customerss
 * @return List<Customers>
 */
 public List<Customers> searchPrototypeCustomers(List<Customers> customerss) ;    

 /**
 * Searches a list of Customers entity
 * @param Customers customers
 * @return List
 */
 public List<Customers> searchPrototypeCustomers(Customers customersPositive, Customers customersNegative) ;

 /**
 * Load a paginated list of Customers entity dependent of pagination criteria
 * @param PaginationCriteria paginationCriteria
 * @return List
 */
 public List loadPaginatedCustomers (Customers customers, PaginationCriteria paginationCriteria) ;

}


package mp.demo.sales.dao.face.admin;

import mp.demo.sales.domain.admin.Customers;
import java.util.List;
import net.sf.minuteProject.architecture.filter.data.Criteria;
import net.sf.minuteProject.architecture.bsla.dao.face.DataAccessObject;

/**
 *
 * <p>Title: CustomersExtDao</p>
 *
 * <p>Description: Interface of a Data access object dealing with CustomersExtDao
 * persistence. It offers extended DAO functionalities</p>
 *
 */
public interface CustomersExtDao extends DataAccessObject {

 /**
 * Inserts a Customers entity with cascade of its children
 * @param Customers customers
 */
 public void insertCustomersWithCascade(Customers customers) ;

 /**
 * Inserts a list of Customers entity with cascade of its children
 * @param List<Customers> customerss
 */
 public void insertCustomerssWithCascade(List<Customers> customerss) ;        

 /**
 * lookup Customers entity Customers, criteria and max result number
 */
 public List<Customers> lookupCustomers(Customers customers, Criteria criteria, int numberOfResult);

 public Integer updateNotNullOnlyCustomers (Customers customers, Criteria criteria);

 /**
 * Affect the first customers retrieved corresponding to the customers criteria.
 * Blank criteria are mapped to null.
 * If no criteria is found, null is returned.
 */
 public Customers affectCustomers (Customers customers);

 public Customers affectCustomersUseCache (Customers customers);

 /**
 * Assign the first customers retrieved corresponding to the customers criteria.
 * Blank criteria are mapped to null.
 * If no criteria is found, null is returned.
 * If there is no customers corresponding in the database. Then customers is
inserted and returned with its primary key(s).
 */
 public Customers assignCustomers (Customers customers);

 public Customers assignCustomersUseCache (Customers customers);

 /**
 * return the first Customers entity found
 */           
 public Customers getFirstCustomers (Customers customers);

 /**
 * checks if the Customers entity exists
 */           
 public boolean existsCustomers (Customers customers);    

 public boolean existsCustomersWhereConditionsAre (Customers customers);

 /**
 * partial load enables to specify the fields you want to load explicitly
 */            
 public List<Customers> partialLoadCustomers(Customers customers, Customers positiveCustomers
, Customers negativeCustomers);

 /**
 * partial load with parent entities
 * variation (list, first, distinct decorator)
 * variation2 (with cache)
 */
 public List<Customers> partialLoadWithParentCustomers(Customers customers, Customers positiveCustomers
, Customers negativeCustomers);

 public List<Customers> partialLoadWithParentCustomersUseCache(Customers customers, Customers positiveCustomers,
 Customers negativeCustomers, Boolean useCache);

 public List<Customers> partialLoadWithParentCustomersUseCacheOnResult(Customers customers, Customers positiveCustomers,
 Customers negativeCustomers, Boolean useCache);

 /**
 * variation first
 */
 public Customers partialLoadWithParentFirstCustomers(Customers customersWhat, Customers positiveCustomers,
 Customers negativeCustomers);

 public Customers partialLoadWithParentFirstCustomersUseCache(Customers customersWhat, Customers positiveCustomers,
 Customers negativeCustomers, Boolean useCache);

 public Customers partialLoadWithParentFirstCustomersUseCacheOnResult(Customers customersWhat,
Customers positiveCustomers, Customers negativeCustomers, Boolean useCache);

 /**
 * variation distinct
 */
 public List<Customers> getDistinctCustomers(Customers customersWhat, Customers positiveCustomers,
 Customers negativeCustomers);

 //
 public List partialLoadWithParentForBean(Object bean, Customers customers, Customers positiveCustomers,
 Customers negativeCustomers);

 /**
 * search on prototype with cache
 */
 public List<Customers> searchPrototypeWithCacheCustomers (Customers customers);

 /**
 * Searches a list of distinct Customers entity based on a Customers mask and a list of Customers
containing Customers matching criteria
 * @param Customers customers
 * @param List<Customers> customerss
 * @return List<Customers>
 */
 public List<Customers> searchDistinctPrototypeCustomers(Customers customersMask, List<Customers> customerss) ;    

 /**
 * generic to move after in superclass
 */
 public List<Object[]> getSQLQueryResult(String query);     

}




About these ads
Tagged with:

5 Responses

Subscribe to comments with RSS.

  1. Liam said, on September 6, 2010 at 6:51 am

    Seems to be interesting,but i do not have the patience to follow all 5 steps.

    • Cristian said, on September 6, 2010 at 6:53 am

      There will be a GUI (graphical interface) that will ease things.
      Practically you will just select the target and specify the connection parameters to the database.
      Thanks for passing by.

  2. [...] This post was mentioned on Twitter by xflo, csergiu77. csergiu77 said: RT @DZone "How to use MinuteProject – A code generation tool " http://dzone.com/koPa [...]

  3. animesh said, on October 3, 2010 at 9:15 pm

    1.SQL script is jumbled up! invoice_details should be last.

    2.
    i should create it?

    3. Alter one of the exiting cmd file and add at the and
    “%JAVA_HOME%\bin\java” %CP% net.sf.minuteProject.application.ModelViewGenerator mp-config-sales.xml

    existing* ?

    which cmd file , and where?

    Better, if we have screenshot of each step as it is difficult to make out , where to run what and which configuration files need to be modified.

    • Cristian said, on October 5, 2010 at 8:24 pm

      Hi Animesh

      Sorry for the late response (busy with a lot of things)

      1) The sql ineed was not ok since in the scipts was missing SET FOREIGN_KEY_CHECKS=0 ; (this is the script for mysql but you can easily port to Oracle)
      Now i corrected this and you can run the script using mysql < name_of_the_file_where_you_put_the_script.sql
      or download Sqlyog – google for it .It is the best mysql tool ever.

      2) and 3) In the demo/config you have samples of the existing configurations .
      Create a file called mp-config-sales.xml as described there and copy the content of the link.

      Step 4) is self explanatory here is a link if not clear of the cmd file you have to create http://pastebin.com/0TLzEZQJ


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: