diff --git a/CODE_REVIEW.md b/CODE_REVIEW.md deleted file mode 100644 index 47ece46..0000000 --- a/CODE_REVIEW.md +++ /dev/null @@ -1,72 +0,0 @@ -# bstore-java Code Review - -Review date: 2026-03-17 - -This review focuses on correctness, architectural fit to the current goals, and -remaining risks before using `bstore-java` as the reference implementation for -other language ports. - -## Findings - -No new correctness findings were discovered in this final pass after the latest -meta-history fixes. - -## Non-Findings - -These areas looked acceptable for the current scope: - -- `dbo` primary-key semantics are now explicit and much less error-prone. -- SQL `IN` handling is parameterized. -- `Action.first()` cleanup is fixed. -- `SQLReader.hasNext()` no longer advances repeatedly. -- `dbo.meta` is now appropriately lean for the current goals. -- `ChangeEvent` as canonical history and `DataOriginator` as module registry is a - coherent split. -- `terminal.save(changeEvent)` now persists the event row without implicitly - applying schema changes. -- `apply_changes(...)` now logs pending events before attempting structural - changes, so failed batches do not lose the canonical change record. -- `upgradeMetaSchema(...)` now respects the caller-supplied `originatorId` and - `migrationId`. - -## Current Limits That Seem Acceptable - -These are limitations, but they appear aligned with the current requirements: - -- field rename is treated as drop + add rather than a first-class rename -- schema moves are rejected explicitly -- PK/auto-increment/unique/index rewrites are not yet supported in `apply_changes(...)` -- downgrade support is schema-shape oriented, not a full data-preserving rollback engine -- migration batches are still best-effort rather than transactional across all - DDL plus history writes; the log is preserved, but partial application can - still occur on backends or change sets that are not fully transactional - -## Suggested TODO List - -Priority 1 - -- Decide whether to add optional transactional migration batches on backends - that support transactional DDL, or keep the current best-effort semantics as - the long-term contract. -- Add a short public example showing when to use `terminal.save(changeEvent)` - versus `meta.apply_changes(...)`. - -Priority 2 - -- If `ChangeEventHero` is no longer part of the intended public design, remove it - or explicitly deprecate it to avoid confusion. -- Consider exposing an explicit "planned but unapplied" query path for pending - changes now that unapplied events are preserved in the log. - -Priority 3 - -- Review old exploratory tests and either remove them permanently or mine any - remaining useful cases into the curated suites. -- Prepare a concise cross-language contract document derived from the current - Java `dbo` and `meta` behavior before porting further. - -## Bottom Line - -The project is in a strong reference-implementation state for the original goals. -The remaining important risks are mostly around future migration ergonomics and -transaction semantics, not everyday CRUD correctness or core meta design. diff --git a/DEVELOPER_EXPERIENCE_IMPROVEMENTS.md b/DEVELOPER_EXPERIENCE_IMPROVEMENTS.md deleted file mode 100644 index bc84b7e..0000000 --- a/DEVELOPER_EXPERIENCE_IMPROVEMENTS.md +++ /dev/null @@ -1,361 +0,0 @@ -# Developer Experience Improvements for bstore-java - -## Current State Analysis - -### Current API Patterns -- Field access: `Product.name.set(product, "Alice")` / `Product.name.get(product, null)` -- Slot-based access: `dbo.set(nameSlot, "Alice")` / `dbo.get(nameSlot, null)` -- Positional access: `dbo.set(0, value)` / `dbo.get(0)` (already Java-like!) -- Field-based queries: `PersonDBO.AGE.gte(18)` -- Action chaining: `terminal.begin().load(PersonDBO).filterBy(...).execute()` - -### Issues Identified -1. **Verbose field access**: `Product.name.set(product, "Alice")` is verbose -2. **No convenience methods**: Can't use `dbo.get(Product.NAME)` or `dbo.set(Product.NAME, "Alice")` -3. **No equals/hashCode**: Can't compare DBOs by value -4. **No cloning**: Can't easily copy DBO instances -5. **No map conversion**: Can't convert to/from `Map` -6. **No fluent API**: Missing `withField()` methods for method chaining -7. **No field lookup by name**: Entity doesn't have `getField(String name)` method -8. **toString() could be better**: Currently returns JSON, could have human-readable format - -## Proposed Improvements - -### 1. Convenience Methods for Field Access (High Impact) ✅ -**Goal**: Allow `dbo.get(Product.NAME)` instead of `Product.NAME.get(dbo, null)` - -**Implementation**: -```java -/** - * Get field value by Field instance. - * - * @param field Field to get value for - * @return Field value, or null if not set - */ -public Object get(Field field) { - return get(field, null); -} - -/** - * Get field value by Field instance with default. - * - * @param field Field to get value for - * @param defaultValue Default value if field is null - * @return Field value, or defaultValue if not set - */ -public Object get(Field field, Object defaultValue) { - return get((Slot)field, defaultValue); -} - -/** - * Set field value by Field instance. - * - * @param field Field to set value for - * @param value Value to set - * @return Self for chaining - */ -public DBO set(Field field, Object value) { - return (DBO)set((Slot)field, value); -} -``` - -**Benefits**: -- More intuitive: `person.get(PersonDBO.NAME)` vs `PersonDBO.NAME.get(person, null)` -- Consistent with positional access pattern -- Backward compatible (Field.get/set still work) - -**Trade-offs**: -- Minimal - just convenience wrappers - -### 2. Equals and HashCode (Medium Impact) -**Goal**: Value-based comparison - -**Implementation**: -```java -@Override -public boolean equals(Object obj) { - if (this == obj) return true; - if (obj == null || getClass() != obj.getClass()) return false; - DBO other = (DBO)obj; - - // Compare entity types - if (type != other.type) return false; - if (type == null) return true; - - // Compare by primary key if available - Field pk = type.getPk(); - if (pk != null) { - Object thisPk = get(pk); - Object otherPk = other.get(pk); - if (thisPk != null && otherPk != null) { - return thisPk.equals(otherPk); - } - } - - // Compare all values - if (values == null) return other.values == null; - if (other.values == null) return false; - if (values.length != other.values.length) return false; - for (int i = 0; i < values.length; i++) { - if (!java.util.Objects.equals(values[i], other.values[i])) { - return false; - } - } - return true; -} - -@Override -public int hashCode() { - if (type == null) return System.identityHashCode(this); - - // Hash by primary key if available - Field pk = type.getPk(); - if (pk != null) { - Object pkValue = get(pk); - if (pkValue != null) { - return java.util.Objects.hash(type.getName(), pkValue); - } - } - - // Hash by all values - return java.util.Objects.hash(type.getName(), java.util.Arrays.hashCode(values)); -} -``` - -### 3. Cloning Support (Low Effort) -**Goal**: Standard Java pattern - -**Implementation**: -```java -/** - * Create a shallow copy of this DBO. - * - * @return New DBO instance with copied values - */ -public DBO clone() { - DBO cloned = new DBO(); - cloned.setType(type); - cloned.setTerminal(terminal); - cloned.status = status; - if (values != null) { - cloned.values = values.clone(); - } - return cloned; -} -``` - -### 4. Map Conversion (Medium Impact) -**Goal**: Dictionary-like access - -**Implementation**: -```java -import java.util.Map; -import java.util.HashMap; - -/** - * Convert DBO to Map with field names as keys. - * - * @return Map with field names as keys and values as values - */ -public Map toMap() { - Map result = new HashMap<>(); - if (type != null) { - FieldSlice slice = new FieldSlice(type); - while (slice.hasNext()) { - Field field = slice.next(); - Object value = get(field); - if (value != null) { - result.put(field.getName(), value); - } - } - } - return result; -} - -/** - * Create DBO instance from Map. - * - * @param cls DBO class - * @param data Map with field values - * @param terminal Optional terminal to attach - * @return New DBO instance - */ -public static T fromMap(Class cls, Map data, Terminal terminal) { - try { - T instance = cls.getDeclaredConstructor().newInstance(); - if (terminal != null) { - instance.setTerminal(terminal); - } - Entity entity = Entity.recall(cls); - if (entity != null && data != null) { - for (Map.Entry entry : data.entrySet()) { - Field field = entity.getField(entry.getKey()); - if (field != null) { - instance.set(field, entry.getValue()); - } - } - } - return instance; - } catch (Exception e) { - throw new RuntimeException("Failed to create DBO from map", e); - } -} -``` - -### 5. Fluent API (Low Effort) -**Goal**: Method chaining - -**Implementation**: -```java -/** - * Set field value (fluent API). - * - * @param field Field to set - * @param value Value to set - * @return Self for chaining - */ -public DBO withField(Field field, Object value) { - set(field, value); - return this; -} - -/** - * Set multiple fields from Map (fluent API). - * - * @param data Map with field values - * @return Self for chaining - */ -public DBO withFields(Map data) { - if (type != null && data != null) { - for (Map.Entry entry : data.entrySet()) { - Field field = type.getField(entry.getKey()); - if (field != null) { - set(field, entry.getValue()); - } - } - } - return this; -} -``` - -### 6. Entity Field Lookup by Name (Low Effort) -**Goal**: Find fields by name - -**Implementation**: -```java -// In Entity class -/** - * Get field by name (case-insensitive). - * - * @param name Field name to find - * @return Field instance or null if not found - */ -public Field getField(String name) { - if (name == null) return null; - - // Search own fields - for (Slot slot : getOwnSlots()) { - if (slot instanceof Field && slot.equals(name)) { - return (Field)slot; - } - } - - // Search base entity - if (base != null) { - Field field = base.getField(name); - if (field != null) return field; - } - - return null; -} -``` - -### 7. Better toString() (Low Effort) -**Goal**: Human-readable representation - -**Implementation**: -```java -/** - * Return human-readable string representation. - * - * @return String like "PersonDBO(name=Alice, age=30)" - */ -public String toDisplayString() { - if (type == null) { - return getClass().getSimpleName() + "()"; - } - - StringBuilder sb = new StringBuilder(getClass().getSimpleName()).append("("); - FieldSlice slice = new FieldSlice(type); - boolean first = true; - while (slice.hasNext()) { - Field field = slice.next(); - Object value = get(field); - if (value != null) { - if (!first) sb.append(", "); - sb.append(field.getName()).append("=").append(value); - first = false; - } - } - sb.append(")"); - return sb.toString(); -} - -// Keep existing toString() for JSON representation -``` - -## Priority Recommendations - -### Phase 1: Quick Wins (Low Effort, High Impact) -1. ✅ **Convenience methods** (`get(Field)`, `set(Field, value)`) -2. ✅ **Entity.getField(String)** - field lookup by name -3. ✅ **Fluent API** (`withField()`, `withFields()`) - -### Phase 2: Standard Java Patterns (Medium Effort, High Value) -4. ✅ **Equals and hashCode** - value comparison -5. ✅ **Clone support** - object copying -6. ✅ **Map conversion** - `toMap()`, `fromMap()` - -### Phase 3: Nice to Have -7. ✅ **Better toString()** - human-readable format (keep JSON as default) - -## Implementation Notes - -- All changes should be **backward compatible** -- Maintain existing `Field.get()`/`Field.set()` methods -- Add new methods alongside old ones -- Follow Java conventions (PEP 8 equivalent: Java Code Conventions) -- Use `@Override` where appropriate -- Add comprehensive Javadoc - -## Example Usage After Improvements - -```java -// Before (still works): -Product product = new Product(); -Product.name.set(product, "Widget"); -String name = (String)Product.name.get(product, null); - -// After (new convenience methods): -Product product = new Product(); -product.set(Product.NAME, "Widget"); // Convenience method -String name = (String)product.get(Product.NAME); // Convenience method - -// Fluent API: -Product product = new Product() - .withField(Product.NAME, "Widget") - .withField(Product.PRICE, 19.99); - -// Map conversion: -Map data = product.toMap(); -Product product2 = DBO.fromMap(Product.class, data, terminal); - -// Equality: -if (product1.equals(product2)) { - System.out.println("Same product"); -} - -// Cloning: -Product copy = product.clone(); -``` - diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b2cae77 --- /dev/null +++ b/LICENSE @@ -0,0 +1,60 @@ +GNU LESSER GENERAL PUBLIC LICENSE +Version 3, 29 June 2007 + +Copyright (C) 2007 Free Software Foundation, Inc. + +Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. + +This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. + +0. Additional Definitions. +As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. + +"The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. + +An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. + +A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". + +The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. + +The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. + +1. Exception to Section 3 of the GNU GPL. +You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. + +2. Conveying Modified Versions. +If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: + +a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or +b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. + +3. Object Code Incorporating Material from Library Header Files. +The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: + +a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. +b) Accompany the object code with a copy of the GNU GPL and this license document. + +4. Combined Works. +You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: + +a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. +b) Accompany the Combined Work with a copy of the GNU GPL and this license document. +c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. +d) Do one of the following: +0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. +1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. +e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) + +5. Combined Libraries. +You may place library facilities that are a work based on the Library side by side in a single library together with other library facilities that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: + +a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. +b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. + +6. Revised Versions of the GNU Lesser General Public License. +The Free Software Foundation may publish revised and/or new versions of the GNU Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. + +If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library.