Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ebean-api/src/main/java/io/ebean/DB.java
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,8 @@ public static Set<Property> checkUniqueness(Object bean) {
/**
* Same as {@link #checkUniqueness(Object)} but with given transaction.
*/
public static Set<Property> checkUniqueness(Object bean, Transaction transaction) {
return getDefault().checkUniqueness(bean, transaction);
public static Set<Property> checkUniqueness(Object bean, Transaction transaction, boolean useQueryCache, boolean skipClean) {
return getDefault().checkUniqueness(bean, transaction, useQueryCache, skipClean);
}

/**
Expand Down
17 changes: 15 additions & 2 deletions ebean-api/src/main/java/io/ebean/Database.java
Original file line number Diff line number Diff line change
Expand Up @@ -1073,12 +1073,21 @@ static DatabaseBuilder builder() {
* @param bean The entity bean to check uniqueness on
* @return a set of Properties if constraint validation was detected or empty list.
*/
Set<Property> checkUniqueness(Object bean);
default Set<Property> checkUniqueness(Object bean) {
return checkUniqueness(bean, null, false, true);
}

/**
* Same as {@link #checkUniqueness(Object)}. but with given transaction.
*/
Set<Property> checkUniqueness(Object bean, Transaction transaction);
default Set<Property> checkUniqueness(Object bean, Transaction transaction) {
return checkUniqueness(bean, transaction, false, true);
}

/**
* Same as {@link #checkUniqueness(Object)}. but with given transaction and extended search options.
*/
Set<Property> checkUniqueness(Object bean, Transaction transaction, boolean useQueryCache, boolean skipClean);

/**
* Marks the entity bean as dirty.
Expand Down Expand Up @@ -1508,4 +1517,8 @@ static DatabaseBuilder builder() {
*/
void truncate(Class<?>... beanTypes);

/**
* RunDdl manually. This can be used if 'db.ddl.run=false' is set and you plan to run DDL manually.
*/
void runDdl();
}
32 changes: 32 additions & 0 deletions ebean-api/src/main/java/io/ebean/DatabaseBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import io.ebean.event.changelog.ChangeLogRegister;
import io.ebean.event.readaudit.ReadAuditLogger;
import io.ebean.event.readaudit.ReadAuditPrepare;
import io.ebean.plugin.CustomDeployParser;
import jakarta.persistence.EnumType;

import javax.sql.DataSource;
Expand Down Expand Up @@ -896,6 +897,12 @@ default DatabaseBuilder backgroundExecutorWrapper(BackgroundExecutorWrapper back
@Deprecated
DatabaseBuilder setBackgroundExecutorWrapper(BackgroundExecutorWrapper backgroundExecutorWrapper);

/**
* Sets the tenant partitioning mode for caches. This means, caches are created on demand,
* but they may not get invalidated across tenant boundaries *
*/
void setTenantPartitionedCache(boolean tenantPartitionedCache);

/**
* Set the L2 cache default max size.
*/
Expand Down Expand Up @@ -1827,6 +1834,11 @@ default DatabaseBuilder resourceDirectory(String resourceDirectory) {
*/
DatabaseBuilder addServerConfigStartup(ServerConfigStartup configStartupListener);

/**
* Add a CustomDeployParser.
*/
DatabaseConfig addCustomDeployParser(CustomDeployParser customDeployParser);

/**
* Register all the BeanPersistListener instances.
* <p>
Expand Down Expand Up @@ -2084,6 +2096,11 @@ default DatabaseBuilder queryPlanEnable(boolean queryPlanEnable) {
@Deprecated
DatabaseBuilder setQueryPlanEnable(boolean queryPlanEnable);

/**
* Set platform specific query plan options.
*/
DatabaseBuilder queryPlanOptions(String queryPlanOptions);

/**
* Set the query plan collection threshold in microseconds.
* <p>
Expand Down Expand Up @@ -2568,6 +2585,11 @@ interface Settings extends DatabaseBuilder {
*/
boolean isAutoPersistUpdates();

/**
* Returns, if the caches are partitioned by tenant.
*/
boolean isTenantPartitionedCache();

/**
* Return the L2 cache default max size.
*/
Expand Down Expand Up @@ -2980,6 +3002,11 @@ interface Settings extends DatabaseBuilder {
*/
List<ServerConfigStartup> getServerConfigStartupListeners();

/**
* Returns the registered CustomDeployParsers.
*/
List<CustomDeployParser> getCustomDeployParsers();

/**
* Return the default PersistenceContextScope to be used if one is not explicitly set on a query.
* <p/>
Expand Down Expand Up @@ -3071,6 +3098,11 @@ interface Settings extends DatabaseBuilder {
*/
boolean isQueryPlanEnable();

/**
* Returns platform specific query plan options.
*/
String getQueryPlanOptions();

/**
* Return the query plan collection threshold in microseconds.
*/
Expand Down
6 changes: 6 additions & 0 deletions ebean-api/src/main/java/io/ebean/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@ static Transaction current() {
*/
void setUpdateAllLoadedProperties(boolean updateAllLoadedProperties);

/**
* If set to false (default is true) generated propertes are only set, if it is the version property or have a null value.
* This may be useful in backup & restore scenarios, if you want set WhenCreated/WhenModified.
*/
void setOverwriteGeneratedProperties(boolean overwriteGeneratedProperties);

/**
* Set if the L2 cache should be skipped for "find by id" and "find by natural key" queries.
* <p>
Expand Down
7 changes: 7 additions & 0 deletions ebean-api/src/main/java/io/ebean/bean/BeanCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,13 @@ enum ModifyListenMode {
*/
Collection<?> actualEntries();

/**
* Returns entries, that were lazily added at the end of the list. Might be null.
*/
default Collection<E> getLazyAddedEntries(boolean reset) {
return null;
}

/**
* return true if there are real rows held. Return false is this is using
* Deferred fetch to lazy load the rows and the rows have not yet been
Expand Down
26 changes: 13 additions & 13 deletions ebean-api/src/main/java/io/ebean/common/BeanList.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@
/**
* List capable of lazy loading and modification awareness.
*/
public final class BeanList<E> extends AbstractBeanCollection<E> implements List<E>, BeanCollectionAdd {
public class BeanList<E> extends AbstractBeanCollection<E> implements List<E>, BeanCollectionAdd {

private static final long serialVersionUID = 1L;

/**
* The underlying List implementation.
*/
private List<E> list;
List<E> list;

/**
* Specify the underlying List implementation.
Expand Down Expand Up @@ -111,30 +111,30 @@ public boolean checkEmptyLazyLoad() {
}
}

protected void initList(boolean skipLoad, boolean onlyIds) {
if (skipLoad) {
list = new ArrayList<>();
} else {
lazyLoadCollection(onlyIds);
}
}

private void initClear() {
lock.lock();
try {
if (list == null) {
if (!disableLazyLoad && modifyListening) {
lazyLoadCollection(true);
} else {
list = new ArrayList<>();
}
initList(disableLazyLoad || !modifyListening, true);
}
} finally {
lock.unlock();
}
}

private void init() {
void init() {
lock.lock();
try {
if (list == null) {
if (disableLazyLoad) {
list = new ArrayList<>();
} else {
lazyLoadCollection(false);
}
initList(disableLazyLoad, false);
}
} finally {
lock.unlock();
Expand Down
133 changes: 133 additions & 0 deletions ebean-api/src/main/java/io/ebean/common/BeanListLazyAdd.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package io.ebean.common;

import io.ebean.bean.BeanCollection;
import io.ebean.bean.BeanCollectionLoader;
import io.ebean.bean.EntityBean;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
* This bean list can perform additions without populating the list.
* This might be useful, if you just want to add entries to an existing collection.
* Works only for lists and only if there is no order column
*/
public class BeanListLazyAdd<E> extends BeanList<E> {

public BeanListLazyAdd(BeanCollectionLoader loader, EntityBean ownerBean, String propertyName) {
super(loader, ownerBean, propertyName);
}

private List<E> lazyAddedEntries;

@Override
public boolean add(E bean) {
checkReadOnly();

lock.lock();
try {
if (list == null) {
// list is not yet initialized, so we may add elements to a spare list
if (lazyAddedEntries == null) {
lazyAddedEntries = new ArrayList<>();
}
lazyAddedEntries.add(bean);
} else {
list.add(bean);
}
} finally {
lock.unlock();
}

if (modifyListening) {
modifyAddition(bean);
}
return true;
}

@Override
public boolean addAll(Collection<? extends E> beans) {
checkReadOnly();

lock.lock();
try {
if (list == null) {
// list is not yet initialized, so we may add elements to a spare list
if (lazyAddedEntries == null) {
lazyAddedEntries = new ArrayList<>();
}
lazyAddedEntries.addAll(beans);
} else {
list.addAll(beans);
}
} finally {
lock.unlock();
}

if (modifyListening) {
getModifyHolder().modifyAdditionAll(beans);
}

return true;
}


@Override
public void loadFrom(BeanCollection<?> other) {
super.loadFrom(other);
if (lazyAddedEntries != null) {
list.addAll(lazyAddedEntries);
lazyAddedEntries = null;
}
}

/**
* on init, this happens on all accessor methods except on 'add' and addAll,
* we add the lazy added entries at the end of the list
*/
@Override
protected void initList(boolean skipLoad, boolean onlyIds) {
if (skipLoad) {
if (lazyAddedEntries != null) {
list = lazyAddedEntries;
lazyAddedEntries = null;
} else {
list = new ArrayList<>();
}
} else {
lazyLoadCollection(onlyIds);
if (lazyAddedEntries != null) {
list.addAll(lazyAddedEntries);
lazyAddedEntries = null;
}
}
}

@Override
public List<E> getLazyAddedEntries(boolean reset) {
List<E> ret = lazyAddedEntries;
if (reset) {
lazyAddedEntries = null;
}
return ret;
}

@Override
public boolean isSkipSave() {
return lazyAddedEntries == null && super.isSkipSave();
}

public boolean checkEmptyLazyLoad() {
if (list != null) {
return false;
} else if (lazyAddedEntries == null) {
list = new ArrayList<>();
return true;
} else {
list = lazyAddedEntries;
lazyAddedEntries = null;
return false;
}
}
}
Loading