Added utility method release701
authorDarrshan <darrshan@netbeans.org>
Thu, 06 Oct 2011 09:22:56 +0530
branchrelease701
changeset 33ff8797b40f95
parent 31 60338572f39d
child 34 6716096b5a44
Added utility method
Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseContentUtilities.java
     1.1 --- a/Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseContentUtilities.java	Thu Oct 06 08:37:32 2011 +0530
     1.2 +++ b/Utilities/Oracle/src/org/netbeans/modules/plsqlsupport/db/DatabaseContentUtilities.java	Thu Oct 06 09:22:56 2011 +0530
     1.3 @@ -254,6 +254,42 @@
     1.4        return columns;
     1.5     }
     1.6  
     1.7 +   public static Map<String, String> getColumnDataTypeLengths(String name, String owner, Connection connection) throws SQLException {
     1.8 +      Map<String, String> columns = new LinkedHashMap<String, String>();
     1.9 +      PreparedStatement stmt = null;
    1.10 +      String query = "SELECT COLUMN_NAME,DATA_LENGTH FROM ALL_TAB_COLUMNS WHERE TABLE_NAME=? AND OWNER=?";
    1.11 +      if(!name.startsWith("\"")) {
    1.12 +         name = name.toUpperCase(Locale.ENGLISH);
    1.13 +      } else {
    1.14 +         name = name.substring(1, name.length()-1);
    1.15 +      }
    1.16 +      try {
    1.17 +         if (connection != null) {
    1.18 +            stmt = connection.prepareStatement(query);
    1.19 +            stmt.setString(1, name);
    1.20 +            stmt.setString(2, owner.toUpperCase(Locale.ENGLISH));
    1.21 +            ResultSet columnSet = stmt.executeQuery();
    1.22 +            while (columnSet.next()) {
    1.23 +               String column = columnSet.getString(1);
    1.24 +               if(isCaseInsensitiveDbName(column)) {
    1.25 +                  column = column.toLowerCase(Locale.ENGLISH);
    1.26 +               } else {
    1.27 +                  column = "\"" + column + "\"";
    1.28 +               }
    1.29 +               int datatypeLength = columnSet.getInt(2);
    1.30 +               columns.put(column, Integer.toString(datatypeLength));
    1.31 +            }
    1.32 +            columnSet.close();
    1.33 +         }
    1.34 +      } finally {
    1.35 +         if (stmt != null) {
    1.36 +            stmt.close();
    1.37 +         }
    1.38 +      }
    1.39 +
    1.40 +      return columns;
    1.41 +   }
    1.42 +
    1.43     public static void getObjectNames(String objectType, String lastFetchDate, List<String> objects, List<DatabaseObjectInfo> owners, Connection connection) throws SQLException {
    1.44        CallableStatement plstmt = null;
    1.45        try {