Skip to content

Commit 85be392

Browse files
committed
#77: Mark projections as deprecated for removal in YOJ 3.0.0
1 parent a5e854b commit 85be392

File tree

9 files changed

+86
-4
lines changed

9 files changed

+86
-4
lines changed

repository-ydb-v2/src/main/java/tech/ydb/yoj/repository/ydb/table/YdbTable.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,16 @@ public void delete(Entity.Id<T> id) {
558558
* If the entity has projections, its {@link Entity#createProjections() createProjections()}
559559
* method <strong>MUST NOT</strong> fail when called on a raw, non-{@link Entity#postLoad() post-loaded} entity.
560560
*
561+
* @deprecated This method will be removed in YOJ 3.0.0, along with projection-related logic; because without projection magic&trade;,
562+
* it will works the same as {@code Table.find()} + {@code Table.save()} (which will apply the {@code Entity.postLoad()} and
563+
* {@code Entity.preSave()} and save the entity only if it has been changed by these calls).
564+
*
565+
* @see <a href="https://github.com/ydb-platform/yoj-project/issues/77">#77</a>
566+
*
561567
* @param id entity ID
562568
* @param <ID> entity ID type
563569
*/
570+
@Deprecated(forRemoval = true)
564571
public <ID extends Id<T>> void migrate(ID id) {
565572
var statement = new FindYqlStatement<>(tableDescriptor, schema, schema);
566573
List<T> foundRaw = executor.execute(statement, id);

repository/src/main/java/tech/ydb/yoj/repository/db/Entity.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ default E preSave() {
2222
return (E) this;
2323
}
2424

25+
/**
26+
* @deprecated Projections will be removed from the core YOJ API in 3.0.0 and possibly reintroduced as an optional module.
27+
* @see <a href="https://github.com/ydb-platform/yoj-project/issues/77">#77</a>
28+
*/
29+
@Deprecated(forRemoval = true)
2530
default List<Entity<?>> createProjections() {
2631
return List.of();
2732
}

repository/src/main/java/tech/ydb/yoj/repository/db/cache/TransactionLocal.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,12 @@ public <X> X instance(@NonNull Supplier<X> supplier) {
4646
/**
4747
* <strong>Warning:</strong> Unlike {@link #log()}, this method is not intended to be used by end-users,
4848
* only by the YOJ implementation itself.
49-
* <p>Also, projection support <em>might</em> be dropped or seriously reworked in YOJ 3.x, so please
50-
* do not rely on this implementation detail.
49+
*
50+
* @deprecated Projections will be removed from the core YOJ API in 3.0.0 and possibly reintroduced as an optional module.
51+
* @see <a href="https://github.com/ydb-platform/yoj-project/issues/77">#77</a>
5152
*/
5253
@InternalApi
54+
@Deprecated(forRemoval = true)
5355
public ProjectionCache projectionCache() {
5456
return instance(projectionCacheSupplier);
5557
}

repository/src/main/java/tech/ydb/yoj/repository/db/projection/ProjectionCache.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
import tech.ydb.yoj.repository.db.Entity;
66
import tech.ydb.yoj.repository.db.RepositoryTransaction;
77

8+
/**
9+
* @deprecated Projections will be removed from the core YOJ API in 3.0.0 and possibly reintroduced as an optional module.
10+
* @see <a href="https://github.com/ydb-platform/yoj-project/issues/77">#77</a>
11+
*/
812
@InternalApi
13+
@Deprecated(forRemoval = true)
914
public interface ProjectionCache {
1015
void load(Entity<?> entity);
1116

repository/src/main/java/tech/ydb/yoj/repository/db/projection/ProjectionMappings.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.google.common.collect.HashBiMap;
66
import lombok.NonNull;
77
import lombok.RequiredArgsConstructor;
8+
import tech.ydb.yoj.DeprecationWarnings;
89
import tech.ydb.yoj.databind.schema.Schema;
910
import tech.ydb.yoj.repository.db.Entity;
1011
import tech.ydb.yoj.repository.db.EntityIdSchema;
@@ -22,6 +23,11 @@
2223
import static java.util.stream.Collectors.toList;
2324
import static lombok.AccessLevel.PRIVATE;
2425

26+
/**
27+
* @see <a href="https://github.com/ydb-platform/yoj-project/issues/77">#77</a>
28+
* @deprecated Projections will be removed from the core YOJ API in 3.0.0 and possibly reintroduced as an optional module.
29+
*/
30+
@Deprecated(forRemoval = true)
2531
public final class ProjectionMappings {
2632
private ProjectionMappings() {
2733
}
@@ -90,6 +96,9 @@ public static <P extends Entity<P>, T extends Entity<T>> Map<String, String> len
9096
@NonNull
9197
public static <P extends Entity<P>, T extends Entity<T>> Map<String, String> strictFieldMapping(
9298
@NonNull Class<P> projectionType, @NonNull Class<T> entityType) {
99+
DeprecationWarnings.warnOnce("ProjectionMappings.*fieldMapping", "You are using ProjectionMappings.{lenient,strict}FieldMapping(). "
100+
+ "Projections will be removed from YOJ core in YOJ 3.0.0. See https://github.com/ydb-platform/yoj-project/issues/77");
101+
93102
EntitySchema<T> entitySchema = EntitySchema.of(entityType);
94103
Class<?> entityIdType = entitySchema.getIdSchema().getType();
95104
List<Schema.JavaField> projectionIdFields = EntityIdSchema.ofEntity(projectionType).getFields();
@@ -144,9 +153,15 @@ private static Schema.JavaField getMatchingIdField(@NonNull Schema.JavaField pro
144153

145154
@NonNull
146155
public static <P extends Entity<P>> ListViaProjection<P> listViaProjection(@NonNull Class<P> projectionType) {
156+
DeprecationWarnings.warnOnce("ProjectionMappings.listViaProjection", "You are using ProjectionMappings.listViaProjection(). "
157+
+ "Projections will be removed from YOJ core in YOJ 3.0.0. See https://github.com/ydb-platform/yoj-project/issues/77");
147158
return new ListViaProjection<>(projectionType);
148159
}
149160

161+
/**
162+
* @see <a href="https://github.com/ydb-platform/yoj-project/issues/77">#77</a>
163+
* @deprecated Projections will be removed from the core YOJ API in 3.0.0 and possibly reintroduced as an optional module.
164+
*/
150165
@RequiredArgsConstructor(access = PRIVATE)
151166
public static final class ListViaProjection<P extends Entity<P>> {
152167
private final Class<P> projectionType;
@@ -176,6 +191,10 @@ public <T extends Entity<T>> Listing<T, P> entities(@NonNull ListRequest<T> requ
176191
return new Listing<>(request, request.forEntity(projectionType, fieldMapping));
177192
}
178193

194+
/**
195+
* @see <a href="https://github.com/ydb-platform/yoj-project/issues/77">#77</a>
196+
* @deprecated Projections will be removed from the core YOJ API in 3.0.0 and possibly reintroduced as an optional module.
197+
*/
179198
@RequiredArgsConstructor(access = PRIVATE)
180199
public static final class Listing<T extends Entity<T>, P extends Entity<P>> {
181200
private final ListRequest<T> request;
@@ -192,6 +211,10 @@ public ListResult<P> run(@NonNull Function<ListRequest<P>, ListResult<P>> listFu
192211
}
193212
}
194213

214+
/**
215+
* @see <a href="https://github.com/ydb-platform/yoj-project/issues/77">#77</a>
216+
* @deprecated Projections will be removed from the core YOJ API in 3.0.0 and possibly reintroduced as an optional module.
217+
*/
195218
@RequiredArgsConstructor(access = PRIVATE)
196219
public static final class TransformedListing<T extends Entity<T>, P extends Entity<P>> {
197220
private final Listing<T, P> listing;

repository/src/main/java/tech/ydb/yoj/repository/db/projection/Projections.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
import java.lang.annotation.RetentionPolicy;
88
import java.lang.annotation.Target;
99

10+
/**
11+
* @deprecated Projections will be removed from the core YOJ API in 3.0.0 and possibly reintroduced as an optional module.
12+
* @see <a href="https://github.com/ydb-platform/yoj-project/issues/77">#77</a>
13+
*/
14+
@Deprecated(forRemoval = true)
1015
@Target(ElementType.TYPE)
1116
@Retention(RetentionPolicy.RUNTIME)
1217
public @interface Projections {

repository/src/main/java/tech/ydb/yoj/repository/db/projection/RoProjectionCache.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@
44
import tech.ydb.yoj.repository.db.Entity;
55
import tech.ydb.yoj.repository.db.RepositoryTransaction;
66

7+
/**
8+
* @deprecated Projections will be removed from the core YOJ API in 3.0.0 and possibly reintroduced as an optional module.
9+
* @see <a href="https://github.com/ydb-platform/yoj-project/issues/77">#77</a>
10+
*/
711
@InternalApi
12+
@Deprecated(forRemoval = true)
813
public class RoProjectionCache implements ProjectionCache {
914
@Override
1015
public void load(Entity<?> entity) {

repository/src/main/java/tech/ydb/yoj/repository/db/projection/RwProjectionCache.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
package tech.ydb.yoj.repository.db.projection;
22

3+
import lombok.NonNull;
34
import org.slf4j.Logger;
45
import org.slf4j.LoggerFactory;
6+
import tech.ydb.yoj.DeprecationWarnings;
57
import tech.ydb.yoj.InternalApi;
68
import tech.ydb.yoj.repository.db.Entity;
79
import tech.ydb.yoj.repository.db.RepositoryTransaction;
810

911
import java.util.LinkedHashMap;
12+
import java.util.List;
1013
import java.util.Map;
1114
import java.util.stream.Stream;
1215

1316
import static java.util.stream.Collectors.toMap;
1417

18+
/**
19+
* @deprecated Projections will be removed from the core YOJ API in 3.0.0 and possibly reintroduced as an optional module.
20+
* @see <a href="https://github.com/ydb-platform/yoj-project/issues/77">#77</a>
21+
*/
1522
@InternalApi
23+
@Deprecated(forRemoval = true)
1624
public class RwProjectionCache implements ProjectionCache {
1725
private static final Logger log = LoggerFactory.getLogger(RwProjectionCache.class);
1826

@@ -104,11 +112,27 @@ void delete() {
104112
}
105113

106114
Stream<Entity<?>> projectionsBefore() {
107-
return writable && loaded != null ? loaded.createProjections().stream() : Stream.empty();
115+
return projectionStream(loaded);
108116
}
109117

110118
Stream<Entity<?>> projectionsAfter() {
111-
return writable && saved != null ? saved.createProjections().stream() : Stream.empty();
119+
return projectionStream(saved);
120+
}
121+
122+
@NonNull
123+
private Stream<Entity<?>> projectionStream(Entity<?> entity) {
124+
if (writable && entity != null) {
125+
List<Entity<?>> projectionList = entity.createProjections();
126+
if (!projectionList.isEmpty()) {
127+
String entityClassName = entity.getClass().getName();
128+
DeprecationWarnings.warnOnce("RwProjectionCache/" + entityClassName, "You are using projections for " + entityClassName + ". "
129+
+ "Projections will be removed from YOJ core in YOJ 3.0.0. See https://github.com/ydb-platform/yoj-project/issues/77");
130+
}
131+
132+
return projectionList.stream();
133+
} else {
134+
return Stream.empty();
135+
}
112136
}
113137

114138
void flush() {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/**
2+
* @deprecated Projections will be removed from the core YOJ API in 3.0.0 and possibly reintroduced as an optional module.
3+
* @see <a href="https://github.com/ydb-platform/yoj-project/issues/77">#77</a>
4+
*/
5+
@Deprecated(forRemoval = true)
6+
package tech.ydb.yoj.repository.db.projection;

0 commit comments

Comments
 (0)