Changeset 8087 for branches/3.19-stable
- Timestamp:
- Oct 31, 2022, 9:25:23 AM (7 months ago)
- Location:
- branches/3.19-stable/src/core/net/sf/basedb/util/listable
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.19-stable/src/core/net/sf/basedb/util/listable/BioSourceToSampleTransformer.java
r6848 r8087 56 56 public Set<Integer> transform(TransformContext context, Set<Integer> source) 57 57 { 58 context.collect(getSourceItemType(), source); 58 59 ItemQuery<Sample> query = Sample.getQuery(); 59 60 query.setIncludes(context.getInclude()); … … 65 66 Expressions.parameter("biosources") 66 67 )); 67 return safeIdList(context.getDbControl(), query, "biosources", source);68 return context.avoid(getTargetItemType(), safeIdList(context.getDbControl(), query, "biosources", source)); 68 69 } 69 70 -
branches/3.19-stable/src/core/net/sf/basedb/util/listable/DerivedBioAssayToChildDerivedBioAssayTransformer.java
r6848 r8087 79 79 while (parents.size() > 0) 80 80 { 81 Set<Integer> children = safeIdList(dc, query, "parents", parents); 81 context.collect(getSourceItemType(), parents); 82 Set<Integer> children = context.avoid(getTargetItemType(), safeIdList(dc, query, "parents", parents)); 82 83 83 84 // Store new children and "used" parents -
branches/3.19-stable/src/core/net/sf/basedb/util/listable/DerivedBioAssayToParentDerivedBioAssayTransformer.java
r6848 r8087 79 79 while (children.size() > 0) 80 80 { 81 Set<Integer> parents = safeIdList(dc, query, "children", children); 81 context.collect(getSourceItemType(), children); 82 Set<Integer> parents = context.avoid(getTargetItemType(), safeIdList(dc, query, "children", children)); 82 83 83 84 // Store new parents and "used" children -
branches/3.19-stable/src/core/net/sf/basedb/util/listable/DerivedBioAssayToPhysicalBioAssayTransformer.java
r6848 r8087 24 24 import java.util.Set; 25 25 26 import net.sf.basedb.core.DbControl;27 26 import net.sf.basedb.core.Item; 28 27 import net.sf.basedb.core.ItemQuery; … … 54 53 public Set<Integer> transform(TransformContext context, Set<Integer> source) 55 54 { 56 DbControl dc = context.getDbControl(); 57 55 context.collect(getSourceItemType(), source); 58 56 ItemQuery<PhysicalBioAssay> query = PhysicalBioAssay.getQuery(); 59 57 query.setIncludes(context.getInclude()); … … 66 64 ); 67 65 68 return safeIdList(context.getDbControl(), query, "bioAssays", source);66 return context.avoid(getTargetItemType(), safeIdList(context.getDbControl(), query, "bioAssays", source)); 69 67 } 70 68 -
branches/3.19-stable/src/core/net/sf/basedb/util/listable/DerivedBioAssayToRawBioAssayTransformer.java
r6848 r8087 67 67 public Set<Integer> transform(TransformContext context, Set<Integer> source) 68 68 { 69 context.collect(getSourceItemType(), source); 69 70 DbControl dc = context.getDbControl(); 70 71 … … 78 79 ) 79 80 ); 80 Set<Integer> all = safeIdList(dc, query, "bioAssays", source);81 Set<Integer> all = context.avoid(getTargetItemType(), safeIdList(dc, query, "bioAssays", source)); 81 82 82 83 if (collectedExtracts != null) -
branches/3.19-stable/src/core/net/sf/basedb/util/listable/ExtractToChildExtractTransformer.java
r8086 r8087 101 101 while (parents.size() > 0) 102 102 { 103 Set<Integer> children = safeIdList(dc, query, "parents", parents); 103 context.collect(getSourceItemType(), parents); 104 Set<Integer> children = context.avoid(getTargetItemType(), safeIdList(dc, query, "parents", parents)); 104 105 105 106 // Store new children and "used" parents -
branches/3.19-stable/src/core/net/sf/basedb/util/listable/ExtractToParentExtractTransformer.java
r7836 r8087 136 136 while (children.size() > 0) 137 137 { 138 Set<Integer> parents = safeIdList(dc, query, "children", children); 138 context.collect(getSourceItemType(), children); 139 Set<Integer> parents = context.avoid(getTargetItemType(), safeIdList(dc, query, "children", children)); 139 140 if (upstream != null) parents.removeAll(upstream); 140 141 if (downstream != null) parents.retainAll(downstream); -
branches/3.19-stable/src/core/net/sf/basedb/util/listable/ExtractToPhysicalBioAssayTransformer.java
r6848 r8087 24 24 import java.util.Set; 25 25 26 import net.sf.basedb.core.DbControl;27 26 import net.sf.basedb.core.Item; 28 27 import net.sf.basedb.core.ItemQuery; … … 53 52 public Set<Integer> transform(TransformContext context, Set<Integer> source) 54 53 { 55 DbControl dc = context.getDbControl(); 56 54 context.collect(getSourceItemType(), source); 57 55 ItemQuery<PhysicalBioAssay> query = PhysicalBioAssay.getQuery(); 58 56 query.setIncludes(context.getInclude()); … … 65 63 Expressions.parameter("parents") 66 64 )); 67 return safeIdList(context.getDbControl(), query, "parents", source);65 return context.avoid(getTargetItemType(), safeIdList(context.getDbControl(), query, "parents", source)); 68 66 } 69 67 -
branches/3.19-stable/src/core/net/sf/basedb/util/listable/ExtractToSampleTransformer.java
r7772 r8087 74 74 public Set<Integer> transform(TransformContext context, Set<Integer> source) 75 75 { 76 context.collect(getSourceItemType(), source); 76 77 ItemQuery<Sample> query = Sample.getQuery(); 77 78 query.setIncludes(context.getInclude()); … … 88 89 query.restrict(Restrictions.eq(Hql.property("st", "pushAnnotations"), Expressions.bool(true))); 89 90 } 90 return safeIdList(context.getDbControl(), query, "extracts", source);91 return context.avoid(getTargetItemType(), safeIdList(context.getDbControl(), query, "extracts", source)); 91 92 } 92 93 -
branches/3.19-stable/src/core/net/sf/basedb/util/listable/PhysicalBioAssayToDerivedBioAssayTransformer.java
r6848 r8087 80 80 ) 81 81 ); 82 Set<Integer> all = safeIdList(dc, query, "bioAssays", source); 82 context.collect(getSourceItemType(), source); 83 Set<Integer> all = context.avoid(getTargetItemType(), safeIdList(dc, query, "bioAssays", source)); 83 84 84 85 if (collectedExtracts != null) -
branches/3.19-stable/src/core/net/sf/basedb/util/listable/PhysicalBioAssayToExtractTransformer.java
r6848 r8087 55 55 public Set<Integer> transform(TransformContext context, Set<Integer> source) 56 56 { 57 context.collect(getSourceItemType(), source); 57 58 ItemQuery<Extract> query = Extract.getQuery(); 58 59 query.setIncludes(context.getInclude()); … … 66 67 ) 67 68 ); 68 return safeIdList(context.getDbControl(), query, "bioAssays", source);69 return context.avoid(getTargetItemType(), safeIdList(context.getDbControl(), query, "bioAssays", source)); 69 70 } 70 71 -
branches/3.19-stable/src/core/net/sf/basedb/util/listable/RawBioAssayToDerivedBioAssayTransformer.java
r6848 r8087 24 24 import java.util.Set; 25 25 26 import net.sf.basedb.core.DbControl;27 26 import net.sf.basedb.core.DerivedBioAssay; 28 27 import net.sf.basedb.core.Item; … … 55 54 public Set<Integer> transform(TransformContext context, Set<Integer> source) 56 55 { 57 DbControl dc = context.getDbControl(); 58 56 context.collect(getSourceItemType(), source); 59 57 ItemQuery<DerivedBioAssay> query = DerivedBioAssay.getQuery(); 60 58 query.setIncludes(context.getInclude()); … … 66 64 ) 67 65 ); 68 return safeIdList(context.getDbControl(), query, "rawBioAssays", source);66 return context.avoid(getTargetItemType(), safeIdList(context.getDbControl(), query, "rawBioAssays", source)); 69 67 } 70 68 -
branches/3.19-stable/src/core/net/sf/basedb/util/listable/SampleToBioSourceTransformer.java
r7772 r8087 71 71 public Set<Integer> transform(TransformContext context, Set<Integer> source) 72 72 { 73 context.collect(getSourceItemType(), source); 73 74 ItemQuery<BioSource> query = BioSource.getQuery(); 74 75 query.setIncludes(context.getInclude()); … … 85 86 query.restrict(Restrictions.eq(Hql.property("st", "pushAnnotations"), Expressions.bool(true))); 86 87 } 87 return safeIdList(context.getDbControl(), query, "samples", source);88 return context.avoid(getTargetItemType(), safeIdList(context.getDbControl(), query, "samples", source)); 88 89 } 89 90 -
branches/3.19-stable/src/core/net/sf/basedb/util/listable/SampleToChildSampleTransformer.java
r8086 r8087 29 29 import net.sf.basedb.core.ItemQuery; 30 30 import net.sf.basedb.core.Sample; 31 import net.sf.basedb.core.Type;32 31 import net.sf.basedb.core.query.Expressions; 33 32 import net.sf.basedb.core.query.Hql; … … 102 101 while (parents.size() > 0) 103 102 { 104 query.setParameter("parents", parents, Type.INT);105 Set<Integer> children = safeIdList(dc, query, "parents", parents);103 context.collect(getSourceItemType(), parents); 104 Set<Integer> children = context.avoid(getTargetItemType(), safeIdList(dc, query, "parents", parents)); 106 105 107 106 // Store new children and "used" parents -
branches/3.19-stable/src/core/net/sf/basedb/util/listable/SampleToExtractTransformer.java
r6848 r8087 57 57 public Set<Integer> transform(TransformContext context, Set<Integer> source) 58 58 { 59 context.collect(getSourceItemType(), source); 59 60 ItemQuery<Extract> query = Extract.getQuery(); 60 61 query.setIncludes(context.getInclude()); … … 66 67 Expressions.parameter("samples") 67 68 )); 68 return safeIdList(context.getDbControl(), query, "samples", source);69 return context.avoid(getTargetItemType(), safeIdList(context.getDbControl(), query, "samples", source)); 69 70 } 70 71 -
branches/3.19-stable/src/core/net/sf/basedb/util/listable/SampleToParentSampleTransformer.java
r7772 r8087 103 103 while (children.size() > 0) 104 104 { 105 Set<Integer> parents = safeIdList(dc, query, "children", children); 105 context.collect(getSourceItemType(), children); 106 Set<Integer> parents = context.avoid(getTargetItemType(), safeIdList(dc, query, "children", children)); 106 107 107 108 // Store new parents and "used" children -
branches/3.19-stable/src/core/net/sf/basedb/util/listable/SourceItemTransformerChain.java
r6801 r8087 102 102 for (SourceItemTransformer sit : chain) 103 103 { 104 //System.out.println(sit + " before: " + sit.getSourceItemType() + "=" + source.size() +":" + source);105 104 source = sit.transform(context, source); 106 //System.out.println("After: " + sit.getTargetItemType() + "=" + source.size());107 105 } 108 106 return source; -
branches/3.19-stable/src/core/net/sf/basedb/util/listable/TransformContext.java
r7770 r8087 23 23 24 24 import java.util.Collection; 25 import java.util.HashMap; 26 import java.util.HashSet; 27 import java.util.Map; 28 import java.util.Set; 25 29 26 30 import net.sf.basedb.core.DbControl; 27 31 import net.sf.basedb.core.Include; 32 import net.sf.basedb.core.Item; 28 33 29 34 /** … … 89 94 } 90 95 96 private boolean collecting; 97 private boolean avoiding; 98 private Map<Item, Set<Integer>> collectedByItemType; 99 100 101 /** 102 Enable/disable collecting of all source items that the transformers in 103 this context are using. 104 @since 3.19.5 105 */ 106 public void setCollecting(boolean collecting) 107 { 108 this.collecting = collecting; 109 } 110 111 /** 112 Shortcut for enabling 'collecting' and disabling 'avoiding'. 113 @since 3.19.5 114 */ 115 public void setCollecting() 116 { 117 this.collecting = true; 118 this.avoiding = false; 119 } 120 121 public boolean isCollecting() 122 { 123 return collecting; 124 } 125 126 /** 127 Enable/disable avoiding of returning any source items that has 128 been previously collected. 129 @since 3.19.5 130 */ 131 public void setAvoiding(boolean avoiding) 132 { 133 this.avoiding = avoiding; 134 } 135 /** 136 Shortcut for enabling 'avoiding' and disabling 'collecting'. 137 @since 3.19.5 138 */ 139 public void setAvoiding() 140 { 141 this.collecting = false; 142 this.avoiding = true; 143 } 144 145 public boolean isAvoiding() 146 { 147 return avoiding; 148 } 149 150 /** 151 Clear all collected items and disable both 'collecting' and 152 'avoiding'. 153 @since 3.19.5 154 */ 155 public void resetCollected() 156 { 157 this.collecting = false; 158 this.avoiding = false; 159 if (collectedByItemType != null) collectedByItemType.clear(); 160 } 161 162 /** 163 Store collected items for later use if collecting has been enabled. 164 @return The source items 165 */ 166 public Set<Integer> collect(Item itemType, Set<Integer> source) 167 { 168 if (collecting && source.size() > 0) 169 { 170 if (collectedByItemType == null) collectedByItemType = new HashMap<>(); 171 Set<Integer> collected = collectedByItemType.get(itemType); 172 if (collected == null) 173 { 174 collected = new HashSet<>(); 175 collectedByItemType.put(itemType, collected); 176 } 177 collected.addAll(source); 178 } 179 return source; 180 } 181 182 /** 183 Avoid collected items by removing them from the source set. 184 Note that this method modified the source set directly. 185 @return The source set 186 */ 187 public Set<Integer> avoid(Item itemType, Set<Integer> source) 188 { 189 if (avoiding && source.size() > 0) 190 { 191 if (collectedByItemType != null && collectedByItemType.containsKey(itemType)) 192 { 193 Set<Integer> collected = collectedByItemType.get(itemType); 194 source.removeAll(collected); 195 } 196 } 197 return source; 198 } 199 91 200 }
Note: See TracChangeset
for help on using the changeset viewer.