Source:
public void createSymbolizer(ILayer layer) { if (layer != null) { try { Symbolizer symb = null; try(Connection connection = layer.getDataManager().getDataSource().getConnection()) { TableLocation location = TableLocation.parse(layer.getTableReference()); List<String> geoms = SFSUtilities.getGeometryFields(connection, location); String geomFieldName = "the_geom"; if(!geoms.isEmpty()) { geomFieldName = TableLocation.quoteIdentifier(geoms.get(0)); } int typeCode = SFSUtilities.getGeometryType(connection,location,""); if(typeCode== GeometryTypeCodes.GEOMETRY || typeCode==GeometryTypeCodes.GEOMCOLLECTION) { try(Statement st = connection.createStatement(); ResultSet rs = st.executeQuery("SELECT MIN(ST_DIMENSION("+ geomFieldName + ")) minDim FROM "+location.toString()+" WHERE ST_DIMENSION(" + geomFieldName + ") IS NOT NULL;")) { if(rs.next()) { switch (rs.getInt("minDim")) { case 2: typeCode = GeometryTypeCodes.POLYGON; break; case 1: typeCode = GeometryTypeCodes.LINESTRING; break; case 0: if(!rs.wasNull()) { typeCode = GeometryTypeCodes.POINT; } break; } } } catch (SQLException ex) { } } switch (typeCode) { case GeometryTypeCodes.POINT: case GeometryTypeCodes.MULTIPOINT: symb = new PointSymbolizer(); break; case GeometryTypeCodes.LINESTRING: case GeometryTypeCodes.MULTILINESTRING: symb = new LineSymbolizer(); break; case GeometryTypeCodes.POLYGON: case GeometryTypeCodes.MULTIPOLYGON: symb = new AreaSymbolizer(); break; default: symb = new PointSymbolizer(); } symbolizer.addSymbolizer(symb); } } catch (SQLException ex) { Logger.getLogger(Rule.class.getName()).log(Level.SEVERE, null, ex); } } }

Target:
public void createSymbolizer(ILayer layer) { if (layer != null) { try { Symbolizer symb = null; try(Connection connection = layer.getDataManager().getDataSource().getConnection()) { TableLocation location = TableLocation.parse(layer.getTableReference()); List<String> geoms = SFSUtilities.getGeometryFields(connection, location); String geomFieldName = "the_geom"; if(!geoms.isEmpty()) { geomFieldName = TableLocation.quoteIdentifier(geoms.get(0)); } int typeCode = SFSUtilities.getGeometryType(connection,location,""); if(typeCode== GeometryTypeCodes.GEOMETRY || typeCode==GeometryTypeCodes.GEOMCOLLECTION) { String dimQuery = String.format("SELECT MIN(gdim) minDim from (SELECT ST_DIMENSION(%s) gdim" + " from %s WHERE ST_DIMENSION(%s) IS NOT NULL LIMIT %d)",geomFieldName, location.toString(),geomFieldName, FETCH_DIMENSION_LIMIT); try(Statement st = connection.createStatement(); ResultSet rs = st.executeQuery(dimQuery)) { if(rs.next()) { switch (rs.getInt("minDim")) { case 2: typeCode = GeometryTypeCodes.POLYGON; break; case 1: typeCode = GeometryTypeCodes.LINESTRING; break; case 0: if(!rs.wasNull()) { typeCode = GeometryTypeCodes.POINT; } break; } } } catch (SQLException ex) { } } switch (typeCode) { case GeometryTypeCodes.POINT: case GeometryTypeCodes.MULTIPOINT: symb = new PointSymbolizer(); break; case GeometryTypeCodes.LINESTRING: case GeometryTypeCodes.MULTILINESTRING: symb = new LineSymbolizer(); break; case GeometryTypeCodes.POLYGON: case GeometryTypeCodes.MULTIPOLYGON: symb = new AreaSymbolizer(); break; default: symb = new PointSymbolizer(); } symbolizer.addSymbolizer(symb); } } catch (SQLException ex) { Logger.getLogger(Rule.class.getName()).log(Level.SEVERE, null, ex); } } }