001package io.ebeaninternal.server.deploy; 002 003import io.ebean.Query; 004import io.ebean.Transaction; 005import io.ebean.bean.BeanCollection; 006import io.ebean.bean.BeanCollectionAdd; 007import io.ebean.bean.BeanCollectionLoader; 008import io.ebean.bean.EntityBean; 009import io.ebeaninternal.api.SpiEbeanServer; 010import io.ebeaninternal.api.json.SpiJsonWriter; 011import io.ebeaninternal.server.query.CQueryCollectionAdd; 012 013import java.io.IOException; 014import java.util.Collection; 015 016/** 017 * Helper functions for performing tasks on Lists Sets or Maps. 018 */ 019public interface BeanCollectionHelp<T> extends CQueryCollectionAdd<T> { 020 021 /** 022 * Set the EbeanServer that owns the configuration. 023 */ 024 void setLoader(BeanCollectionLoader loader); 025 026 /** 027 * Return the underlying collection of beans. 028 */ 029 Collection underlying(Object value); 030 031 /** 032 * Return the mechanism to add beans to the underlying collection. 033 * <p> 034 * For Map's this needs to take the mapKey. 035 * </p> 036 */ 037 BeanCollectionAdd getBeanCollectionAdd(Object bc, String mapKey); 038 039 /** 040 * Create an empty collection of the correct type without a parent bean. 041 */ 042 @Override 043 BeanCollection<T> createEmptyNoParent(); 044 045 /** 046 * Create an empty collection of the correct type. 047 */ 048 BeanCollection<T> createEmpty(EntityBean bean); 049 050 /** 051 * Add a bean to the List Set or Map. 052 */ 053 @Override 054 void add(BeanCollection<?> collection, EntityBean bean, boolean withCheck); 055 056 /** 057 * Create a lazy loading proxy for a List Set or Map. 058 */ 059 BeanCollection<T> createReference(EntityBean parentBean); 060 061 /** 062 * Refresh the List Set or Map. 063 */ 064 void refresh(SpiEbeanServer server, Query<?> query, Transaction t, EntityBean parentBean); 065 066 /** 067 * Apply the new refreshed BeanCollection to the appropriate property of the parent bean. 068 */ 069 void refresh(BeanCollection<?> bc, EntityBean parentBean); 070 071 /** 072 * Write the collection out as json. 073 */ 074 void jsonWrite(SpiJsonWriter ctx, String name, Object collection, boolean explicitInclude) throws IOException; 075 076}