All Downloads are FREE. Search and download functionalities are using the official Maven repository.

play.db.Model Maven / Gradle / Ivy

package play.db;

import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.List;
import play.Play;
import play.exceptions.UnexpectedException;

public interface Model {

    public void _save();
    public void _delete();
    public Object _key();

    public static class Property {

        public String name;
        public Class type;
        public Field field;
        public boolean isSearchable;
        public boolean isMultiple;
        public boolean isRelation;
        public boolean isGenerated;
        public Class relationType;
        public Choices choices;

    }

    public static interface Choices {

        public List list();

    }

    public static interface Factory {

        public String keyName();
        public Class keyType();
        public Object keyValue(Model m);
        public Model findById(Object id);
        public List fetch(int offset, int length, String orderBy, String orderDirection, List properties, String keywords, String where);
        public Long count(List properties, String keywords, String where);
        public void deleteAll();
        public List listProperties();

    }

    public static class Manager {

        public static Model.Factory factoryFor(Class clazz) {
            if(Model.class.isAssignableFrom(clazz)) {
                Model.Factory factory = Play.pluginCollection.modelFactory(clazz);
                if( factory != null) {
                    return factory;
                }
            }
            throw new UnexpectedException("Model " + clazz.getName() + " is not managed by any plugin");
        }

    }

    public static interface BinaryField {

        public InputStream get();
        public void set(InputStream is, String type);
        public long length();
        public String type();
        public boolean exists();

    }

}