package org.minimalj.example.petclinic.model;

import java.util.List;
import java.util.Random;

import org.minimalj.backend.Backend;
import org.minimalj.model.Keys;
import org.minimalj.model.Rendering;
import org.minimalj.model.annotation.NotEmpty;
import org.minimalj.model.annotation.Size;
import org.minimalj.transaction.criteria.Criteria;
import org.minimalj.util.mock.MockName;
import org.minimalj.util.mock.Mocking;

public class Owner implements Rendering, Mocking {
	public static final Owner $ = Keys.of(Owner.class);
	
	public Object id;
	
	public final Person person = new Person();
	
    @NotEmpty @Size(255)
    public String address;

    @NotEmpty @Size(80)
    public String city;

    @NotEmpty @Size(20)
    // @Digits(fraction = 0, integer = 10)
    public String telephone;
    
//    private transient List<Pet> pets;
    
    public List<Pet> getPets() {
    	if (Keys.isKeyObject(this)) return Keys.methodOf(this, "pets", List.class);
//    	if (pets == null) {
//    		pets = Backend.persistence().read(Pet.class, Criteria.equals(Pet.$.owner, this), 100);
//    	}
//		return pets;
    	return Backend.persistence().read(Pet.class, Criteria.equals(Pet.$.owner, this), 100);
	}
    
    @Override
    public String render(RenderType renderType) {
    	return person.render(renderType);
    }
    
    @Override
    public void mock() {
    	person.mock();
    	address = MockName.street();
    	city = MockName.officialName() + "city";
    	telephone = String.valueOf(100000 + new Random().nextInt(900000));
    }

}
@@ -723,386 +723,150 @@
     
-// @Digits(fraction = 0, integer = 10)%0A    public String telephone;%0A    %0A//    private transient List%3CPet%3E pets;%0A    %0A    public List%3CPet%3E getPets() %7B%0A    %09if (Keys.isKeyObject(this)) return Keys.methodOf(this, %22pets%22, List.class);%0A//    %09if (pets == null) %7B%0A//    %09%09pets = Backend.persistence().read(Pet.class, Criteria.equals(Pet.$.owner, this), 100);%0A//    %09%7D%0A//%09%09return pets
+public String telephone;%0A    %0A    public List%3CPet%3E getPets() %7B%0A    %09if (Keys.isKeyObject(this)) return Keys.methodOf(this, %22pets%22, List.class)
 ;%0A  

clean dead comments