/*
 * Copyright (c) 2008-2016 Haulmont.
 *
 * 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 com.haulmont.cuba.core.sys.persistence;

import com.haulmont.bali.db.DbUtils;
import com.haulmont.cuba.core.sys.AppContext;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nullable;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

/**
 */
@SuppressWarnings("UnusedDeclaration")
public class OracleDbmsFeatures implements DbmsFeatures {

    private static Logger log = LoggerFactory.getLogger(OracleDbmsFeatures.class);

    @Override
    public Map<String, String> getJpaParameters() {
        Map<String, String> params = new HashMap<>();
        params.put("eclipselink.target-database", "com.haulmont.cuba.core.sys.persistence.CubaOraclePlatform");
        putDbSchema(params);
        return params;
    }

    private static void putDbSchema(Map<String, String> params) {
        String dsName = AppContext.getProperty("cuba.dataSourceJndiName");
        DataSource ds;
        try {
            InitialContext context = new InitialContext();
            ds = (DataSource) context.lookup(dsName);
        } catch (NamingException e) {
            throw new RuntimeException("Error locating datasource " + dsName, e);
        }
        Connection connection = null;
        try {
            connection = ds.getConnection();
            String userName = connection.getMetaData().getUserName();
            // todo EL: Oracle schema name
//            if (!StringUtils.isEmpty(userName)) {
//                params.put("openjpa.jdbc.Schema", userName.toUpperCase());
//                log.info("Set openjpa.jdbc.Schema=" + userName.toUpperCase());
//            } else {
//                log.warn("Unable to set openjpa.jdbc.Schema: DatabaseMetaData.getUserName() returns nothing");
//            }
        } catch (SQLException e) {
            throw new RuntimeException("Unable to set openjpa.jdbc.Schema", e);
        } finally {
            DbUtils.closeQuietly(connection);
        }
    }

    @Override
    public String getIdColumn() {
        return "ID";
    }

    @Override
    public String getDeleteTsColumn() {
        return "DELETE_TS";
    }

    @Override
    public String getTimeStampType() {
        return "timestamp";
    }

    @Nullable
    @Override
    public String getUuidTypeClassName() {
        return null;
    }

    @Nullable
    @Override
    public String getTransactionTimeoutStatement() {
        return null;
    }

    @Override
    public String getUniqueConstraintViolationPattern() {
        return "unique constraint \\((.+)\\) violated";
    }

    @Override
    public boolean isNullsLastSorting() {
        return true;
    }
}

@@ -659,378 +659,91 @@
 ort 
-com.haulmont.bali.db.DbUtils;%0Aimport com.haulmont.cuba.core.sys.AppContext;%0Aimport org.apache.commons.lang.StringUtils;%0Aimport org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport javax.annotation.Nullable;%0Aimport javax.naming.InitialContext;%0Aimport javax.naming.NamingException;%0Aimport javax.sql.DataSource;%0Aimport java.sql.Connection;%0Aimport java.sql.SQLException
+org.slf4j.Logger;%0Aimport org.slf4j.LoggerFactory;%0A%0Aimport javax.annotation.Nullable
 ;%0Aim
@@ -1223,1242 +1223,22 @@
     
-putDbSchema(params);%0A        return params;%0A    %7D%0A%0A    private static void putDbSchema(Map%3CString, String%3E params) %7B%0A        String dsName = AppContext.getProperty(%22cuba.dataSourceJndiName%22);%0A        DataSource ds;%0A        try %7B%0A            InitialContext context = new InitialContext();%0A            ds = (DataSource) context.lookup(dsName);%0A        %7D catch (NamingException e) %7B%0A            throw new RuntimeException(%22Error locating datasource %22 + dsName, e);%0A        %7D%0A        Connection connection = null;%0A        try %7B%0A            connection = ds.getConnection();%0A            String userName = connection.getMetaData().getUserName();%0A            // todo EL: Oracle schema name%0A//            if (!StringUtils.isEmpty(userName)) %7B%0A//                params.put(%22openjpa.jdbc.Schema%22, userName.toUpperCase());%0A//                log.info(%22Set openjpa.jdbc.Schema=%22 + userName.toUpperCase());%0A//            %7D else %7B%0A//                log.warn(%22Unable to set openjpa.jdbc.Schema: DatabaseMetaData.getUserName() returns nothing%22);%0A//            %7D%0A        %7D catch (SQLException e) %7B%0A            throw new RuntimeException(%22Unable to set openjpa.jdbc.Schema%22, e);%0A        %7D finally %7B%0A            DbUtils.closeQuietly(connection);%0A        %7D
+return params;
 %0A   

Remove old unused code