private DomainXmlBuilder addDatabase(Database database) {
        logger.info("Insert DataSource " + database.getName());
        // <jdbc-connection-pool>
        Element connectionPool = xmlDocument.createElement("jdbc-connection-pool");
        connectionPool.setAttribute("driver-classname", database.getJavaDriver());
        connectionPool.setAttribute("connection-validation-method", database.getProperty("connection-validation-method", "auto-commit"));
        connectionPool.setAttribute("is-connection-validation-required", database.getProperty("is-connection-validation-required", "true"));
        connectionPool.setAttribute("validation-table-name", database.getProperty("validation-table-name", ""));

        connectionPool.setAttribute("datasource-classname", database.getDataSourceClassName());
        connectionPool.setAttribute("max-pool-size", database.getProperty("max-pool-size", "20"));
        connectionPool.setAttribute("wrap-jdbc-objects", "false");
        connectionPool.setAttribute("res-type", "javax.sql.DataSource");
        connectionPool.setAttribute("steady-pool-size", database.getProperty("steady-pool-size", "1"));
        String connectionPoolName = database.getName() + "ConnectionPool";
        connectionPool.setAttribute("name", connectionPoolName);

        String jdbcUrl = "jdbc:" + database.getUrl();
        addProperty("URL", jdbcUrl, connectionPool);
        addProperty("Url", jdbcUrl, connectionPool);
        Properties properties;
        try {
            properties = new NonRegisteringDriver().parseURL(jdbcUrl, null);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

        addProperty("ServerName", properties.getProperty(NonRegisteringDriver.HOST_PROPERTY_KEY), connectionPool);
        addProperty("Port", properties.getProperty(NonRegisteringDriver.PORT_PROPERTY_KEY), connectionPool);
        addProperty("DatabaseName", properties.getProperty(NonRegisteringDriver.DBNAME_PROPERTY_KEY), connectionPool);
        addProperty("User", database.getUsername(), connectionPool);
        addProperty("Password", database.getPassword(), connectionPool);

        Map<String, String> optionalParameters = database.filterProperties(databaseProperties);
        for (Map.Entry<String, String> entry : optionalParameters.entrySet()) {
            connectionPool.setAttribute(entry.getKey(), entry.getValue());
        }
        Element glassfishResourcesElement = XmlUtils.getUniqueElement(xmlDocument, "/domain/resources");

        glassfishResourcesElement.appendChild(connectionPool);

        // <jdbc-resource>
        Element jdbcResource = xmlDocument.createElement("jdbc-resource");
        jdbcResource.setAttribute("pool-name", connectionPoolName);
        String jndiName = "jdbc/" + database.getName();
        jdbcResource.setAttribute("jndi-name", jndiName);
        glassfishResourcesElement.appendChild(jdbcResource);


        // <resource-ref ref="..." />
        Element glassfishServerElement = XmlUtils.getUniqueElement(xmlDocument, "/domain/servers/server");

        Element resourceRefElement = xmlDocument.createElement("resource-ref");
        resourceRefElement.setAttribute("ref", jndiName);
        glassfishServerElement.appendChild(resourceRefElement);

        return this;
    }