Changeset 4620


Ignore:
Timestamp:
2011-02-02 15:34:06 (2 years ago)
Author:
bruno
Message:

Removed the Record objects that were embedded in certain exceptions. Fixes #214. In most cases, these objects were especially constructed for the purpose of embedding them in the exception, and only contain the recordId. Only for the InvalidRecordException? they contained a 'real' record.
Switching to using single quotes for quotation in exception messages (instead of <...>).

Location:
trunk/cr/repository
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/cr/repository/api/src/main/java/org/lilyproject/repository/api/InvalidRecordException.java

    r4592 r4620  
    1818public class InvalidRecordException extends RepositoryException { 
    1919 
    20     private final Record record; 
     20    private final RecordId recordId; 
    2121    private final String message; 
    2222 
    23     public InvalidRecordException(Record record, String message) { 
    24         this.record = record; 
    25         // TODO Auto-generated constructor stub 
     23    public InvalidRecordException(String message) { 
     24        this(message, null); 
     25    } 
     26 
     27    public InvalidRecordException(String message, RecordId recordId) { 
     28        this.recordId = recordId; 
    2629        this.message = message; 
    2730    } 
    28      
    29     public Record getRecord() { 
    30         return record; 
     31 
     32    public RecordId getRecordId() { 
     33        return recordId; 
    3134    } 
    32      
     35 
    3336    @Override 
    3437    public String getMessage() { 
    35         return "Record <"+record.getId()+">: " + message; 
     38        if (recordId != null) { 
     39            return "Record '" + recordId + "': " + message; 
     40        } else { 
     41            return message; 
     42        } 
    3643    } 
    3744 
  • trunk/cr/repository/api/src/main/java/org/lilyproject/repository/api/RecordExistsException.java

    r4592 r4620  
    1818 
    1919public class RecordExistsException extends RepositoryException { 
    20     private final Record record; 
     20    private final RecordId recordId; 
    2121 
    22     public RecordExistsException(Record record) { 
    23         this.record = record; 
     22    public RecordExistsException(RecordId recordId) { 
     23        this.recordId = recordId; 
    2424    } 
    2525 
    26     public Record getRecord() { 
    27         return record; 
     26    public RecordId getRecordId() { 
     27        return recordId; 
    2828    } 
    2929     
    3030    @Override 
    3131    public String getMessage() { 
    32         StringBuilder message = new StringBuilder(); 
    33         message.append("Record <"); 
    34         message.append(record.getId()); 
    35         message.append("> "); 
    36         message.append("already exists"); 
    37         return message.toString(); 
     32        return "Record '" + recordId + "' already exists."; 
    3833    } 
    3934} 
  • trunk/cr/repository/api/src/main/java/org/lilyproject/repository/api/RecordNotFoundException.java

    r4592 r4620  
    1818public class RecordNotFoundException extends RepositoryException { 
    1919 
    20     private final Record record; 
     20    private final RecordId recordId; 
    2121 
    22     public RecordNotFoundException(Record record) { 
    23         this.record = record; 
     22    public RecordNotFoundException(RecordId recordId) { 
     23        this.recordId = recordId; 
    2424    } 
    2525     
    26     public Record getRecord() { 
    27         return record; 
     26    public RecordId getRecordId() { 
     27        return recordId; 
    2828    } 
    2929     
    3030    @Override 
    3131    public String getMessage() { 
    32         StringBuilder message = new StringBuilder(); 
    33         message.append("Record <"); 
    34         message.append(record.getId()); 
    35         message.append("> "); 
    36         message.append("not found"); 
    37         return message.toString(); 
     32        return "Record '" + recordId + "' not found."; 
    3833    } 
    3934} 
  • trunk/cr/repository/api/src/main/java/org/lilyproject/repository/api/VersionNotFoundException.java

    r4592 r4620  
    1818public class VersionNotFoundException extends RepositoryException { 
    1919 
    20     private final Record record; 
     20    private final RecordId recordId; 
     21    private final long version; 
    2122 
    22     public VersionNotFoundException(Record record) { 
    23         this.record = record; 
     23    public VersionNotFoundException(RecordId recordId, long version) { 
     24        this.recordId = recordId; 
     25        this.version = version; 
    2426    } 
    2527 
    26     public Record getRecord() { 
    27         return record; 
     28    public RecordId getRecordId() { 
     29        return recordId; 
     30    } 
     31 
     32    public long getVersion() { 
     33        return version; 
    2834    } 
    2935 
    3036    @Override 
    3137    public String getMessage() { 
    32         StringBuilder message = new StringBuilder(); 
    33         message.append("Record <"); 
    34         message.append(record.getId()); 
    35         message.append("> "); 
    36         Long version = record.getVersion(); 
    37         if (version != null) { 
    38             message.append("<version:"); 
    39             message.append(version); 
    40             message.append(">"); 
    41         } 
    42         message.append("not found"); 
    43         return message.toString(); 
     38        return "Record '" + recordId + "', version " + version + " not found."; 
    4439    } 
    4540} 
  • trunk/cr/repository/impl/src/main/avro/lily.avpr

    r4592 r4620  
    100100      "type": "error", 
    101101      "fields": [ 
    102           {"name": "record", "type": "AvroRecord"}, 
     102          {"name": "recordId", "type": "bytes"}, 
    103103          {"name": "remoteCauses", "type": ["null", {"type": "array", "items": "AvroExceptionCause"}]} 
    104104      ] 
     
    109109      "type": "error", 
    110110      "fields": [ 
    111         {"name": "record", "type": "AvroRecord"}, 
     111        {"name": "recordId", "type": "bytes"}, 
    112112        {"name": "remoteCauses", "type": ["null", {"type": "array", "items": "AvroExceptionCause"}]} 
    113113      ] 
     
    118118      "type": "error", 
    119119      "fields": [ 
    120         {"name": "record", "type": "AvroRecord"}, 
     120        {"name": "recordId", "type": "bytes"}, 
     121        {"name": "version", "type": "long"}, 
    121122        {"name": "remoteCauses", "type": ["null", {"type": "array", "items": "AvroExceptionCause"}]} 
    122123      ] 
     
    136137      "type": "error", 
    137138      "fields": [ 
    138         {"name": "record", "type": "AvroRecord"}, 
     139        {"name": "recordId", "type": ["bytes", "null"]}, 
    139140        {"name": "message", "type": ["string", "null"]}, 
    140141        {"name": "remoteCauses", "type": ["null", {"type": "array", "items": "AvroExceptionCause"}]} 
  • trunk/cr/repository/impl/src/main/java/org/lilyproject/repository/avro/AvroConverter.java

    r4609 r4620  
    526526 
    527527        AvroRecordExistsException avroException = new AvroRecordExistsException(); 
    528         avroException.record = convert(exception.getRecord()); 
     528        avroException.recordId = convert(exception.getRecordId()); 
    529529        avroException.remoteCauses = buildCauses(exception); 
    530530        return avroException; 
     
    536536 
    537537        AvroRecordNotFoundException avroException = new AvroRecordNotFoundException(); 
    538         avroException.record = convert(exception.getRecord()); 
     538        avroException.recordId = convert(exception.getRecordId()); 
    539539        avroException.remoteCauses = buildCauses(exception); 
    540540        return avroException; 
     
    545545 
    546546        AvroVersionNotFoundException avroException = new AvroVersionNotFoundException(); 
    547         avroException.record = convert(exception.getRecord()); 
     547        avroException.recordId = convert(exception.getRecordId()); 
     548        avroException.version = exception.getVersion(); 
    548549        avroException.remoteCauses = buildCauses(exception); 
    549550        return avroException; 
     
    554555 
    555556        AvroInvalidRecordException avroException = new AvroInvalidRecordException(); 
    556         avroException.record = convert(exception.getRecord()); 
     557        avroException.recordId = convert(exception.getRecordId()); 
    557558        avroException.message = exception.getMessage(); 
    558559        avroException.remoteCauses = buildCauses(exception); 
     
    568569 
    569570    public RecordExistsException convert(AvroRecordExistsException avroException) { 
    570         try { 
    571             RecordExistsException exception = new RecordExistsException(convert(avroException.record)); 
    572             restoreCauses(avroException.remoteCauses, exception); 
    573             return exception; 
    574         } catch (Exception e) { 
    575             // TODO this is not good, exceptions should never fail to deserialize 
    576             throw new RuntimeException("Error deserializing exception.", e); 
    577         } 
     571        RecordExistsException exception = new RecordExistsException(convertAvroRecordId(avroException.recordId)); 
     572        restoreCauses(avroException.remoteCauses, exception); 
     573        return exception; 
    578574    } 
    579575 
    580576    public RecordNotFoundException convert(AvroRecordNotFoundException avroException) { 
    581         try { 
    582             RecordNotFoundException exception = new RecordNotFoundException(convert(avroException.record)); 
    583             restoreCauses(avroException.remoteCauses, exception); 
    584             return exception; 
    585         } catch (Exception e) { 
    586             // TODO this is not good, exceptions should never fail to deserialize 
    587             throw new RuntimeException("Error deserializing exception.", e); 
    588         } 
     577        RecordNotFoundException exception = new RecordNotFoundException(convertAvroRecordId(avroException.recordId)); 
     578        restoreCauses(avroException.remoteCauses, exception); 
     579        return exception; 
    589580    } 
    590581 
    591582    public VersionNotFoundException convert(AvroVersionNotFoundException avroException) { 
    592         try { 
    593             VersionNotFoundException exception = new VersionNotFoundException(convert(avroException.record)); 
    594             restoreCauses(avroException.remoteCauses, exception); 
    595             return exception; 
    596         } catch (Exception e) { 
    597             // TODO this is not good, exceptions should never fail to deserialize 
    598             throw new RuntimeException("Error deserializing exception.", e); 
    599         } 
     583        VersionNotFoundException exception = new VersionNotFoundException(convertAvroRecordId(avroException.recordId), 
     584                avroException.version); 
     585        restoreCauses(avroException.remoteCauses, exception); 
     586        return exception; 
    600587    } 
    601588 
    602589    public InvalidRecordException convert(AvroInvalidRecordException avroException) { 
    603         try { 
    604             InvalidRecordException exception = new InvalidRecordException(convert(avroException.record), convert(avroException.message)); 
    605             restoreCauses(avroException.remoteCauses, exception); 
    606             return exception; 
    607         } catch (Exception e) { 
    608             // TODO this is not good, exceptions should never fail to deserialize 
    609             throw new RuntimeException("Error deserializing exception.", e); 
    610         } 
     590        RecordId recordId = avroException.recordId == null ? null : convertAvroRecordId(avroException.recordId); 
     591        InvalidRecordException exception = new InvalidRecordException(convert(avroException.message), recordId); 
     592        restoreCauses(avroException.remoteCauses, exception); 
     593        return exception; 
    611594    } 
    612595     
  • trunk/cr/repository/impl/src/main/java/org/lilyproject/repository/impl/HBaseRepository.java

    r4611 r4620  
    293293        ArgumentValidator.notNull(record, "record"); 
    294294        if (record.getRecordTypeName() == null) { 
    295             throw new InvalidRecordException(record, "The recordType cannot be null for a record to be created."); 
     295            throw new InvalidRecordException("The recordType cannot be null for a record to be created.", record.getId()); 
    296296        } 
    297297        if (record.getFields().isEmpty()) { 
    298             throw new InvalidRecordException(record, "Creating an empty record is not allowed"); 
     298            throw new InvalidRecordException("Creating an empty record is not allowed", record.getId()); 
    299299        } 
    300300    } 
     
    308308        try { 
    309309            if (record.getId() == null) { 
    310                 throw new InvalidRecordException(record, "The recordId cannot be null for a record to be updated."); 
     310                throw new InvalidRecordException("The recordId cannot be null for a record to be updated.", record.getId()); 
    311311            } 
    312312            try { 
     
    470470                QName fieldName = fieldType.getName(); 
    471471                if (fieldsToDelete.contains(fieldName)) { 
    472                     throw new InvalidRecordException(record, "Field: <"+fieldName+"> is mandatory."); 
     472                    throw new InvalidRecordException("Field: <"+fieldName+"> is mandatory.", record.getId()); 
    473473                } 
    474474                try { 
     
    478478                        originalRecord.getField(fieldName); 
    479479                    } catch (FieldNotFoundException notFoundOnOriginalRecord) { 
    480                         throw new InvalidRecordException(record, "Field: <"+fieldName+"> is mandatory."); 
     480                        throw new InvalidRecordException("Field: <"+fieldName+"> is mandatory.", record.getId()); 
    481481                    } 
    482482                } 
     
    590590        Long version = record.getVersion(); 
    591591        if (version == null) { 
    592             throw new InvalidRecordException(record, 
    593                     "The version of the record cannot be null to update mutable fields"); 
     592            throw new InvalidRecordException("The version of the record cannot be null to update mutable fields", 
     593                    record.getId()); 
    594594        } 
    595595 
     
    798798            } else { 
    799799                if (latestVersion == null || latestVersion < requestedVersion ) { 
    800                     Record record = newRecord(recordId); 
    801                     record.setVersion(requestedVersion); 
    802                     throw new VersionNotFoundException(record); 
     800                    throw new VersionNotFoundException(recordId, requestedVersion); 
    803801                } 
    804802            } 
     
    857855             
    858856            if (result == null || result.isEmpty()) 
    859                 throw new RecordNotFoundException(newRecord(recordId)); 
     857                throw new RecordNotFoundException(recordId); 
    860858             
    861859            // Check if the record was deleted 
    862860            byte[] deleted = result.getValue(systemColumnFamily, RecordColumn.DELETED.bytes); 
    863861            if ((deleted == null) || (Bytes.toBoolean(deleted))) { 
    864                 throw new RecordNotFoundException(newRecord(recordId)); 
     862                throw new RecordNotFoundException(recordId); 
    865863            } 
    866864        } catch (IOException e) { 
     
    10341032                } 
    10351033            } else { 
    1036                 throw new RecordNotFoundException(newRecord(recordId)); 
     1034                throw new RecordNotFoundException(recordId); 
    10371035            } 
    10381036        } catch (RowLogException e) { 
Note: See TracChangeset for help on using the changeset viewer.