public static long getMaxIdForClass ( PersistenceBroker brokerForClass , ClassDescriptor cldForOriginalOrExtent , FieldDescriptor original ) throws PersistenceBrokerException { FieldDescriptor field = null ; if ( ! original . getClassDescriptor ( ) . equals ( cldForOriginalOrExtent ) ) { // check if extent match not the same table if ( ! original . getClassDescriptor ( ) . getFullTableName ( ) . equals ( cldForOriginalOrExtent . getFullTableName ( ) ) ) { // we have to look for id's in extent class table field = cldForOriginalOrExtent . getFieldDescriptorByName ( original . getAttributeName ( ) ) ; } } else { field = original ; } if ( field == null ) { // if null skip this call return 0 ; } String column = field . getColumnName ( ) ; long result = 0 ; ResultSet rs = null ; Statement stmt = null ; StatementManagerIF sm = brokerForClass . serviceStatementManager ( ) ; String table = cldForOriginalOrExtent . getFullTableName ( ) ; // String column = cld.getFieldDescriptorByName(fieldName).getColumnName(); String sql = SM_SELECT_MAX + column + SM_FROM + table ; try { //lookup max id for the current class stmt = sm . getGenericStatement ( cldForOriginalOrExtent , Query . NOT_SCROLLABLE ) ; rs = stmt . executeQuery ( sql ) ; rs . next ( ) ; result = rs . getLong ( 1 ) ; } catch ( Exception e ) { log . warn ( "Cannot lookup max value from table " + table + " for column " + column + ", PB was " + brokerForClass + ", using jdbc-descriptor " + brokerForClass . serviceConnectionManager ( ) . getConnectionDescriptor ( ) , e ) ; } finally { try { sm . closeResources ( stmt , rs ) ; } catch ( Exception ignore ) { // ignore it } } return result ; }
lookup current maximum value for a single field in table the given class descriptor was associated .