package er.cayenne.example.persistent.auto; import java.util.Date; import java.util.List; import org.apache.cayenne.ObjectContext; import org.apache.cayenne.exp.Expression; import org.apache.cayenne.query.Ordering; import org.apache.cayenne.query.SelectQuery; import er.cayenne.CayenneObject; import er.cayenne.example.Key; import er.cayenne.example.persistent.Artist; import er.cayenne.example.persistent.Painting; /** * Class _Artist was generated by Cayenne. * It is probably a good idea to avoid changing this class manually, * since it may be overwritten next time code is regenerated. * If you need to make any customizations, please use subclass. */ public abstract class _Artist extends CayenneObject { public static final String ENTITY_NAME = "Artist"; public static final Key DATE_OF_BIRTH = new Key("dateOfBirth"); public static final Key NAME = new Key("name"); public static final Key PAINTINGS = new Key("paintings"); public static final String DATE_OF_BIRTH_KEY = "dateOfBirth"; public static final String NAME_KEY = "name"; public static final String PAINTINGS_KEY = "paintings"; public static final String ID_PK_COLUMN = "ID"; public static Artist createArtist(ObjectContext ec , String name ) { Artist result = new Artist(); ec.registerNewObject(result); result.setName(name); return result; } public void setDateOfBirth(Date dateOfBirth) { writeProperty("dateOfBirth", dateOfBirth); } public Date dateOfBirth() { return (Date)readProperty("dateOfBirth"); } public void setName(String name) { writeProperty("name", name); } public String name() { return (String)readProperty("name"); } public void addToPaintings(Painting obj) { addToManyTarget("paintings", obj, true); } public void removeFromPaintings(Painting obj) { removeToManyTarget("paintings", obj, true); } public Painting createPaintingsRelationship() { Painting obj = getObjectContext().newObject(Painting.class); addToManyTarget("paintings", obj, true); return obj; } public void deletePaintingsRelationship(Painting obj) { removeToManyTarget("paintings", obj, true); getObjectContext().deleteObject(obj); } @SuppressWarnings("unchecked") public List<Painting> paintings() { return (List<Painting>)readProperty("paintings"); } public List<Painting> paintings(Expression expression) { return expression.filterObjects(paintings()); } @SuppressWarnings("unchecked") public static java.util.List<Artist> fetchAll( ObjectContext oc ) { SelectQuery q = new SelectQuery( Artist.class ); return oc.performQuery( q ); } @SuppressWarnings("unchecked") public static java.util.List<Artist> fetch( ObjectContext oc, Expression expression ) { SelectQuery q = new SelectQuery( Artist.class, expression ); return oc.performQuery( q ); } @SuppressWarnings("unchecked") public static java.util.List<Artist> fetch( ObjectContext oc, Expression expression, java.util.List<Ordering> orderings ) { SelectQuery q = new SelectQuery( Artist.class, expression ); if ( orderings != null ) { for( Ordering ordering : orderings ) { q.addOrdering( ordering ); } } return oc.performQuery( q ); } @SuppressWarnings("unchecked") public static java.util.List<Artist> fetchAll( ObjectContext oc, java.util.List<Ordering> orderings ) { SelectQuery q = new SelectQuery( Artist.class); if ( orderings != null ) { for( Ordering ordering : orderings ) { q.addOrdering( ordering ); } } return oc.performQuery( q ); } public static Artist fetchOne(ObjectContext oc, Expression expression) { java.util.List<Artist> objects = fetch(oc, expression); Artist obj; int count = objects.size(); if (count == 0) { obj = null; } else if (count == 1) { obj = objects.get(0); } else { throw new IllegalStateException("There was more than one Artist that matched the qualifier '" + expression + "'."); } return obj; } }