Changeset 4620
- Timestamp:
- 2011-02-02 15:34:06 (2 years ago)
- Location:
- trunk/cr/repository
- Files:
-
- 7 edited
-
api/src/main/java/org/lilyproject/repository/api/InvalidRecordException.java (modified) (1 diff)
-
api/src/main/java/org/lilyproject/repository/api/RecordExistsException.java (modified) (1 diff)
-
api/src/main/java/org/lilyproject/repository/api/RecordNotFoundException.java (modified) (1 diff)
-
api/src/main/java/org/lilyproject/repository/api/VersionNotFoundException.java (modified) (1 diff)
-
impl/src/main/avro/lily.avpr (modified) (4 diffs)
-
impl/src/main/java/org/lilyproject/repository/avro/AvroConverter.java (modified) (5 diffs)
-
impl/src/main/java/org/lilyproject/repository/impl/HBaseRepository.java (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/cr/repository/api/src/main/java/org/lilyproject/repository/api/InvalidRecordException.java
r4592 r4620 18 18 public class InvalidRecordException extends RepositoryException { 19 19 20 private final Record record;20 private final RecordId recordId; 21 21 private final String message; 22 22 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; 26 29 this.message = message; 27 30 } 28 29 public Record getRecord() {30 return record ;31 32 public RecordId getRecordId() { 33 return recordId; 31 34 } 32 35 33 36 @Override 34 37 public String getMessage() { 35 return "Record <"+record.getId()+">: " + message; 38 if (recordId != null) { 39 return "Record '" + recordId + "': " + message; 40 } else { 41 return message; 42 } 36 43 } 37 44 -
trunk/cr/repository/api/src/main/java/org/lilyproject/repository/api/RecordExistsException.java
r4592 r4620 18 18 19 19 public class RecordExistsException extends RepositoryException { 20 private final Record record;20 private final RecordId recordId; 21 21 22 public RecordExistsException(Record record) {23 this.record = record;22 public RecordExistsException(RecordId recordId) { 23 this.recordId = recordId; 24 24 } 25 25 26 public Record getRecord() {27 return record ;26 public RecordId getRecordId() { 27 return recordId; 28 28 } 29 29 30 30 @Override 31 31 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."; 38 33 } 39 34 } -
trunk/cr/repository/api/src/main/java/org/lilyproject/repository/api/RecordNotFoundException.java
r4592 r4620 18 18 public class RecordNotFoundException extends RepositoryException { 19 19 20 private final Record record;20 private final RecordId recordId; 21 21 22 public RecordNotFoundException(Record record) {23 this.record = record;22 public RecordNotFoundException(RecordId recordId) { 23 this.recordId = recordId; 24 24 } 25 25 26 public Record getRecord() {27 return record ;26 public RecordId getRecordId() { 27 return recordId; 28 28 } 29 29 30 30 @Override 31 31 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."; 38 33 } 39 34 } -
trunk/cr/repository/api/src/main/java/org/lilyproject/repository/api/VersionNotFoundException.java
r4592 r4620 18 18 public class VersionNotFoundException extends RepositoryException { 19 19 20 private final Record record; 20 private final RecordId recordId; 21 private final long version; 21 22 22 public VersionNotFoundException(Record record) { 23 this.record = record; 23 public VersionNotFoundException(RecordId recordId, long version) { 24 this.recordId = recordId; 25 this.version = version; 24 26 } 25 27 26 public Record getRecord() { 27 return record; 28 public RecordId getRecordId() { 29 return recordId; 30 } 31 32 public long getVersion() { 33 return version; 28 34 } 29 35 30 36 @Override 31 37 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."; 44 39 } 45 40 } -
trunk/cr/repository/impl/src/main/avro/lily.avpr
r4592 r4620 100 100 "type": "error", 101 101 "fields": [ 102 {"name": "record ", "type": "AvroRecord"},102 {"name": "recordId", "type": "bytes"}, 103 103 {"name": "remoteCauses", "type": ["null", {"type": "array", "items": "AvroExceptionCause"}]} 104 104 ] … … 109 109 "type": "error", 110 110 "fields": [ 111 {"name": "record ", "type": "AvroRecord"},111 {"name": "recordId", "type": "bytes"}, 112 112 {"name": "remoteCauses", "type": ["null", {"type": "array", "items": "AvroExceptionCause"}]} 113 113 ] … … 118 118 "type": "error", 119 119 "fields": [ 120 {"name": "record", "type": "AvroRecord"}, 120 {"name": "recordId", "type": "bytes"}, 121 {"name": "version", "type": "long"}, 121 122 {"name": "remoteCauses", "type": ["null", {"type": "array", "items": "AvroExceptionCause"}]} 122 123 ] … … 136 137 "type": "error", 137 138 "fields": [ 138 {"name": "record ", "type": "AvroRecord"},139 {"name": "recordId", "type": ["bytes", "null"]}, 139 140 {"name": "message", "type": ["string", "null"]}, 140 141 {"name": "remoteCauses", "type": ["null", {"type": "array", "items": "AvroExceptionCause"}]} -
trunk/cr/repository/impl/src/main/java/org/lilyproject/repository/avro/AvroConverter.java
r4609 r4620 526 526 527 527 AvroRecordExistsException avroException = new AvroRecordExistsException(); 528 avroException.record = convert(exception.getRecord());528 avroException.recordId = convert(exception.getRecordId()); 529 529 avroException.remoteCauses = buildCauses(exception); 530 530 return avroException; … … 536 536 537 537 AvroRecordNotFoundException avroException = new AvroRecordNotFoundException(); 538 avroException.record = convert(exception.getRecord());538 avroException.recordId = convert(exception.getRecordId()); 539 539 avroException.remoteCauses = buildCauses(exception); 540 540 return avroException; … … 545 545 546 546 AvroVersionNotFoundException avroException = new AvroVersionNotFoundException(); 547 avroException.record = convert(exception.getRecord()); 547 avroException.recordId = convert(exception.getRecordId()); 548 avroException.version = exception.getVersion(); 548 549 avroException.remoteCauses = buildCauses(exception); 549 550 return avroException; … … 554 555 555 556 AvroInvalidRecordException avroException = new AvroInvalidRecordException(); 556 avroException.record = convert(exception.getRecord());557 avroException.recordId = convert(exception.getRecordId()); 557 558 avroException.message = exception.getMessage(); 558 559 avroException.remoteCauses = buildCauses(exception); … … 568 569 569 570 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; 578 574 } 579 575 580 576 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; 589 580 } 590 581 591 582 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; 600 587 } 601 588 602 589 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; 611 594 } 612 595 -
trunk/cr/repository/impl/src/main/java/org/lilyproject/repository/impl/HBaseRepository.java
r4611 r4620 293 293 ArgumentValidator.notNull(record, "record"); 294 294 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()); 296 296 } 297 297 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()); 299 299 } 300 300 } … … 308 308 try { 309 309 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()); 311 311 } 312 312 try { … … 470 470 QName fieldName = fieldType.getName(); 471 471 if (fieldsToDelete.contains(fieldName)) { 472 throw new InvalidRecordException( record, "Field: <"+fieldName+"> is mandatory.");472 throw new InvalidRecordException("Field: <"+fieldName+"> is mandatory.", record.getId()); 473 473 } 474 474 try { … … 478 478 originalRecord.getField(fieldName); 479 479 } catch (FieldNotFoundException notFoundOnOriginalRecord) { 480 throw new InvalidRecordException( record, "Field: <"+fieldName+"> is mandatory.");480 throw new InvalidRecordException("Field: <"+fieldName+"> is mandatory.", record.getId()); 481 481 } 482 482 } … … 590 590 Long version = record.getVersion(); 591 591 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()); 594 594 } 595 595 … … 798 798 } else { 799 799 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); 803 801 } 804 802 } … … 857 855 858 856 if (result == null || result.isEmpty()) 859 throw new RecordNotFoundException( newRecord(recordId));857 throw new RecordNotFoundException(recordId); 860 858 861 859 // Check if the record was deleted 862 860 byte[] deleted = result.getValue(systemColumnFamily, RecordColumn.DELETED.bytes); 863 861 if ((deleted == null) || (Bytes.toBoolean(deleted))) { 864 throw new RecordNotFoundException( newRecord(recordId));862 throw new RecordNotFoundException(recordId); 865 863 } 866 864 } catch (IOException e) { … … 1034 1032 } 1035 1033 } else { 1036 throw new RecordNotFoundException( newRecord(recordId));1034 throw new RecordNotFoundException(recordId); 1037 1035 } 1038 1036 } catch (RowLogException e) {
Note: See TracChangeset
for help on using the changeset viewer.