Example usage for com.liferay.portal.kernel.dao.jdbc DataAccess getConnection

List of usage examples for com.liferay.portal.kernel.dao.jdbc DataAccess getConnection

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.dao.jdbc DataAccess getConnection.

Prototype

public static Connection getConnection() throws SQLException 

Source Link

Usage

From source file:com.fingence.slayer.service.impl.MyResultServiceImpl.java

License:Open Source License

public JSONArray getCollateralBreakdown(String portfolioIds) {

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    Connection conn = null;/*from  ww w.j  a v  a2  s.  c o  m*/
    try {
        conn = DataAccess.getConnection();

        String[] tokens = { "[$PORTFOLIO_IDS$]", "[$FING_BOND_COLUMNS$]", "[$FING_BOND_TABLE$]",
                "[$FING_BOND_WHERE_CLAUSE$]" };
        String[] replacements = { portfolioIds, ",f.*, DATEDIFF(f.maturity_dt,now()) AS maturing_after",
                ",fing_Bond f", "and a.assetId = f.assetId" };

        String sql = StringUtil.replace(CustomSQLUtil.get(QUERY), tokens, replacements);

        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(sql);

        double totalMarketValue = getTotalMarketValue(portfolioIds);
        double totalValueOfBonds = 0.0;

        while (rs.next()) {
            String collatTyp = rs.getString("collat_typ");
            double currentMarketValue = rs.getDouble("currentMarketValue");
            totalValueOfBonds += currentMarketValue;

            JSONObject jsonObj = null;
            if (jsonArray.length() > 0) {
                for (int i = 0; i < jsonArray.length(); i++) {
                    JSONObject _jsonObj = jsonArray.getJSONObject(i);
                    if (_jsonObj.getString("bucket").equalsIgnoreCase(collatTyp)) {
                        jsonObj = _jsonObj;
                        break;
                    }
                }
            }

            if (Validator.isNull(jsonObj)) {
                jsonObj = JSONFactoryUtil.createJSONObject();
                jsonObj.put("bucket", collatTyp);
                jsonObj.put("market_value", 0.0);
                jsonObj.put("bond_holdings_percent", 0.0);
                jsonObj.put("total_holdings_percent", 0.0);
                jsonArray.put(jsonObj);
            }

            jsonObj.put("market_value", jsonObj.getDouble("market_value") + currentMarketValue);
            jsonObj.put("total_holdings_percent",
                    jsonObj.getDouble("total_holdings_percent") + currentMarketValue * 100 / totalMarketValue);
        }

        rs.close();
        stmt.close();

        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject jsonObj = jsonArray.getJSONObject(i);
            jsonObj.put("bond_holdings_percent", jsonObj.getDouble("market_value") * 100 / totalValueOfBonds);
        }

    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        DataAccess.cleanUp(conn);
    }

    return jsonArray;
}

From source file:com.fingence.slayer.service.impl.MyResultServiceImpl.java

License:Open Source License

public JSONArray getCashFlow(String portfolioIds) {

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    Connection conn = null;//from w  w w . ja  va2s . c o  m
    try {
        conn = DataAccess.getConnection();

        String[] tokens = { "[$PORTFOLIO_IDS$]", "[$FING_BOND_COLUMNS$]", "[$FING_BOND_TABLE$]",
                "[$FING_BOND_WHERE_CLAUSE$]" };
        String[] replacements = { portfolioIds, ",b.portfolioName ,f.*", ", fing_Bond f",
                "and a.assetId = f.assetId" };

        String sql = StringUtil.replace(CustomSQLUtil.get(QUERY), tokens, replacements);

        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(sql);

        while (rs.next()) {
            String portfolioName = rs.getString("portfolioName");

            Date date = new Date();
            double calcTyp = rs.getDouble("calc_typ");
            String collatTyp = rs.getString("collat_typ");
            String isBondNoCalcTyp = rs.getString("is_bond_no_calctyp");

            // if bond
            if (calcTyp > 0.0d && Validator.isNotNull(collatTyp) && Validator.isNotNull(isBondNoCalcTyp)) {
                Date issueDate = rs.getDate("issue_dt");
                List<History> histories = null;
                try {
                    //System.out.println("Entered If, assetId :: " + rs.getLong("assetId"));
                    OrderByComparator comparator = OrderByComparatorFactoryUtil
                            .create(HistoryModelImpl.TABLE_NAME, "logDate", true);
                    histories = historyPersistence.findByAssetId_Type(rs.getLong("assetId"), 3, 0,
                            historyPersistence.countByAssetId(rs.getLong("assetId")), comparator);

                    for (History history : histories) {
                        //System.out.println("Asset Id :: " + rs.getLong("assetId") + ", History Log Date :: " + history.getLogDate() + ", issueDate :: " + issueDate);
                    }

                    //date = history.getLogDate();
                } catch (SystemException e) {
                    e.printStackTrace();
                }
            } else {
                //date = rs.getDate("purchaseDate");
                //System.out.println("Entered Else");
            }

            String nameSecurityDes = rs.getString("name") + StringPool.SPACE + rs.getString("security_des");
            String idIsin = rs.getString("id_isin");
            double purchaseQty = rs.getDouble("purchaseQty");
            double most_recent_reported_factor = rs.getDouble("amount_outstanding")
                    / rs.getDouble("amount_issued");
            double amountOutstanding = purchaseQty * most_recent_reported_factor;
            double cashFlow = amountOutstanding * (rs.getDouble("cpn") / (rs.getDouble("cpn_freq") * 100));
            String currency = rs.getString("currencyDesc");
            String currencySymbol = rs.getString("currencySymbol");
            double currencyConversionRate = rs.getDouble("current_fx");
            double cashFlowCurrency = cashFlow * currencyConversionRate;

            JSONObject jsonObj = JSONFactoryUtil.createJSONObject();
            ;
            jsonObj.put("portfolioName", portfolioName);

            DateFormat dateFormat = new SimpleDateFormat("dd/MMM/YYYY");
            jsonObj.put("date", dateFormat.format(date));

            jsonObj.put("nameSecurityDes", nameSecurityDes);
            jsonObj.put("securityID", idIsin);
            jsonObj.put("purchaseQty", purchaseQty);
            jsonObj.put("amountOutstanding", amountOutstanding);
            jsonObj.put("transaction", "");
            jsonObj.put("cashFlow", cashFlow);
            jsonObj.put("currency", currency);
            jsonObj.put("currencySymbol", currencySymbol);
            jsonObj.put("currencyConversionRate", currencyConversionRate);
            jsonObj.put("cashFlowCurrency", cashFlowCurrency);

            jsonArray.put(jsonObj);
        }

        rs.close();
        stmt.close();
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        DataAccess.cleanUp(conn);
    }

    return jsonArray;
}

From source file:com.fingence.slayer.service.impl.MyResultServiceImpl.java

License:Open Source License

public JSONArray getBondsMaturing(String portfolioIds) {

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    // initialization of JSONArray with default values
    for (int i = 0; i < bucketNames.length; i++) {
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
        jsonObject.put("bucket", bucketNames[i]);
        jsonObject.put("market_value", 0.0);
        jsonObject.put("bond_holdings_percent", 0.0);
        jsonObject.put("total_holdings_percent", 0.0);
        jsonArray.put(jsonObject);// ww w .  j  a  v  a 2  s .c o  m
    }

    Connection conn = null;
    try {
        conn = DataAccess.getConnection();

        String[] tokens = { "[$PORTFOLIO_IDS$]", "[$FING_BOND_COLUMNS$]", "[$FING_BOND_TABLE$]",
                "[$FING_BOND_WHERE_CLAUSE$]" };
        String[] replacements = { portfolioIds, ",f.*, round(mty_years_tdy * 360) AS maturing_after",
                ",fing_Bond f", "and a.assetId = f.assetId" };

        String sql = StringUtil.replace(CustomSQLUtil.get(QUERY), tokens, replacements);

        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(sql);

        double totalMarketValue = getTotalMarketValue(portfolioIds);
        double totalValueOfBonds = 0.0;

        while (rs.next()) {
            int maturingAfter = rs.getInt("maturing_after");
            double currentMarketValue = rs.getDouble("currentMarketValue");
            totalValueOfBonds += currentMarketValue;

            int index = 0;
            if (maturingAfter > 0 && maturingAfter <= 210) {
                index = 1;
            } else if (maturingAfter > 210 && maturingAfter <= 365) {
                index = 2;
            } else if (maturingAfter > 365 && maturingAfter <= 730) {
                index = 3;
            } else if (maturingAfter > 730 && maturingAfter <= 1825) {
                index = 4;
            } else if (maturingAfter > 1825 && maturingAfter <= 3650) {
                index = 5;
            } else if (maturingAfter > 3650) {
                index = 6;
            }

            JSONObject jsonObj = jsonArray.getJSONObject(index);

            jsonObj.put("market_value", jsonObj.getDouble("market_value") + currentMarketValue);
            jsonObj.put("total_holdings_percent",
                    jsonObj.getDouble("total_holdings_percent") + currentMarketValue * 100 / totalMarketValue);
        }

        rs.close();
        stmt.close();

        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject jsonObj = jsonArray.getJSONObject(i);
            jsonObj.put("bond_holdings_percent", jsonObj.getDouble("market_value") * 100 / totalValueOfBonds);
        }

    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        DataAccess.cleanUp(conn);
    }

    return jsonArray;
}

From source file:com.fingence.slayer.service.impl.MyResultServiceImpl.java

License:Open Source License

public JSONArray getYldToMaturity(String portfolioIds) {

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    for (int i = 0; i < yldToMaturityRange.length; i++) {
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
        if (i <= 5) {
            jsonObject.put("yldToMaturityRange",
                    yldToMaturityRange[i][0] + StringPool.DASH + yldToMaturityRange[i][1]);
        } else {//from   w w w  .j a va2  s. c  o  m
            jsonObject.put("yldToMaturityRange", yldToMaturityRange[i][0] + StringPool.PLUS);
        }
        for (int j = 0; j < durationRange.length; j++) {
            jsonObject.put((int) durationRange[j][0] + StringPool.DASH + (int) durationRange[j][1], 0.0d);
            jsonObject.put("index" + j, (i + StringPool.COLON + j));
        }
        jsonArray.put(jsonObject);
    }

    Connection conn = null;
    try {
        conn = DataAccess.getConnection();

        String[] tokens = { "[$PORTFOLIO_IDS$]", "[$FING_BOND_COLUMNS$]", "[$FING_BOND_TABLE$]",
                "[$FING_BOND_WHERE_CLAUSE$]" };
        String[] replacements = { portfolioIds, ",f.*", ",fing_Bond f", "and a.assetId = f.assetId" };

        String sql = StringUtil.replace(CustomSQLUtil.get(QUERY), tokens, replacements);

        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(sql);

        double totalValueOfBonds = 0.0;

        while (rs.next()) {
            double dur_mid = rs.getDouble("dur_mid");
            double yld_ytm_bid = rs.getDouble("yld_ytm_bid");

            double currentMarketValue = rs.getDouble("currentMarketValue");
            totalValueOfBonds += currentMarketValue;

            for (int i = 0; i < yldToMaturityRange.length; i++) {
                if (yld_ytm_bid > yldToMaturityRange[i][0] && yld_ytm_bid <= yldToMaturityRange[i][1]) {
                    JSONObject jsonObj = jsonArray.getJSONObject(i);
                    for (int j = 0; j < durationRange.length; j++) {
                        if (dur_mid > durationRange[j][0] && dur_mid <= durationRange[j][1]) {
                            String key = (int) durationRange[j][0] + StringPool.DASH
                                    + (int) durationRange[j][1];
                            jsonObj.put(key, jsonObj.getDouble(key) + currentMarketValue);
                        }
                    }
                }
            }
        }

        rs.close();
        stmt.close();

        for (int i = 0; i < yldToMaturityRange.length; i++) {
            JSONObject jsonObj = jsonArray.getJSONObject(i);
            for (int j = 0; j < durationRange.length; j++) {
                String key = (int) durationRange[j][0] + StringPool.DASH + (int) durationRange[j][1];
                jsonObj.put(key, jsonObj.getDouble(key) * 100 / totalValueOfBonds);
            }
        }

        // append a summary row
        JSONObject summary = JSONFactoryUtil.createJSONObject();
        summary.put("summary", true);
        summary.put("yldToMaturityRange", "Total");
        for (int i = 0; i < yldToMaturityRange.length; i++) {
            JSONObject jsonObj = jsonArray.getJSONObject(i);
            for (int j = 0; j < durationRange.length; j++) {
                String key = (int) durationRange[j][0] + StringPool.DASH + (int) durationRange[j][1];
                if (Double.isNaN(summary.getDouble(key))) {
                    summary.put(key, jsonObj.getDouble(key));
                } else {
                    summary.put(key, summary.getDouble(key) + jsonObj.getDouble(key));
                }
            }
        }

        jsonArray.put(summary);

    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        DataAccess.cleanUp(conn);
    }

    return jsonArray;
}

From source file:com.fingence.slayer.service.impl.MyResultServiceImpl.java

License:Open Source License

public JSONArray getCpnTypVsMtyTyp(String portfolioIds) {

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    List<String> cpnTypes = getDistinctValues("cpn_typ", portfolioIds);
    List<String> mtyTypes = getDistinctValues("mty_typ", portfolioIds);

    for (String cpnType : cpnTypes) {
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();

        jsonObject.put("cpnType", cpnType);
        int i = 0;
        for (String mtyType : mtyTypes) {
            jsonObject.put(mtyType, 0.0d);
            jsonObject.put(cpnType + ++i, mtyType + StringPool.COLON + cpnType);

        }/*from  w w w . ja  v a 2  s.com*/
        jsonObject.put("grandTotal", 0.0d);

        jsonArray.put(jsonObject);
    }

    Connection conn = null;
    try {
        conn = DataAccess.getConnection();

        String[] tokens = { "[$PORTFOLIO_IDS$]", "[$FING_BOND_COLUMNS$]", "[$FING_BOND_TABLE$]",
                "[$FING_BOND_WHERE_CLAUSE$]" };
        String[] replacements = { portfolioIds, ",f.*", ",fing_Bond f", "and a.assetId = f.assetId" };

        String sql = StringUtil.replace(CustomSQLUtil.get(QUERY), tokens, replacements);

        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(sql);

        double totalValueOfBonds = 0.0;

        while (rs.next()) {
            String cpn_typ = rs.getString("cpn_typ");
            String mty_typ = rs.getString("mty_typ");

            double currentMarketValue = rs.getDouble("currentMarketValue");
            totalValueOfBonds += currentMarketValue;

            for (int i = 0; i < cpnTypes.size(); i++) {
                if (cpn_typ.equalsIgnoreCase(cpnTypes.get(i))) {
                    JSONObject jsonObj = jsonArray.getJSONObject(i);
                    for (String mtyType : mtyTypes) {
                        if (mtyType.equalsIgnoreCase(mty_typ)) {
                            jsonObj.put(mtyType, jsonObj.getDouble(mtyType) + currentMarketValue);
                        }
                    }
                }
            }
        }

        rs.close();
        stmt.close();

        for (int i = 0; i < cpnTypes.size(); i++) {
            JSONObject jsonObj = jsonArray.getJSONObject(i);
            for (String mtyType : mtyTypes) {
                jsonObj.put(mtyType, jsonObj.getDouble(mtyType) * 100 / totalValueOfBonds);
                if (Double.isNaN(jsonObj.getDouble("grandTotal"))) {
                    jsonObj.put("grandTotal", jsonObj.getDouble(mtyType));
                } else {
                    jsonObj.put("grandTotal", jsonObj.getDouble(mtyType) + jsonObj.getDouble("grandTotal"));
                }
            }
        }

        // append a summary row
        double grandTotal = 0.0d;
        JSONObject summary = JSONFactoryUtil.createJSONObject();
        summary.put("summary", true);
        summary.put("cpnType", "Grand Total");
        for (int i = 0; i < cpnTypes.size(); i++) {
            JSONObject jsonObj = jsonArray.getJSONObject(i);
            for (String mtyType : mtyTypes) {
                if (Double.isNaN(summary.getDouble(mtyType))) {
                    summary.put(mtyType, jsonObj.getDouble(mtyType));
                } else {
                    summary.put(mtyType, summary.getDouble(mtyType) + jsonObj.getDouble(mtyType));
                    grandTotal += summary.getDouble(mtyType);
                }
            }
        }

        summary.put("grandTotal", grandTotal);
        jsonArray.put(summary);

    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        DataAccess.cleanUp(conn);
    }

    return jsonArray;
}

From source file:com.fingence.slayer.service.impl.MyResultServiceImpl.java

License:Open Source License

public JSONArray getBondsQuality(String portfolioIds) {

    String[] categories = { "Investment", "Non Investment", "Others" };

    JSONArray jsonArray = JSONFactoryUtil.createJSONArray();

    // initialization of JSONArray with default values
    for (int i = 0; i < categories.length; i++) {
        JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
        jsonObject.put("category", categories[i]);
        jsonObject.put("children", JSONFactoryUtil.createJSONArray());
        jsonArray.put(jsonObject);/*from w w w . j a v  a2s .  c  om*/
    }

    Connection conn = null;
    try {
        conn = DataAccess.getConnection();

        String[] tokens = { "[$PORTFOLIO_IDS$]", "[$FING_BOND_COLUMNS$]", "[$FING_BOND_TABLE$]",
                "[$FING_BOND_WHERE_CLAUSE$]" };
        String[] replacements = { portfolioIds, ",f.*", ",fing_Bond f", "and a.assetId = f.assetId" };

        String sql = StringUtil.replace(CustomSQLUtil.get(QUERY), tokens, replacements);

        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(sql);

        double totalMarketValue = getTotalMarketValue(portfolioIds);
        double totalValueOfBonds = 0.0;

        while (rs.next()) {
            double currentMarketValue = rs.getDouble("currentMarketValue");
            totalValueOfBonds += currentMarketValue;

            String spRating = rs.getString("rtg_sp");
            String moodyRating = rs.getString("rtg_moody");

            Rating rating = null;
            try {
                rating = ratingPersistence.fetchBySP_Moody(spRating, moodyRating);
            } catch (SystemException e) {
                e.printStackTrace();
            }

            // identify the object 
            int index = 2;
            String description = "No Rating Available";
            if (Validator.isNotNull(rating)) {
                String category = rating.getCategory();
                description = rating.getDescription();

                for (int i = 0; i < categories.length; i++) {
                    if (categories[i].equalsIgnoreCase(category)) {
                        index = i;
                    }
                }
            }

            JSONArray children = jsonArray.getJSONObject(index).getJSONArray("children");

            // identify the child within the parent
            JSONObject child = null;

            if (children.length() == 0) {
                child = JSONFactoryUtil.createJSONObject();
                child.put("bucket", description);
                child.put("market_value", 0.0);
                child.put("bond_holdings_percent", 0.0);
                child.put("total_holdings_percent", 0.0);
                children.put(child);
            }

            for (int i = 0; i < children.length(); i++) {
                child = children.getJSONObject(i);
                if (child.getString("bucket").equalsIgnoreCase(description)) {
                    child.put("market_value", child.getDouble("market_value") + currentMarketValue);
                    child.put("total_holdings_percent", child.getDouble("total_holdings_percent")
                            + currentMarketValue * 100 / totalMarketValue);
                }
            }
        }

        rs.close();
        stmt.close();

        for (int i = 0; i < jsonArray.length(); i++) {
            JSONObject parent = jsonArray.getJSONObject(i);
            JSONArray children = parent.getJSONArray("children");

            for (int j = 0; j < children.length(); j++) {
                JSONObject child = children.getJSONObject(j);
                child.put("bond_holdings_percent", child.getDouble("market_value") * 100 / totalValueOfBonds);
            }
        }
    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        DataAccess.cleanUp(conn);
    }

    return jsonArray;
}

From source file:com.fingence.slayer.service.impl.MyResultServiceImpl.java

License:Open Source License

public List<String> getDistinctValues(String columnName, String portfolioIds) {

    List<String> distinctValues = new ArrayList<String>();
    Connection conn = null;//w  ww .j a v  a 2  s  . c o m
    try {
        conn = DataAccess.getConnection();

        String[] tokens = { "[$COLUMN_NAME$]", "[$PORTFOLIO_IDS$]" };
        String[] replacements = { columnName, portfolioIds };

        String sql = StringUtil.replace(CustomSQLUtil.get(QUERY2), tokens, replacements);

        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery(sql);

        while (rs.next()) {
            distinctValues.add(rs.getString(1));
        }

        rs.close();
        stmt.close();

    } catch (SQLException e) {
        e.printStackTrace();
    } finally {
        DataAccess.cleanUp(conn);
    }
    return distinctValues;
}

From source file:com.liferay.calendar.test.util.CalendarUpgradeTestUtil.java

License:Open Source License

public static UpgradeDatabaseTestHelper getUpgradeDatabaseTestHelper() throws SQLException {

    return new UpgradeDatabaseTestHelperImpl(DataAccess.getConnection());
}

From source file:com.liferay.customsql.CustomSQL.java

License:Open Source License

public void reloadCustomSQL() throws SQLException {
    PortalUtil.initCustomSQL();//  w w  w. j a v a  2  s  . c o m

    Connection con = DataAccess.getConnection();

    String functionIsNull = PortalUtil.getCustomSQLFunctionIsNull();
    String functionIsNotNull = PortalUtil.getCustomSQLFunctionIsNotNull();

    try {
        if (Validator.isNotNull(functionIsNull) && Validator.isNotNull(functionIsNotNull)) {

            _functionIsNull = functionIsNull;
            _functionIsNotNull = functionIsNotNull;

            if (_log.isDebugEnabled()) {
                _log.debug("functionIsNull is manually set to " + functionIsNull);
                _log.debug("functionIsNotNull is manually set to " + functionIsNotNull);
            }
        } else if (con != null) {
            DatabaseMetaData metaData = con.getMetaData();

            String dbName = GetterUtil.getString(metaData.getDatabaseProductName());

            if (_log.isInfoEnabled()) {
                _log.info("Database name " + dbName);
            }

            if (dbName.startsWith("DB2")) {
                _vendorDB2 = true;
                _functionIsNull = DB2_FUNCTION_IS_NULL;
                _functionIsNotNull = DB2_FUNCTION_IS_NOT_NULL;

                if (_log.isInfoEnabled()) {
                    _log.info("Detected DB2 with database name " + dbName);
                }
            } else if (dbName.startsWith("HSQL")) {
                _vendorHSQL = true;

                if (_log.isInfoEnabled()) {
                    _log.info("Detected HSQL with database name " + dbName);
                }
            } else if (dbName.startsWith("Informix")) {
                _vendorInformix = true;
                _functionIsNull = INFORMIX_FUNCTION_IS_NULL;
                _functionIsNotNull = INFORMIX_FUNCTION_IS_NOT_NULL;

                if (_log.isInfoEnabled()) {
                    _log.info("Detected Informix with database name " + dbName);
                }
            } else if (dbName.startsWith("MySQL")) {
                _vendorMySQL = true;
                //_functionIsNull = MYSQL_FUNCTION_IS_NULL;
                //_functionIsNotNull = MYSQL_FUNCTION_IS_NOT_NULL;

                if (_log.isInfoEnabled()) {
                    _log.info("Detected MySQL with database name " + dbName);
                }
            } else if (dbName.startsWith("Sybase") || dbName.equals("ASE")) {
                _vendorSybase = true;
                _functionIsNull = SYBASE_FUNCTION_IS_NULL;
                _functionIsNotNull = SYBASE_FUNCTION_IS_NOT_NULL;

                if (_log.isInfoEnabled()) {
                    _log.info("Detected Sybase with database name " + dbName);
                }
            } else if (dbName.startsWith("Oracle")) {
                _vendorOracle = true;

                if (_log.isInfoEnabled()) {
                    _log.info("Detected Oracle with database name " + dbName);
                }
            } else if (dbName.startsWith("PostgreSQL")) {
                _vendorPostgreSQL = true;

                if (_log.isInfoEnabled()) {
                    _log.info("Detected PostgreSQL with database name " + dbName);
                }
            } else {
                if (_log.isDebugEnabled()) {
                    _log.debug("Unable to detect database with name " + dbName);
                }
            }
        }
    } catch (Exception e) {
        _log.error(e, e);
    } finally {
        DataAccess.cleanUp(con);
    }

    if (_sqlPool == null) {
        _sqlPool = new HashMap<String, String>();
    } else {
        _sqlPool.clear();
    }

    try {
        Class<?> clazz = getClass();

        ClassLoader classLoader = clazz.getClassLoader();

        String[] configs = getConfigs();

        for (String _config : configs) {
            read(classLoader, _config);
        }
    } catch (Exception e) {
        _log.error(e, e);
    }
}

From source file:com.liferay.knowledgebase.hook.upgrade.v1_0_0.UpgradeRatingsEntry.java

License:Open Source License

protected long getClassNameId(String className) throws Exception {
    Connection con = null;/*from   ww w  . j av  a  2  s.  c o m*/
    PreparedStatement ps = null;
    ResultSet rs = null;

    try {
        con = DataAccess.getConnection();

        ps = con.prepareStatement("select classNameId from ClassName_ where value = ?");

        ps.setString(1, className);

        rs = ps.executeQuery();

        if (rs.next()) {
            return rs.getLong("classNameId");
        }

        return 0;
    } finally {
        DataAccess.cleanUp(con, ps, rs);
    }
}