com.abubusoft.kripton.android.annotation.BindSqlChildSelect Maven / Gradle / Ivy
Show all versions of kripton-orm Show documentation
/*******************************************************************************
* Copyright 2015, 2017 Francesco Benincasa ([email protected]).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*******************************************************************************/
package com.abubusoft.kripton.android.annotation;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
*
* DAOs work with associated entities, so usually it can be used to
* insert/update/select/delete a specific type of bean. Suppose you have a data
* source which data model is composed by two entities: album and song. There is
* a one-2-many relation between them.
*
*
*
* @BindTable
* public class Album {
* public long id;
* public String name;
*
* @BindRelation(foreignKey = "albumId")
* public List songs;
* }
*
*
*
* @BindTable
* public class Song {
* public long id;
* public String name;
*
* @BindColumn(parentEntity = Album.class)
* public long albumId;
* }
*
*
* albumId is the foreign key of the relation. songs field, marked with
* @BindRelation
, can contains all album's songs and it can not be
* stored in a table column. Every class is managed by its DAO. If you want, you
* can link associated DAO to load an album and its songs with the use of child
* selects.
*
*
*
* @BindDao(Album.class)
* public interface DaoAlbum extends DaoBase {
* @BindSqlSelect(childrenSelects = { @BindSqlChildSelect(relation = "songs", method = "selectByAlbumId") })
* List selectAlbums();
* }
*
* @BindDao(Song.class)
* public interface DaoSong extends DaoBase {
*
* @BindSqlSelect
* List selectAll();
*
* @BindSqlSelect(where = "albumId=${albumId}")
* List selectByAlbumId(@BindSqlParam("albumId") long dummy);
* }
*
*
* In the above DAO definitions, method selectAlbum load all albums and for each
* album, to valorize songs field, uses the DaoSong#selectByAlbumId.
*
*
* @author Francesco Benincasa ([email protected])
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.ANNOTATION_TYPE)
public @interface BindSqlChildSelect {
/**
* Field annnotated with BindRelation
that need to be valorized
* with this subquery.
*
* @return name of relation
*/
String field();
/**
* method's name of dao associated to child entity of relation to invoke to fill
* field. This method must have only one parameter: the foreign key value
*
* @return method of child dao to use
*/
String method();
}