/**
 * Copyright 2015-2016 Red Hat, Inc, and individual contributors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.wildfly.swarm.jpa;

import org.wildfly.swarm.config.JPA;
import org.wildfly.swarm.config.datasources.DataSource;
import org.wildfly.swarm.config.datasources.JDBCDriver;
import org.wildfly.swarm.container.Container;
import org.wildfly.swarm.container.Fraction;
import org.wildfly.swarm.datasources.DatasourcesFraction;

/**
 * @author Ken Finnigan
 * @author Lance Ball
 */
public class JPAFraction extends JPA<JPAFraction> implements Fraction {

    private boolean inhibitDefaultDatasource = false;

    public JPAFraction() {
    }

    public static JPAFraction createDefaultFraction() {
        return new JPAFraction()
                .defaultExtendedPersistenceInheritance(DefaultExtendedPersistenceInheritance.DEEP);

    }

    public JPAFraction inhibitDefaultDatasource() {
        this.inhibitDefaultDatasource = true;
        return this;
    }

    @Override
    public void initialize(Container.InitContext initContext) {
        if (!inhibitDefaultDatasource) {
            final DatasourcesFraction datasources = new DatasourcesFraction()
                    .jdbcDriver(new JDBCDriver("h2")
                            .driverName("h2")
                            .driverDatasourceClassName("org.h2.driver")
                            .driverXaDatasourceClassName("org.h2.jdbcx.JdbcDataSource")
                            .driverModuleName("com.h2database.h2"))
                    .dataSource(new DataSource("ExampleDS")
                            .connectionUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE")
                            .userName("sa")
                            .password("sa")
                            .driverName("h2"));

            initContext.fraction(datasources);
            System.err.println("setting default Datasource to ExampleDS");
            defaultDatasource("jboss/datasources/ExampleDS");
        }
    }
}

@@ -1724,74 +1724,22 @@
 ver(
-new JDBCDriver(%22h2%22)%0A                            .driverName(%22h2%22)
+%22h2%22, (d) -%3E %7B
 %0A   
@@ -1763,29 +1763,16 @@
     
-    
+d
 .driver
-Datasource
 Clas
@@ -1789,16 +1789,17 @@
 .h2.
-d
+D
 river%22)
+;
 %0A   
@@ -1823,20 +1823,11 @@
     
-    .driverX
+d.x
 aDat
@@ -1834,28 +1834,24 @@
 asourceClass
-Name
 (%22org.h2.jdb
@@ -1869,16 +1869,17 @@
 Source%22)
+;
 %0A       
@@ -1891,28 +1891,25 @@
             
-    
+d
 .driverModul
@@ -1934,16 +1934,39 @@
 ase.h2%22)
+;%0A                    %7D
 )%0A      
@@ -1995,64 +1995,102 @@
 rce(
-new DataSource(%22ExampleDS%22)%0A                            
+%22ExampleDS%22, (ds) -%3E %7B%0A                        ds.driverName(%22h2%22);%0A                        ds
 .con
@@ -2160,16 +2160,17 @@
 =FALSE%22)
+;
 %0A       
@@ -2186,20 +2186,18 @@
         
-    
+ds
 .userNam
@@ -2199,24 +2199,25 @@
 erName(%22sa%22)
+;
 %0A           
@@ -2229,20 +2229,18 @@
         
-    
+ds
 .passwor
@@ -2246,16 +2246,17 @@
 rd(%22sa%22)
+;
 %0A       
@@ -2272,33 +2272,9 @@
     
-        .driverName(%22h2%22)
+%7D
 );%0A%0A

Fix setting Driver