Compare commits

..
Author SHA1 Message Date
Rob BygraveandGitHub d92abbbe9c Merge branch 'master' into feature/sequencedSet 2024-02-10 14:13:21 +13:00
Rob Bygrave 39500567c3 Build needs to use Java 21 to support the multi-release jar 2024-02-10 13:29:40 +13:00
Rob Bygrave ded6fd71b2 Refactor rename method getBeanCollectionAdd() -> collectionAdd() 2024-01-12 16:42:58 +13:00
Rob Bygrave cbc4883672 Refactor BeanSet, BeanList, BeanMap replacing setActualSet|List|Map
Replace with collectionAdd() and refresh() methods.
2024-01-12 16:41:32 +13:00
Rob Bygrave 64e227117b Add support for Java 21 SequencedSet and SequencedMap
Such that these can be used in place of Set and Map if desired.
2024-01-12 16:14:08 +13:00
118 changed files with 1751 additions and 813 deletions
+1 -1
View File
@@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java_version: [11]
java_version: [21]
os: [ubuntu-latest]
steps:
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-clickhouse</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
</dependencies>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-postgres</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
</dependencies>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-db2</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
</dependencies>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-h2</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
</dependencies>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-hana</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
</dependencies>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-mariadb</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
</dependencies>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-mysql</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
</dependencies>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-nuodb</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
</dependencies>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-oracle</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
</dependencies>
+6 -6
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<relativePath>../..</relativePath>
</parent>
@@ -22,13 +22,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
@@ -47,19 +47,19 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-postgres</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-postgis-types</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-postgres</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
</dependencies>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-sqlite</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
</dependencies>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-sqlserver</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
</dependencies>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
@@ -42,13 +42,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-postgres</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
</dependencies>
+6 -6
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<relativePath>../..</relativePath>
</parent>
@@ -17,13 +17,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
@@ -41,7 +41,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-jackson-mapper</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
@@ -60,13 +60,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-all</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
</dependencies>
+1 -1
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</parent>
<artifactId>composites</artifactId>
+48 -1
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</parent>
<name>ebean api</name>
@@ -126,6 +126,53 @@
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<release>11</release>
</configuration>
</execution>
<execution>
<id>compile-21</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<release>21</release>
<compileSourceRoots>
<compileSourceRoot>${project.basedir}/src/main/java21</compileSourceRoot>
</compileSourceRoots>
<multiReleaseOutput>true</multiReleaseOutput>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
<manifestEntries>
<Multi-Release>true</Multi-Release>
</manifestEntries>
</archive>
</configuration>
<!-- <manifest>-->
<!-- <addDefaultImplementationEntries>true</addDefaultImplementationEntries>-->
<!-- </manifest>-->
</plugin>
</plugins>
</build>
</project>
+49
View File
@@ -266,6 +266,55 @@ public final class DB {
getDefault().register(transactionCallback);
}
/**
* Deprecated for removal migrate using try-with-resources and commit on the transaction itself.
* <p>
* Commit the current transaction.
*/
@Deprecated(forRemoval = true)
public static void commitTransaction() {
getDefault().commitTransaction();
}
/**
* Deprecated for removal migrate to using try-with-resources and rollback on the transaction itself.
* <p>
* Rollback the current transaction.
*/
@Deprecated(forRemoval = true)
public static void rollbackTransaction() {
getDefault().rollbackTransaction();
}
/**
* If the current transaction has already been committed do nothing otherwise
* rollback the transaction.
* <p>
* It is preferable to use <em>try with resources</em> rather than this.
* <p>
* Useful to put in a finally block to ensure the transaction is ended, rather
* than a rollbackTransaction() in each catch block.
* <p>
* Code example:
*
* <pre>{@code
* DB.beginTransaction();
* try {
* // do some fetching and or persisting
*
* // commit at the end
* DB.commitTransaction();
*
* } finally {
* // if commit didn't occur then rollback the transaction
* DB.endTransaction();
* }
* }</pre>
*/
public static void endTransaction() {
getDefault().endTransaction();
}
/**
* Mark the current transaction as rollback only.
*/
@@ -666,6 +666,49 @@ public interface Database {
*/
void flush();
/**
* Deprecated for removal migrate using try-with-resources and commit on the transaction itself.
* <p>
* Commit the current transaction.
*/
@Deprecated(forRemoval = true)
void commitTransaction();
/**
* Deprecated for removal migrate to using try-with-resources and rollback on the transaction itself.
* <p>
* Rollback the current transaction.
*/
@Deprecated(forRemoval = true)
void rollbackTransaction();
/**
* If the current transaction has already been committed do nothing otherwise
* rollback the transaction.
* <p>
* Useful to put in a finally block to ensure the transaction is ended, rather
* than a rollbackTransaction() in each catch block.
* <p>
* Code example:
* <p>
* <pre>{@code
*
* database.beginTransaction();
* try {
* // do some fetching and or persisting ...
*
* // commit at the end
* database.commitTransaction();
*
* } finally {
* // if commit didn't occur then rollback the transaction
* database.endTransaction();
* }
*
* }</pre>
*/
void endTransaction();
/**
* Refresh the values of a bean.
* <p>
@@ -141,14 +141,16 @@ public final class BeanList<E> extends AbstractBeanCollection<E> implements List
}
}
/**
* Set the actual underlying list.
* <p>
* This is primarily for the deferred fetching function.
*/
@SuppressWarnings("unchecked")
public void setActualList(List<?> list) {
this.list = (List<E>) list;
public BeanCollectionAdd collectionAdd() {
if (list == null) {
list = new ArrayList<>();
}
return this;
}
public void refresh(ModifyListenMode modifyListenMode, BeanList<E> newList) {
setModifyListening(modifyListenMode);
this.list = newList.actualList();
}
/**
@@ -1,9 +1,6 @@
package io.ebean.common;
import io.ebean.bean.BeanCollection;
import io.ebean.bean.BeanCollectionLoader;
import io.ebean.bean.EntityBean;
import io.ebean.bean.ToStringBuilder;
import io.ebean.bean.*;
import java.util.*;
@@ -17,12 +14,12 @@ public final class BeanMap<K, E> extends AbstractBeanCollection<E> implements Ma
/**
* The underlying map implementation.
*/
private Map<K, E> map;
private LinkedHashMap<K, E> map;
/**
* Create with a given Map.
*/
public BeanMap(Map<K, E> map) {
public BeanMap(LinkedHashMap<K, E> map) {
this.map = map;
}
@@ -160,18 +157,23 @@ public final class BeanMap<K, E> extends AbstractBeanCollection<E> implements Ma
}
}
/**
* Set the actual underlying map. Used for performing lazy fetch.
*/
public LinkedHashMap<K, E> collectionAdd() {
if (map == null) {
map = new LinkedHashMap<>();
}
return map;
}
@SuppressWarnings("unchecked")
public void setActualMap(Map<?, ?> map) {
this.map = (Map<K, E>) map;
public void refresh(ModifyListenMode modifyListenMode, BeanMap<?, ?> newMap) {
setModifyListening(modifyListenMode);
this.map = (LinkedHashMap<K, E>) newMap.actualMap();
}
/**
* Return the actual underlying map.
*/
public Map<K, E> actualMap() {
public LinkedHashMap<K, E> actualMap() {
return map;
}
@@ -3,10 +3,7 @@ package io.ebean.common;
import io.ebean.bean.*;
import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import java.util.*;
/**
* Set capable of lazy loading and modification aware.
@@ -18,12 +15,12 @@ public final class BeanSet<E> extends AbstractBeanCollection<E> implements Set<E
/**
* The underlying Set implementation.
*/
private Set<E> set;
private LinkedHashSet<E> set;
/**
* Create with a specific Set implementation.
*/
public BeanSet(Set<E> set) {
public BeanSet(LinkedHashSet<E> set) {
this.set = set;
}
@@ -144,18 +141,22 @@ public final class BeanSet<E> extends AbstractBeanCollection<E> implements Set<E
}
}
/**
* Set the underlying set (used for lazy fetch).
*/
@SuppressWarnings("unchecked")
public void setActualSet(Set<?> set) {
this.set = (Set<E>) set;
public BeanCollectionAdd collectionAdd() {
if (set == null) {
set = new LinkedHashSet<>();
}
return this;
}
public void refresh(ModifyListenMode modifyListenMode, BeanSet<E> newSet) {
setModifyListening(modifyListenMode);
this.set = newSet.actualSet();
}
/**
* Return the actual underlying set.
*/
public Set<E> actualSet() {
public LinkedHashSet<E> actualSet() {
return set;
}
@@ -236,7 +236,7 @@ public class DatabaseConfig implements DatabaseBuilder.Settings {
*/
private PersistBatch persistBatchOnCascade = PersistBatch.INHERIT;
private int persistBatchSize = 100;
private int persistBatchSize = 20;
private EnumType defaultEnumType = EnumType.ORDINAL;
@@ -0,0 +1,450 @@
package io.ebean.common;
import io.ebean.bean.BeanCollection;
import io.ebean.bean.BeanCollectionLoader;
import io.ebean.bean.EntityBean;
import io.ebean.bean.ToStringBuilder;
import java.util.*;
/**
* Map capable of lazy loading and modification aware.
*/
public final class BeanMap<K, E> extends AbstractBeanCollection<E> implements SequencedMap<K, E> {
private static final long serialVersionUID = 1L;
/**
* The underlying map implementation.
*/
private LinkedHashMap<K, E> map;
/**
* Create with a given Map.
*/
public BeanMap(LinkedHashMap<K, E> map) {
this.map = map;
}
/**
* Create using a underlying LinkedHashMap.
*/
public BeanMap() {
this(new LinkedHashMap<>());
}
public BeanMap(BeanCollectionLoader ebeanServer, EntityBean ownerBean, String propertyName) {
super(ebeanServer, ownerBean, propertyName);
}
@Override
public void toString(ToStringBuilder builder) {
if (map == null || map.isEmpty()) {
builder.addRaw("{}");
} else {
builder.addRaw("{");
for (Entry<K, E> entry : map.entrySet()) {
builder.add(String.valueOf(entry.getKey()), entry.getValue());
}
builder.addRaw("}");
}
}
@Override
public void reset(EntityBean ownerBean, String propertyName) {
this.ownerBean = ownerBean;
this.propertyName = propertyName;
this.map = null;
}
@Override
public boolean isSkipSave() {
return map == null || (map.isEmpty() && !holdsModifications());
}
@Override
@SuppressWarnings("unchecked")
public void loadFrom(BeanCollection<?> other) {
BeanMap<K, E> otherMap = (BeanMap<K, E>) other;
internalPutNull();
map.putAll(otherMap.actualMap());
}
public void internalPutNull() {
if (map == null) {
map = new LinkedHashMap<>();
}
}
@SuppressWarnings("unchecked")
public void internalPut(Object key, Object bean) {
if (map == null) {
map = new LinkedHashMap<>();
}
if (key != null) {
map.put((K) key, (E) bean);
}
}
public void internalPutWithCheck(Object key, Object bean) {
if (map == null || key == null || !map.containsKey(key)) {
internalPut(key, bean);
}
}
@Override
public void internalAddWithCheck(Object bean) {
throw new RuntimeException("Not allowed for map");
}
@Override
public void internalAdd(Object bean) {
throw new RuntimeException("Not allowed for map");
}
/**
* Return true if the underlying map has been populated. Returns false if it
* has a deferred fetch pending.
*/
@Override
public boolean isPopulated() {
return map != null;
}
/**
* Return true if this is a reference (lazy loading) bean collection. This is
* the same as !isPopulated();
*/
@Override
public boolean isReference() {
return map == null;
}
@Override
public boolean checkEmptyLazyLoad() {
if (map == null) {
map = new LinkedHashMap<>();
return true;
} else {
return false;
}
}
private void initClear() {
lock.lock();
try {
if (map == null) {
if (!disableLazyLoad && modifyListening) {
lazyLoadCollection(true);
} else {
map = new LinkedHashMap<>();
}
}
} finally {
lock.unlock();
}
}
private void init() {
lock.lock();
try {
if (map == null) {
if (disableLazyLoad) {
map = new LinkedHashMap<>();
} else {
lazyLoadCollection(false);
}
}
} finally {
lock.unlock();
}
}
public LinkedHashMap<K, E> collectionAdd() {
if (map == null) {
map = new LinkedHashMap<>();
}
return map;
}
@SuppressWarnings("unchecked")
public void refresh(ModifyListenMode modifyListenMode, BeanMap<?, ?> newMap) {
setModifyListening(modifyListenMode);
this.map = (LinkedHashMap<K, E>) newMap.actualMap();
}
/**
* Return the actual underlying map.
*/
public LinkedHashMap<K, E> actualMap() {
return map;
}
/**
* Returns the collection of beans (map values).
*/
@Override
public Collection<E> actualDetails() {
return map.values();
}
/**
* Returns the map entrySet.
*/
@Override
public Collection<?> actualEntries() {
return map.entrySet();
}
@Override
public String toString() {
if (map == null) {
return "BeanMap<deferred>";
} else {
return map.toString();
}
}
/**
* Equal if object is a Map and equal in a Map sense.
*/
@Override
public boolean equals(Object object) {
init();
return map.equals(object);
}
@Override
public int hashCode() {
init();
return map.hashCode();
}
@Override
public void clear() {
checkReadOnly();
initClear();
if (modifyListening) {
// add all beans to the removal list
for (E bean : map.values()) {
modifyRemoval(bean);
}
}
map.clear();
}
@Override
public boolean containsKey(Object key) {
init();
return map.containsKey(key);
}
@Override
public boolean containsValue(Object value) {
init();
return map.containsValue(value);
}
@Override
public Set<Entry<K, E>> entrySet() {
init();
if (readOnly) {
return Collections.unmodifiableSet(map.entrySet());
}
return modifyListening ? new ModifyEntrySet<>(this, map.entrySet()) : map.entrySet();
}
@Override
public E get(Object key) {
init();
return map.get(key);
}
@Override
public boolean isEmpty() {
init();
return map.isEmpty();
}
@Override
public Set<K> keySet() {
init();
if (readOnly) {
return Collections.unmodifiableSet(map.keySet());
}
return modifyListening ? new ModifyKeySet<>(this, map.keySet()) : map.keySet();
}
@Override
public E put(K key, E value) {
checkReadOnly();
init();
if (modifyListening) {
E oldBean = map.put(key, value);
if (value != oldBean) {
// register the add of the new and the removal of the old
modifyAddition(value);
modifyRemoval(oldBean);
}
return oldBean;
} else {
return map.put(key, value);
}
}
@Override
public void putAll(Map<? extends K, ? extends E> puts) {
checkReadOnly();
init();
if (modifyListening) {
for (Entry<? extends K, ? extends E> entry : puts.entrySet()) {
Object oldBean = map.put(entry.getKey(), entry.getValue());
if (entry.getValue() != oldBean) {
modifyAddition(entry.getValue());
modifyRemoval(oldBean);
}
}
} else {
map.putAll(puts);
}
}
@Override
public void addBean(E bean) {
throw new IllegalStateException("Method not allowed on Map. Please use List instead.");
}
@Override
public void removeBean(E bean) {
throw new IllegalStateException("Method not allowed on Map. Please use List instead.");
}
@Override
public E remove(Object key) {
checkReadOnly();
init();
if (modifyListening) {
E o = map.remove(key);
modifyRemoval(o);
return o;
}
return map.remove(key);
}
@Override
public int size() {
init();
return map.size();
}
@Override
public Collection<E> values() {
init();
if (readOnly) {
return Collections.unmodifiableCollection(map.values());
}
return modifyListening ? new ModifyCollection<>(this, map.values()) : map.values();
}
@Override
public BeanCollection<E> shallowCopy() {
BeanMap<K, E> copy = new BeanMap<>(new LinkedHashMap<>(map));
copy.setFromOriginal(this);
return copy;
}
@Override
public SequencedMap<K, E> reversed() {
init();
if (modifyListening) {
throw new UnsupportedOperationException("Not supported on modify listening map");
}
return map.reversed();
}
@Override
public Entry<K, E> firstEntry() {
init();
return map.firstEntry();
}
@Override
public Entry<K, E> lastEntry() {
init();
return map.lastEntry();
}
@Override
public Entry<K, E> pollFirstEntry() {
checkReadOnly();
init();
var entry = map.pollFirstEntry();
if (modifyListening && entry != null) {
modifyRemoval(entry.getValue());
}
return entry;
}
@Override
public Entry<K, E> pollLastEntry() {
checkReadOnly();
init();
var entry = map.pollLastEntry();
if (modifyListening && entry != null) {
modifyRemoval(entry.getValue());
}
return entry;
}
@Override
public E putFirst(K key, E value) {
checkReadOnly();
init();
if (modifyListening) {
E oldBean = map.putFirst(key, value);
if (value != oldBean) {
// register the add of the new and the removal of the old
modifyAddition(value);
modifyRemoval(oldBean);
}
return oldBean;
} else {
return map.putFirst(key, value);
}
}
@Override
public E putLast(K key, E value) {
checkReadOnly();
init();
if (modifyListening) {
E oldBean = map.putLast(key, value);
if (value != oldBean) {
// register the add of the new and the removal of the old
modifyAddition(value);
modifyRemoval(oldBean);
}
return oldBean;
} else {
return map.putLast(key, value);
}
}
@Override
public SequencedSet<K> sequencedKeySet() {
init();
return map.sequencedKeySet();
}
@Override
public SequencedCollection<E> sequencedValues() {
init();
return map.sequencedValues();
}
@Override
public SequencedSet<Entry<K, E>> sequencedEntrySet() {
init();
return map.sequencedEntrySet();
}
}
@@ -0,0 +1,460 @@
package io.ebean.common;
import io.ebean.bean.*;
import java.io.Serializable;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.SequencedSet;
/**
* Set capable of lazy loading and modification aware.
*/
public final class BeanSet<E> extends AbstractBeanCollection<E> implements SequencedSet<E>, BeanCollectionAdd {
private static final long serialVersionUID = 1L;
/**
* The underlying Set implementation.
*/
private LinkedHashSet<E> set;
/**
* Create with a specific Set implementation.
*/
public BeanSet(LinkedHashSet<E> set) {
this.set = set;
}
/**
* Create using an underlying LinkedHashSet.
*/
public BeanSet() {
this(new LinkedHashSet<>());
}
public BeanSet(BeanCollectionLoader loader, EntityBean ownerBean, String propertyName) {
super(loader, ownerBean, propertyName);
}
@Override
public void toString(ToStringBuilder builder) {
builder.addCollection(set);
}
@Override
public void reset(EntityBean ownerBean, String propertyName) {
this.ownerBean = ownerBean;
this.propertyName = propertyName;
this.set = null;
}
@Override
public boolean isSkipSave() {
return set == null || (set.isEmpty() && !holdsModifications());
}
@Override
@SuppressWarnings("unchecked")
public void addEntityBean(EntityBean bean) {
set.add((E) bean);
}
@Override
@SuppressWarnings("unchecked")
public void loadFrom(BeanCollection<?> other) {
if (set == null) {
set = new LinkedHashSet<>();
}
set.addAll((Collection<? extends E>) other.actualDetails());
}
@Override
public void internalAddWithCheck(Object bean) {
// set add() already de-dups so just add it
internalAdd(bean);
}
@Override
@SuppressWarnings("unchecked")
public void internalAdd(Object bean) {
if (set == null) {
set = new LinkedHashSet<>();
}
if (bean != null) {
set.add((E) bean);
}
}
/**
* Returns true if the underlying set has its data.
*/
@Override
public boolean isPopulated() {
return set != null;
}
/**
* Return true if this is a reference (lazy loading) bean collection. This is
* the same as !isPopulated();
*/
@Override
public boolean isReference() {
return set == null;
}
@Override
public boolean checkEmptyLazyLoad() {
if (set == null) {
set = new LinkedHashSet<>();
return true;
} else {
return false;
}
}
private void initClear() {
lock.lock();
try {
if (set == null) {
if (!disableLazyLoad && modifyListening) {
lazyLoadCollection(false);
} else {
set = new LinkedHashSet<>();
}
}
} finally {
lock.unlock();
}
}
private void init() {
lock.lock();
try {
if (set == null) {
if (disableLazyLoad) {
set = new LinkedHashSet<>();
} else {
lazyLoadCollection(false);
}
}
} finally {
lock.unlock();
}
}
public BeanCollectionAdd collectionAdd() {
if (set == null) {
set = new LinkedHashSet<>();
}
return this;
}
public void refresh(ModifyListenMode modifyListenMode, BeanSet<E> newSet) {
setModifyListening(modifyListenMode);
this.set = newSet.actualSet();
}
/**
* Return the actual underlying set.
*/
public LinkedHashSet<E> actualSet() {
return set;
}
@Override
public Collection<E> actualDetails() {
return set;
}
@Override
public Collection<?> actualEntries() {
return set;
}
@Override
public String toString() {
if (set == null) {
return "BeanSet<deferred>";
} else {
return set.toString();
}
}
/**
* Equal if obj is a Set and equal in a Set sense.
*/
@Override
public boolean equals(Object obj) {
init();
return set.equals(obj);
}
@Override
public int hashCode() {
init();
return set.hashCode();
}
@Override
public void addBean(E bean) {
add(bean);
}
@Override
public void removeBean(E bean) {
if (set.remove(bean)) {
getModifyHolder().modifyRemoval(bean);
}
}
// -----------------------------------------------------//
// proxy method for map
// -----------------------------------------------------//
@Override
public boolean add(E bean) {
checkReadOnly();
init();
if (modifyListening) {
if (set.add(bean)) {
modifyAddition(bean);
return true;
} else {
return false;
}
}
return set.add(bean);
}
@Override
public boolean addAll(Collection<? extends E> beans) {
checkReadOnly();
init();
if (modifyListening) {
boolean changed = false;
for (E bean : beans) {
if (set.add(bean)) {
// register the addition of the bean
modifyAddition(bean);
changed = true;
}
}
return changed;
}
return set.addAll(beans);
}
@Override
public void clear() {
checkReadOnly();
initClear();
if (modifyListening) {
for (E bean : set) {
modifyRemoval(bean);
}
}
set.clear();
}
@Override
public boolean contains(Object bean) {
init();
return set.contains(bean);
}
@Override
public boolean containsAll(Collection<?> beans) {
init();
return set.containsAll(beans);
}
@Override
public boolean isEmpty() {
init();
return set.isEmpty();
}
@Override
public Iterator<E> iterator() {
init();
if (readOnly) {
return new ReadOnlyIterator<>(set.iterator());
}
if (modifyListening) {
return new ModifyIterator<>(this, set.iterator());
}
return set.iterator();
}
@Override
public boolean remove(Object bean) {
checkReadOnly();
init();
if (modifyListening) {
if (set.remove(bean)) {
modifyRemoval(bean);
return true;
}
return false;
}
return set.remove(bean);
}
@Override
public boolean removeAll(Collection<?> beans) {
checkReadOnly();
init();
if (modifyListening) {
boolean changed = false;
for (Object bean : beans) {
if (set.remove(bean)) {
modifyRemoval(bean);
changed = true;
}
}
return changed;
}
return set.removeAll(beans);
}
@Override
public boolean retainAll(Collection<?> beans) {
checkReadOnly();
init();
if (modifyListening) {
boolean changed = false;
Iterator<?> it = set.iterator();
while (it.hasNext()) {
Object bean = it.next();
if (!beans.contains(bean)) {
// not retaining this bean so add it to the removal list
it.remove();
modifyRemoval(bean);
changed = true;
}
}
return changed;
}
return set.retainAll(beans);
}
@Override
public int size() {
init();
return set.size();
}
@Override
public Object[] toArray() {
init();
return set.toArray();
}
@Override
public <T> T[] toArray(T[] array) {
init();
//noinspection SuspiciousToArrayCall
return set.toArray(array);
}
@Override
public SequencedSet<E> reversed() {
init();
if (modifyListening) {
throw new UnsupportedOperationException("Not supported on modify listening set");
}
return set.reversed();
}
@Override
public void addFirst(E bean) {
checkReadOnly();
init();
if (modifyListening) {
modifyAddition(bean);
}
set.addFirst(bean);
}
@Override
public void addLast(E bean) {
checkReadOnly();
init();
if (modifyListening) {
modifyAddition(bean);
}
set.addLast(bean);
}
@Override
public E getFirst() {
init();
return set.getFirst();
}
@Override
public E getLast() {
init();
return set.getLast();
}
@Override
public E removeFirst() {
checkReadOnly();
init();
if (modifyListening) {
var bean = set.removeFirst();
modifyRemoval(bean);
return bean;
}
return set.removeFirst();
}
@Override
public E removeLast() {
checkReadOnly();
init();
if (modifyListening) {
var bean = set.removeLast();
modifyRemoval(bean);
return bean;
}
return set.removeLast();
}
private static final class ReadOnlyIterator<E> implements Iterator<E>, Serializable {
private static final long serialVersionUID = 2577697326745352605L;
private final Iterator<E> it;
ReadOnlyIterator(Iterator<E> it) {
this.it = it;
}
@Override
public boolean hasNext() {
return it.hasNext();
}
@Override
public E next() {
return it.next();
}
@Override
public void remove() {
throw new IllegalStateException("This collection is in ReadOnly mode");
}
}
@Override
public BeanCollection<E> shallowCopy() {
BeanSet<E> copy = new BeanSet<>(new LinkedHashSet<>(set));
copy.setFromOriginal(this);
return copy;
}
}
@@ -136,13 +136,13 @@ class ToStringBuilderTest {
@Test
void beanSet_null_empty() {
assertThat(toStringFor(new BeanSet<String>(null))).isEqualTo("[]");
assertThat(toStringFor(new BeanSet<String>(Collections.emptySet()))).isEqualTo("[]");
assertThat(toStringFor(new BeanSet<String>(new LinkedHashSet<>()))).isEqualTo("[]");
}
@Test
void beanMap_null_empty() {
assertThat(toStringFor(new BeanMap<String, String>(null))).isEqualTo("{}");
assertThat(toStringFor(new BeanMap<String, String>(Collections.emptyMap()))).isEqualTo("{}");
assertThat(toStringFor(new BeanMap<String, String>(new LinkedHashMap<>()))).isEqualTo("{}");
}
@Test
@@ -159,7 +159,7 @@ class ToStringBuilderTest {
@Test
void beanMap_some() {
Map<String, Recurse> under = new LinkedHashMap<>();
var under = new LinkedHashMap<String, Recurse>();
under.put("a", new Recurse(1, "a"));
under.put("b", new Recurse(2, "b"));
BeanMap<String, Recurse> list = new BeanMap<>(under);
+26 -26
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</parent>
<name>ebean bom</name>
@@ -89,25 +89,25 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core-type</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
@@ -125,13 +125,13 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-jackson-mapper</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-ddl-generator</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
@@ -155,37 +155,37 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>querybean-generator</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>kotlin-querybean-generator</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-test</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-redis</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-spring-txn</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<!-- platforms -->
@@ -193,79 +193,79 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-clickhouse</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-db2</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-h2</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-hana</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-mariadb</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-mysql</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-nuodb</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-oracle</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-postgres</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-postgis</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-postgis-types</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-sqlite</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-sqlserver</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
</dependencies>
+2 -2
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</parent>
<artifactId>ebean-core-type</artifactId>
@@ -16,7 +16,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
+6 -6
View File
@@ -3,7 +3,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</parent>
<artifactId>ebean-core</artifactId>
@@ -22,7 +22,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
@@ -46,7 +46,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core-type</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
@@ -159,21 +159,21 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-h2</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-postgres</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-sqlserver</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>test</scope>
</dependency>
@@ -3,8 +3,6 @@ package io.ebeaninternal.api;
import io.ebean.TxScope;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
/**
* Used internally to handle the scoping of transactions for methods.
@@ -49,11 +47,6 @@ public final class ScopeTrans {
private boolean nestedCommit;
private boolean nestedUseSavepoint;
/**
* The UserObjects when using in nested transactions.
*/
private Map<String, Object> userObjects;
public ScopeTrans(boolean rollbackOnChecked, boolean created, SpiTransaction transaction, TxScope txScope) {
this.rollbackOnChecked = rollbackOnChecked;
this.created = created;
@@ -225,17 +218,4 @@ public final class ScopeTrans {
return e instanceof RuntimeException || rollbackOnChecked;
}
public void putUserObject(String name, Object value) {
if (userObjects == null) {
userObjects = new HashMap<>();
}
userObjects.put(name, value);
}
public Object getUserObject(String name) {
if (userObjects == null) {
return null;
}
return userObjects.get(name);
}
}
@@ -2,6 +2,7 @@ package io.ebeaninternal.api;
import io.ebeaninternal.server.transaction.TransactionScopeManager;
import io.ebeaninternal.server.util.ArrayStack;
import jakarta.persistence.PersistenceException;
/**
@@ -172,31 +173,4 @@ public final class ScopedTransaction extends SpiTransactionProxy {
return current.caughtThrowable(e);
}
/**
* New user objects are always written to the current ScopeTrans.
*/
@Override
public void putUserObject(String name, Object value) {
current.putUserObject(name, value);
}
/**
* Returns the userObject in the stack, Herew we search
* the stack and return the first found userObject
*/
@Override
public Object getUserObject(String name) {
Object obj = current.getUserObject(name);
if (obj != null) {
return obj;
}
for (ScopeTrans trans : stack) {
obj = trans.getUserObject(name);
if (obj != null) {
return obj;
}
}
return transaction.getUserObject(name);
}
}
@@ -86,11 +86,6 @@ public interface SpiEbeanServer extends SpiServer, ExtendedServer, BeanCollectio
*/
SpiTransactionManager transactionManager();
/**
* End the current transaction if it is active.
*/
void endTransaction();
/**
* Return all the descriptors.
*/
@@ -756,6 +756,16 @@ public final class DefaultServer implements SpiServer, SpiEbeanServer {
currentTransaction().flush();
}
@Override
public void commitTransaction() {
currentTransaction().commit();
}
@Override
public void rollbackTransaction() {
currentTransaction().rollback();
}
@Override
public void endTransaction() {
Transaction transaction = transactionManager.inScope();
@@ -773,10 +773,4 @@ public final class OrmQueryRequest<T> extends BeanRequest implements SpiOrmQuery
public int forwardOnlyFetchSize() {
return queryEngine.forwardOnlyFetchSize();
}
public void clearContext() {
if (!transaction.isAutoPersistUpdates()) {
beanDescriptor.contextClear(transaction.persistenceContext());
}
}
}
@@ -77,13 +77,10 @@ public final class PersistRequestOrmUpdate extends PersistRequest {
*/
@Override
public void postExecute() {
OrmUpdateType ormUpdateType = ormUpdate.ormUpdateType();
if (OrmUpdateType.INSERT != ormUpdateType && !transaction.isAutoPersistUpdates()) {
beanDescriptor.contextClear(transaction.persistenceContext());
}
if (startNanos > 0) {
persistExecute.collectOrmUpdate(label, startNanos);
}
OrmUpdateType ormUpdateType = ormUpdate.ormUpdateType();
String tableName = ormUpdate.baseTable();
if (transaction.isLogSummary()) {
transaction.logSummary("{0} table[{1}] rows[{2}] bind[{3}]", ormUpdateType, tableName, rowCount, bindLog);
@@ -3,13 +3,10 @@ package io.ebeaninternal.server.core;
import io.ebeaninternal.api.SpiEbeanServer;
import io.ebeaninternal.api.SpiSqlUpdate;
import io.ebeaninternal.api.SpiTransaction;
import io.ebeaninternal.server.deploy.BeanDescriptor;
import io.ebeaninternal.server.persist.BatchControl;
import io.ebeaninternal.server.persist.PersistExecute;
import io.ebeaninternal.server.persist.TrimLogSql;
import java.util.List;
/**
* Persist request specifically for CallableSql.
*/
@@ -159,14 +156,6 @@ public final class PersistRequestUpdateSql extends PersistRequest {
*/
@Override
public void postExecute() {
if (sqlType != SqlType.SQL_INSERT && !transaction.isAutoPersistUpdates()) {
List<BeanDescriptor<?>> descriptors = server.descriptors(tableName);
if (descriptors != null) {
for (BeanDescriptor<?> descriptor : descriptors) {
descriptor.contextClear(transaction.persistenceContext());
}
}
}
if (startNanos > 0) {
persistExecute.collectSqlUpdate(label, startNanos);
}
@@ -1,12 +1,9 @@
package io.ebeaninternal.server.deploy;
import io.ebean.Transaction;
import io.ebean.bean.BeanCollection;
import io.ebean.bean.BeanCollectionAdd;
import io.ebean.bean.BeanCollectionLoader;
import io.ebean.bean.EntityBean;
import io.ebeaninternal.api.SpiEbeanServer;
import io.ebeaninternal.api.SpiQuery;
import io.ebeaninternal.api.json.SpiJsonWriter;
import io.ebeaninternal.server.query.CQueryCollectionAdd;
@@ -34,7 +31,7 @@ public interface BeanCollectionHelp<T> extends CQueryCollectionAdd<T> {
* For Map's this needs to take the mapKey.
* </p>
*/
BeanCollectionAdd getBeanCollectionAdd(Object bc, String mapKey);
BeanCollectionAdd collectionAdd(Object bc, String mapKey);
/**
* Create an empty collection of the correct type without a parent bean.
@@ -2056,13 +2056,6 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType, SpiBeanType {
pc.clear(rootBeanType, idValue);
}
/**
* Clear a bean from the persistence context.
*/
public void contextClear(PersistenceContext pc) {
pc.clear(rootBeanType);
}
/**
* Delete a bean from the persistence context (such that we don't fetch it in the same transaction).
*/
@@ -399,7 +399,7 @@ public final class BeanDescriptorManager implements BeanDescriptorMap, SpiBeanTy
* Return the BeanDescriptors mapped to the table.
*/
public List<BeanDescriptor<?>> descriptors(String tableName) {
return tableName == null ? Collections.emptyList() : tableToDescMap.get(tableName.toLowerCase());
return tableToDescMap.get(tableName.toLowerCase());
}
/**
@@ -1,16 +1,12 @@
package io.ebeaninternal.server.deploy;
import io.ebean.Transaction;
import io.ebean.bean.BeanCollection;
import io.ebean.bean.BeanCollectionAdd;
import io.ebean.bean.EntityBean;
import io.ebean.common.BeanList;
import io.ebeaninternal.api.SpiEbeanServer;
import io.ebeaninternal.api.SpiQuery;
import io.ebeaninternal.api.json.SpiJsonWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -23,19 +19,11 @@ public class BeanListHelp<T> extends BaseCollectionHelp<T> {
super(many);
}
BeanListHelp() {
super();
}
@Override
public final BeanCollectionAdd getBeanCollectionAdd(Object bc, String mapKey) {
public final BeanCollectionAdd collectionAdd(Object bc, String mapKey) {
if (bc instanceof BeanList<?>) {
BeanList<?> bl = (BeanList<?>) bc;
if (bl.actualList() == null) {
bl.setActualList(new ArrayList<>());
}
return bl;
return bl.collectionAdd();
} else {
throw new RuntimeException("Unhandled type " + bc);
}
@@ -67,20 +55,20 @@ public class BeanListHelp<T> extends BaseCollectionHelp<T> {
return beanList;
}
@SuppressWarnings("unchecked")
@Override
public final void refresh(BeanCollection<?> bc, EntityBean parentBean) {
BeanList<?> newBeanList = (BeanList<?>) bc;
BeanList<T> newBeanList = (BeanList<T>) bc;
List<?> currentList = (List<?>) many.getValue(parentBean);
newBeanList.setModifyListening(many.modifyListenMode());
if (currentList == null) {
// the currentList is null? Not really expecting this...
many.setValue(parentBean, newBeanList);
} else if (currentList instanceof BeanList<?>) {
} else if (currentList instanceof BeanList) {
// normally this case, replace just the underlying list
BeanList<?> currentBeanList = (BeanList<?>) currentList;
currentBeanList.setActualList(newBeanList.actualList());
currentBeanList.setModifyListening(many.modifyListenMode());
BeanList<T> currentBeanList = (BeanList<T>) currentList;
currentBeanList.refresh(many.modifyListenMode(), newBeanList);
} else {
// replace the entire list with the BeanList
@@ -1,17 +1,13 @@
package io.ebeaninternal.server.deploy;
import io.ebean.Transaction;
import io.ebean.bean.BeanCollection;
import io.ebean.bean.BeanCollectionAdd;
import io.ebean.bean.EntityBean;
import io.ebean.common.BeanMap;
import io.ebeaninternal.api.SpiEbeanServer;
import io.ebeaninternal.api.SpiQuery;
import io.ebeaninternal.api.json.SpiJsonWriter;
import java.io.IOException;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
@@ -37,20 +33,14 @@ public class BeanMapHelp<T> extends BaseCollectionHelp<T> {
@Override
@SuppressWarnings("unchecked")
public final BeanCollectionAdd getBeanCollectionAdd(Object bc, String mapKey) {
public final BeanCollectionAdd collectionAdd(Object bc, String mapKey) {
if (mapKey == null) {
mapKey = many.mapKey();
}
BeanProperty beanProp = targetDescriptor.beanProperty(mapKey);
if (bc instanceof BeanMap<?, ?>) {
BeanMap<Object, Object> bm = (BeanMap<Object, Object>) bc;
Map<Object, Object> actualMap = bm.actualMap();
if (actualMap == null) {
actualMap = new LinkedHashMap<>();
bm.setActualMap(actualMap);
}
return new Adder(beanProp, actualMap);
return new Adder(beanProp, bm.collectionAdd());
} else {
throw new RuntimeException("Unhandled type " + bc);
}
@@ -126,8 +116,7 @@ public class BeanMapHelp<T> extends BaseCollectionHelp<T> {
} else if (current instanceof BeanMap<?, ?>) {
// normally this case, replace just the underlying list
BeanMap<?, ?> currentBeanMap = (BeanMap<?, ?>) current;
currentBeanMap.setActualMap(newBeanMap.actualMap());
currentBeanMap.setModifyListening(many.modifyListenMode());
currentBeanMap.refresh(many.modifyListenMode(), newBeanMap);
} else {
// replace the entire set
@@ -655,7 +655,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
}
private BeanCollectionAdd beanCollectionAdd(Object bc) {
return help.getBeanCollectionAdd(bc, null);
return help.collectionAdd(bc, null);
}
public Object parentId(EntityBean parentBean) {
@@ -1,17 +1,13 @@
package io.ebeaninternal.server.deploy;
import io.ebean.Transaction;
import io.ebean.bean.BeanCollection;
import io.ebean.bean.BeanCollectionAdd;
import io.ebean.bean.EntityBean;
import io.ebean.common.BeanSet;
import io.ebeaninternal.api.SpiEbeanServer;
import io.ebeaninternal.api.SpiQuery;
import io.ebeaninternal.api.json.SpiJsonWriter;
import java.io.IOException;
import java.util.Collections;
import java.util.LinkedHashSet;
import java.util.Set;
/**
@@ -26,21 +22,11 @@ public class BeanSetHelp<T> extends BaseCollectionHelp<T> {
super(many);
}
/**
* For a query that returns a set.
*/
BeanSetHelp() {
super();
}
@Override
public final BeanCollectionAdd getBeanCollectionAdd(Object bc, String mapKey) {
public final BeanCollectionAdd collectionAdd(Object bc, String mapKey) {
if (bc instanceof BeanSet<?>) {
BeanSet<?> beanSet = (BeanSet<?>) bc;
if (beanSet.actualSet() == null) {
beanSet.setActualSet(new LinkedHashSet<>());
}
return beanSet;
return beanSet.collectionAdd();
} else {
throw new RuntimeException("Unhandled type " + bc);
}
@@ -72,9 +58,10 @@ public class BeanSetHelp<T> extends BaseCollectionHelp<T> {
return beanSet;
}
@SuppressWarnings("unchecked")
@Override
public final void refresh(BeanCollection<?> bc, EntityBean parentBean) {
BeanSet<?> newBeanSet = (BeanSet<?>) bc;
BeanSet<T> newBeanSet = (BeanSet<T>) bc;
Set<?> current = (Set<?>) many.getValue(parentBean);
newBeanSet.setModifyListening(many.modifyListenMode());
if (current == null) {
@@ -83,9 +70,8 @@ public class BeanSetHelp<T> extends BaseCollectionHelp<T> {
} else if (current instanceof BeanSet<?>) {
// normally this case, replace just the underlying list
BeanSet<?> currentBeanSet = (BeanSet<?>) current;
currentBeanSet.setActualSet(newBeanSet.actualSet());
currentBeanSet.setModifyListening(many.modifyListenMode());
BeanSet<T> currentBeanSet = (BeanSet<T>) current;
currentBeanSet.refresh(many.modifyListenMode(), newBeanSet);
} else {
// replace the entire set
@@ -4,7 +4,6 @@ import io.ebean.bean.BeanCollection;
import io.ebean.common.BeanMap;
import java.util.LinkedHashMap;
import java.util.Map;
final class ElementHelpMap implements ElementHelp {
@@ -15,7 +14,7 @@ final class ElementHelpMap implements ElementHelp {
private static class Collector implements ElementCollector {
private final Map<Object, Object> map = new LinkedHashMap<>();
private final LinkedHashMap<Object, Object> map = new LinkedHashMap<>();
@Override
public void addElement(Object element) {
@@ -4,7 +4,6 @@ import io.ebean.bean.BeanCollection;
import io.ebean.common.BeanSet;
import java.util.LinkedHashSet;
import java.util.Set;
final class ElementHelpSet implements ElementHelp {
@@ -15,7 +14,7 @@ final class ElementHelpSet implements ElementHelp {
private static class Collector implements ElementCollector {
private final Set<Object> set = new LinkedHashSet<>();
private final LinkedHashSet<Object> set = new LinkedHashSet<>();
@Override
public void addElement(Object element) {
@@ -122,7 +122,7 @@ public final class DeployCreateProperties {
return new DeployBeanProperty(desc, propertyType, field.getGenericType());
}
// check for Collection type (list, set or map)
ManyType manyType = determineManyType.getManyType(propertyType);
ManyType manyType = determineManyType.manyType(propertyType);
if (manyType != null) {
// List, Set or Map based object
Class<?> targetType = determineTargetType(field);
@@ -11,14 +11,14 @@ import java.util.Set;
*/
final class DetermineManyType {
ManyType getManyType(Class<?> type) {
ManyType manyType(Class<?> type) {
if (type.equals(List.class)) {
return ManyType.LIST;
}
if (type.equals(Set.class)) {
if (type.equals(Set.class) || type.getCanonicalName().equals("java.util.SequencedSet")) {
return ManyType.SET;
}
if (type.equals(Map.class)) {
if (type.equals(Map.class) || type.getCanonicalName().equals("java.util.SequencedMap")) {
return ManyType.MAP;
}
return null;
@@ -74,9 +74,6 @@ public final class CQueryEngine {
if (request.logSql()) {
request.logSql("{0}; --bind({1}) --micros({2}) --rows({3})", query.generatedSql(), query.bindLog(), query.micros(), rows);
}
if (rows > 0) {
request.clearContext();
}
return rows;
} catch (SQLException e) {
throw translate(request, query.bindLog(), query.generatedSql(), e);
@@ -61,7 +61,6 @@ final class CQueryUpdate implements SpiProfileTransactionEvent, CancelableQuery
/**
* Execute the update or delete statement returning the row count.
*/
@SuppressWarnings("resource")
public int execute() throws SQLException {
long startNano = System.nanoTime();
try {
@@ -110,7 +109,6 @@ final class CQueryUpdate implements SpiProfileTransactionEvent, CancelableQuery
pstmt = null;
}
@SuppressWarnings("resource")
@Override
public void profile() {
transaction()
@@ -2,13 +2,12 @@ package io.ebeaninternal.server.util;
import java.util.ArrayList;
import java.util.EmptyStackException;
import java.util.Iterator;
import java.util.List;
/**
* Stack based on ArrayList.
*/
public class ArrayStack<E> implements Iterable<E> {
public class ArrayStack<E> {
private final List<E> list;
@@ -90,9 +89,4 @@ public class ArrayStack<E> implements Iterable<E> {
public boolean contains(E o) {
return list.contains(o);
}
@Override
public Iterator<E> iterator() {
return list.iterator();
}
}
+4 -4
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</parent>
<name>ebean ddl generation</name>
@@ -28,14 +28,14 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core-type</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>provided</scope>
</dependency>
@@ -65,7 +65,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-all</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>test</scope>
</dependency>
+2 -2
View File
@@ -3,7 +3,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</parent>
<modelVersion>4.0.0</modelVersion>
@@ -14,7 +14,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core-type</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>provided</scope>
</dependency>
+4 -4
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</parent>
<name>ebean postgis types</name>
@@ -19,14 +19,14 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-postgres</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<!-- provided scope -->
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>provided</scope>
</dependency>
@@ -62,7 +62,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-test</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>test</scope>
</dependency>
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</parent>
<name>ebean querybean</name>
@@ -17,7 +17,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>provided</scope>
</dependency>
@@ -63,14 +63,14 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-ddl-generator</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-test</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>test</scope>
</dependency>
@@ -84,7 +84,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>querybean-generator</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>provided</scope>
</dependency>
+6 -6
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</parent>
<artifactId>ebean-redis</artifactId>
@@ -22,28 +22,28 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-test</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>test</scope>
</dependency>
@@ -57,7 +57,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>querybean-generator</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>provided</scope>
</dependency>
+3 -3
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</parent>
<artifactId>ebean-spring-txn</artifactId>
@@ -28,7 +28,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>provided</scope>
</dependency>
@@ -77,7 +77,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-test</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>test</scope>
</dependency>
+6 -6
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</parent>
<name>ebean test</name>
@@ -33,20 +33,20 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-h2</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-ddl-generator</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
@@ -149,14 +149,14 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-jackson-mapper</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-all</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>test</scope>
</dependency>
@@ -1,6 +1,5 @@
package io.ebean.xtest.base;
import io.ebean.Transaction;
import io.ebean.xtest.BaseTestCase;
import io.ebean.DB;
import org.junit.jupiter.api.AfterEach;
@@ -19,17 +18,15 @@ import org.tests.model.basic.ResetBasicData;
*/
public abstract class TransactionalTestCase extends BaseTestCase {
private Transaction transaction;
@BeforeEach
public void startTransaction() {
ResetBasicData.reset();
transaction = DB.beginTransaction();
DB.beginTransaction();
}
@AfterEach
public void endTransaction() {
transaction.rollback();
transaction.end();
DB.rollbackTransaction();
DB.endTransaction();
}
}
@@ -578,6 +578,14 @@ public class TDSpiEbeanServer extends TDSpiServer implements SpiEbeanServer {
public void flush() {
}
@Override
public void commitTransaction() {
}
@Override
public void rollbackTransaction() {
}
@Override
public void endTransaction() {
}
@@ -222,6 +222,21 @@ public class TDSpiServer implements SpiServer {
}
@Override
public void commitTransaction() {
}
@Override
public void rollbackTransaction() {
}
@Override
public void endTransaction() {
}
@Override
public void refresh(Object bean) {
@@ -79,7 +79,9 @@ public class DefaultTransactionThreadLocalTest extends BaseTestCase {
@ForPlatform({Platform.H2})
@Test
public void end_withoutActiveTransaction_isFine() {
assertNull(DB.currentTransaction());
DB.endTransaction();
}
@ForPlatform({Platform.H2})
@@ -1,6 +1,5 @@
package org.tests.basic;
import io.ebean.Transaction;
import io.ebean.xtest.BaseTestCase;
import io.ebean.BeanState;
import io.ebean.DB;
@@ -37,11 +36,13 @@ public class TestDynamicUpdate extends BaseTestCase {
server.save(b2);
try (Transaction txn = server.beginTransaction()) {
server.beginTransaction();
try {
EMain b3 = server.find(EMain.class, b.getId());
assertEquals("ABC", b3.getEmbeddable().getDescription());
} finally {
server.endTransaction();
}
EMain b4 = server.find(EMain.class, b.getId());
b4.setName("bbb");
b4.getEmbeddable().setDescription("123");
@@ -1,6 +1,5 @@
package org.tests.basic;
import io.ebean.Transaction;
import io.ebean.xtest.BaseTestCase;
import io.ebean.DB;
import org.junit.jupiter.api.Test;
@@ -18,7 +17,8 @@ public class TestInheritRef extends BaseTestCase {
@Test
public void testAssocOne() {
try (Transaction txn = DB.beginTransaction()) {
DB.beginTransaction();
try {
DB.createUpdate(Vehicle.class, "delete from vehicle");
Car c = new Car();
@@ -52,6 +52,9 @@ public class TestInheritRef extends BaseTestCase {
assertEquals(1, found);
assertTrue(foundTruck.getCapacity() == 20D);
} finally {
DB.rollbackTransaction();
}
}
}
@@ -47,9 +47,10 @@ public class TestPersistenceContext extends BaseTestCase {
// implicit transaction with its own persistence context
Order oBefore = DB.find(Order.class, 1);
// start a persistence context
DB.beginTransaction();
Order order;
try (Transaction txn = DB.beginTransaction()) {
try {
order = DB.find(Order.class, 1);
// not the same instance ...as a different persistence context
assertNotSame(order, oBefore);
@@ -62,6 +63,9 @@ public class TestPersistenceContext extends BaseTestCase {
// all the same instance
assertSame(order, o2);
assertSame(order, o3);
} finally {
DB.endTransaction();
}
// implicit transaction with its own persistence context
@@ -70,7 +74,8 @@ public class TestPersistenceContext extends BaseTestCase {
assertNotSame(oAfter, order);
// start a persistence context
try (Transaction txn = DB.beginTransaction()) {
DB.beginTransaction();
try {
Order testOrder = ResetBasicData.createOrderCustAndOrder("testPC");
Integer id = testOrder.getCustomer().getId();
Integer orderId = testOrder.getId();
@@ -89,6 +94,9 @@ public class TestPersistenceContext extends BaseTestCase {
assertEquals(customer.getId(), customer2.getId());
assertSame(customer, customer2);
} finally {
DB.endTransaction();
}
}
@@ -1,6 +1,5 @@
package org.tests.cache;
import io.ebean.Transaction;
import io.ebean.xtest.BaseTestCase;
import io.ebean.DB;
import org.junit.jupiter.api.Test;
@@ -27,7 +26,8 @@ public class TestCacheInterceptSaveWhenLazyLoaded extends BaseTestCase {
order.setCustomer(customer);
DB.save(order);
try (Transaction txn = DB.beginTransaction()) {
DB.beginTransaction();
try {
Order foundOrder = DB.find(Order.class)
.where().eq("id", order.getId())
@@ -47,6 +47,9 @@ public class TestCacheInterceptSaveWhenLazyLoaded extends BaseTestCase {
assertSame(foundOrder, order1);
assertTrue(DB.beanState(foundOrder).isDirty());
} finally {
DB.endTransaction();
}
// cleanup
@@ -1,7 +1,6 @@
package org.tests.genkey;
import io.ebean.DB;
import io.ebean.Transaction;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.TOne;
@@ -20,10 +19,12 @@ public class TestGeneratedKeys {
c1.setName("Two");
c1.setDescription("Test Gen Key Two");
try (Transaction txn = DB.beginTransaction()) {
DB.beginTransaction();
try {
DB.save(c);
DB.save(c1);
txn.commit();
} finally {
DB.commitTransaction();
}
Integer id = c.getId();
assertNotNull(id);
@@ -1,6 +1,9 @@
package org.tests.insert;
import io.ebean.*;
import io.ebean.DB;
import io.ebean.Database;
import io.ebean.InsertOptions;
import io.ebean.Transaction;
import io.ebean.annotation.Platform;
import io.ebean.test.LoggedSql;
import io.ebean.xtest.BaseTestCase;
@@ -8,10 +11,6 @@ import io.ebean.xtest.ForPlatform;
import org.junit.jupiter.api.Test;
import org.tests.update.EPersonOnline;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import static io.ebean.InsertOptions.ON_CONFLICT_NOTHING;
@@ -289,119 +288,6 @@ class TestInsertOnConflict extends BaseTestCase {
assertThat(list.get(0).getWhenUpdated()).isEqualTo(bean.getWhenUpdated());
}
@ForPlatform({Platform.POSTGRES, Platform.YUGABYTE})
@Test
void updateQueryReturning() throws SQLException {
Database db = DB.getDefault();
db.truncate(EPersonOnline.class);
var bean1 = newBean("a1@bee.com");
var bean2 = newBean("a2@cee.com");
var bean3 = newBean("a3@bee.com");
db.saveAll(bean1, bean2, bean3);
String sql = "update e_person_online set email = concat('x',email) where email like ? returning id, email, online_status";
try (Transaction txn = db.createTransaction()) {
Connection connection = txn.connection();
try (PreparedStatement pstmt = connection.prepareStatement(sql)) {
pstmt.setString(1, "%bee.com");
try (ResultSet resultSet = pstmt.executeQuery()) {
while (resultSet.next()) {
long id = resultSet.getLong(1);
String email = resultSet.getString(2);
boolean status = resultSet.getBoolean(3);
// do something with the id, email and status
assertThat(id).isGreaterThan(0);
assertThat(email).startsWith("x");
assertThat(status).isTrue();
}
}
}
txn.commit();
}
try (Transaction txn = db.beginTransaction()) {
List<SqlRow> sqlRowList = DB.sqlQuery(sql)
.setParameter("%bee.com")
.findList();
assertThat(sqlRowList).hasSize(2);
assertThat(sqlRowList.get(0).getString("email")).startsWith("xx");
txn.addModification("e_person_online", false, true, false);
txn.commit();
}
try (Transaction txn = db.beginTransaction()) {
List<ReturnDto> dtoList = db.findDto(ReturnDto.class, sql)
.setParameter("%bee.com")
.findList();
assertThat(dtoList).hasSize(2);
assertThat(dtoList.get(0).email).startsWith("xxx");
txn.addModification("e_person_online", false, true, false);
txn.commit();
}
try (Transaction txn = db.beginTransaction()) {
List<ReturnDto2> dtoList2 = db.findDto(ReturnDto2.class, sql)
.setParameter("%bee.com")
.findList();
assertThat(dtoList2).hasSize(2);
assertThat(dtoList2.get(0).email).startsWith("xxxx");
assertThat(dtoList2.get(0).id).isGreaterThan(0);
txn.addModification("e_person_online", false, true, false);
txn.commit();
}
}
public static class ReturnDto {
private final long id;
private final String email;
private final boolean onlineStatus;
public ReturnDto(long id, String email, boolean onlineStatus) {
this.id = id;
this.email = email;
this.onlineStatus = onlineStatus;
}
}
public static class ReturnDto2 {
private long id;
private String email;
private boolean onlineStatus;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public boolean isOnlineStatus() {
return onlineStatus;
}
public void setOnlineStatus(boolean onlineStatus) {
this.onlineStatus = onlineStatus;
}
}
private static EPersonOnline newBean(String email) {
EPersonOnline bean = new EPersonOnline();
bean.setEmail(email);
@@ -35,9 +35,11 @@ public class TestPersistCascade extends BaseTestCase {
assertThat(sql.get(23)).contains("insert into pcf_city");
assertSqlBind(sql, 24, 26);
assertThat(sql.get(28)).contains("insert into pcf_event");
assertSqlBind(sql, 29, 128);
assertThat(sql.get(130)).contains("insert into pcf_event");
assertSqlBind(sql, 131, 150);
assertSqlBind(sql, 29, 48);
assertThat(sql.get(50)).contains("insert into pcf_event");
assertSqlBind(sql, 51, 70);
assertThat(sql.get(72)).contains("insert into pcf_event");
assertSqlBind(sql, 73, 87);
}
country.deletePermanent();
@@ -1,6 +1,5 @@
package org.tests.level.test;
import io.ebean.Transaction;
import io.ebean.xtest.BaseTestCase;
import io.ebean.DB;
import org.junit.jupiter.api.Test;
@@ -20,7 +19,8 @@ public class ManyToManyTest extends BaseTestCase {
@Test
public void test() {
try (Transaction txn = DB.beginTransaction()) {
DB.beginTransaction();
try {
Level4 i = new Level4("i");
Level4 ii = new Level4("ii");
Level4 iii = new Level4("iii");
@@ -92,6 +92,9 @@ public class ManyToManyTest extends BaseTestCase {
.findList();
validateObjectGraph(i, ii, iii, one, two, x1, x2, x3, x4, x5, things);
} finally {
DB.endTransaction();
}
}
@@ -54,6 +54,7 @@ public class TestDeleteUnloadedChildren extends BaseTestCase {
@Test
public void testCascadeDelete2() {
init();
try (Transaction txn = DB.beginTransaction()) {
@@ -67,14 +68,18 @@ public class TestDeleteUnloadedChildren extends BaseTestCase {
@Test
public void testCascadeDelete3() {
init();
try (Transaction txn = DB.beginTransaction()) {
DB.beginTransaction();
try {
EdExtendedParent extendedParent = DB.find(EdExtendedParent.class).where()
.eq("name", "My second computer").findOne();
extendedParent.getChildren().size();
DB.delete(extendedParent);
txn.commit();
DB.commitTransaction();
} finally {
DB.endTransaction();
}
}
@@ -49,7 +49,7 @@ public class TestInsertBatchThenFlushThenUpdate extends BaseTestCase {
// nothing flushed yet
assertThat(LoggedSql.start()).isEmpty();
txn.commit();
DB.commitTransaction();
// insert statements for EdExtendedParent
List<String> loggedSql2 = LoggedSql.start();
@@ -44,7 +44,7 @@ public class TestInsertBatchThenUpdate extends BaseTestCase {
parent.setName("MyDesk");
DB.save(parent);
txn.commit();
DB.commitTransaction();
// insert statements for EdExtendedParent
List<String> loggedSql = LoggedSql.stop();
@@ -87,7 +87,7 @@ public class TestInsertBatchThenUpdate extends BaseTestCase {
DB.save(parent);
// flush
txn.commit();
DB.commitTransaction();
// insert statements for EdExtendedParent
List<String> loggedSql = LoggedSql.stop();
@@ -58,7 +58,7 @@ public class TestInsertBatchWithDifferentRootTypes extends BaseTestCase {
// insert statements for EdParent
List<String> loggedSql1 = LoggedSql.start();
txn.commit();
DB.commitTransaction();
assertEquals(0, loggedSql1.size());
@@ -1,6 +1,5 @@
package org.tests.persistencecontext;
import io.ebean.Transaction;
import io.ebean.xtest.BaseTestCase;
import io.ebean.DB;
import io.ebean.Database;
@@ -13,9 +12,12 @@ public class TestPersistenceContextOnUpdateDuringTxn extends BaseTestCase {
@Test
public void test() {
Database server = DB.getDefault();
try (Transaction txn = server.beginTransaction()) {
server.beginTransaction();
try {
EBasic bean1 = new EBasic();
bean1.setName("hello");
@@ -31,7 +33,11 @@ public class TestPersistenceContextOnUpdateDuringTxn extends BaseTestCase {
EBasic loadedEntity = server.find(EBasic.class, bean1.getId());
assertThat(loadedEntity.getName()).isEqualTo("hello-changed");
} finally {
server.endTransaction();
}
}
}
@@ -1,6 +1,5 @@
package org.tests.persistencecontext;
import io.ebean.Transaction;
import io.ebean.xtest.BaseTestCase;
import io.ebean.DB;
import org.junit.jupiter.api.Test;
@@ -8,22 +7,25 @@ import org.tests.model.basic.EBasicVer;
import static io.ebean.PersistenceContextScope.QUERY;
import static io.ebean.PersistenceContextScope.TRANSACTION;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertSame;
class TestPersistenceContextQueryScope extends BaseTestCase {
public class TestPersistenceContextQueryScope extends BaseTestCase {
@Test
void test() {
public void test() {
EBasicVer bean = new EBasicVer("first");
DB.save(bean);
try (Transaction txn = DB.beginTransaction()) {
//DB.cacheManager().setCaching(EBasicVer.class, true);
DB.beginTransaction();
try {
EBasicVer bean1 = DB.find(EBasicVer.class, bean.getId());
// do an update of the name in the DB
// With #3295 this now automatically clears the persistence context for BasicVer.class
int rowCount = DB.sqlUpdate("update e_basicver set name=? where id=?")
.setParameter("second")
.setParameter(bean.getId())
@@ -31,21 +33,22 @@ class TestPersistenceContextQueryScope extends BaseTestCase {
assertEquals(1, rowCount);
// Prior to #3295 this returns the same bean via transaction scoped Persistence Context
// With #3295 this is now a fresh bean
// fetch the bean again... but doesn't hit DB as it
// is in the PersistenceContext which is transaction scoped
EBasicVer bean2 = DB.find(EBasicVer.class)
.setId(bean.getId())
.setUseCache(false) // ignore L2 cache
.findOne();
// QUERY scope hits the DB (doesn't use the existing transactions persistence context)
// ... also explicitly not use bean cache
EBasicVer bean3 = DB.find(EBasicVer.class)
.setId(bean.getId())
.setUseCache(false) // ignore L2 cache
.setPersistenceContextScope(QUERY)
.findOne();
// TRANSACTION scope ... same as bean2 and does not hit the DB
// TRANsACTION scope ... same as bean2 and does not hit the DB
EBasicVer bean5 = DB.find(EBasicVer.class)
.setId(bean.getId())
.setUseCache(false) // ignore L2 cache
@@ -54,180 +57,18 @@ class TestPersistenceContextQueryScope extends BaseTestCase {
assertEquals("first", bean.getName());
assertEquals("first", bean1.getName());
assertEquals("second", bean2.getName());
assertEquals("second", bean3.getName());
assertEquals("second", bean5.getName());
assertNotSame(bean1, bean2);
assertNotSame(bean1, bean5);
assertSame(bean2, bean5);
assertNotSame(bean3, bean5);
assertEquals("first", bean2.getName());
assertEquals("first", bean5.getName());
assertSame(bean1, bean2);
assertSame(bean1, bean5);
assertEquals("second", bean3.getName());
DB.delete(bean3);
txn.commit();
}
}
DB.commitTransaction();
@Test
void ormUpdateQuery_expect_clearsContext() {
EBasicVer bean = new EBasicVer("first");
DB.save(bean);
try (Transaction txn = DB.beginTransaction()) {
EBasicVer bean1 = DB.find(EBasicVer.class, bean.getId());
// do an update of the name in the DB
// With #3295 this now automatically clears the persistence context for BasicVer.class
int rowCount = DB.update(EBasicVer.class)
.set("name", "second")
.where().idEq(bean.getId())
.update();
assertEquals(1, rowCount);
// Prior to #3295 this returns the same bean via transaction scoped Persistence Context
// With #3295 this is now a fresh bean
EBasicVer bean2 = DB.find(EBasicVer.class)
.setId(bean.getId())
.setUseCache(false) // ignore L2 cache
.findOne();
// QUERY scope hits the DB (doesn't use the existing transactions persistence context)
EBasicVer bean3 = DB.find(EBasicVer.class)
.setId(bean.getId())
.setUseCache(false) // ignore L2 cache
.setPersistenceContextScope(QUERY)
.findOne();
// TRANSACTION scope ... same as bean2 and does not hit the DB
EBasicVer bean5 = DB.find(EBasicVer.class)
.setId(bean.getId())
.setUseCache(false) // ignore L2 cache
.setPersistenceContextScope(TRANSACTION)
.findOne();
assertEquals("first", bean.getName());
assertEquals("first", bean1.getName());
assertEquals("second", bean2.getName());
assertEquals("second", bean3.getName());
assertEquals("second", bean5.getName());
assertNotSame(bean1, bean2);
assertNotSame(bean1, bean5);
assertSame(bean2, bean5);
assertNotSame(bean3, bean5);
DB.delete(bean3);
txn.commit();
}
}
@Test
void ormUpdate_expect_clearsContext() {
EBasicVer bean = new EBasicVer("first");
DB.save(bean);
try (Transaction txn = DB.beginTransaction()) {
EBasicVer bean1 = DB.find(EBasicVer.class, bean.getId());
// do an update of the name in the DB
// With #3295 this now automatically clears the persistence context for BasicVer.class
int rowCount = DB.createUpdate(EBasicVer.class, "update ebasicver set name = ? where id = ?")
.setParameter(1, "second")
.setParameter(2, bean.getId())
.execute();
assertEquals(1, rowCount);
// fetch the bean again...
// Prior to #3295 this returns the same bean via transaction scoped Persistence Context
// With #3295 this is now a fresh bean
EBasicVer bean2 = DB.find(EBasicVer.class)
.setId(bean.getId())
.setUseCache(false) // ignore L2 cache
.findOne();
// QUERY scope hits the DB (doesn't use the existing transactions persistence context)
EBasicVer bean3 = DB.find(EBasicVer.class)
.setId(bean.getId())
.setUseCache(false) // ignore L2 cache
.setPersistenceContextScope(QUERY)
.findOne();
// TRANSACTION scope ... same as bean2 and does not hit the DB
EBasicVer bean5 = DB.find(EBasicVer.class)
.setId(bean.getId())
.setUseCache(false) // ignore L2 cache
.setPersistenceContextScope(TRANSACTION)
.findOne();
assertEquals("first", bean.getName());
assertEquals("first", bean1.getName());
assertEquals("second", bean2.getName());
assertEquals("second", bean3.getName());
assertEquals("second", bean5.getName());
assertNotSame(bean1, bean2);
assertNotSame(bean1, bean5);
assertSame(bean2, bean5);
assertNotSame(bean3, bean5);
DB.delete(bean3);
txn.commit();
}
}
@Test
void ormUpdateQueryWithAutoPersist_expect_clearsContext() {
EBasicVer bean = new EBasicVer("first");
DB.save(bean);
try (Transaction txn = DB.beginTransaction()) {
txn.setAutoPersistUpdates(true);
EBasicVer bean1 = DB.find(EBasicVer.class, bean.getId());
// do an update of the name in the DB
// With #3295 this now automatically clears the persistence context for BasicVer.class
int rowCount = DB.update(EBasicVer.class)
.set("name", "second")
.where().idEq(bean.getId())
.update();
assertEquals(1, rowCount);
// Prior to #3295 this returns the same bean via transaction scoped Persistence Context
// With #3295 this is now a fresh bean
EBasicVer bean2 = DB.find(EBasicVer.class)
.setId(bean.getId())
.setUseCache(false) // ignore L2 cache
.findOne();
// QUERY scope hits the DB (doesn't use the existing transactions persistence context)
EBasicVer bean3 = DB.find(EBasicVer.class)
.setId(bean.getId())
.setUseCache(false) // ignore L2 cache
.setPersistenceContextScope(QUERY)
.findOne();
// TRANSACTION scope ... same as bean2 and does not hit the DB
EBasicVer bean5 = DB.find(EBasicVer.class)
.setId(bean.getId())
.setUseCache(false) // ignore L2 cache
.setPersistenceContextScope(TRANSACTION)
.findOne();
assertEquals("first", bean.getName());
assertEquals("first", bean1.getName());
assertEquals("first", bean2.getName()); // This is still first
assertEquals("second", bean3.getName());
assertEquals("first", bean5.getName()); // This is still first
assertSame(bean1, bean2); // Now the same
assertSame(bean1, bean5); // Now the same
assertSame(bean2, bean5);
assertNotSame(bean3, bean5);
DB.delete(bean3);
txn.commit();
} finally {
DB.endTransaction();
}
}
}
@@ -1,6 +1,5 @@
package org.tests.query;
import io.ebean.Transaction;
import io.ebean.xtest.BaseTestCase;
import io.ebean.DB;
import io.ebean.Query;
@@ -51,18 +50,23 @@ public class TestConnectionCloseOnSqlerr extends BaseTestCase {
try {
for (int i = 0; i < 100; i++) {
try (Transaction txn = DB.beginTransaction()) {
DB.beginTransaction();
try {
Query<Customer> q0 = DB.find(Customer.class).where().icontains("namexxx", "Rob")
.query();
q0.findList();
txn.commit();
DB.commitTransaction();
} catch (Exception e) {
if (e.getMessage().contains("Unsuccessfully waited")) {
fail("No connections found while only one thread is running. (after " + i + " queries)");
} else {
e.printStackTrace();
}
} finally {
if (DB.currentTransaction().isActive()) {
DB.rollbackTransaction();
}
}
}
@@ -219,7 +219,8 @@ public class TestQueryFindPagedList extends BaseTestCase {
// kinda not normal but just wrap in a transaction to assert
// the background fetch does not occur (which explicitly creates
// its own transaction) ... so a bit naughty with the test here
try (Transaction txn = DB.beginTransaction()) {
DB.beginTransaction();
try {
List<Order> orders = pagedList.getList();
int totalRowCount = pagedList.getTotalCount();
@@ -237,9 +238,13 @@ public class TestQueryFindPagedList extends BaseTestCase {
String secTxn = loggedSql.get(1).substring(0, 10);
assertEquals(firstTxn, secTxn);
} finally {
DB.endTransaction();
}
}
@Test
public void test_usingAlias() {
@@ -84,10 +84,15 @@ public class TestCustomerFinder extends BaseTestCase {
@Test
public void currentTransaction() {
try (Transaction txn = DB.beginTransaction()) {
DB.beginTransaction();
try {
Transaction t1 = DB.currentTransaction();
Transaction t2 = Customer.find.currentTransaction();
assertThat(t2).isSameAs(t1);
} finally {
DB.endTransaction();
}
}
@@ -1,10 +1,9 @@
package org.tests.query.joins;
import io.ebean.xtest.BaseTestCase;
import io.ebean.DB;
import io.ebean.Expr;
import io.ebean.Query;
import io.ebean.Transaction;
import io.ebean.xtest.BaseTestCase;
import org.junit.jupiter.api.Test;
import org.tests.basic.one2one.Wheel;
import org.tests.model.basic.MRole;
@@ -19,7 +18,8 @@ public class TestDisjunctWhereOuterJoin extends BaseTestCase {
@Test
public void test() {
try (Transaction txn = DB.beginTransaction()) {
DB.beginTransaction();
try {
MRole r1 = new MRole();
r1.setRoleName("role1B");
@@ -63,6 +63,8 @@ public class TestDisjunctWhereOuterJoin extends BaseTestCase {
assertSqlOuterJoins(sql);
assertThat(sql).contains(".role_name = ?");
} finally {
DB.rollbackTransaction();
}
}
@@ -74,7 +76,7 @@ public class TestDisjunctWhereOuterJoin extends BaseTestCase {
.eq("roles.roleid", roleid)
.endOr().query();
query.findList();
query.findList();
String sql = sqlOf(query);
assertSqlOuterJoins(sql);
@@ -83,16 +85,19 @@ public class TestDisjunctWhereOuterJoin extends BaseTestCase {
@Test
public void testSelectOneToOneDisjunction() {
try (Transaction txn = DB.beginTransaction()) {
DB.beginTransaction();
try {
Query<Wheel> query = DB.find(Wheel.class)
.select("id")
.where().or()
.ge("tire.id", 100)
.lt("tire.id", 100)
.endOr().query();
.select("id")
.where().or()
.ge("tire.id", 100)
.lt("tire.id", 100)
.endOr().query();
query.findList();
String sql = sqlOf(query);
assertThat(sql).contains("join");
} finally {
DB.rollbackTransaction();
}
}
@@ -1,6 +1,5 @@
package org.tests.query.other;
import io.ebean.Transaction;
import io.ebean.xtest.BaseTestCase;
import io.ebean.DB;
import io.ebeaninternal.api.SpiEbeanServer;
@@ -45,7 +44,8 @@ public class TestManyLazyLoadingQuery extends BaseTestCase {
// start transaction to keep PC going to lazy query
try (Transaction txn = DB.beginTransaction()) {
DB.beginTransaction();
try {
DB.find(Order.class, 1);
SpiQuery<?> query0 = (SpiQuery<?>) DB.find(OrderDetail.class);
@@ -57,6 +57,9 @@ public class TestManyLazyLoadingQuery extends BaseTestCase {
query0.findList();
assertThat(query0.getGeneratedSql()).contains(" from o_order_detail t0 where (t0.order_id) ");
platformAssertIn(query0.getGeneratedSql(), "where (t0.order_id)");
} finally {
DB.endTransaction();
}
List<OrderDetail> details = DB.find(OrderDetail.class)
@@ -62,7 +62,8 @@ public class TestBatchPersistCascade extends BaseTestCase {
List<UTMaster> list = server.find(UTMaster.class).fetch("details").findList();
try (Transaction txn = DB.beginTransaction()) {
Transaction txn = server.beginTransaction();
try {
txn.setBatchMode(true);
txn.setBatchOnCascade(true);
@@ -102,8 +103,11 @@ public class TestBatchPersistCascade extends BaseTestCase {
logger.info("commit ------------ ");
txn.commit();
server.commitTransaction();
} finally {
server.endTransaction();
}
}
private UTDetail createUTDetail(String master, int count) {
@@ -1,6 +1,5 @@
package org.tests.transaction;
import io.ebean.Transaction;
import io.ebean.xtest.BaseTestCase;
import io.ebean.DB;
import io.ebeaninternal.api.SpiTransaction;
@@ -20,8 +19,9 @@ public class TestDeleteFromPersistenceContext extends BaseTestCase {
EBasicVer bean = new EBasicVer("Please Delete Me");
DB.save(bean);
try (Transaction txn = DB.beginTransaction()) {
SpiTransaction spiTransaction = (SpiTransaction)txn;
SpiTransaction transaction = (SpiTransaction) DB.beginTransaction();
try {
EBasicVer bean2 = DB.find(EBasicVer.class, bean.getId());
assertNotSame(bean, bean2);
@@ -29,15 +29,18 @@ public class TestDeleteFromPersistenceContext extends BaseTestCase {
// same instance from PersistenceContext
assertSame(bean2, bean3);
Object bean4 = spiTransaction.persistenceContext().get(EBasicVer.class, bean.getId());
Object bean4 = transaction.persistenceContext().get(EBasicVer.class, bean.getId());
assertSame(bean2, bean4);
DB.delete(bean2);
Object bean5 = spiTransaction.persistenceContext().get(EBasicVer.class, bean.getId());
Object bean5 = transaction.persistenceContext().get(EBasicVer.class, bean.getId());
assertNull(bean5);
txn.commit();
DB.commitTransaction();
} finally {
DB.endTransaction();
}
EBasicVer bean6 = DB.find(EBasicVer.class).where().eq("id", bean.getId()).findOne();
@@ -1,14 +1,11 @@
package org.tests.transaction;
import io.ebean.DB;
import io.ebean.DataIntegrityException;
import io.ebean.Transaction;
import io.ebean.TxScope;
import io.ebean.*;
import io.ebean.xtest.BaseTestCase;
import io.ebean.xtest.ForPlatform;
import io.ebean.annotation.PersistBatch;
import io.ebean.annotation.Platform;
import io.ebean.annotation.Transactional;
import io.ebean.xtest.BaseTestCase;
import io.ebean.xtest.ForPlatform;
import io.ebeaninternal.api.SpiTransaction;
import org.junit.jupiter.api.Test;
import org.tests.model.basic.Customer;
@@ -46,7 +43,7 @@ public class TestExecuteComplete extends BaseTestCase {
try {
DB.execute(TxScope.required().setBatch(PersistBatch.ALL), () ->
DB.execute(() -> {
DB.execute(() -> {
Customer customer = DB.reference(Customer.class, 42424242L);
Order order = new Order();
@@ -161,26 +158,4 @@ public class TestExecuteComplete extends BaseTestCase {
assertThat(getInScopeTransaction()).isNull();
}
@ForPlatform(Platform.H2)
@Test
public void test_nested_userobjects() {
try (Transaction txn1 = DB.beginTransaction()) {
assertThat(getInScopeTransaction()).isNotNull();
getInScopeTransaction().putUserObject("foo", "bar");
try (Transaction txn2 = DB.beginTransaction()) {
assertThat(getInScopeTransaction().getUserObject("foo")).isEqualTo("bar");
getInScopeTransaction().putUserObject("foo", "xxx");
getInScopeTransaction().putUserObject("test", "xxx");
assertThat(getInScopeTransaction().getUserObject("foo")).isEqualTo("xxx");
txn2.commit();
}
// CHECKME: What would we expect here? I would expect "bar" but get "xxx"
// NOTE: with TxScope.requiresNew() - I'll get "bar"
assertThat(getInScopeTransaction().getUserObject("test")).isNull();
assertThat(getInScopeTransaction().getUserObject("foo")).isEqualTo("bar");
}
}
}
@@ -37,7 +37,8 @@ public class TestNestedSubTransaction extends BaseTestCase {
try (Transaction txn1 = server.beginTransaction()) {
bean.setName("x2");
server.save(bean);
txn1.commit();
//txn1.commit();
server.commitTransaction();
}
EBasic fresh = server.find(EBasic.class, bean.getId());
@@ -47,7 +48,8 @@ public class TestNestedSubTransaction extends BaseTestCase {
try (Transaction txn2 = server.beginTransaction()) {
bean.setName("barney");
DB.save(bean);
txn2.commit();
//txn2.commit();
server.commitTransaction();
}
fresh = server.find(EBasic.class)
@@ -1,6 +1,5 @@
package org.tests.transaction;
import io.ebean.Transaction;
import io.ebean.xtest.BaseTestCase;
import io.ebean.DB;
import org.junit.jupiter.api.Test;
@@ -13,7 +12,10 @@ public class TestStatelessUpdateClearPC extends BaseTestCase {
@Test
public void test() {
try (Transaction txn = DB.beginTransaction()) {
DB.beginTransaction();
try {
EBasic newUser = new EBasic();
newUser.setName("any@email.com");
DB.save(newUser);
@@ -30,6 +32,8 @@ public class TestStatelessUpdateClearPC extends BaseTestCase {
EBasic loadedUser = DB.find(EBasic.class, newUser.getId());
assertEquals("anyNew@email.com", loadedUser.getName());
} finally {
DB.rollbackTransaction();
}
}
}
@@ -31,8 +31,11 @@ public class TestTransactionCallback extends BaseTestCase {
assertEquals(0, countPreRollback);
assertEquals(0, countPostRollback);
try (Transaction txn = DB.beginTransaction()) {
DB.beginTransaction();
try {
DB.register(new MyCallback());
} finally {
DB.rollbackTransaction();
}
assertEquals(1, countPreCommit);
@@ -32,7 +32,8 @@ public class TestTransactionalNotSupports extends BaseTestCase {
public void withOuterTransaction_expect_currentTransaction_null_and_originalTxnRestored() {
outerTxn = null;
try (Transaction txn = DB.beginTransaction()) {
DB.beginTransaction();
try {
currentTxn = DB.currentTransaction();
assertNotNull(currentTxn);
new SomeTransactionalWithNotSupported().doStuff();
@@ -43,6 +44,8 @@ public class TestTransactionalNotSupports extends BaseTestCase {
// the original transaction was restored
Transaction restored = DB.currentTransaction();
assertSame(currentTxn, restored);
} finally {
DB.endTransaction();
}
}
@@ -40,7 +40,8 @@ public class TestTransactionalRequired extends BaseTestCase {
public void withOuterBegin() {
outerTxn = null;
try (Transaction txn = DB.beginTransaction()) {
DB.beginTransaction();
try {
currentTxn = DB.currentTransaction();
assertNotNull(currentTxn);
new OuterTransactionalWithRequired().doOuter();
@@ -50,6 +51,8 @@ public class TestTransactionalRequired extends BaseTestCase {
assertSame(currentTxn, restored);
assertSame(currentTxn, innerTxn);
assertSame(currentTxn, outerTxn);
} finally {
DB.endTransaction();
}
assertNull(DB.currentTransaction());
@@ -68,8 +68,11 @@ public class TestTransactionalRequiresNew extends BaseTestCase {
Database server = server();
try(Transaction txn = server.beginTransaction()) {
String txnName = txn.toString();
try (Transaction txn2 = DB.beginTransaction(TxScope.requiresNew())) {
txn2.commit();
DB.beginTransaction(TxScope.requiresNew());
try {
DB.commitTransaction();
} finally {
DB.endTransaction();
}
assertThat(txn.toString()).isEqualTo(txnName);
}
@@ -80,8 +83,11 @@ public class TestTransactionalRequiresNew extends BaseTestCase {
Database server = server();
try (Transaction txn = server.beginTransaction()) {
String txnName = txn.toString();
try (Transaction txn2 = server.beginTransaction(TxScope.requiresNew())) {
txn2.commit();
server.beginTransaction(TxScope.requiresNew());
try {
server.commitTransaction();
} finally {
server.endTransaction();
}
assertThat(txn.toString()).isEqualTo(txnName);
}
@@ -92,8 +98,11 @@ public class TestTransactionalRequiresNew extends BaseTestCase {
Database server = server();
try (Transaction txn = server.beginTransaction()) {
String txnName = txn.toString();
try (Transaction txn2 = DB.beginTransaction(TxScope.requiresNew())) {
Transaction txn2 = DB.beginTransaction(TxScope.requiresNew());
try {
txn2.commit();
} finally {
txn2.end();
}
assertThat(txn.toString()).isEqualTo(txnName);
}
@@ -33,9 +33,12 @@ public class TestTransactionalSupports extends BaseTestCase {
public void withOuterTransaction_expect_currentTransactionAvailable() {
outerTxn = null;
try (Transaction txn = DB.beginTransaction()) {
DB.beginTransaction();
try {
new SomeTransactionalWithSupports().doStuff();
assertNotNull(outerTxn);
} finally {
DB.endTransaction();
}
}
@@ -177,7 +177,9 @@ public class TestSqlUpdateInTxn extends BaseTestCase {
assertEquals("foo3", log4.getDescription());
assertEquals("mod1", log4.getModifiedDescription());
try (Transaction txn = DB.beginTransaction()) {
DB.beginTransaction();
try {
SqlUpdate update = DB.sqlUpdate(updateDml);
update.setParameter("desc", "foo4");
update.setParameter("id", id);
@@ -187,7 +189,9 @@ public class TestSqlUpdateInTxn extends BaseTestCase {
updateMod.setParameter("desc", "mod2");
updateMod.execute();
txn.commit();
DB.commitTransaction();
} finally {
DB.endTransaction();
}
AuditLog log5 = DB.find(AuditLog.class, log.getId());
assertEquals("foo4", log5.getDescription());
+12 -12
View File
@@ -71,18 +71,18 @@ datasource.db.password=
datasource.db.databaseUrl=jdbc:h2:file:~/tests
datasource.db.databaseDriver=org.h2.Driver
datasource.db.username=sa
datasource.db.password=
datasource.db.url=jdbc:h2:mem:testsMem;DB_CLOSE_ON_EXIT=FALSE;NON_KEYWORDS=KEY,VALUE
datasource.db.poolListener=org.tests.basic.MyTestDataSourcePoolListener
#datasource.db.minConnections=1
#datasource.db.maxConnections=25
#datasource.db.capturestacktrace=true
#datasource.db.maxStackTraceSize=20
#datasource.db.driver=org.h2.Driver
#datasource.db.heartbeatsql=select 1
#datasource.db.isolationlevel=read_committed
#datasource.db.customProperties=IGNORECASE=TRUE;MODE=Oracle;
datasource.h2.username=sa
datasource.h2.password=
datasource.h2.url=jdbc:h2:mem:testsMem;DB_CLOSE_ON_EXIT=FALSE;NON_KEYWORDS=KEY,VALUE
datasource.h2.poolListener=org.tests.basic.MyTestDataSourcePoolListener
#datasource.h2.minConnections=1
#datasource.h2.maxConnections=25
#datasource.h2.capturestacktrace=true
#datasource.h2.maxStackTraceSize=20
#datasource.h2.driver=org.h2.Driver
#datasource.h2.heartbeatsql=select 1
#datasource.h2.isolationlevel=read_committed
#datasource.h2.customProperties=IGNORECASE=TRUE;MODE=Oracle;
datasource.h2multitenant.username=sa
+5 -5
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</parent>
<name>kotlin querybean generator</name>
@@ -21,7 +21,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-querybean</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>test</scope>
</dependency>
@@ -35,7 +35,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-core</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>test</scope>
</dependency>
@@ -56,14 +56,14 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-h2</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-ddl-generator</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<scope>test</scope>
</dependency>
+14 -14
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<relativePath>../..</relativePath>
</parent>
@@ -15,67 +15,67 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-h2</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-clickhouse</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-db2</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-hana</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-hsqldb</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-mysql</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-mariadb</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-nuodb</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-oracle</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-postgres</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-sqlanywhere</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-sqlite</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-sqlserver</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
</dependencies>
+2 -2
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<relativePath>../..</relativePath>
</parent>
@@ -15,7 +15,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
</dependencies>
+2 -2
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<relativePath>../..</relativePath>
</parent>
@@ -15,7 +15,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
</dependencies>
+2 -2
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<relativePath>../..</relativePath>
</parent>
@@ -15,7 +15,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
<!-- Provided scope so that the H2HistoryTrigger can live in Ebean core
+2 -2
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<relativePath>../..</relativePath>
</parent>
@@ -15,7 +15,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-api</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
</dependencies>
+2 -2
View File
@@ -4,7 +4,7 @@
<parent>
<artifactId>ebean-parent</artifactId>
<groupId>io.ebean</groupId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
<relativePath>../..</relativePath>
</parent>
@@ -15,7 +15,7 @@
<dependency>
<groupId>io.ebean</groupId>
<artifactId>ebean-platform-h2</artifactId>
<version>14.0.0</version>
<version>13.26.1-jakarta</version>
</dependency>
</dependencies>

Some files were not shown because too many files have changed in this diff Show More