27 fevereiro 2014

Maven - Standard Directory Layout

src/main/javaApplication/Library sources
src/main/resourcesApplication/Library resources
src/main/filtersResource filter files
src/main/assemblyAssembly descriptors
src/main/configConfiguration files
src/main/scriptsApplication/Library scripts
src/main/webappWeb application sources
src/test/javaTest sources
src/test/resourcesTest resources
src/test/filtersTest resource filter files
src/siteSite
LICENSE.txtProject's license
NOTICE.txtNotices and attributions required by libraries that the project depends on
README.txtProject's readme

More in Maven

20 fevereiro 2014

Web Article - Spring 3 and JPA with Hibernate

This article shows how to set up Spring with JPA, using Hibernate as a persistence provider.

The JPA Spring Configuration with Java
@Configuration
@EnableTransactionManagement
public class PersistenceJPAConfig{
 
   @Bean
   public LocalContainerEntityManagerFactoryBean entityManagerFactoryBean() {
      LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
      em.setDataSource(dataSource());
      em.setPackagesToScan(new String[] { "org.baeldung.persistence.model" });
 
      JpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
      em.setJpaVendorAdapter(vendorAdapter);
      em.setJpaProperties(additionalProperties());
 
      return em;
   }
 
   @Bean
   public DataSource dataSource(){
      DriverManagerDataSource dataSource = new DriverManagerDataSource();
      dataSource.setDriverClassName("com.mysql.jdbc.Driver");
      dataSource.setUrl("jdbc:mysql://localhost:3306/spring_jpa");
      dataSource.setUsername( "tutorialuser" );
      dataSource.setPassword( "tutorialmy5ql" );
      return dataSource;
   }
 
   @Bean
   public PlatformTransactionManager transactionManager(EntityManagerFactory emf){
      JpaTransactionManager transactionManager = new JpaTransactionManager();
      transactionManager.setEntityManagerFactory(emf);
 
      return transactionManager;
   }
 
   @Bean
   public PersistenceExceptionTranslationPostProcessor exceptionTranslation(){
      return new PersistenceExceptionTranslationPostProcessor();
   }
 
   Properties additionalProperties() {
      return new Properties() {
         {  // Hibernate Specific: 
            setProperty("hibernate.hbm2ddl.auto", "create-drop");
            setProperty("hibernate.dialect", "org.hibernate.dialect.MySQL5Dialect");
         }
      };
   }
}
The JPA Spring Configuration with XML

 
   
      
      
      
         
      
      
         
            create-drop
            org.hibernate.dialect.MySQL5Dialect
         
      
   
 
   
      
      
      
      
   
 
   
      
   
   
 
   
 

This Spring JPA Tutorial can be found in the github project – this is an Eclipse based project, so it should be easy to import and run as it is.
Source and full article in Baeldung.com


14 fevereiro 2014

13º Meeting PT.JUG

CDI/Deltaspike 
Jean-Louis Monteiro
Apache TomEE 
Jean-Louis Monteiro
More info in http://jug.pt/2014/02/11/meeting-13/

06 fevereiro 2014

Web Article - Fast, Effective, Double-Checked Locking in Android and Java Apps

public class Foo {
    private volatile Map< String, String > data;

    public Foo() { }

    public void setData(String key, String value) {
        if (data == null) {
            synchronized (this) {
                if (data == null)
                    data = new ConcurrentHashMap < String, String >();
            }
        }

        data.put(key, value);
    }
}

"There are two important things here. The first is adding the volatile modifier to the data field. This will instruct the compiler and eventually the Dalvik VM to ensure reads and writes are performed in a happened-before order (see here for more details). In other words, writes to the field always happen before reads (without this keyword, the compiler or JIT optimizer may decide to reverse them). Next, we add another null check for data outside the synchronized block. This will ensure once data has been allocated, we never synchronize again. However, if data is indeed null, we synchronize and then double-check if data is null just to make sure another thread hasn’t assigned a value between the two checks. If we lost the race, we’ll just continue normally and exit the synchronized block."

Source: Dzone

03 fevereiro 2014

Spring Framework 4 - A Guided Tour


About:
Spring Framework 4 builds the foundation for the next major generation of the Java application framework. The talk gives a practical overview about fundamental infrastructure improvements such as Java 8 support and the integration with the latest Java EE APIs. It also covers major enhancements all across the framework such as advanced support for Groovy, hypermedia aspects for REST web services as well as WebSockets support. Filmed at JAX London 2013.

More information in http://spring.io/