Changeset 223

Show
Ignore:
Timestamp:
12/29/07 22:45:45 (1 year ago)
Author:
chris
Message:

Add methods to get enumeration constant names.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lex/trunk/src/com/qwirx/lex/emdros/EmdrosDatabase.java

    r168 r223  
    1111import java.sql.ResultSet; 
    1212import java.sql.SQLException; 
     13import java.util.ArrayList; 
    1314import java.util.Hashtable; 
     15import java.util.List; 
    1416import java.util.Map; 
    1517 
    1618import jemdros.BadMonadsException; 
    17 import jemdros.EMdFDBDBError; 
    1819import jemdros.EmdrosEnv; 
    19 import jemdros.EmdrosException; 
    2020import jemdros.MatchedObject; 
    2121import jemdros.MonadSetElement; 
     
    8383            bDBResult = env.executeString(query, bCompilerResult, false, false); 
    8484        } 
    85         catch (TableException e) 
    86         { 
    87             throw new DatabaseException("Failed to execute query", e, query); 
    88         } 
    89         catch (BadMonadsException e) 
    90         { 
    91             throw new DatabaseException("Failed to execute query", e, query); 
    92         } 
    93         catch (EMdFDBDBError e) 
    94         { 
    95             throw new DatabaseException("Failed to execute query", e, query); 
    96         } 
    97         catch (EmdrosException e) 
     85        catch (Exception e) 
    9886        { 
    9987            throw new DatabaseException("Failed to execute query", e, query); 
     
    175163        } 
    176164         
    177         public Map getEnumerationConstants(String type, boolean byName)  
     165        public Map<String, String> getEnumerationConstants(String type, 
     166        boolean byName)  
    178167        throws DatabaseException  
    179168    { 
    180                 Hashtable result = new Hashtable(); 
     169                Hashtable<String, String> result = new Hashtable<String, String>(); 
    181170                 
    182171                Table table = getTable("SELECT ENUMERATION CONSTANTS FROM "+type); 
     
    194183                         
    195184                        if (byName) 
     185                { 
    196186                                result.put(name, number); 
    197                         else 
    198                                 result.put(number, name); 
     187                } 
     188                else 
     189                { 
     190                    result.put(number, name); 
     191                } 
    199192                } 
    200193        } 
     
    207200                return result; 
    208201        } 
    209      
     202 
     203    public List<String> getEnumerationConstantNames(String type)  
     204    throws DatabaseException  
     205    { 
     206        List<String> result = new ArrayList<String>(); 
     207         
     208        String query = "SELECT ENUMERATION CONSTANTS FROM " + type; 
     209        Table table = getTable(query); 
     210         
     211        TableIterator rows = table.iterator(); 
     212         
     213        try  
     214        { 
     215            while (rows.hasNext())  
     216            { 
     217                TableRow row = rows.next(); 
     218                String name   = row.getColumn(1); 
     219                // String number = row.getColumn(2); 
     220                result.add(name); 
     221            } 
     222        } 
     223        catch (TableException e) 
     224        { 
     225            throw new DatabaseException("Failed to get enumeration constants",  
     226                e, query); 
     227        } 
     228         
     229        return result; 
     230    } 
     231     
     232    public String getEnumConstNameFromValue(String enumName, int value) 
     233    throws DatabaseException 
     234    { 
     235        boolean[] dbOK = new boolean[1]; 
     236         
     237        String result = env.getEnumConstNameFromValue(value, enumName, dbOK); 
     238     
     239        if (!dbOK[0]) 
     240        { 
     241            throw new DatabaseException("Failed to get name for enum " +  
     242                enumName + " value " + value, 
     243                new Exception(env.getDBError()));  
     244        } 
     245         
     246        return result; 
     247    } 
     248 
    210249    public String getMonadSet(String query) 
    211250    throws DatabaseException