mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Compare commits
29
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
03669dc307 | ||
|
|
2a8fad7364 | ||
|
|
e62db11f01 | ||
|
|
8c8f2b95da | ||
|
|
576eb01187 | ||
|
|
8b18b2a20e | ||
|
|
f5c12a916d | ||
|
|
2f8a99c304 | ||
|
|
cd9a43c3ab | ||
|
|
f251ca5431 | ||
|
|
2c44c80f65 | ||
|
|
d9efeac0a1 | ||
|
|
f4a7d0b6ad | ||
|
|
bc5db1e46a | ||
|
|
8743148238 | ||
|
|
68db6723d0 | ||
|
|
9b1fa43792 | ||
|
|
5f2454831e | ||
|
|
140178bb47 | ||
|
|
f95b4b5c4b | ||
|
|
d3b3a79342 | ||
|
|
52398317bc | ||
|
|
7f2e4f54ff | ||
|
|
9f19ed5376 | ||
|
|
d49a7c415f | ||
|
|
8ffc9ede85 | ||
|
|
eba521563a | ||
|
|
ed71e106df | ||
|
|
050ae49f6b |
@@ -9,7 +9,7 @@
|
||||
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean</artifactId>
|
||||
<version>11.40.1</version>
|
||||
<version>11.41.1</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>ebean</name>
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
<scm>
|
||||
<developerConnection>scm:git:git@github.com:ebean-orm/ebean.git</developerConnection>
|
||||
<tag>ebean-11.40.1</tag>
|
||||
<tag>ebean-11.41.1</tag>
|
||||
</scm>
|
||||
|
||||
<profiles>
|
||||
@@ -117,7 +117,7 @@
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-annotation</artifactId>
|
||||
<version>4.10</version>
|
||||
<version>4.11</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -250,7 +250,7 @@
|
||||
<dependency>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-agent</artifactId>
|
||||
<version>11.40.1</version>
|
||||
<version>11.41.1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
@@ -330,7 +330,7 @@
|
||||
<plugin>
|
||||
<groupId>io.ebean</groupId>
|
||||
<artifactId>ebean-maven-plugin</artifactId>
|
||||
<version>11.40.1</version>
|
||||
<version>11.41.1</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>test</id>
|
||||
|
||||
@@ -80,7 +80,6 @@ public final class OrderBy<T> implements Serializable {
|
||||
* Add a property with ascending order to this OrderBy.
|
||||
*/
|
||||
public Query<T> asc(String propertyName, String collation) {
|
||||
|
||||
list.add(new Property(propertyName, true, collation));
|
||||
return query;
|
||||
}
|
||||
@@ -89,7 +88,6 @@ public final class OrderBy<T> implements Serializable {
|
||||
* Add a property with descending order to this OrderBy.
|
||||
*/
|
||||
public Query<T> desc(String propertyName) {
|
||||
|
||||
list.add(new Property(propertyName, false));
|
||||
return query;
|
||||
}
|
||||
@@ -98,7 +96,6 @@ public final class OrderBy<T> implements Serializable {
|
||||
* Add a property with descending order to this OrderBy.
|
||||
*/
|
||||
public Query<T> desc(String propertyName, String collation) {
|
||||
|
||||
list.add(new Property(propertyName, false, collation));
|
||||
return query;
|
||||
}
|
||||
@@ -108,7 +105,6 @@ public final class OrderBy<T> implements Serializable {
|
||||
* Return true if the property is known to be contained in the order by clause.
|
||||
*/
|
||||
public boolean containsProperty(String propertyName) {
|
||||
|
||||
for (Property aList : list) {
|
||||
if (propertyName.equals(aList.getProperty())) {
|
||||
return true;
|
||||
@@ -161,10 +157,9 @@ public final class OrderBy<T> implements Serializable {
|
||||
* Return a copy of the OrderBy.
|
||||
*/
|
||||
public OrderBy<T> copy() {
|
||||
|
||||
OrderBy<T> copy = new OrderBy<>();
|
||||
for (Property aList : list) {
|
||||
copy.add(aList.copy());
|
||||
for (Property property : list) {
|
||||
copy.add(property.copy());
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
@@ -241,6 +236,18 @@ public final class OrderBy<T> implements Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this order by can be used in select clause.
|
||||
*/
|
||||
public boolean supportsSelect() {
|
||||
for (Property property : list) {
|
||||
if (!property.supportsSelect()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* A property and its ascending descending order.
|
||||
*/
|
||||
@@ -401,6 +408,12 @@ public final class OrderBy<T> implements Serializable {
|
||||
this.ascending = ascending;
|
||||
}
|
||||
|
||||
/**
|
||||
* Support use in select clause if no collation or nulls ordering.
|
||||
*/
|
||||
boolean supportsSelect() {
|
||||
return nulls == null && collation == null;
|
||||
}
|
||||
}
|
||||
|
||||
private void parse(String orderByClause) {
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package io.ebean.plugin;
|
||||
|
||||
import io.ebean.bean.EntityBean;
|
||||
|
||||
/**
|
||||
* Property of a entity bean that is a ToMany property.
|
||||
*/
|
||||
public interface PropertyAssocMany extends Property {
|
||||
|
||||
/**
|
||||
* Add the loaded current bean to its associated parent.
|
||||
* <p>
|
||||
* Helper method used by Ebean Elastic integration when loading with a persistence context.
|
||||
*/
|
||||
void lazyLoadMany(EntityBean current);
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import java.lang.reflect.AnnotatedElement;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentMap;
|
||||
@@ -107,9 +108,7 @@ public class AnnotationUtil {
|
||||
* Finds all annotations recusively for a class and its superclasses or interfaces.
|
||||
*/
|
||||
public static <A extends Annotation> Set<A> findAnnotationsRecursive(Class<?> clazz, Class<A> annotationType) {
|
||||
if (annotationType == null) {
|
||||
return null;
|
||||
}
|
||||
Objects.requireNonNull(annotationType);
|
||||
Set<A> ret = new LinkedHashSet<>();
|
||||
Set<Annotation> visited = new HashSet<>();
|
||||
Set<Class<?>> visitedInterfaces = new HashSet<>();
|
||||
|
||||
+1
-2
@@ -49,8 +49,7 @@ class ModelBuildIntersectionTable {
|
||||
|
||||
private void buildFkConstraints() {
|
||||
|
||||
PropertyForeignKey foreignKey = manyProp.getForeignKey();
|
||||
if (foreignKey == null || !foreignKey.isNoConstraint()) {
|
||||
if (manyProp.hasForeignKeyConstraint()) {
|
||||
ctx.fkeyBuilder(intersectionTable)
|
||||
.addForeignKey(manyProp.getBeanDescriptor(), intersectionTableJoin, true)
|
||||
.addForeignKey(manyProp.getTargetDescriptor(), tableJoin, false);
|
||||
|
||||
+11
-6
@@ -170,8 +170,6 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor {
|
||||
|
||||
List<MColumn> modelColumns = new ArrayList<>(columns.length);
|
||||
|
||||
PropertyForeignKey foreignKey = p.getForeignKey();
|
||||
|
||||
MCompoundForeignKey compoundKey = null;
|
||||
if (columns.length > 1) {
|
||||
// compound foreign key
|
||||
@@ -196,7 +194,7 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor {
|
||||
col.setDbMigrationInfos(p.getDbMigrationInfos());
|
||||
col.setDefaultValue(p.getDbColumnDefault());
|
||||
if (columns.length == 1) {
|
||||
if (p.hasForeignKey() && !importedProperty.getBeanDescriptor().suppressForeignKey()) {
|
||||
if (p.hasForeignKeyConstraint() && !importedProperty.getBeanDescriptor().suppressForeignKey()) {
|
||||
// single references column (put it on the column)
|
||||
String refTable = importedProperty.getBeanDescriptor().getBaseTable();
|
||||
if (refTable == null) {
|
||||
@@ -208,6 +206,7 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor {
|
||||
if (p.hasForeignKeyIndex()) {
|
||||
col.setForeignKeyIndex(determineForeignKeyIndexName(col.getName()));
|
||||
}
|
||||
PropertyForeignKey foreignKey = p.getForeignKey();
|
||||
if (foreignKey != null) {
|
||||
col.setForeignKeyModes(foreignKey.getOnDelete(), foreignKey.getOnUpdate());
|
||||
}
|
||||
@@ -256,9 +255,15 @@ public class ModelBuildPropertyVisitor extends BaseTablePropertyVisitor {
|
||||
}
|
||||
TableJoin primaryKeyJoin = p.getBeanDescriptor().getPrimaryKeyJoin();
|
||||
if (primaryKeyJoin != null && !table.isPartitioned()) {
|
||||
TableJoinColumn[] columns = primaryKeyJoin.columns();
|
||||
col.setReferences(primaryKeyJoin.getTable() + "." + columns[0].getForeignDbColumn());
|
||||
col.setForeignKeyName(determineForeignKeyConstraintName(col.getName()));
|
||||
final PropertyForeignKey foreignKey = primaryKeyJoin.getForeignKey();
|
||||
if (foreignKey == null || !foreignKey.isNoConstraint()) {
|
||||
TableJoinColumn[] columns = primaryKeyJoin.columns();
|
||||
col.setReferences(primaryKeyJoin.getTable() + "." + columns[0].getForeignDbColumn());
|
||||
col.setForeignKeyName(determineForeignKeyConstraintName(col.getName()));
|
||||
if (foreignKey != null) {
|
||||
col.setForeignKeyModes(foreignKey.getOnDelete(), foreignKey.getOnUpdate());
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
col.setDefaultValue(p.getDbColumnDefault());
|
||||
|
||||
@@ -163,7 +163,7 @@ public class InternalConfiguration {
|
||||
|
||||
private final SpiLogManager logManager;
|
||||
|
||||
public InternalConfiguration(boolean online, ClusterManager clusterManager, SpiBackgroundExecutor backgroundExecutor,
|
||||
InternalConfiguration(boolean online, ClusterManager clusterManager, SpiBackgroundExecutor backgroundExecutor,
|
||||
ServerConfig serverConfig, BootupClasses bootupClasses) {
|
||||
|
||||
this.online = online;
|
||||
@@ -237,7 +237,7 @@ public class InternalConfiguration {
|
||||
return docStoreFactory;
|
||||
}
|
||||
|
||||
public ClockService getClockService() {
|
||||
ClockService getClockService() {
|
||||
return clockService;
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ public class InternalConfiguration {
|
||||
/**
|
||||
* Return the ReadAuditLogger implementation to use.
|
||||
*/
|
||||
public ReadAuditLogger getReadAuditLogger() {
|
||||
ReadAuditLogger getReadAuditLogger() {
|
||||
ReadAuditLogger found = bootupClasses.getReadAuditLogger();
|
||||
return plugin(found != null ? found : new DefaultReadAuditLogger());
|
||||
}
|
||||
@@ -300,7 +300,7 @@ public class InternalConfiguration {
|
||||
/**
|
||||
* Return the ReadAuditPrepare implementation to use.
|
||||
*/
|
||||
public ReadAuditPrepare getReadAuditPrepare() {
|
||||
ReadAuditPrepare getReadAuditPrepare() {
|
||||
ReadAuditPrepare found = bootupClasses.getReadAuditPrepare();
|
||||
return plugin(found != null ? found : new DefaultReadAuditPrepare());
|
||||
}
|
||||
@@ -334,27 +334,27 @@ public class InternalConfiguration {
|
||||
return new MultiValueBind();
|
||||
}
|
||||
|
||||
public SpiJsonContext createJsonContext(SpiEbeanServer server) {
|
||||
SpiJsonContext createJsonContext(SpiEbeanServer server) {
|
||||
return new DJsonContext(server, jsonFactory, typeManager);
|
||||
}
|
||||
|
||||
public AutoTuneService createAutoTuneService(SpiEbeanServer server) {
|
||||
AutoTuneService createAutoTuneService(SpiEbeanServer server) {
|
||||
return AutoTuneServiceFactory.create(server, serverConfig);
|
||||
}
|
||||
|
||||
public DtoQueryEngine createDtoQueryEngine() {
|
||||
DtoQueryEngine createDtoQueryEngine() {
|
||||
return new DtoQueryEngine(binder);
|
||||
}
|
||||
|
||||
public RelationalQueryEngine createRelationalQueryEngine() {
|
||||
RelationalQueryEngine createRelationalQueryEngine() {
|
||||
return new DefaultRelationalQueryEngine(binder, serverConfig.getDatabaseBooleanTrue(), serverConfig.getPlatformConfig().getDbUuid().useBinaryOptimized());
|
||||
}
|
||||
|
||||
public OrmQueryEngine createOrmQueryEngine() {
|
||||
OrmQueryEngine createOrmQueryEngine() {
|
||||
return new DefaultOrmQueryEngine(cQueryEngine, binder);
|
||||
}
|
||||
|
||||
public Persister createPersister(SpiEbeanServer server) {
|
||||
Persister createPersister(SpiEbeanServer server) {
|
||||
return new DefaultPersister(server, binder, beanDescriptorManager);
|
||||
}
|
||||
|
||||
@@ -382,7 +382,7 @@ public class InternalConfiguration {
|
||||
return binder;
|
||||
}
|
||||
|
||||
public BeanDescriptorManager getBeanDescriptorManager() {
|
||||
BeanDescriptorManager getBeanDescriptorManager() {
|
||||
return beanDescriptorManager;
|
||||
}
|
||||
|
||||
@@ -398,7 +398,7 @@ public class InternalConfiguration {
|
||||
return deployUtil;
|
||||
}
|
||||
|
||||
public CQueryEngine getCQueryEngine() {
|
||||
CQueryEngine getCQueryEngine() {
|
||||
return cQueryEngine;
|
||||
}
|
||||
|
||||
@@ -414,14 +414,14 @@ public class InternalConfiguration {
|
||||
/**
|
||||
* Create the DocStoreIntegration components for the given server.
|
||||
*/
|
||||
public DocStoreIntegration createDocStoreIntegration(SpiServer server) {
|
||||
DocStoreIntegration createDocStoreIntegration(SpiServer server) {
|
||||
return plugin(docStoreFactory.create(server));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the TransactionManager taking into account autoCommit mode.
|
||||
*/
|
||||
public TransactionManager createTransactionManager(DocStoreUpdateProcessor indexUpdateProcessor) {
|
||||
TransactionManager createTransactionManager(DocStoreUpdateProcessor indexUpdateProcessor) {
|
||||
|
||||
TransactionScopeManager scopeManager = createTransactionScopeManager();
|
||||
boolean notifyL2CacheInForeground = cacheManager.isLocalL2Caching() || serverConfig.isNotifyL2CacheInForeground();
|
||||
@@ -496,9 +496,9 @@ public class InternalConfiguration {
|
||||
}
|
||||
if (externalTransactionManager != null) {
|
||||
logger.info("Using Transaction Manager [" + externalTransactionManager.getClass() + "]");
|
||||
return new ExternalTransactionScopeManager(serverConfig.getName(), externalTransactionManager);
|
||||
return new ExternalTransactionScopeManager(externalTransactionManager);
|
||||
} else {
|
||||
return new DefaultTransactionScopeManager(serverConfig.getName());
|
||||
return new DefaultTransactionScopeManager();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -559,11 +559,11 @@ public class InternalConfiguration {
|
||||
return multiValueBind;
|
||||
}
|
||||
|
||||
public DtoBeanManager getDtoBeanManager() {
|
||||
DtoBeanManager getDtoBeanManager() {
|
||||
return dtoBeanManager;
|
||||
}
|
||||
|
||||
public SpiLogManager getLogManager() {
|
||||
SpiLogManager getLogManager() {
|
||||
return logManager;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ import java.sql.SQLException;
|
||||
*/
|
||||
abstract class AssocOneHelp {
|
||||
|
||||
protected final BeanPropertyAssocOne<?> property;
|
||||
final BeanPropertyAssocOne<?> property;
|
||||
|
||||
protected final BeanDescriptor<?> target;
|
||||
private final BeanDescriptor<?> target;
|
||||
|
||||
private final String path;
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ class AssocOneHelpRefInherit extends AssocOneHelp {
|
||||
@Override
|
||||
void appendSelect(DbSqlContext ctx, boolean subQuery) {
|
||||
|
||||
if (!subQuery) {
|
||||
if (!subQuery && inherit.hasChildren()) {
|
||||
// add discriminator column
|
||||
String relativePrefix = ctx.getRelativePrefix(property.getName());
|
||||
String tableAlias = ctx.getTableAlias(relativePrefix);
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.Collection;
|
||||
abstract class BaseCollectionHelp<T> implements BeanCollectionHelp<T> {
|
||||
|
||||
final BeanPropertyAssocMany<T> many;
|
||||
final BeanDescriptor<T> targetDescriptor;
|
||||
private final BeanDescriptor<T> targetDescriptor;
|
||||
final String propertyName;
|
||||
|
||||
BeanCollectionLoader loader;
|
||||
|
||||
@@ -36,8 +36,6 @@ public class BeanCascadeInfo {
|
||||
refresh = true;
|
||||
break;
|
||||
case PERSIST:
|
||||
save = true;
|
||||
break;
|
||||
case MERGE:
|
||||
save = true;
|
||||
break;
|
||||
|
||||
@@ -92,6 +92,7 @@ import io.ebeanservice.docstore.api.mapping.DocumentMapping;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
@@ -142,11 +143,6 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
ORM, EMBEDDED, VIEW, SQL, DOC
|
||||
}
|
||||
|
||||
/**
|
||||
* The EbeanServer name. Same as the plugin name.
|
||||
*/
|
||||
private final String serverName;
|
||||
|
||||
/**
|
||||
* The nature/type of this bean.
|
||||
*/
|
||||
@@ -290,14 +286,14 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
/**
|
||||
* Inheritance information. Server side only.
|
||||
*/
|
||||
protected final InheritInfo inheritInfo;
|
||||
final InheritInfo inheritInfo;
|
||||
|
||||
private final boolean abstractType;
|
||||
|
||||
/**
|
||||
* Derived list of properties that make up the unique id.
|
||||
*/
|
||||
protected final BeanProperty idProperty;
|
||||
private final BeanProperty idProperty;
|
||||
|
||||
private final int idPropertyIndex;
|
||||
|
||||
@@ -434,7 +430,6 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
|
||||
this.owner = owner;
|
||||
this.multiValueSupported = owner.isMultiValueSupported();
|
||||
this.serverName = owner.getServerName();
|
||||
this.entityType = deploy.getEntityType();
|
||||
this.properties = deploy.getProperties();
|
||||
this.name = InternString.intern(deploy.getName());
|
||||
@@ -609,7 +604,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
/**
|
||||
* Create an entity bean that is used as a prototype/factory to create new instances.
|
||||
*/
|
||||
protected EntityBean createPrototypeEntityBean(Class<T> beanType) {
|
||||
EntityBean createPrototypeEntityBean(Class<T> beanType) {
|
||||
if (Modifier.isAbstract(beanType.getModifiers())) {
|
||||
return null;
|
||||
}
|
||||
@@ -667,7 +662,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
return entityType;
|
||||
}
|
||||
|
||||
public String[] getProperties() {
|
||||
private String[] getProperties() {
|
||||
return properties;
|
||||
}
|
||||
|
||||
@@ -1289,13 +1284,6 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
return cacheHelp.getNaturalKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if there is bean or query caching for this type.
|
||||
*/
|
||||
public boolean isCaching() {
|
||||
return cacheHelp.isCaching();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if there is currently bean caching for this type of bean.
|
||||
*/
|
||||
@@ -1508,7 +1496,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
/**
|
||||
* Invalidate parts of cache due to SqlUpdate or external modification etc.
|
||||
*/
|
||||
public void cachePersistTableIUD(TableIUD tableIUD, CacheChangeSet changeSet) {
|
||||
void cachePersistTableIUD(TableIUD tableIUD, CacheChangeSet changeSet) {
|
||||
cacheHelp.persistTableIUD(tableIUD, changeSet);
|
||||
}
|
||||
|
||||
@@ -1626,7 +1614,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
return new DeployUpdateParser(this).parse(ormUpdateStatement);
|
||||
}
|
||||
|
||||
public void collectQueryPlans(QueryPlanRequest request) {
|
||||
void collectQueryPlans(QueryPlanRequest request) {
|
||||
for (CQueryPlan queryPlan : queryPlanCache.values()) {
|
||||
if (request.includeLabel(queryPlan.getLabel())) {
|
||||
queryPlan.collectQueryPlan(request);
|
||||
@@ -1657,7 +1645,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
/**
|
||||
* Trim query plans not used since the passed in epoch time.
|
||||
*/
|
||||
public List<CQueryPlan> trimQueryPlans(long unusedSince) {
|
||||
List<CQueryPlan> trimQueryPlans(long unusedSince) {
|
||||
|
||||
List<CQueryPlan> list = new ArrayList<>();
|
||||
|
||||
@@ -1723,7 +1711,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
* Return true if save does not recurse to other beans. That is return true if
|
||||
* there are no assoc one or assoc many beans that cascade save.
|
||||
*/
|
||||
public boolean isSaveRecurseSkippable() {
|
||||
boolean isSaveRecurseSkippable() {
|
||||
return saveRecurseSkippable;
|
||||
}
|
||||
|
||||
@@ -1731,7 +1719,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
* Return true if delete does not recurse to other beans. That is return true
|
||||
* if there are no assoc one or assoc many beans that cascade delete.
|
||||
*/
|
||||
public boolean isDeleteRecurseSkippable() {
|
||||
boolean isDeleteRecurseSkippable() {
|
||||
return deleteRecurseSkippable;
|
||||
}
|
||||
|
||||
@@ -1813,7 +1801,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
/**
|
||||
* Return a raw expression for 'where parent id in ...' clause.
|
||||
*/
|
||||
public String getParentIdInExpr(int parentIdSize, String rawWhere) {
|
||||
String getParentIdInExpr(int parentIdSize, String rawWhere) {
|
||||
String inClause = idBinder.getIdInValueExpr(false, parentIdSize);
|
||||
return idBinder.isIdInExpandedForm() ? inClause : rawWhere + inClause;
|
||||
}
|
||||
@@ -1829,7 +1817,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
/**
|
||||
* Return true if this bean type has a simple single Id property.
|
||||
*/
|
||||
public boolean isSimpleId() {
|
||||
boolean isSimpleId() {
|
||||
return idBinder instanceof IdBinderSimple;
|
||||
}
|
||||
|
||||
@@ -1897,7 +1885,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
* a reference (then {@link BeanPostLoad#postLoad(Object)} will be invoked
|
||||
* on first access (lazy load) or immediately (eager load)
|
||||
*/
|
||||
public EntityBean createEntityBean(boolean isNew) {
|
||||
private EntityBean createEntityBean(boolean isNew) {
|
||||
if (prototypeEntityBean == null) {
|
||||
throw new UnsupportedOperationException("cannot create entity bean for abstract entity " + getName());
|
||||
}
|
||||
@@ -2117,13 +2105,6 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a property value from a bean of this type.
|
||||
*/
|
||||
public Object getValue(EntityBean bean, String property) {
|
||||
return getBeanProperty(property).getValue(bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this bean type should use IdGeneration.
|
||||
* <p>
|
||||
@@ -2146,6 +2127,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
* Return the class type this BeanDescriptor describes.
|
||||
*/
|
||||
@Override
|
||||
@Nonnull
|
||||
public Class<T> getBeanType() {
|
||||
return beanType;
|
||||
}
|
||||
@@ -2158,6 +2140,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
* </p>
|
||||
*/
|
||||
@Override
|
||||
@Nonnull
|
||||
public String getFullName() {
|
||||
return fullName;
|
||||
}
|
||||
@@ -2166,6 +2149,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
* Return the short name of the entity bean.
|
||||
*/
|
||||
@Override
|
||||
@Nonnull
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -2248,7 +2232,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
/**
|
||||
* Return the cache key for the given bean (based on id value).
|
||||
*/
|
||||
public String cacheKeyForBean(EntityBean bean) {
|
||||
String cacheKeyForBean(EntityBean bean) {
|
||||
return cacheKey(idProperty.getValue(bean));
|
||||
}
|
||||
|
||||
@@ -2285,7 +2269,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
* The usage is to provide simple id types for JSON processing (for embeddedId's).
|
||||
* </p>
|
||||
*/
|
||||
public Object convertIdFromJson(Object idValue) {
|
||||
Object convertIdFromJson(Object idValue) {
|
||||
return idBinder.convertIdFromJson(idValue);
|
||||
}
|
||||
|
||||
@@ -2510,7 +2494,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
return elProp;
|
||||
}
|
||||
|
||||
protected ElPropertyValue buildElGetValue(String propName, ElPropertyChainBuilder chain, boolean propertyDeploy) {
|
||||
ElPropertyValue buildElGetValue(String propName, ElPropertyChainBuilder chain, boolean propertyDeploy) {
|
||||
|
||||
if (propertyDeploy && chain != null) {
|
||||
ElPropertyDeploy fk = elDeployCache.get(propName);
|
||||
@@ -2626,13 +2610,6 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the name of the server this BeanDescriptor belongs to.
|
||||
*/
|
||||
public String getServerName() {
|
||||
return serverName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this bean can cache sharable instances.
|
||||
* <p>
|
||||
@@ -2651,11 +2628,6 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
return autoTunable;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isElementType() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Inheritance mapping information. This will be null if this type
|
||||
* of bean is not involved in any ORM inheritance mapping.
|
||||
@@ -2928,7 +2900,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
softDeleteProperty.setSoftDeleteValue(bean);
|
||||
}
|
||||
|
||||
public String getSoftDeleteDbSet() {
|
||||
String getSoftDeleteDbSet() {
|
||||
return softDeleteProperty.getSoftDeleteDbSet();
|
||||
}
|
||||
|
||||
@@ -2950,7 +2922,6 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return true if this entity type is draftable.
|
||||
*/
|
||||
@@ -3000,7 +2971,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
}
|
||||
}
|
||||
|
||||
public void setUnmappedJson(EntityBean bean, Map<String, Object> unmappedProperties) {
|
||||
void setUnmappedJson(EntityBean bean, Map<String, Object> unmappedProperties) {
|
||||
if (unmappedJson != null) {
|
||||
unmappedJson.setValueIntercept(bean, unmappedProperties);
|
||||
}
|
||||
@@ -3141,6 +3112,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public Collection<? extends Property> allProperties() {
|
||||
return propertiesAll();
|
||||
}
|
||||
@@ -3229,7 +3201,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
return ebi.isReference() || hasIdPropertyOnly(ebi);
|
||||
}
|
||||
|
||||
public boolean hasIdPropertyOnly(EntityBeanIntercept ebi) {
|
||||
boolean hasIdPropertyOnly(EntityBeanIntercept ebi) {
|
||||
return ebi.hasIdOnly(idPropertyIndex);
|
||||
}
|
||||
|
||||
@@ -3237,11 +3209,11 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
return ebi.isLoadedProperty(idPropertyIndex);
|
||||
}
|
||||
|
||||
public boolean hasIdValue(EntityBean bean) {
|
||||
boolean hasIdValue(EntityBean bean) {
|
||||
return (idProperty != null && !DmlUtil.isNullOrZero(idProperty.getValue(bean)));
|
||||
}
|
||||
|
||||
public boolean hasVersionProperty(EntityBeanIntercept ebi) {
|
||||
boolean hasVersionProperty(EntityBeanIntercept ebi) {
|
||||
return versionPropertyIndex > -1 && ebi.isLoadedProperty(versionPropertyIndex);
|
||||
}
|
||||
|
||||
@@ -3490,7 +3462,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
jsonHelp.jsonWriteDirty(writeJson, bean, dirtyProps);
|
||||
}
|
||||
|
||||
protected void jsonWriteDirtyProperties(SpiJsonWriter writeJson, EntityBean bean, boolean[] dirtyProps) throws IOException {
|
||||
void jsonWriteDirtyProperties(SpiJsonWriter writeJson, EntityBean bean, boolean[] dirtyProps) throws IOException {
|
||||
jsonHelp.jsonWriteDirtyProperties(writeJson, bean, dirtyProps);
|
||||
}
|
||||
|
||||
@@ -3514,7 +3486,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
jsonHelp.jsonWrite(writeJson, bean, key);
|
||||
}
|
||||
|
||||
protected void jsonWriteProperties(SpiJsonWriter writeJson, EntityBean bean) throws IOException {
|
||||
void jsonWriteProperties(SpiJsonWriter writeJson, EntityBean bean) {
|
||||
jsonHelp.jsonWriteProperties(writeJson, bean);
|
||||
}
|
||||
|
||||
@@ -3522,7 +3494,7 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
return jsonHelp.jsonRead(jsonRead, path, true);
|
||||
}
|
||||
|
||||
public T jsonReadObject(SpiJsonReader jsonRead, String path) throws IOException {
|
||||
T jsonReadObject(SpiJsonReader jsonRead, String path) throws IOException {
|
||||
return jsonHelp.jsonRead(jsonRead, path, false);
|
||||
}
|
||||
|
||||
@@ -3553,5 +3525,4 @@ public class BeanDescriptor<T> implements BeanType<T>, STreeType {
|
||||
getInheritInfo().visitChildren(info -> visitor.accept(info.desc()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.List;
|
||||
*
|
||||
* @param <T> The entity bean type
|
||||
*/
|
||||
public final class BeanDescriptorDraftHelp<T> {
|
||||
final class BeanDescriptorDraftHelp<T> {
|
||||
|
||||
private final BeanDescriptor<T> desc;
|
||||
|
||||
@@ -19,7 +19,7 @@ public final class BeanDescriptorDraftHelp<T> {
|
||||
|
||||
private final BeanProperty[] resetProperties;
|
||||
|
||||
public BeanDescriptorDraftHelp(BeanDescriptor<T> desc) {
|
||||
BeanDescriptorDraftHelp(BeanDescriptor<T> desc) {
|
||||
this.desc = desc;
|
||||
this.draftDirty = desc.getDraftDirty();
|
||||
this.resetProperties = resetProperties();
|
||||
@@ -45,7 +45,7 @@ public final class BeanDescriptorDraftHelp<T> {
|
||||
/**
|
||||
* Set the value of all the 'reset properties' to null on the draft bean.
|
||||
*/
|
||||
public boolean draftReset(T draftBean) {
|
||||
boolean draftReset(T draftBean) {
|
||||
|
||||
EntityBean draftEntityBean = (EntityBean) draftBean;
|
||||
|
||||
@@ -102,7 +102,7 @@ public final class BeanDescriptorDraftHelp<T> {
|
||||
/**
|
||||
* Fetch draftable element relationships.
|
||||
*/
|
||||
public void draftQueryOptimise(Query<T> query) {
|
||||
void draftQueryOptimise(Query<T> query) {
|
||||
|
||||
BeanPropertyAssocOne<?>[] one = desc.propertiesOne();
|
||||
for (BeanPropertyAssocOne<?> anOne : one) {
|
||||
|
||||
@@ -32,11 +32,6 @@ abstract class BeanDescriptorElement<T> extends BeanDescriptor<T> {
|
||||
return props[0].getScalarType();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isElementType() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Our entity beans used are somewhat fake ones (ElementEntityBean) such that we hold the unidirectional property
|
||||
* value (foreign key) and the actual element collection value (scalar or embedded plus map key).
|
||||
|
||||
@@ -663,7 +663,7 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
return (BeanManager<T>) getBeanManager(entityType.getName());
|
||||
}
|
||||
|
||||
public BeanManager<?> getBeanManager(String beanClassName) {
|
||||
private BeanManager<?> getBeanManager(String beanClassName) {
|
||||
return beanManagerMap.get(beanClassName);
|
||||
}
|
||||
|
||||
@@ -1654,8 +1654,7 @@ public class BeanDescriptorManager implements BeanDescriptorMap {
|
||||
String baseTable = prop.getDesc().getBaseTable();
|
||||
DeployTableJoin inverse = prop.getTableJoin().createInverse(baseTable);
|
||||
|
||||
TableJoin inverseJoin = new TableJoin(inverse);
|
||||
|
||||
TableJoin inverseJoin = new TableJoin(inverse, prop.getForeignKey());
|
||||
DeployBeanInfo<?> target = deployInfoMap.get(prop.getTargetType());
|
||||
target.setPrimaryKeyJoin(inverseJoin);
|
||||
}
|
||||
|
||||
@@ -3,9 +3,9 @@ package io.ebeaninternal.server.deploy;
|
||||
public class BeanEmbeddedMeta {
|
||||
|
||||
|
||||
final BeanProperty[] properties;
|
||||
private final BeanProperty[] properties;
|
||||
|
||||
public BeanEmbeddedMeta(BeanProperty[] properties) {
|
||||
BeanEmbeddedMeta(BeanProperty[] properties) {
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.util.Map;
|
||||
* Creates BeanProperties for Embedded beans that have deployment information
|
||||
* such as the actual DB column name and table alias.
|
||||
*/
|
||||
public class BeanEmbeddedMetaFactory {
|
||||
class BeanEmbeddedMetaFactory {
|
||||
|
||||
/**
|
||||
* Create BeanProperties for embedded beans using the deployment specific DB column name and table alias.
|
||||
|
||||
@@ -11,25 +11,24 @@ import java.util.List;
|
||||
/**
|
||||
* Default implementation for BeanFinderFactory.
|
||||
*/
|
||||
public class BeanFinderManager {
|
||||
class BeanFinderManager {
|
||||
|
||||
final Logger logger = LoggerFactory.getLogger(BeanFinderManager.class);
|
||||
private final Logger logger = LoggerFactory.getLogger(BeanFinderManager.class);
|
||||
|
||||
private final List<BeanFindController> list;
|
||||
|
||||
public BeanFinderManager(BootupClasses bootupClasses) {
|
||||
BeanFinderManager(BootupClasses bootupClasses) {
|
||||
list = bootupClasses.getBeanFindControllers();
|
||||
}
|
||||
|
||||
public int getRegisterCount() {
|
||||
int getRegisterCount() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the BeanPersistController for a given entity type.
|
||||
*/
|
||||
public void addFindControllers(DeployBeanDescriptor<?> deployDesc) {
|
||||
|
||||
void addFindControllers(DeployBeanDescriptor<?> deployDesc) {
|
||||
for (BeanFindController c : list) {
|
||||
if (c.isRegisterFor(deployDesc.getBeanType())) {
|
||||
logger.debug("BeanFindController on[{}] {}", deployDesc.getFullName(), c.getClass().getName());
|
||||
|
||||
@@ -141,11 +141,11 @@ class BeanLifecycleAdapterFactory {
|
||||
/**
|
||||
* Utility method to covert List of Method into array (because we care about performance here).
|
||||
*/
|
||||
static Method[] toArray(List<Method> methodList) {
|
||||
private static Method[] toArray(List<Method> methodList) {
|
||||
return methodList.toArray(new Method[0]);
|
||||
}
|
||||
|
||||
static RuntimeException unwrapException(ReflectiveOperationException e) {
|
||||
private static RuntimeException unwrapException(ReflectiveOperationException e) {
|
||||
if (e instanceof InvocationTargetException) {
|
||||
Throwable targetException = ((InvocationTargetException)e).getTargetException();
|
||||
if (targetException instanceof RuntimeException) {
|
||||
|
||||
@@ -7,16 +7,15 @@ import io.ebeaninternal.server.persist.dml.DmlBeanPersisterFactory;
|
||||
/**
|
||||
* Creates BeanManagers.
|
||||
*/
|
||||
public class BeanManagerFactory {
|
||||
class BeanManagerFactory {
|
||||
|
||||
final BeanPersisterFactory persisterFactory;
|
||||
private final BeanPersisterFactory persisterFactory;
|
||||
|
||||
public BeanManagerFactory(DatabasePlatform dbPlatform) {
|
||||
BeanManagerFactory(DatabasePlatform dbPlatform) {
|
||||
persisterFactory = new DmlBeanPersisterFactory(dbPlatform);
|
||||
}
|
||||
|
||||
public <T> BeanManager<T> create(BeanDescriptor<T> desc) {
|
||||
|
||||
return new BeanManager<>(desc, persisterFactory.create(desc));
|
||||
}
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ import io.ebeanservice.docstore.api.support.DocStructure;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
@@ -65,19 +66,19 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
/**
|
||||
* Flag to mark this is the id property.
|
||||
*/
|
||||
final boolean id;
|
||||
private final boolean id;
|
||||
|
||||
final boolean importedPrimaryKey;
|
||||
private final boolean importedPrimaryKey;
|
||||
|
||||
/**
|
||||
* Flag to make this as a dummy property for unidirecitonal relationships.
|
||||
*/
|
||||
final boolean unidirectionalShadow;
|
||||
private final boolean unidirectionalShadow;
|
||||
|
||||
/**
|
||||
* Flag set if this maps to the inheritance discriminator column
|
||||
*/
|
||||
final boolean discriminator;
|
||||
private final boolean discriminator;
|
||||
|
||||
/**
|
||||
* Flag to mark the property as embedded. This could be on
|
||||
@@ -89,55 +90,55 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
/**
|
||||
* Flag indicating if this the version property.
|
||||
*/
|
||||
final boolean version;
|
||||
private final boolean version;
|
||||
|
||||
final boolean naturalKey;
|
||||
private final boolean naturalKey;
|
||||
|
||||
/**
|
||||
* Set if this property is nullable.
|
||||
*/
|
||||
final boolean nullable;
|
||||
private final boolean nullable;
|
||||
|
||||
final boolean unique;
|
||||
private final boolean unique;
|
||||
|
||||
/**
|
||||
* Is this property include in database resultSet.
|
||||
*/
|
||||
final boolean dbRead;
|
||||
private final boolean dbRead;
|
||||
|
||||
/**
|
||||
* Include in DB insert.
|
||||
*/
|
||||
final boolean dbInsertable;
|
||||
private final boolean dbInsertable;
|
||||
|
||||
/**
|
||||
* Include in DB update.
|
||||
*/
|
||||
final boolean dbUpdatable;
|
||||
private final boolean dbUpdatable;
|
||||
|
||||
/**
|
||||
* True if the property is based on a SECONDARY table.
|
||||
*/
|
||||
final boolean secondaryTable;
|
||||
private final boolean secondaryTable;
|
||||
|
||||
final TableJoin secondaryTableJoin;
|
||||
final String secondaryTableJoinPrefix;
|
||||
private final TableJoin secondaryTableJoin;
|
||||
private final String secondaryTableJoinPrefix;
|
||||
|
||||
/**
|
||||
* The property is inherited from a super class.
|
||||
*/
|
||||
final boolean inherited;
|
||||
private final boolean inherited;
|
||||
|
||||
final Class<?> owningType;
|
||||
private final Class<?> owningType;
|
||||
|
||||
final boolean local;
|
||||
private final boolean local;
|
||||
|
||||
/**
|
||||
* True if the property is a Clob, Blob LongVarchar or LongVarbinary.
|
||||
*/
|
||||
final boolean lob;
|
||||
private final boolean lob;
|
||||
|
||||
final boolean fetchEager;
|
||||
private final boolean fetchEager;
|
||||
|
||||
final boolean isTransient;
|
||||
|
||||
@@ -151,62 +152,62 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
/**
|
||||
* The reflected field.
|
||||
*/
|
||||
final Field field;
|
||||
private final Field field;
|
||||
|
||||
/**
|
||||
* The bean type.
|
||||
*/
|
||||
final Class<?> propertyType;
|
||||
private final Class<?> propertyType;
|
||||
|
||||
final String dbBind;
|
||||
private final String dbBind;
|
||||
|
||||
/**
|
||||
* The database column. This can include quoted identifiers.
|
||||
*/
|
||||
final String dbColumn;
|
||||
|
||||
final String elPrefix;
|
||||
private final String elPrefix;
|
||||
final String elPlaceHolder;
|
||||
final String elPlaceHolderEncrypted;
|
||||
|
||||
/**
|
||||
* Select part of a SQL Formula used to populate this property.
|
||||
*/
|
||||
final String sqlFormulaSelect;
|
||||
private final String sqlFormulaSelect;
|
||||
|
||||
/**
|
||||
* Join part of a SQL Formula.
|
||||
*/
|
||||
final String sqlFormulaJoin;
|
||||
|
||||
final String aggregation;
|
||||
private final String aggregation;
|
||||
|
||||
final boolean formula;
|
||||
private final boolean formula;
|
||||
|
||||
/**
|
||||
* Set to true if stored encrypted.
|
||||
*/
|
||||
final boolean dbEncrypted;
|
||||
private final boolean dbEncrypted;
|
||||
|
||||
final boolean localEncrypted;
|
||||
private final boolean localEncrypted;
|
||||
|
||||
final int dbEncryptedType;
|
||||
private final int dbEncryptedType;
|
||||
|
||||
/**
|
||||
* The jdbc data type this maps to.
|
||||
*/
|
||||
final int dbType;
|
||||
private final int dbType;
|
||||
|
||||
final boolean excludedFromHistory;
|
||||
|
||||
/**
|
||||
* Generator for insert or update timestamp etc.
|
||||
*/
|
||||
final GeneratedProperty generatedProperty;
|
||||
private final GeneratedProperty generatedProperty;
|
||||
|
||||
final BeanPropertyGetter getter;
|
||||
private final BeanPropertyGetter getter;
|
||||
|
||||
final BeanPropertySetter setter;
|
||||
private final BeanPropertySetter setter;
|
||||
|
||||
final BeanDescriptor<?> descriptor;
|
||||
|
||||
@@ -217,56 +218,56 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
@SuppressWarnings("rawtypes")
|
||||
final ScalarType scalarType;
|
||||
|
||||
final DocPropertyOptions docOptions;
|
||||
private final DocPropertyOptions docOptions;
|
||||
|
||||
/**
|
||||
* The length or precision for DB column.
|
||||
*/
|
||||
final int dbLength;
|
||||
private final int dbLength;
|
||||
|
||||
/**
|
||||
* The scale for DB column (decimal).
|
||||
*/
|
||||
final int dbScale;
|
||||
private final int dbScale;
|
||||
|
||||
/**
|
||||
* Deployment defined DB column definition.
|
||||
*/
|
||||
final String dbColumnDefn;
|
||||
private final String dbColumnDefn;
|
||||
|
||||
/**
|
||||
* DB Column default value for DDL definition (FALSE, NOW etc).
|
||||
*/
|
||||
final String dbColumnDefault;
|
||||
final List<DbMigrationInfo> dbMigrationInfos;
|
||||
private final String dbColumnDefault;
|
||||
private final List<DbMigrationInfo> dbMigrationInfos;
|
||||
|
||||
/**
|
||||
* Database DDL column comment.
|
||||
*/
|
||||
final String dbComment;
|
||||
private final String dbComment;
|
||||
|
||||
final DbEncryptFunction dbEncryptFunction;
|
||||
private final DbEncryptFunction dbEncryptFunction;
|
||||
|
||||
int deployOrder;
|
||||
private int deployOrder;
|
||||
|
||||
final boolean jsonSerialize;
|
||||
final boolean jsonDeserialize;
|
||||
final boolean unmappedJson;
|
||||
final boolean tenantId;
|
||||
private final boolean unmappedJson;
|
||||
private final boolean tenantId;
|
||||
|
||||
final boolean draft;
|
||||
private final boolean draft;
|
||||
|
||||
final boolean draftOnly;
|
||||
private final boolean draftOnly;
|
||||
|
||||
final boolean draftDirty;
|
||||
private final boolean draftDirty;
|
||||
|
||||
final boolean draftReset;
|
||||
private final boolean draftReset;
|
||||
|
||||
final boolean softDelete;
|
||||
private final boolean softDelete;
|
||||
|
||||
final String softDeleteDbSet;
|
||||
private final String softDeleteDbSet;
|
||||
|
||||
final String softDeleteDbPredicate;
|
||||
private final String softDeleteDbPredicate;
|
||||
|
||||
public BeanProperty(DeployBeanProperty deploy) {
|
||||
this(null, deploy);
|
||||
@@ -545,7 +546,7 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
return dbEncryptFunction.getDecryptSql(this.getDbColumn());
|
||||
}
|
||||
|
||||
public String getDecryptSql(String tableAlias) {
|
||||
private String getDecryptSql(String tableAlias) {
|
||||
return dbEncryptFunction.getDecryptSql(tableAlias + "." + this.getDbColumn());
|
||||
}
|
||||
|
||||
@@ -702,7 +703,7 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
/**
|
||||
* Return true if this object is part of an inheritance hierarchy.
|
||||
*/
|
||||
public boolean isInherited() {
|
||||
private boolean isInherited() {
|
||||
return inherited;
|
||||
}
|
||||
|
||||
@@ -728,21 +729,21 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
/**
|
||||
* Return the DB literal expression to set the deleted state to true.
|
||||
*/
|
||||
public String getSoftDeleteDbSet() {
|
||||
String getSoftDeleteDbSet() {
|
||||
return softDeleteDbSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the DB literal predicate used to filter out soft deleted rows from a query.
|
||||
*/
|
||||
public String getSoftDeleteDbPredicate(String tableAlias) {
|
||||
String getSoftDeleteDbPredicate(String tableAlias) {
|
||||
return tableAlias + softDeleteDbPredicate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the soft delete property value on the bean without invoking lazy loading.
|
||||
*/
|
||||
public void setSoftDeleteValue(EntityBean bean) {
|
||||
void setSoftDeleteValue(EntityBean bean) {
|
||||
// assumes boolean deleted true being set which is ok limitation for now
|
||||
setValue(bean, true);
|
||||
bean._ebean_getIntercept().setChangedProperty(propertyIndex);
|
||||
@@ -909,7 +910,7 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
/**
|
||||
* Return the name of the property.
|
||||
*/
|
||||
@Override
|
||||
@Override @Nonnull
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
@@ -1018,7 +1019,7 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
* Return true if the mutable value is considered dirty.
|
||||
* This is only used for 'mutable' scalar types like hstore etc.
|
||||
*/
|
||||
public boolean isDirtyValue(Object value) {
|
||||
boolean isDirtyValue(Object value) {
|
||||
return scalarType.isDirty(value);
|
||||
}
|
||||
|
||||
@@ -1061,14 +1062,14 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
/**
|
||||
* Return the DB scale for numeric columns.
|
||||
*/
|
||||
public int getDbScale() {
|
||||
private int getDbScale() {
|
||||
return dbScale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a specific column DDL definition if specified (otherwise null).
|
||||
*/
|
||||
public String getDbColumnDefn() {
|
||||
private String getDbColumnDefn() {
|
||||
return dbColumnDefn;
|
||||
}
|
||||
|
||||
@@ -1112,7 +1113,7 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
/**
|
||||
* Return the bean Field associated with this property.
|
||||
*/
|
||||
public Field getField() {
|
||||
private Field getField() {
|
||||
return field;
|
||||
}
|
||||
|
||||
@@ -1148,14 +1149,14 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
/**
|
||||
* Return true if this is a generated property mapping to @WhenCreated or @CreatedTimestamp.
|
||||
*/
|
||||
public boolean isGeneratedWhenCreated() {
|
||||
boolean isGeneratedWhenCreated() {
|
||||
return generatedProperty instanceof GeneratedWhenCreated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this is a generated property mapping to @WhenModified or @UpdatedTimestamp.
|
||||
*/
|
||||
public boolean isGeneratedWhenModified() {
|
||||
boolean isGeneratedWhenModified() {
|
||||
return generatedProperty instanceof GeneratedWhenModified;
|
||||
}
|
||||
|
||||
@@ -1191,7 +1192,7 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
* Return true if this is a draftOnly property on a non-asDraft query and as such this
|
||||
* property should not be included in a sql query.
|
||||
*/
|
||||
protected boolean ignoreDraftOnlyProperty(boolean draftQuery) {
|
||||
private boolean ignoreDraftOnlyProperty(boolean draftQuery) {
|
||||
return draftOnly && !draftQuery;
|
||||
}
|
||||
|
||||
@@ -1232,7 +1233,7 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
/**
|
||||
* Perform DB to Logical type conversion (if necessary).
|
||||
*/
|
||||
public Object convertToLogicalType(Object value) {
|
||||
private Object convertToLogicalType(Object value) {
|
||||
if (scalarType != null) {
|
||||
return scalarType.toBeanType(value);
|
||||
}
|
||||
@@ -1258,12 +1259,9 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
public static boolean isLobType(int type) {
|
||||
switch (type) {
|
||||
case Types.CLOB:
|
||||
return true;
|
||||
case Types.BLOB:
|
||||
return true;
|
||||
case Types.LONGVARBINARY:
|
||||
return true;
|
||||
case Types.LONGVARCHAR:
|
||||
case Types.LONGVARBINARY:
|
||||
return true;
|
||||
|
||||
default:
|
||||
@@ -1311,13 +1309,6 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
return excludedFromHistory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this is a ManyToMany with history support (on the intersection table).
|
||||
*/
|
||||
public boolean isManyToManyWithHistory() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this property hold unmapped JSON.
|
||||
*/
|
||||
@@ -1358,7 +1349,7 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
/**
|
||||
* Return true if this property is reset/cleared on publish (on the draft bean).
|
||||
*/
|
||||
public boolean isDraftReset() {
|
||||
boolean isDraftReset() {
|
||||
return draftReset;
|
||||
}
|
||||
|
||||
@@ -1386,7 +1377,7 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
/**
|
||||
* Return true if this property is included in database queries.
|
||||
*/
|
||||
public boolean isDbRead() {
|
||||
private boolean isDbRead() {
|
||||
return dbRead;
|
||||
}
|
||||
|
||||
@@ -1401,7 +1392,7 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
/**
|
||||
* Return the property type.
|
||||
*/
|
||||
@Override
|
||||
@Override @Nonnull
|
||||
public Class<?> getPropertyType() {
|
||||
return propertyType;
|
||||
}
|
||||
@@ -1533,7 +1524,7 @@ public class BeanProperty implements ElPropertyValue, Property, STreeProperty {
|
||||
/**
|
||||
* Populate diff map comparing the property values.
|
||||
*/
|
||||
public void diffVal(String prefix, Map<String, ValuePair> map, Object newVal, Object oldVal) {
|
||||
void diffVal(String prefix, Map<String, ValuePair> map, Object newVal, Object oldVal) {
|
||||
if (!ValueUtil.areEqual(newVal, oldVal)) {
|
||||
String propName = (prefix == null) ? name : prefix + "." + name;
|
||||
map.put(propName, new ValuePair(newVal, oldVal));
|
||||
|
||||
@@ -53,7 +53,7 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
|
||||
/**
|
||||
* Derived list of exported property and matching foreignKey
|
||||
*/
|
||||
protected ExportedProperty[] exportedProperties;
|
||||
ExportedProperty[] exportedProperties;
|
||||
|
||||
/**
|
||||
* Persist settings.
|
||||
@@ -70,7 +70,7 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
|
||||
/**
|
||||
* The type of the joined bean.
|
||||
*/
|
||||
final Class<T> targetType;
|
||||
private final Class<T> targetType;
|
||||
|
||||
/**
|
||||
* The join table information.
|
||||
@@ -79,18 +79,18 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
|
||||
|
||||
final String mappedBy;
|
||||
|
||||
final String docStoreDoc;
|
||||
private final String docStoreDoc;
|
||||
|
||||
final String extraWhere;
|
||||
private final String extraWhere;
|
||||
|
||||
final int fetchPreference;
|
||||
private final int fetchPreference;
|
||||
|
||||
boolean saveRecurseSkippable;
|
||||
private boolean saveRecurseSkippable;
|
||||
|
||||
/**
|
||||
* Construct the property.
|
||||
*/
|
||||
public BeanPropertyAssoc(BeanDescriptor<?> descriptor, DeployBeanPropertyAssoc<T> deploy) {
|
||||
BeanPropertyAssoc(BeanDescriptor<?> descriptor, DeployBeanPropertyAssoc<T> deploy) {
|
||||
super(descriptor, deploy);
|
||||
this.foreignKey = deploy.getForeignKey();
|
||||
this.extraWhere = InternString.intern(deploy.getExtraWhere());
|
||||
@@ -108,7 +108,7 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
|
||||
* Copy constructor for ManyToOne inside Embeddable.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public BeanPropertyAssoc(BeanPropertyAssoc source, BeanPropertyOverride override) {
|
||||
BeanPropertyAssoc(BeanPropertyAssoc source, BeanPropertyOverride override) {
|
||||
super(source, override);
|
||||
foreignKey = source.foreignKey;
|
||||
extraWhere = source.extraWhere;
|
||||
@@ -155,10 +155,24 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
|
||||
return foreignKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if foreign key constraint is enabled on this relationship (not disabled).
|
||||
*/
|
||||
public boolean hasForeignKeyConstraint() {
|
||||
return foreignKey == null || !foreignKey.isNoConstraint();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if foreign key index is enabled on this relationship (not disabled).
|
||||
*/
|
||||
public boolean hasForeignKeyIndex() {
|
||||
return foreignKey == null || !foreignKey.isNoIndex();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a ElPropertyValue for a *ToOne or *ToMany.
|
||||
*/
|
||||
protected ElPropertyValue createElPropertyValue(String propName, String remainder, ElPropertyChainBuilder chain, boolean propertyDeploy) {
|
||||
ElPropertyValue createElPropertyValue(String propName, String remainder, ElPropertyChainBuilder chain, boolean propertyDeploy) {
|
||||
|
||||
// associated or embedded bean
|
||||
BeanDescriptor<?> embDesc = getTargetDescriptor();
|
||||
@@ -228,7 +242,7 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
|
||||
|
||||
/**
|
||||
* Create a new query for the target type.
|
||||
*
|
||||
* <p>
|
||||
* We use target descriptor rather than target property type to support ElementCollection.
|
||||
*/
|
||||
public SpiQuery<T> newQuery(SpiEbeanServer server) {
|
||||
@@ -255,12 +269,11 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
|
||||
/**
|
||||
* Return true if REFRESH should cascade.
|
||||
*/
|
||||
public boolean isCascadeRefresh() {
|
||||
boolean isCascadeRefresh() {
|
||||
return cascadeInfo.isRefresh();
|
||||
}
|
||||
|
||||
public boolean isSaveRecurseSkippable(Object bean) {
|
||||
|
||||
return saveRecurseSkippable && bean instanceof EntityBean && !((EntityBean) bean)._ebean_getIntercept().isNewOrDirty();
|
||||
}
|
||||
|
||||
@@ -284,14 +297,8 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
|
||||
|
||||
BeanDescriptor<?> targetDesc = getTargetDescriptor();
|
||||
BeanProperty idProp = targetDesc.getIdProperty();
|
||||
if (idProp != null) {
|
||||
Object value = idProp.getValue(bean);
|
||||
if (value == null) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// all the unique properties are non-null
|
||||
return true;
|
||||
return idProp == null || idProp.getValue(bean) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -317,7 +324,7 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
|
||||
/**
|
||||
* Return the elastic search doc for this embedded property.
|
||||
*/
|
||||
public String getDocStoreDoc() {
|
||||
private String getDocStoreDoc() {
|
||||
return docStoreDoc;
|
||||
}
|
||||
|
||||
@@ -348,7 +355,7 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
|
||||
/**
|
||||
* Include the property in the document store by default.
|
||||
*/
|
||||
protected void docStoreIncludeByDefault(PathProperties pathProps) {
|
||||
void docStoreIncludeByDefault(PathProperties pathProps) {
|
||||
pathProps.addToPath(null, name);
|
||||
}
|
||||
|
||||
@@ -430,7 +437,7 @@ public abstract class BeanPropertyAssoc<T> extends BeanProperty implements STree
|
||||
* Build the list of imported property. Matches BeanProperty from the target
|
||||
* descriptor back to local database columns in the TableJoin.
|
||||
*/
|
||||
protected ImportedId createImportedId(BeanPropertyAssoc<?> owner, BeanDescriptor<?> target, TableJoin join) {
|
||||
ImportedId createImportedId(BeanPropertyAssoc<?> owner, BeanDescriptor<?> target, TableJoin join) {
|
||||
|
||||
BeanProperty idProp = target.getIdProperty();
|
||||
BeanProperty[] others = target.propertiesBaseScalar();
|
||||
|
||||
@@ -9,6 +9,7 @@ import io.ebean.bean.BeanCollection.ModifyListenMode;
|
||||
import io.ebean.bean.BeanCollectionAdd;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebean.bean.PersistenceContext;
|
||||
import io.ebean.plugin.PropertyAssocMany;
|
||||
import io.ebean.text.PathProperties;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.api.SpiExpressionRequest;
|
||||
@@ -27,7 +28,6 @@ import org.slf4j.LoggerFactory;
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -37,7 +37,7 @@ import java.util.Map;
|
||||
/**
|
||||
* Property mapped to a List Set or Map.
|
||||
*/
|
||||
public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements STreePropertyAssocMany {
|
||||
public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements STreePropertyAssocMany, PropertyAssocMany {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(BeanPropertyAssocMany.class);
|
||||
|
||||
@@ -105,7 +105,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
|
||||
/**
|
||||
* Property on the 'child' bean that links back to the 'master'.
|
||||
*/
|
||||
protected BeanPropertyAssocOne<?> childMasterProperty;
|
||||
private BeanPropertyAssocOne<?> childMasterProperty;
|
||||
|
||||
private String childMasterIdProperty;
|
||||
|
||||
@@ -201,7 +201,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
|
||||
/**
|
||||
* Initialise after the target bean descriptors have been all set.
|
||||
*/
|
||||
public void initialisePostTarget() {
|
||||
void initialisePostTarget() {
|
||||
if (childMasterProperty != null) {
|
||||
BeanProperty masterId = childMasterProperty.getTargetDescriptor().getIdProperty();
|
||||
if (masterId != null) { // in docstore only, the master-id may be not available
|
||||
@@ -348,6 +348,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
|
||||
*
|
||||
* Helper method used by Elastic integration when loading with a persistence context.
|
||||
*/
|
||||
@Override
|
||||
public void lazyLoadMany(EntityBean current) {
|
||||
EntityBean parentBean = childMasterProperty.getValueAsEntityBean(current);
|
||||
if (parentBean != null) {
|
||||
@@ -424,7 +425,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object read(DbReadContext ctx) throws SQLException {
|
||||
public Object read(DbReadContext ctx) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -636,8 +637,8 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
|
||||
return help.createEmpty(parentBean);
|
||||
}
|
||||
|
||||
public BeanCollectionAdd getBeanCollectionAdd(Object bc, String mapKey) {
|
||||
return help.getBeanCollectionAdd(bc, mapKey);
|
||||
private BeanCollectionAdd getBeanCollectionAdd(Object bc) {
|
||||
return help.getBeanCollectionAdd(bc, null);
|
||||
}
|
||||
|
||||
public Object getParentId(EntityBean parentBean) {
|
||||
@@ -782,7 +783,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
|
||||
/**
|
||||
* Register the mapping of intersection table to associated draft table.
|
||||
*/
|
||||
public void registerDraftIntersectionTable(BeanDescriptorInitContext initContext) {
|
||||
void registerDraftIntersectionTable(BeanDescriptorInitContext initContext) {
|
||||
if (hasDraftIntersection()) {
|
||||
initContext.addDraftIntersection(intersectionPublishTable, intersectionDraftTable);
|
||||
}
|
||||
@@ -883,7 +884,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void publishMany(EntityBean draft, EntityBean live) {
|
||||
void publishMany(EntityBean draft, EntityBean live) {
|
||||
|
||||
// collections will not be null due to enhancement
|
||||
BeanCollection<T> draftVal = (BeanCollection<T>) getValueIntercept(draft);
|
||||
@@ -955,15 +956,11 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
|
||||
return targetDescriptor.isDocStoreMapped();
|
||||
}
|
||||
|
||||
public BeanCollectionHelp<T> getHelp() {
|
||||
return help;
|
||||
}
|
||||
|
||||
public void jsonWriteMapEntry(SpiJsonWriter ctx, Map.Entry<?, ?> entry) throws IOException {
|
||||
void jsonWriteMapEntry(SpiJsonWriter ctx, Map.Entry<?, ?> entry) throws IOException {
|
||||
elementDescriptor.jsonWriteMapEntry(ctx, entry);
|
||||
}
|
||||
|
||||
public void jsonWriteElementValue(SpiJsonWriter ctx, Object element) {
|
||||
void jsonWriteElementValue(SpiJsonWriter ctx, Object element) {
|
||||
elementDescriptor.jsonWriteElement(ctx, element);
|
||||
}
|
||||
|
||||
@@ -1011,7 +1008,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
|
||||
/**
|
||||
* Read the collection as JSON.
|
||||
*/
|
||||
public Object jsonReadCollection(String json) throws IOException {
|
||||
private Object jsonReadCollection(String json) throws IOException {
|
||||
SpiJsonReader ctx = descriptor.createJsonReader(json);
|
||||
JsonParser parser = ctx.getParser();
|
||||
JsonToken event = parser.nextToken();
|
||||
@@ -1024,7 +1021,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
|
||||
/**
|
||||
* Write the collection to JSON.
|
||||
*/
|
||||
public void jsonWriteCollection(SpiJsonWriter ctx, String name, Object value, boolean explicitInclude) throws IOException {
|
||||
private void jsonWriteCollection(SpiJsonWriter ctx, String name, Object value, boolean explicitInclude) throws IOException {
|
||||
help.jsonWrite(ctx, name, value, explicitInclude);
|
||||
}
|
||||
|
||||
@@ -1038,7 +1035,7 @@ public class BeanPropertyAssocMany<T> extends BeanPropertyAssoc<T> implements ST
|
||||
}
|
||||
|
||||
BeanCollection<?> collection = createEmpty(parentBean);
|
||||
BeanCollectionAdd add = getBeanCollectionAdd(collection, null);
|
||||
BeanCollectionAdd add = getBeanCollectionAdd(collection);
|
||||
do {
|
||||
EntityBean detailBean = (EntityBean) targetDescriptor.jsonRead(readJson, name);
|
||||
if (detailBean == null) {
|
||||
|
||||
@@ -47,7 +47,7 @@ class BeanPropertyAssocManySqlHelp<T> {
|
||||
|
||||
StringBuilder sb = new StringBuilder(200);
|
||||
sb.append("insert into ").append(many.targetTable()).append(" (");
|
||||
append(sb, "", ",", "");
|
||||
append(sb);
|
||||
|
||||
Cols cols = new Cols(sb);
|
||||
VisitAllUsing.visitOne(many.targetDescriptor, cols);
|
||||
@@ -59,7 +59,7 @@ class BeanPropertyAssocManySqlHelp<T> {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String insertElementCollection() {
|
||||
String insertElementCollection() {
|
||||
return elementCollectionInsertSql;
|
||||
}
|
||||
|
||||
@@ -191,16 +191,16 @@ class BeanPropertyAssocManySqlHelp<T> {
|
||||
}
|
||||
}
|
||||
|
||||
private void append(StringBuilder sb, String tableAlias, String prefix, String suffix) {
|
||||
private void append(StringBuilder sb) {
|
||||
for (int i = 0; i < exportedProperties.length; i++) {
|
||||
String fkColumn = exportedProperties[i].getForeignDbColumn();
|
||||
if (i > 0) {
|
||||
sb.append(prefix);
|
||||
sb.append(",");
|
||||
}
|
||||
sb.append(tableAlias).append(fkColumn);
|
||||
sb.append(suffix);
|
||||
sb.append(fkColumn);
|
||||
}
|
||||
}
|
||||
|
||||
private String deriveWhereParentIdSql(boolean inClause, String tableAlias) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
@@ -45,14 +45,15 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
|
||||
private final boolean orphanRemoval;
|
||||
|
||||
private final boolean primaryKeyExport;
|
||||
private final boolean primaryKeyJoin;
|
||||
|
||||
private AssocOneHelp localHelp;
|
||||
|
||||
protected final BeanProperty[] embeddedProps;
|
||||
final BeanProperty[] embeddedProps;
|
||||
|
||||
private final HashMap<String, BeanProperty> embeddedPropsMap;
|
||||
|
||||
protected ImportedId importedId;
|
||||
ImportedId importedId;
|
||||
|
||||
private String deleteByParentIdSql;
|
||||
private String deleteByParentIdInSql;
|
||||
@@ -75,6 +76,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
|
||||
|
||||
super(descriptor, deploy);
|
||||
primaryKeyExport = deploy.isPrimaryKeyExport();
|
||||
primaryKeyJoin = deploy.isPrimaryKeyJoin();
|
||||
oneToOne = deploy.isOneToOne();
|
||||
oneToOneExported = deploy.isOneToOneExported();
|
||||
orphanRemoval = deploy.isOrphanRemoval();
|
||||
@@ -100,6 +102,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
|
||||
public BeanPropertyAssocOne(BeanPropertyAssocOne source, BeanPropertyOverride override) {
|
||||
super(source, override);
|
||||
primaryKeyExport = source.primaryKeyExport;
|
||||
primaryKeyJoin = source.primaryKeyJoin;
|
||||
oneToOne = source.oneToOne;
|
||||
oneToOneExported = source.oneToOneExported;
|
||||
orphanRemoval = source.orphanRemoval;
|
||||
@@ -154,7 +157,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
|
||||
/**
|
||||
* Derive late in lifecycle cache notification on this relationship.
|
||||
*/
|
||||
public void initialisePostTarget() {
|
||||
void initialisePostTarget() {
|
||||
this.cacheNotifyRelationship = isCacheNotifyRelationship();
|
||||
}
|
||||
|
||||
@@ -357,11 +360,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
|
||||
}
|
||||
|
||||
public boolean hasForeignKey() {
|
||||
return foreignKey == null || !foreignKey.isNoConstraint();
|
||||
}
|
||||
|
||||
public boolean hasForeignKeyIndex() {
|
||||
return foreignKey == null || !foreignKey.isNoIndex();
|
||||
return foreignKey == null || primaryKeyJoin || !foreignKey.isNoConstraint();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -391,10 +390,11 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
|
||||
return;
|
||||
}
|
||||
|
||||
String nextPrefix = (prefix == null) ? name : prefix + "." + name;
|
||||
|
||||
if (embedded) {
|
||||
prefix = (prefix == null) ? name : prefix + "." + name;
|
||||
BeanDescriptor<T> targetDescriptor = getTargetDescriptor();
|
||||
targetDescriptor.diff(prefix, map, (EntityBean) newEmb, (EntityBean) oldEmb);
|
||||
targetDescriptor.diff(nextPrefix, map, (EntityBean) newEmb, (EntityBean) oldEmb);
|
||||
|
||||
} else {
|
||||
// we are only interested in the Id value
|
||||
@@ -407,8 +407,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
|
||||
Object newId = (newBean == null) ? null : idProperty.getValue(newBean);
|
||||
Object oldId = (oldBean == null) ? null : idProperty.getValue(oldBean);
|
||||
if (newId != null || oldId != null) {
|
||||
prefix = (prefix == null) ? name : prefix + "." + name;
|
||||
idProperty.diffVal(prefix, map, newId, oldId);
|
||||
idProperty.diffVal(nextPrefix, map, newId, oldId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -466,7 +465,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
|
||||
return targetDescriptor.getIdProperty();
|
||||
}
|
||||
|
||||
public ScalarType getIdScalarType() {
|
||||
ScalarType getIdScalarType() {
|
||||
return targetDescriptor.getIdProperty().scalarType;
|
||||
}
|
||||
|
||||
@@ -675,7 +674,7 @@ public class BeanPropertyAssocOne<T> extends BeanPropertyAssoc<T> implements STr
|
||||
}
|
||||
}
|
||||
|
||||
void setEmbeddedOwner(EntityBean bean, Object value) {
|
||||
private void setEmbeddedOwner(EntityBean bean, Object value) {
|
||||
((EntityBean) value)._ebean_getIntercept().setEmbeddedOwner(bean, propertyIndex);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,11 +9,11 @@ import io.ebeaninternal.server.core.InternString;
|
||||
* Typically this is for Embedded Beans.
|
||||
* </p>
|
||||
*/
|
||||
public class BeanPropertyOverride {
|
||||
class BeanPropertyOverride {
|
||||
|
||||
private final String dbColumn;
|
||||
|
||||
public BeanPropertyOverride(String dbColumn) {
|
||||
BeanPropertyOverride(String dbColumn) {
|
||||
this.dbColumn = InternString.intern(dbColumn);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,25 +11,25 @@ import java.util.List;
|
||||
/**
|
||||
* Default implementation for creating BeanControllers.
|
||||
*/
|
||||
public class BeanQueryAdapterManager {
|
||||
class BeanQueryAdapterManager {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(BeanQueryAdapterManager.class);
|
||||
|
||||
private final List<BeanQueryAdapter> list;
|
||||
|
||||
public BeanQueryAdapterManager(BootupClasses bootupClasses) {
|
||||
BeanQueryAdapterManager(BootupClasses bootupClasses) {
|
||||
|
||||
list = bootupClasses.getBeanQueryAdapters();
|
||||
}
|
||||
|
||||
public int getRegisterCount() {
|
||||
int getRegisterCount() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the BeanPersistController for a given entity type.
|
||||
*/
|
||||
public void addQueryAdapter(DeployBeanDescriptor<?> deployDesc) {
|
||||
void addQueryAdapter(DeployBeanDescriptor<?> deployDesc) {
|
||||
|
||||
for (BeanQueryAdapter c : list) {
|
||||
if (c.isRegisterFor(deployDesc.getBeanType())) {
|
||||
|
||||
@@ -32,11 +32,6 @@ public interface DbSqlContext {
|
||||
*/
|
||||
BeanProperty[] getEncryptedProps();
|
||||
|
||||
/**
|
||||
* Append a char directly to the SQL buffer.
|
||||
*/
|
||||
DbSqlContext append(char s);
|
||||
|
||||
/**
|
||||
* Append a string directly to the SQL buffer.
|
||||
*/
|
||||
|
||||
@@ -10,7 +10,7 @@ import io.ebeanservice.docstore.api.mapping.DocPropertyOptions;
|
||||
*/
|
||||
public class DeployDocPropertyOptions {
|
||||
|
||||
private static DocPropertyOptions EMPTY = new DocPropertyOptions();
|
||||
private static final DocPropertyOptions EMPTY = new DocPropertyOptions();
|
||||
|
||||
private DocPropertyOptions mapping;
|
||||
|
||||
|
||||
@@ -10,45 +10,45 @@ public abstract class DeployParser {
|
||||
/**
|
||||
* used to identify sql literal.
|
||||
*/
|
||||
protected static final char SINGLE_QUOTE = '\'';
|
||||
private static final char SINGLE_QUOTE = '\'';
|
||||
|
||||
/**
|
||||
* used to identify query named parameters.
|
||||
*/
|
||||
protected static final char COLON = ':';
|
||||
private static final char COLON = ':';
|
||||
|
||||
/**
|
||||
* Used to determine when a column name terminates.
|
||||
*/
|
||||
protected static final char UNDERSCORE = '_';
|
||||
private static final char UNDERSCORE = '_';
|
||||
|
||||
protected static final char OPEN_SQUARE_BRACKET = '[';
|
||||
protected static final char CLOSE_SQUARE_BRACKET = ']';
|
||||
protected static final char DOUBLE_QUOTE = '\"';
|
||||
protected static final char BACK_QUOTE = '`';
|
||||
private static final char OPEN_SQUARE_BRACKET = '[';
|
||||
private static final char CLOSE_SQUARE_BRACKET = ']';
|
||||
private static final char DOUBLE_QUOTE = '\"';
|
||||
private static final char BACK_QUOTE = '`';
|
||||
|
||||
/**
|
||||
* Used to determine when a column name terminates.
|
||||
*/
|
||||
protected static final char PERIOD = '.';
|
||||
private static final char PERIOD = '.';
|
||||
|
||||
protected static final char OPEN_BRACKET = '(';
|
||||
private static final char OPEN_BRACKET = '(';
|
||||
|
||||
protected boolean encrypted;
|
||||
boolean encrypted;
|
||||
|
||||
protected String source;
|
||||
private String source;
|
||||
|
||||
protected StringBuilder sb;
|
||||
private StringBuilder sb;
|
||||
|
||||
protected int sourceLength;
|
||||
private int sourceLength;
|
||||
|
||||
protected int pos;
|
||||
private int pos;
|
||||
|
||||
protected String priorWord;
|
||||
String priorWord;
|
||||
|
||||
protected String word;
|
||||
String word;
|
||||
|
||||
protected char wordTerminator;
|
||||
private char wordTerminator;
|
||||
|
||||
private StringBuilder wordBuffer;
|
||||
|
||||
@@ -98,7 +98,7 @@ public abstract class DeployParser {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
protected boolean skipWordConvert() {
|
||||
boolean skipWordConvert() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ public final class DeployUpdateParser extends DeployParser {
|
||||
}
|
||||
|
||||
// append up to the dot
|
||||
localBuffer.append(currentWord.substring(start, dotPos + 1));
|
||||
localBuffer.append(currentWord, start, dotPos + 1);
|
||||
|
||||
if (dotPos == currentWord.length() - 1) {
|
||||
// ends with a "." ???
|
||||
@@ -63,7 +63,7 @@ public final class DeployUpdateParser extends DeployParser {
|
||||
|
||||
// get the remainder after the dot
|
||||
start = dotPos + 1;
|
||||
String remainder = currentWord.substring(start, currentWord.length());
|
||||
String remainder = currentWord.substring(start);
|
||||
|
||||
String dbWord = getDeployWord(remainder);
|
||||
if (dbWord != null) {
|
||||
|
||||
@@ -5,7 +5,6 @@ import io.ebeaninternal.server.type.DataReader;
|
||||
import io.ebeaninternal.server.type.ScalarType;
|
||||
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Dynamic property based on aggregation (max, min, avg, count).
|
||||
@@ -39,7 +38,7 @@ class DynamicPropertyAggregationFormula extends DynamicPropertyBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object read(DataReader dataReader) throws SQLException {
|
||||
public Object read(DataReader dataReader) {
|
||||
try {
|
||||
return scalarType.read(dataReader);
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -11,9 +11,9 @@ import java.util.List;
|
||||
*/
|
||||
abstract class DynamicPropertyBase implements STreeProperty {
|
||||
|
||||
final String name;
|
||||
private final String name;
|
||||
final String fullName;
|
||||
final String elPrefix;
|
||||
private final String elPrefix;
|
||||
final ScalarType<?> scalarType;
|
||||
|
||||
DynamicPropertyBase(String name, String fullName, String elPrefix, ScalarType<?> scalarType) {
|
||||
|
||||
@@ -9,7 +9,7 @@ import io.ebeaninternal.server.core.InternString;
|
||||
* Used to for Assoc Manys to create references etc.
|
||||
* </p>
|
||||
*/
|
||||
public class ExportedProperty {
|
||||
class ExportedProperty {
|
||||
|
||||
private final String foreignDbColumn;
|
||||
|
||||
@@ -17,7 +17,7 @@ public class ExportedProperty {
|
||||
|
||||
private final boolean embedded;
|
||||
|
||||
public ExportedProperty(boolean embedded, String foreignDbColumn, BeanProperty property) {
|
||||
ExportedProperty(boolean embedded, String foreignDbColumn, BeanProperty property) {
|
||||
this.embedded = embedded;
|
||||
this.foreignDbColumn = InternString.intern(foreignDbColumn);
|
||||
this.property = property;
|
||||
|
||||
@@ -11,15 +11,6 @@ public class IndexDefinition {
|
||||
|
||||
private final boolean unique;
|
||||
|
||||
/**
|
||||
* A single column index.
|
||||
*/
|
||||
public IndexDefinition(String column, String name, boolean unique) {
|
||||
this.columns = new String[]{column};
|
||||
this.unique = unique;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public IndexDefinition(String[] columns, String name, boolean unique) {
|
||||
this.columns = columns;
|
||||
this.unique = unique;
|
||||
|
||||
@@ -6,11 +6,12 @@ import io.ebeaninternal.server.deploy.id.IdBinder;
|
||||
import io.ebeaninternal.server.deploy.parse.DeployInheritInfo;
|
||||
import io.ebeaninternal.server.query.SqlTreeProperties;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import javax.persistence.PersistenceException;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -33,7 +34,7 @@ public class InheritInfo {
|
||||
|
||||
private final Class<?> type;
|
||||
|
||||
private final ArrayList<InheritInfo> children = new ArrayList<>();
|
||||
private final List<InheritInfo> children = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Map of discriminator values to InheritInfo.
|
||||
@@ -111,7 +112,7 @@ public class InheritInfo {
|
||||
* return true if anything in the inheritance hierarchy has a relationship with a save cascade on
|
||||
* it.
|
||||
*/
|
||||
public boolean isSaveRecurseSkippable() {
|
||||
boolean isSaveRecurseSkippable() {
|
||||
return root.isNodeSaveRecurseSkippable();
|
||||
}
|
||||
|
||||
@@ -131,7 +132,7 @@ public class InheritInfo {
|
||||
* return true if anything in the inheritance hierarchy has a relationship with a delete cascade
|
||||
* on it.
|
||||
*/
|
||||
public boolean isDeleteRecurseSkippable() {
|
||||
boolean isDeleteRecurseSkippable() {
|
||||
return root.isNodeDeleteRecurseSkippable();
|
||||
}
|
||||
|
||||
@@ -171,14 +172,24 @@ public class InheritInfo {
|
||||
/**
|
||||
* Return the children.
|
||||
*/
|
||||
public ArrayList<InheritInfo> getChildren() {
|
||||
public List<InheritInfo> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this node has children.
|
||||
* <p>
|
||||
* When an inheritance node has no children then we don't need
|
||||
* the discriminator column as the type is effectively known.
|
||||
*/
|
||||
public boolean hasChildren() {
|
||||
return !children.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bean property additionally looking in the sub types.
|
||||
*/
|
||||
public BeanProperty findSubTypeProperty(String propertyName) {
|
||||
BeanProperty findSubTypeProperty(String propertyName) {
|
||||
|
||||
BeanProperty prop;
|
||||
|
||||
@@ -200,7 +211,6 @@ public class InheritInfo {
|
||||
|
||||
for (InheritInfo childInfo : children) {
|
||||
selectProps.add(childInfo.descriptor.propertiesLocal());
|
||||
|
||||
childInfo.addChildrenProperties(selectProps);
|
||||
}
|
||||
}
|
||||
@@ -209,15 +219,16 @@ public class InheritInfo {
|
||||
* Return the associated InheritInfo for this DB row read.
|
||||
*/
|
||||
public InheritInfo readType(DbReadContext ctx) throws SQLException {
|
||||
|
||||
String discValue = ctx.getDataReader().getString();
|
||||
return readType(discValue);
|
||||
if (!hasChildren()) {
|
||||
return this;
|
||||
}
|
||||
return readType(ctx.getDataReader().getString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the associated InheritInfo for this discriminator value.
|
||||
*/
|
||||
public InheritInfo readType(String discValue) {
|
||||
InheritInfo readType(String discValue) {
|
||||
|
||||
if (discValue == null) {
|
||||
return null;
|
||||
@@ -327,7 +338,6 @@ public class InheritInfo {
|
||||
* Return the derived where for the discriminator.
|
||||
*/
|
||||
public String getWhere() {
|
||||
|
||||
return where;
|
||||
}
|
||||
|
||||
@@ -362,7 +372,7 @@ public class InheritInfo {
|
||||
/**
|
||||
* Return the discriminator value for this node.
|
||||
*/
|
||||
public String getDiscriminatorStringValue() {
|
||||
String getDiscriminatorStringValue() {
|
||||
return discriminatorStringValue;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
package io.ebeaninternal.server.deploy;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* Helper object to find generic parameter types for a given class.
|
||||
*/
|
||||
public class ParamTypeUtil {
|
||||
|
||||
/**
|
||||
* Find and return the parameter type given a generic interface or class.
|
||||
* <p>
|
||||
* This assumes there is only one generic parameter.
|
||||
* </p>
|
||||
* <p>
|
||||
* Returns null if no match was found.
|
||||
* </p>
|
||||
*
|
||||
* @param cls the class to search for the parameter type
|
||||
* @param matchType the type which has the generic parameter
|
||||
*/
|
||||
public static Class<?> findParamType(Class<?> cls, Class<?> matchType) {
|
||||
|
||||
// search for: implementing a generic interface
|
||||
Type paramType = matchByInterfaces(cls, matchType);
|
||||
if (paramType == null) {
|
||||
// search for: extending a generic class
|
||||
Type genericSuperclass = cls.getGenericSuperclass();
|
||||
if (genericSuperclass != null) {
|
||||
paramType = matchParamType(genericSuperclass, matchType);
|
||||
}
|
||||
}
|
||||
|
||||
if (paramType instanceof Class<?>) {
|
||||
// only interested in classes
|
||||
return (Class<?>) paramType;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the type is a generic one with parameters and of the correct type we are
|
||||
* searching for. Return the parameter type if this matches otherwise return null.
|
||||
*/
|
||||
private static Type matchParamType(Type type, Class<?> matchType) {
|
||||
if (type instanceof ParameterizedType) {
|
||||
ParameterizedType pt = (ParameterizedType) type;
|
||||
Type rawType = pt.getRawType();
|
||||
boolean isAssignable = matchType.isAssignableFrom((Class<?>) rawType);
|
||||
if (isAssignable) {
|
||||
// assume there is only one parameter type
|
||||
Type[] typeArguments = pt.getActualTypeArguments();
|
||||
if (typeArguments.length != 1) {
|
||||
String m = "Expecting only 1 generic paramater but got " + typeArguments.length + " for " + type;
|
||||
throw new RuntimeException(m);
|
||||
}
|
||||
return typeArguments[0];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search the interfaces this class implements.
|
||||
*/
|
||||
private static Type matchByInterfaces(Class<?> cls, Class<?> matchType) {
|
||||
|
||||
Type[] gis = cls.getGenericInterfaces();
|
||||
for (Type gi : gis) {
|
||||
Type match = matchParamType(gi, matchType);
|
||||
if (match != null) {
|
||||
return match;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -11,25 +11,25 @@ import java.util.List;
|
||||
/**
|
||||
* Default implementation for creating BeanControllers.
|
||||
*/
|
||||
public class PersistControllerManager {
|
||||
class PersistControllerManager {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(PersistControllerManager.class);
|
||||
|
||||
private final List<BeanPersistController> list;
|
||||
|
||||
public PersistControllerManager(BootupClasses bootupClasses) {
|
||||
PersistControllerManager(BootupClasses bootupClasses) {
|
||||
|
||||
list = bootupClasses.getBeanPersistControllers();
|
||||
}
|
||||
|
||||
public int getRegisterCount() {
|
||||
int getRegisterCount() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the BeanPersistController for a given entity type.
|
||||
*/
|
||||
public void addPersistControllers(DeployBeanDescriptor<?> deployDesc) {
|
||||
void addPersistControllers(DeployBeanDescriptor<?> deployDesc) {
|
||||
|
||||
for (BeanPersistController c : list) {
|
||||
if (c.isRegisterFor(deployDesc.getBeanType())) {
|
||||
|
||||
@@ -12,24 +12,24 @@ import java.util.List;
|
||||
* Manages the assignment/registration of BeanPersistListener with their
|
||||
* respective DeployBeanDescriptor's.
|
||||
*/
|
||||
public class PersistListenerManager {
|
||||
class PersistListenerManager {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(PersistListenerManager.class);
|
||||
|
||||
private final List<BeanPersistListener> list;
|
||||
|
||||
public PersistListenerManager(BootupClasses bootupClasses) {
|
||||
PersistListenerManager(BootupClasses bootupClasses) {
|
||||
list = bootupClasses.getBeanPersistListeners();
|
||||
}
|
||||
|
||||
public int getRegisterCount() {
|
||||
int getRegisterCount() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the BeanPersistController for a given entity type.
|
||||
*/
|
||||
public <T> void addPersistListeners(DeployBeanDescriptor<T> deployDesc) {
|
||||
<T> void addPersistListeners(DeployBeanDescriptor<T> deployDesc) {
|
||||
|
||||
for (BeanPersistListener listener : list) {
|
||||
if (listener.isRegisterFor(deployDesc.getBeanType())) {
|
||||
|
||||
@@ -11,24 +11,24 @@ import java.util.List;
|
||||
/**
|
||||
* Default implementation for creating BeanControllers.
|
||||
*/
|
||||
public class PostConstructManager {
|
||||
class PostConstructManager {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(PostConstructManager.class);
|
||||
|
||||
private final List<BeanPostConstructListener> list;
|
||||
|
||||
public PostConstructManager(BootupClasses bootupClasses) {
|
||||
PostConstructManager(BootupClasses bootupClasses) {
|
||||
this.list = bootupClasses.getBeanPostConstructoListeners();
|
||||
}
|
||||
|
||||
public int getRegisterCount() {
|
||||
int getRegisterCount() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register BeanPostLoad listeners for a given entity type.
|
||||
*/
|
||||
public void addPostConstructListeners(DeployBeanDescriptor<?> deployDesc) {
|
||||
void addPostConstructListeners(DeployBeanDescriptor<?> deployDesc) {
|
||||
|
||||
for (BeanPostConstructListener c : list) {
|
||||
if (c.isRegisterFor(deployDesc.getBeanType())) {
|
||||
|
||||
@@ -11,24 +11,24 @@ import java.util.List;
|
||||
/**
|
||||
* Default implementation for creating BeanControllers.
|
||||
*/
|
||||
public class PostLoadManager {
|
||||
class PostLoadManager {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(PostLoadManager.class);
|
||||
|
||||
private final List<BeanPostLoad> list;
|
||||
|
||||
public PostLoadManager(BootupClasses bootupClasses) {
|
||||
PostLoadManager(BootupClasses bootupClasses) {
|
||||
this.list = bootupClasses.getBeanPostLoaders();
|
||||
}
|
||||
|
||||
public int getRegisterCount() {
|
||||
int getRegisterCount() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register BeanPostLoad listeners for a given entity type.
|
||||
*/
|
||||
public void addPostLoad(DeployBeanDescriptor<?> deployDesc) {
|
||||
void addPostLoad(DeployBeanDescriptor<?> deployDesc) {
|
||||
|
||||
for (BeanPostLoad c : list) {
|
||||
if (c.isRegisterFor(deployDesc.getBeanType())) {
|
||||
|
||||
@@ -33,11 +33,17 @@ public final class TableJoin {
|
||||
*/
|
||||
private final int queryHash;
|
||||
|
||||
private final PropertyForeignKey foreignKey;
|
||||
|
||||
public TableJoin(DeployTableJoin deploy) {
|
||||
this(deploy, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a TableJoin.
|
||||
*/
|
||||
public TableJoin(DeployTableJoin deploy) {
|
||||
|
||||
public TableJoin(DeployTableJoin deploy, PropertyForeignKey foreignKey) {
|
||||
this.foreignKey = foreignKey;
|
||||
this.table = InternString.intern(deploy.getTable());
|
||||
this.type = deploy.getType();
|
||||
this.inheritInfo = deploy.getInheritInfo();
|
||||
@@ -52,6 +58,7 @@ public final class TableJoin {
|
||||
}
|
||||
|
||||
private TableJoin(TableJoin source, String overrideColumn) {
|
||||
this.foreignKey = null;
|
||||
this.table = source.table;
|
||||
this.type = source.type;
|
||||
this.inheritInfo = source.inheritInfo;
|
||||
@@ -96,14 +103,6 @@ public final class TableJoin {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return a hash value for adding to a query plan.
|
||||
*/
|
||||
public int queryHash() {
|
||||
return queryHash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(30);
|
||||
@@ -114,6 +113,13 @@ public final class TableJoin {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the foreign key options.
|
||||
*/
|
||||
public PropertyForeignKey getForeignKey() {
|
||||
return foreignKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the join columns.
|
||||
*/
|
||||
@@ -128,21 +134,13 @@ public final class TableJoin {
|
||||
return table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type of join. LEFT JOIN etc.
|
||||
*/
|
||||
public SqlJoinType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public SqlJoinType addJoin(SqlJoinType joinType, String prefix, DbSqlContext ctx, String predicate) {
|
||||
public void addJoin(SqlJoinType joinType, String prefix, DbSqlContext ctx, String predicate) {
|
||||
String[] names = SplitName.split(prefix);
|
||||
String a1 = ctx.getTableAlias(names[0]);
|
||||
String a2 = ctx.getTableAlias(prefix);
|
||||
|
||||
SqlJoinType returnJoinType = addJoin(joinType, a1, a2, ctx);
|
||||
addJoin(joinType, a1, a2, ctx);
|
||||
ctx.append("and ").append(a2).append(predicate);
|
||||
return returnJoinType;
|
||||
}
|
||||
|
||||
public SqlJoinType addJoin(SqlJoinType joinType, String prefix, DbSqlContext ctx) {
|
||||
|
||||
@@ -56,7 +56,7 @@ public class TableJoinColumn {
|
||||
this.queryHash = hash();
|
||||
}
|
||||
|
||||
int hash() {
|
||||
private int hash() {
|
||||
int result = localDbColumn != null ? localDbColumn.hashCode() : 0;
|
||||
result = 92821 * result + (foreignDbColumn != null ? foreignDbColumn.hashCode() : 0);
|
||||
result = 92821 * result + (localSqlFormula != null ? localSqlFormula.hashCode() : 0);
|
||||
@@ -93,7 +93,7 @@ public class TableJoinColumn {
|
||||
/**
|
||||
* Return a hash for including in a query plan.
|
||||
*/
|
||||
public int queryHash() {
|
||||
int queryHash() {
|
||||
return queryHash;
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ public class TableJoinColumn {
|
||||
/**
|
||||
* Return true if this column should be updateable.
|
||||
*/
|
||||
public boolean isUpdateable() {
|
||||
boolean isUpdateable() {
|
||||
return updateable;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,11 +13,11 @@ import java.sql.Types;
|
||||
* Aka, Integer, Long, Short etc.
|
||||
* </p>
|
||||
*/
|
||||
public class CounterFactory {
|
||||
class CounterFactory {
|
||||
|
||||
final GeneratedCounterInteger integerCounter = new GeneratedCounterInteger();
|
||||
private final GeneratedCounterInteger integerCounter = new GeneratedCounterInteger();
|
||||
|
||||
final GeneratedCounterLong longCounter = new GeneratedCounterLong();
|
||||
private final GeneratedCounterLong longCounter = new GeneratedCounterLong();
|
||||
|
||||
public void setCounter(DeployBeanProperty property) {
|
||||
|
||||
|
||||
+2
-2
@@ -9,9 +9,9 @@ import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
*/
|
||||
public class GeneratedCounter implements GeneratedProperty {
|
||||
|
||||
final int numberType;
|
||||
private final int numberType;
|
||||
|
||||
public GeneratedCounter(int numberType) {
|
||||
GeneratedCounter(int numberType) {
|
||||
this.numberType = numberType;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ public class GeneratedPropertyFactory {
|
||||
}
|
||||
}
|
||||
|
||||
public void setCounter(DeployBeanProperty property) {
|
||||
private void setCounter(DeployBeanProperty property) {
|
||||
|
||||
counterFactory.setCounter(property);
|
||||
}
|
||||
|
||||
+2
-2
@@ -9,9 +9,9 @@ import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
*/
|
||||
public class GeneratedWhoCreated implements GeneratedProperty {
|
||||
|
||||
final CurrentUserProvider currentUserProvider;
|
||||
private final CurrentUserProvider currentUserProvider;
|
||||
|
||||
public GeneratedWhoCreated(CurrentUserProvider currentUserProvider) {
|
||||
GeneratedWhoCreated(CurrentUserProvider currentUserProvider) {
|
||||
this.currentUserProvider = currentUserProvider;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -9,9 +9,9 @@ import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
*/
|
||||
public class GeneratedWhoModified implements GeneratedProperty {
|
||||
|
||||
final CurrentUserProvider currentUserProvider;
|
||||
private final CurrentUserProvider currentUserProvider;
|
||||
|
||||
public GeneratedWhoModified(CurrentUserProvider currentUserProvider) {
|
||||
GeneratedWhoModified(CurrentUserProvider currentUserProvider) {
|
||||
this.currentUserProvider = currentUserProvider;
|
||||
}
|
||||
|
||||
|
||||
+6
-8
@@ -15,15 +15,14 @@ import java.util.Map;
|
||||
/**
|
||||
* Helper for creating Insert timestamp GeneratedProperty objects.
|
||||
*/
|
||||
public class InsertTimestampFactory {
|
||||
class InsertTimestampFactory {
|
||||
|
||||
final GeneratedInsertLong longTime = new GeneratedInsertLong();
|
||||
private final Map<Class<?>, GeneratedProperty> map = new HashMap<>();
|
||||
|
||||
final Map<Class<?>, GeneratedProperty> map = new HashMap<>();
|
||||
|
||||
public InsertTimestampFactory(ClassLoadConfig classLoadConfig) {
|
||||
InsertTimestampFactory(ClassLoadConfig classLoadConfig) {
|
||||
map.put(Timestamp.class, new GeneratedInsertTimestamp());
|
||||
map.put(java.util.Date.class, new GeneratedInsertDate());
|
||||
GeneratedInsertLong longTime = new GeneratedInsertLong();
|
||||
map.put(Long.class, longTime);
|
||||
map.put(long.class, longTime);
|
||||
|
||||
@@ -37,10 +36,9 @@ public class InsertTimestampFactory {
|
||||
map.put(org.joda.time.LocalDateTime.class, new GeneratedInsertJodaTime.LocalDT());
|
||||
map.put(org.joda.time.DateTime.class, new GeneratedInsertJodaTime.DateTimeDT());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void setInsertTimestamp(DeployBeanProperty property) {
|
||||
void setInsertTimestamp(DeployBeanProperty property) {
|
||||
|
||||
property.setGeneratedProperty(createInsertTimestamp(property));
|
||||
}
|
||||
@@ -48,7 +46,7 @@ public class InsertTimestampFactory {
|
||||
/**
|
||||
* Create the insert GeneratedProperty depending on the property type.
|
||||
*/
|
||||
public GeneratedProperty createInsertTimestamp(DeployBeanProperty property) {
|
||||
GeneratedProperty createInsertTimestamp(DeployBeanProperty property) {
|
||||
|
||||
Class<?> propType = property.getPropertyType();
|
||||
GeneratedProperty generatedProperty = map.get(propType);
|
||||
|
||||
@@ -9,7 +9,7 @@ import java.time.ZonedDateTime;
|
||||
/**
|
||||
* Helper methods for Java time conversion.
|
||||
*/
|
||||
public class JavaTimeUtils {
|
||||
class JavaTimeUtils {
|
||||
|
||||
/**
|
||||
* Return the system millis time as a LocalDateTime.
|
||||
@@ -21,21 +21,21 @@ public class JavaTimeUtils {
|
||||
/**
|
||||
* Return the system millis time as a LocalDateTime.
|
||||
*/
|
||||
public static Object toLocalDateTime(long systemMillis) {
|
||||
static Object toLocalDateTime(long systemMillis) {
|
||||
return new Timestamp(systemMillis).toLocalDateTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the system millis time as a OffsetDateTime.
|
||||
*/
|
||||
public static Object toOffsetDateTime(long systemMillis) {
|
||||
static Object toOffsetDateTime(long systemMillis) {
|
||||
return OffsetDateTime.ofInstant(Instant.ofEpochMilli(systemMillis), ZoneId.systemDefault());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the system millis time as a ZonedDateTime.
|
||||
*/
|
||||
public static Object toZonedDateTime(long systemMillis) {
|
||||
static Object toZonedDateTime(long systemMillis) {
|
||||
return ZonedDateTime.ofInstant(Instant.ofEpochMilli(systemMillis), ZoneId.systemDefault());
|
||||
}
|
||||
}
|
||||
|
||||
+6
-7
@@ -15,15 +15,14 @@ import java.util.Map;
|
||||
/**
|
||||
* Helper for creating Update timestamp GeneratedProperty objects.
|
||||
*/
|
||||
public class UpdateTimestampFactory {
|
||||
class UpdateTimestampFactory {
|
||||
|
||||
final GeneratedUpdateLong longTime = new GeneratedUpdateLong();
|
||||
private final Map<Class<?>, GeneratedProperty> map = new HashMap<>();
|
||||
|
||||
final Map<Class<?>, GeneratedProperty> map = new HashMap<>();
|
||||
|
||||
public UpdateTimestampFactory(ClassLoadConfig classLoadConfig) {
|
||||
UpdateTimestampFactory(ClassLoadConfig classLoadConfig) {
|
||||
map.put(Timestamp.class, new GeneratedUpdateTimestamp());
|
||||
map.put(java.util.Date.class, new GeneratedUpdateDate());
|
||||
GeneratedUpdateLong longTime = new GeneratedUpdateLong();
|
||||
map.put(Long.class, longTime);
|
||||
map.put(long.class, longTime);
|
||||
|
||||
@@ -39,7 +38,7 @@ public class UpdateTimestampFactory {
|
||||
}
|
||||
}
|
||||
|
||||
public void setUpdateTimestamp(DeployBeanProperty property) {
|
||||
void setUpdateTimestamp(DeployBeanProperty property) {
|
||||
|
||||
property.setGeneratedProperty(createUpdateTimestamp(property));
|
||||
}
|
||||
@@ -47,7 +46,7 @@ public class UpdateTimestampFactory {
|
||||
/**
|
||||
* Create the update GeneratedProperty depending on the property type.
|
||||
*/
|
||||
protected GeneratedProperty createUpdateTimestamp(DeployBeanProperty property) {
|
||||
GeneratedProperty createUpdateTimestamp(DeployBeanProperty property) {
|
||||
|
||||
Class<?> propType = property.getPropertyType();
|
||||
GeneratedProperty generatedProperty = map.get(propType);
|
||||
|
||||
@@ -10,8 +10,6 @@ import io.ebeaninternal.server.type.DataBind;
|
||||
|
||||
import java.io.DataInput;
|
||||
import java.io.DataOutput;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@@ -127,7 +125,7 @@ public final class IdBinderEmpty implements IdBinder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bindId(DataBind dataBind, Object value) throws SQLException {
|
||||
public void bindId(DataBind dataBind, Object value) {
|
||||
|
||||
}
|
||||
|
||||
@@ -146,12 +144,12 @@ public final class IdBinderEmpty implements IdBinder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object readSet(DbReadContext ctx, EntityBean bean) throws SQLException {
|
||||
public Object readSet(DbReadContext ctx, EntityBean bean) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object read(DbReadContext ctx) throws SQLException {
|
||||
public Object read(DbReadContext ctx) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -170,12 +168,12 @@ public final class IdBinderEmpty implements IdBinder {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object readData(DataInput dataOutput) throws IOException {
|
||||
public Object readData(DataInput dataOutput) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutput dataOutput, Object idValue) throws IOException {
|
||||
public void writeData(DataOutput dataOutput, Object idValue) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -35,17 +35,15 @@ public final class ImportedIdSimple implements ImportedId, Comparable<ImportedId
|
||||
|
||||
private static final EntryComparator COMPARATOR = new EntryComparator();
|
||||
|
||||
protected final BeanPropertyAssoc<?> owner;
|
||||
final BeanPropertyAssoc<?> owner;
|
||||
|
||||
protected final String localDbColumn;
|
||||
final String localDbColumn;
|
||||
|
||||
protected final String localSqlFormula;
|
||||
private final String localSqlFormula;
|
||||
|
||||
protected final String logicalName;
|
||||
final BeanProperty foreignProperty;
|
||||
|
||||
protected final BeanProperty foreignProperty;
|
||||
|
||||
protected final int position;
|
||||
private final int position;
|
||||
|
||||
/**
|
||||
* If true include in insert.
|
||||
@@ -66,7 +64,6 @@ public final class ImportedIdSimple implements ImportedId, Comparable<ImportedId
|
||||
this.position = position;
|
||||
this.insertable = insertable;
|
||||
this.updateable = updateable;
|
||||
this.logicalName = InternString.intern(owner.getName() + "." + foreignProperty.getName());
|
||||
}
|
||||
|
||||
public ImportedIdSimple(BeanPropertyAssoc<?> owner, String localDbColumn, String localSqlFormula, BeanProperty foreignProperty, int position) {
|
||||
@@ -88,7 +85,7 @@ public final class ImportedIdSimple implements ImportedId, Comparable<ImportedId
|
||||
/**
|
||||
* Return true if it should be included in the update (or insert).
|
||||
*/
|
||||
public boolean isInclude(boolean update) {
|
||||
boolean isInclude(boolean update) {
|
||||
return (update) ? updateable : insertable;
|
||||
}
|
||||
|
||||
@@ -158,7 +155,6 @@ public final class ImportedIdSimple implements ImportedId, Comparable<ImportedId
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void dmlAppend(GenerateDmlRequest request) {
|
||||
request.appendColumn(localDbColumn);
|
||||
|
||||
@@ -37,7 +37,6 @@ import io.ebeaninternal.server.rawsql.SpiRawSql;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
@@ -181,11 +180,6 @@ public class DeployBeanDescriptor<T> {
|
||||
*/
|
||||
private BeanFindController beanFinder;
|
||||
|
||||
/**
|
||||
* The table joins for this bean. Server side only.
|
||||
*/
|
||||
private final ArrayList<DeployTableJoin> tableJoinList = new ArrayList<>(2);
|
||||
|
||||
/**
|
||||
* Inheritance information. Server side only.
|
||||
*/
|
||||
@@ -245,7 +239,7 @@ public class DeployBeanDescriptor<T> {
|
||||
/**
|
||||
* Return true if there is a IdClass set.
|
||||
*/
|
||||
public boolean isIdClass() {
|
||||
boolean isIdClass() {
|
||||
return idClass != null;
|
||||
}
|
||||
|
||||
@@ -270,13 +264,6 @@ public class DeployBeanDescriptor<T> {
|
||||
return manager.getDeploy(cls);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this beanType is an abstract class.
|
||||
*/
|
||||
public boolean isAbstract() {
|
||||
return Modifier.isAbstract(beanType.getModifiers());
|
||||
}
|
||||
|
||||
public void setStorageEngine(String storageEngine) {
|
||||
this.storageEngine = storageEngine;
|
||||
}
|
||||
@@ -502,7 +489,7 @@ public class DeployBeanDescriptor<T> {
|
||||
return cacheOptions;
|
||||
}
|
||||
|
||||
public DeployBeanPropertyAssocOne<?> getIdClassProperty() {
|
||||
DeployBeanPropertyAssocOne<?> getIdClassProperty() {
|
||||
return idClassProperty;
|
||||
}
|
||||
|
||||
@@ -518,7 +505,7 @@ public class DeployBeanDescriptor<T> {
|
||||
this.orderColumn = orderColumn;
|
||||
}
|
||||
|
||||
public DeployBeanProperty getOrderColumn() {
|
||||
DeployBeanProperty getOrderColumn() {
|
||||
return orderColumn;
|
||||
}
|
||||
|
||||
@@ -949,17 +936,6 @@ public class DeployBeanDescriptor<T> {
|
||||
return getFullName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a TableJoin to this type of bean. For Secondary table properties.
|
||||
*/
|
||||
public void addTableJoin(DeployTableJoin join) {
|
||||
tableJoinList.add(join);
|
||||
}
|
||||
|
||||
List<DeployTableJoin> getTableJoins() {
|
||||
return tableJoinList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a collection of all BeanProperty deployment information.
|
||||
*/
|
||||
@@ -1268,7 +1244,7 @@ public class DeployBeanDescriptor<T> {
|
||||
* Returns the jackson annotated class, if jackson is present.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public Object /*AnnotatedClass*/ getJacksonAnnotatedClass() {
|
||||
Object /*AnnotatedClass*/ getJacksonAnnotatedClass() {
|
||||
if (jacksonAnnotatedClass == null) {
|
||||
jacksonAnnotatedClass = new DeployBeanObtainJackson(serverConfig, beanType).obtain();
|
||||
}
|
||||
|
||||
@@ -188,7 +188,7 @@ public class DeployBeanProperty {
|
||||
*/
|
||||
private int dbType;
|
||||
|
||||
private DeployDocPropertyOptions docMapping = new DeployDocPropertyOptions();
|
||||
private final DeployDocPropertyOptions docMapping = new DeployDocPropertyOptions();
|
||||
|
||||
/**
|
||||
* The method used to read the property.
|
||||
@@ -206,7 +206,7 @@ public class DeployBeanProperty {
|
||||
*/
|
||||
private GeneratedProperty generatedProperty;
|
||||
|
||||
protected final DeployBeanDescriptor<?> desc;
|
||||
final DeployBeanDescriptor<?> desc;
|
||||
|
||||
private boolean undirectionalShadow;
|
||||
|
||||
@@ -329,7 +329,7 @@ public class DeployBeanProperty {
|
||||
/**
|
||||
* Return the sortOrder for the properties.
|
||||
*/
|
||||
public int getSortOrder() {
|
||||
int getSortOrder() {
|
||||
return sortOrder;
|
||||
}
|
||||
|
||||
@@ -357,7 +357,7 @@ public class DeployBeanProperty {
|
||||
/**
|
||||
* Mark this property as mapping to the discriminator column.
|
||||
*/
|
||||
public void setDiscriminator() {
|
||||
void setDiscriminator() {
|
||||
this.discriminator = true;
|
||||
}
|
||||
|
||||
@@ -524,7 +524,7 @@ public class DeployBeanProperty {
|
||||
return naturalKey;
|
||||
}
|
||||
|
||||
public void setNaturalKey() {
|
||||
void setNaturalKey() {
|
||||
this.naturalKey = true;
|
||||
}
|
||||
|
||||
@@ -763,29 +763,21 @@ public class DeployBeanProperty {
|
||||
return lob;
|
||||
}
|
||||
|
||||
public boolean isDbNumberType() {
|
||||
boolean isDbNumberType() {
|
||||
return isNumericType(dbType);
|
||||
}
|
||||
|
||||
private boolean isNumericType(int type) {
|
||||
switch (type) {
|
||||
case Types.BIGINT:
|
||||
return true;
|
||||
case Types.DECIMAL:
|
||||
return true;
|
||||
case Types.DOUBLE:
|
||||
return true;
|
||||
case Types.FLOAT:
|
||||
return true;
|
||||
case Types.INTEGER:
|
||||
return true;
|
||||
case Types.NUMERIC:
|
||||
return true;
|
||||
case Types.REAL:
|
||||
return true;
|
||||
case Types.SMALLINT:
|
||||
return true;
|
||||
case Types.TINYINT:
|
||||
case Types.SMALLINT:
|
||||
case Types.REAL:
|
||||
case Types.NUMERIC:
|
||||
case Types.INTEGER:
|
||||
case Types.FLOAT:
|
||||
case Types.DOUBLE:
|
||||
return true;
|
||||
|
||||
default:
|
||||
|
||||
@@ -12,7 +12,7 @@ public abstract class DeployBeanPropertyAssoc<T> extends DeployBeanProperty {
|
||||
/**
|
||||
* The type of the joined bean.
|
||||
*/
|
||||
protected Class<T> targetType;
|
||||
Class<T> targetType;
|
||||
|
||||
/**
|
||||
* Persist settings.
|
||||
@@ -27,7 +27,7 @@ public abstract class DeployBeanPropertyAssoc<T> extends DeployBeanProperty {
|
||||
/**
|
||||
* Join between the beans.
|
||||
*/
|
||||
protected final DeployTableJoin tableJoin = new DeployTableJoin();
|
||||
final DeployTableJoin tableJoin = new DeployTableJoin();
|
||||
|
||||
/**
|
||||
* Literal added to where clause of lazy loading query.
|
||||
|
||||
@@ -66,8 +66,6 @@ public class DeployBeanPropertyLists {
|
||||
|
||||
private final List<BeanProperty> nonTransients = new ArrayList<>();
|
||||
|
||||
private final TableJoin[] tableJoins;
|
||||
|
||||
private final BeanPropertyAssocOne<?> unidirectional;
|
||||
private final BeanProperty orderColumn;
|
||||
|
||||
@@ -138,12 +136,6 @@ public class DeployBeanPropertyLists {
|
||||
// (after the real properties have been organised into their lists)
|
||||
propertyMap.put(discProperty.getName(), discProperty);
|
||||
}
|
||||
|
||||
List<DeployTableJoin> deployTableJoins = deploy.getTableJoins();
|
||||
tableJoins = new TableJoin[deployTableJoins.size()];
|
||||
for (int i = 0; i < deployTableJoins.size(); i++) {
|
||||
tableJoins[i] = new TableJoin(deployTableJoins.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -275,10 +267,6 @@ public class DeployBeanPropertyLists {
|
||||
return propertyMap;
|
||||
}
|
||||
|
||||
public TableJoin[] getTableJoin() {
|
||||
return tableJoins;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the base scalar properties (excludes Id and secondary table
|
||||
* properties).
|
||||
|
||||
@@ -13,27 +13,26 @@ public class DeployTableJoinColumn {
|
||||
/**
|
||||
* The local database column name.
|
||||
*/
|
||||
String localDbColumn;
|
||||
private String localDbColumn;
|
||||
|
||||
/**
|
||||
* SQL formula used for local column
|
||||
*/
|
||||
String localSqlFormula;
|
||||
private String localSqlFormula;
|
||||
|
||||
/**
|
||||
* The foreign database column name.
|
||||
*/
|
||||
String foreignDbColumn;
|
||||
private String foreignDbColumn;
|
||||
|
||||
/**
|
||||
* SQL formula used for foreign column
|
||||
*/
|
||||
String foreignSqlFormula;
|
||||
private String foreignSqlFormula;
|
||||
|
||||
boolean insertable;
|
||||
|
||||
boolean updateable;
|
||||
private boolean insertable;
|
||||
|
||||
private boolean updateable;
|
||||
|
||||
/**
|
||||
* Construct when automatically determining the join.
|
||||
@@ -55,7 +54,7 @@ public class DeployTableJoinColumn {
|
||||
this.updateable = updateable;
|
||||
}
|
||||
|
||||
public void setLocalSqlFormula(String localSqlFormula) {
|
||||
void setLocalSqlFormula(String localSqlFormula) {
|
||||
if (localSqlFormula != null) {
|
||||
this.localSqlFormula = localSqlFormula;
|
||||
this.localDbColumn = null;
|
||||
@@ -178,7 +177,7 @@ public class DeployTableJoinColumn {
|
||||
/**
|
||||
* Set the local database column name.
|
||||
*/
|
||||
public void setLocalDbColumn(String localDbColumn) {
|
||||
void setLocalDbColumn(String localDbColumn) {
|
||||
this.localDbColumn = localDbColumn;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import io.ebean.config.BeanNotRegisteredException;
|
||||
import io.ebean.config.NamingConvention;
|
||||
import io.ebean.config.TableName;
|
||||
import io.ebean.util.CamelCaseHelper;
|
||||
import io.ebean.util.StringHelper;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptorManager;
|
||||
import io.ebeaninternal.server.deploy.BeanProperty;
|
||||
import io.ebeaninternal.server.deploy.BeanTable;
|
||||
@@ -41,6 +40,8 @@ import javax.persistence.OrderBy;
|
||||
import javax.persistence.OrderColumn;
|
||||
import java.util.Set;
|
||||
|
||||
import static io.ebean.util.StringHelper.isNull;
|
||||
|
||||
/**
|
||||
* Read the deployment annotation for Assoc Many beans.
|
||||
*/
|
||||
@@ -68,12 +69,21 @@ class AnnotationAssocManys extends AnnotationParser {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean readOrphanRemoval(OneToMany property) {
|
||||
try {
|
||||
return property.orphanRemoval();
|
||||
} catch (NoSuchMethodError e) {
|
||||
// Support old JPA API
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void read(DeployBeanPropertyAssocMany<?> prop) {
|
||||
|
||||
OneToMany oneToMany = get(prop, OneToMany.class);
|
||||
if (oneToMany != null) {
|
||||
readToOne(oneToMany, prop);
|
||||
if (oneToMany.orphanRemoval()) {
|
||||
if (readOrphanRemoval(oneToMany)) {
|
||||
prop.setModifyListenMode(ModifyListenMode.REMOVALS);
|
||||
prop.getCascadeInfo().setDelete(true);
|
||||
}
|
||||
@@ -164,7 +174,6 @@ class AnnotationAssocManys extends AnnotationParser {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!prop.getTableJoin().hasJoinColumns() && beanTable != null) {
|
||||
|
||||
// use naming convention to define join (based on the bean name for this side of relationship)
|
||||
@@ -340,14 +349,18 @@ class AnnotationAssocManys extends AnnotationParser {
|
||||
* Return the full table name
|
||||
*/
|
||||
private String getFullTableName(JoinTable joinTable) {
|
||||
return append(joinTable.catalog(), joinTable.schema(), joinTable.name());
|
||||
}
|
||||
|
||||
private String append(String catalog, String schema, String name) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (!StringHelper.isNull(joinTable.catalog())) {
|
||||
sb.append(joinTable.catalog()).append(".");
|
||||
if (!isNull(catalog)) {
|
||||
sb.append(catalog).append(".");
|
||||
}
|
||||
if (!StringHelper.isNull(joinTable.schema())) {
|
||||
sb.append(joinTable.schema()).append(".");
|
||||
if (!isNull(schema)) {
|
||||
sb.append(schema).append(".");
|
||||
}
|
||||
sb.append(joinTable.name());
|
||||
sb.append(name);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -358,15 +371,7 @@ class AnnotationAssocManys extends AnnotationParser {
|
||||
if (collectionTable == null || collectionTable.name().isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (!StringHelper.isNull(collectionTable.catalog())) {
|
||||
sb.append(collectionTable.catalog()).append(".");
|
||||
}
|
||||
if (!StringHelper.isNull(collectionTable.schema())) {
|
||||
sb.append(collectionTable.schema()).append(".");
|
||||
}
|
||||
sb.append(collectionTable.name());
|
||||
return sb.toString();
|
||||
return append(collectionTable.catalog(), collectionTable.schema(), collectionTable.name());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -444,26 +449,11 @@ class AnnotationAssocManys extends AnnotationParser {
|
||||
|
||||
manyProp.setMappedBy(propAnn.mappedBy());
|
||||
manyProp.setFetchType(propAnn.fetch());
|
||||
|
||||
setCascadeTypes(propAnn.cascade(), manyProp.getCascadeInfo());
|
||||
|
||||
Class<?> targetType = propAnn.targetEntity();
|
||||
if (targetType.equals(void.class)) {
|
||||
// via reflection of generics type
|
||||
targetType = manyProp.getTargetType();
|
||||
} else {
|
||||
manyProp.setTargetType(targetType);
|
||||
}
|
||||
|
||||
// find the other many table (not intersection)
|
||||
BeanTable assoc = factory.getBeanTable(targetType);
|
||||
if (assoc == null) {
|
||||
throw new BeanNotRegisteredException(errorMsgMissingBeanTable(targetType, manyProp.getFullBeanName()));
|
||||
}
|
||||
|
||||
setTargetType(propAnn.targetEntity(), manyProp);
|
||||
setBeanTable(manyProp);
|
||||
manyProp.setManyToMany();
|
||||
manyProp.setModifyListenMode(ModifyListenMode.ALL);
|
||||
manyProp.setBeanTable(assoc);
|
||||
manyProp.getTableJoin().setType(SqlJoinType.OUTER);
|
||||
}
|
||||
|
||||
@@ -471,34 +461,31 @@ class AnnotationAssocManys extends AnnotationParser {
|
||||
|
||||
manyProp.setMappedBy(propAnn.mappedBy());
|
||||
manyProp.setFetchType(propAnn.fetch());
|
||||
|
||||
setCascadeTypes(propAnn.cascade(), manyProp.getCascadeInfo());
|
||||
|
||||
Class<?> targetType = propAnn.targetEntity();
|
||||
if (targetType.equals(void.class)) {
|
||||
// via reflection of generics type
|
||||
targetType = manyProp.getTargetType();
|
||||
} else {
|
||||
manyProp.setTargetType(targetType);
|
||||
}
|
||||
|
||||
BeanTable assoc = factory.getBeanTable(targetType);
|
||||
if (assoc == null) {
|
||||
throw new BeanNotRegisteredException(errorMsgMissingBeanTable(targetType, manyProp.getFullBeanName()));
|
||||
}
|
||||
|
||||
manyProp.setBeanTable(assoc);
|
||||
setTargetType(propAnn.targetEntity(), manyProp);
|
||||
setBeanTable(manyProp);
|
||||
manyProp.getTableJoin().setType(SqlJoinType.OUTER);
|
||||
}
|
||||
|
||||
private void setTargetType(Class<?> targetType, DeployBeanPropertyAssocMany<?> prop) {
|
||||
if (!targetType.equals(void.class)) {
|
||||
prop.setTargetType(targetType);
|
||||
}
|
||||
}
|
||||
|
||||
private void setBeanTable(DeployBeanPropertyAssocMany<?> manyProp) {
|
||||
BeanTable assoc = factory.getBeanTable(manyProp.getTargetType());
|
||||
if (assoc == null) {
|
||||
throw new BeanNotRegisteredException(errorMsgMissingBeanTable(manyProp.getTargetType(), manyProp.getFullBeanName()));
|
||||
}
|
||||
manyProp.setBeanTable(assoc);
|
||||
}
|
||||
|
||||
private String getM2MJoinTableName(BeanTable lhsTable, BeanTable rhsTable) {
|
||||
|
||||
TableName lhs = new TableName(lhsTable.getBaseTable());
|
||||
TableName rhs = new TableName(rhsTable.getBaseTable());
|
||||
|
||||
TableName joinTable = namingConvention.getM2MJoinTableName(lhs, rhs);
|
||||
|
||||
return joinTable.getQualifiedName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,6 @@ public class AnnotationAssocOnes extends AnnotationParser {
|
||||
*/
|
||||
@Override
|
||||
public void parse() {
|
||||
|
||||
for (DeployBeanProperty prop : descriptor.propertiesAll()) {
|
||||
if (prop instanceof DeployBeanPropertyAssocOne<?>) {
|
||||
readAssocOne((DeployBeanPropertyAssocOne<?>) prop);
|
||||
@@ -133,16 +132,7 @@ public class AnnotationAssocOnes extends AnnotationParser {
|
||||
// check for manually defined joins
|
||||
BeanTable beanTable = prop.getBeanTable();
|
||||
for (JoinColumn joinColumn : getAll(prop, JoinColumn.class)) {
|
||||
if (beanTable == null) {
|
||||
throw new IllegalStateException("Looks like a missing @ManyToOne or @OneToOne on property " + prop.getFullBeanName()+" - no related 'BeanTable'");
|
||||
}
|
||||
prop.getTableJoin().addJoinColumn(false, joinColumn, beanTable);
|
||||
if (!joinColumn.updatable()) {
|
||||
prop.setDbUpdateable(false);
|
||||
}
|
||||
if (!joinColumn.nullable()) {
|
||||
prop.setNullable(false);
|
||||
}
|
||||
setFromJoinColumn(prop, beanTable, joinColumn);
|
||||
checkForNoConstraint(prop, joinColumn);
|
||||
}
|
||||
|
||||
@@ -150,16 +140,7 @@ public class AnnotationAssocOnes extends AnnotationParser {
|
||||
JoinTable joinTable = get(prop, JoinTable.class);
|
||||
if (joinTable != null) {
|
||||
for (JoinColumn joinColumn : joinTable.joinColumns()) {
|
||||
if (beanTable == null) {
|
||||
throw new IllegalStateException("Looks like a missing @ManyToOne or @OneToOne on property " + prop.getFullBeanName()+" - no related 'BeanTable'");
|
||||
}
|
||||
prop.getTableJoin().addJoinColumn(false, joinColumn, beanTable);
|
||||
if (!joinColumn.updatable()) {
|
||||
prop.setDbUpdateable(false);
|
||||
}
|
||||
if (!joinColumn.nullable()) {
|
||||
prop.setNullable(false);
|
||||
}
|
||||
setFromJoinColumn(prop, beanTable, joinColumn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -187,10 +168,27 @@ public class AnnotationAssocOnes extends AnnotationParser {
|
||||
}
|
||||
}
|
||||
|
||||
private void setFromJoinColumn(DeployBeanPropertyAssocOne<?> prop, BeanTable beanTable, JoinColumn joinColumn) {
|
||||
if (beanTable == null) {
|
||||
throw new IllegalStateException("Looks like a missing @ManyToOne or @OneToOne on property " + prop.getFullBeanName() + " - no related 'BeanTable'");
|
||||
}
|
||||
prop.getTableJoin().addJoinColumn(false, joinColumn, beanTable);
|
||||
if (!joinColumn.updatable()) {
|
||||
prop.setDbUpdateable(false);
|
||||
}
|
||||
if (!joinColumn.nullable()) {
|
||||
prop.setNullable(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkForNoConstraint(DeployBeanPropertyAssocOne<?> prop, JoinColumn joinColumn) {
|
||||
ForeignKey foreignKey = joinColumn.foreignKey();
|
||||
if (foreignKey.value() == ConstraintMode.NO_CONSTRAINT) {
|
||||
prop.setForeignKey(new PropertyForeignKey());
|
||||
try {
|
||||
ForeignKey foreignKey = joinColumn.foreignKey();
|
||||
if (foreignKey.value() == ConstraintMode.NO_CONSTRAINT) {
|
||||
prop.setForeignKey(new PropertyForeignKey());
|
||||
}
|
||||
} catch (NoSuchMethodError e) {
|
||||
// support old JPA API
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,17 +225,24 @@ public class AnnotationAssocOnes extends AnnotationParser {
|
||||
prop.setNullable(propAnn.optional());
|
||||
prop.setFetchType(propAnn.fetch());
|
||||
prop.setMappedBy(propAnn.mappedBy());
|
||||
prop.setOrphanRemoval(readOrphanRemoval(propAnn));
|
||||
if (!"".equals(propAnn.mappedBy())) {
|
||||
prop.setOneToOneExported();
|
||||
prop.setOrphanRemoval(propAnn.orphanRemoval());
|
||||
} else if (propAnn.orphanRemoval()) {
|
||||
prop.setOrphanRemoval(true);
|
||||
}
|
||||
|
||||
setCascadeTypes(propAnn.cascade(), prop.getCascadeInfo());
|
||||
prop.setBeanTable(beanTable(prop));
|
||||
}
|
||||
|
||||
private boolean readOrphanRemoval(OneToOne property) {
|
||||
try {
|
||||
return property.orphanRemoval();
|
||||
} catch (NoSuchMethodError e) {
|
||||
// Support old JPA API
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void readPrimaryKeyJoin(PrimaryKeyJoinColumn primaryKeyJoin, DeployBeanPropertyAssocOne<?> prop) {
|
||||
|
||||
if (!prop.isOneToOne()) {
|
||||
|
||||
@@ -38,14 +38,14 @@ import java.util.Set;
|
||||
* <p>This means, searching for <code>JoinColumn</code> will find them also if they are inside a
|
||||
* <code>JoinColumn<b>s</b></code> annotation</p>
|
||||
*/
|
||||
public abstract class AnnotationBase {
|
||||
abstract class AnnotationBase {
|
||||
|
||||
protected final DatabasePlatform databasePlatform;
|
||||
protected final Platform platform;
|
||||
protected final NamingConvention namingConvention;
|
||||
protected final DeployUtil util;
|
||||
final DatabasePlatform databasePlatform;
|
||||
private final Platform platform;
|
||||
final NamingConvention namingConvention;
|
||||
final DeployUtil util;
|
||||
|
||||
protected AnnotationBase(DeployUtil util) {
|
||||
AnnotationBase(DeployUtil util) {
|
||||
this.util = util;
|
||||
this.databasePlatform = util.getDbPlatform();
|
||||
this.platform = databasePlatform.getPlatform();
|
||||
@@ -60,7 +60,7 @@ public abstract class AnnotationBase {
|
||||
/**
|
||||
* Checks string is null or empty .
|
||||
*/
|
||||
protected boolean isEmpty(String s) {
|
||||
boolean isEmpty(String s) {
|
||||
return s == null || s.trim().isEmpty();
|
||||
}
|
||||
|
||||
@@ -78,7 +78,7 @@ public abstract class AnnotationBase {
|
||||
* </p>
|
||||
* <p>
|
||||
*/
|
||||
protected <T extends Annotation> T get(DeployBeanProperty prop, Class<T> annClass) {
|
||||
<T extends Annotation> T get(DeployBeanProperty prop, Class<T> annClass) {
|
||||
T a = null;
|
||||
Field field = prop.getField();
|
||||
if (field != null) {
|
||||
@@ -97,7 +97,7 @@ public abstract class AnnotationBase {
|
||||
* Return all annotations for this property. Annotations are not filtered by platfrom and you'll get
|
||||
* really all annotations that are directly, indirectly or meta-present.
|
||||
*/
|
||||
protected <T extends Annotation> Set<T> getAll(DeployBeanProperty prop, Class<T> annClass) {
|
||||
<T extends Annotation> Set<T> getAll(DeployBeanProperty prop, Class<T> annClass) {
|
||||
Set<T> ret = null;
|
||||
Field field = prop.getField();
|
||||
if (field != null) {
|
||||
@@ -121,12 +121,11 @@ public abstract class AnnotationBase {
|
||||
* (This is used for SequenceGenerator e.g.)
|
||||
* </p>
|
||||
*/
|
||||
protected <T extends Annotation> T find(DeployBeanProperty prop, Class<T> annClass) {
|
||||
<T extends Annotation> T find(DeployBeanProperty prop, Class<T> annClass) {
|
||||
T a = get(prop, annClass);
|
||||
if (a == null) {
|
||||
a = AnnotationUtil.findAnnotation(prop.getOwningType(), annClass, platform);
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ import io.ebean.annotation.StorageEngine;
|
||||
import io.ebean.annotation.UpdateMode;
|
||||
import io.ebean.annotation.View;
|
||||
import io.ebean.config.TableName;
|
||||
import io.ebean.util.AnnotationUtil;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor.EntityType;
|
||||
import io.ebeaninternal.server.deploy.IndexDefinition;
|
||||
import io.ebeaninternal.server.deploy.InheritInfo;
|
||||
@@ -31,7 +30,9 @@ import javax.persistence.IdClass;
|
||||
import javax.persistence.NamedQuery;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.UniqueConstraint;
|
||||
import java.util.Set;
|
||||
|
||||
import static io.ebean.util.AnnotationUtil.findAnnotationRecursive;
|
||||
import static io.ebean.util.AnnotationUtil.findAnnotationsRecursive;
|
||||
|
||||
/**
|
||||
* Read the class level deployment annotations.
|
||||
@@ -50,7 +51,7 @@ public class AnnotationClass extends AnnotationParser {
|
||||
* Create to parse AttributeOverride annotations which is run last
|
||||
* after all the properties/fields have been parsed fully.
|
||||
*/
|
||||
public AnnotationClass(DeployBeanInfo<?> info, ReadAnnotationConfig readConfig) {
|
||||
AnnotationClass(DeployBeanInfo<?> info, ReadAnnotationConfig readConfig) {
|
||||
super(info, readConfig);
|
||||
this.asOfViewSuffix = readConfig.getAsOfViewSuffix();
|
||||
this.versionsBetweenSuffix = readConfig.getVersionsBetweenSuffix();
|
||||
@@ -60,10 +61,10 @@ public class AnnotationClass extends AnnotationParser {
|
||||
/**
|
||||
* Parse any AttributeOverride set on the class.
|
||||
*/
|
||||
public void parseAttributeOverride() {
|
||||
void parseAttributeOverride() {
|
||||
|
||||
Class<?> cls = descriptor.getBeanType();
|
||||
AttributeOverride override = AnnotationUtil.findAnnotationRecursive(cls, AttributeOverride.class);
|
||||
AttributeOverride override = findAnnotationRecursive(cls, AttributeOverride.class);
|
||||
if (override != null) {
|
||||
String propertyName = override.name();
|
||||
Column column = override.column();
|
||||
@@ -105,14 +106,14 @@ public class AnnotationClass extends AnnotationParser {
|
||||
private void read(Class<?> cls) {
|
||||
|
||||
// maybe doc store only so check for this before @Entity
|
||||
DocStore docStore = AnnotationUtil.findAnnotationRecursive(cls, DocStore.class);
|
||||
DocStore docStore = findAnnotationRecursive(cls, DocStore.class);
|
||||
if (docStore != null) {
|
||||
descriptor.readDocStore(docStore);
|
||||
descriptor.setEntityType(EntityType.DOC);
|
||||
descriptor.setName(cls.getSimpleName());
|
||||
}
|
||||
|
||||
Entity entity = AnnotationUtil.findAnnotationRecursive(cls, Entity.class);
|
||||
Entity entity = findAnnotationRecursive(cls, Entity.class);
|
||||
if (entity != null) {
|
||||
descriptor.setEntityType(EntityType.ORM);
|
||||
if (entity.name().isEmpty()) {
|
||||
@@ -122,32 +123,31 @@ public class AnnotationClass extends AnnotationParser {
|
||||
}
|
||||
}
|
||||
|
||||
IdClass idClass = AnnotationUtil.findAnnotationRecursive(cls, IdClass.class);
|
||||
IdClass idClass = findAnnotationRecursive(cls, IdClass.class);
|
||||
if (idClass != null) {
|
||||
descriptor.setIdClass(idClass.value());
|
||||
}
|
||||
|
||||
Embeddable embeddable = AnnotationUtil.findAnnotationRecursive(cls, Embeddable.class);
|
||||
Embeddable embeddable = findAnnotationRecursive(cls, Embeddable.class);
|
||||
if (embeddable != null) {
|
||||
descriptor.setEntityType(EntityType.EMBEDDED);
|
||||
descriptor.setName("Embeddable:" + cls.getSimpleName());
|
||||
}
|
||||
|
||||
Set<Index> indices = AnnotationUtil.findAnnotationsRecursive(cls, Index.class);
|
||||
for (Index index : indices) {
|
||||
for (Index index : findAnnotationsRecursive(cls, Index.class)) {
|
||||
descriptor.addIndex(new IndexDefinition(index.columnNames(), index.name(), index.unique()));
|
||||
}
|
||||
|
||||
UniqueConstraint uc = AnnotationUtil.findAnnotationRecursive(cls, UniqueConstraint.class);
|
||||
UniqueConstraint uc = findAnnotationRecursive(cls, UniqueConstraint.class);
|
||||
if (uc != null) {
|
||||
descriptor.addIndex(new IndexDefinition(uc.columnNames()));
|
||||
}
|
||||
|
||||
View view = AnnotationUtil.findAnnotationRecursive(cls, View.class);
|
||||
View view = findAnnotationRecursive(cls, View.class);
|
||||
if (view != null) {
|
||||
descriptor.setView(view.name(), view.dependentTables());
|
||||
}
|
||||
Table table = AnnotationUtil.findAnnotationRecursive(cls, Table.class);
|
||||
Table table = findAnnotationRecursive(cls, Table.class);
|
||||
if (table != null) {
|
||||
UniqueConstraint[] uniqueConstraints = table.uniqueConstraints();
|
||||
for (UniqueConstraint c : uniqueConstraints) {
|
||||
@@ -155,59 +155,59 @@ public class AnnotationClass extends AnnotationParser {
|
||||
}
|
||||
}
|
||||
|
||||
StorageEngine storage = AnnotationUtil.findAnnotationRecursive(cls, StorageEngine.class);
|
||||
StorageEngine storage = findAnnotationRecursive(cls, StorageEngine.class);
|
||||
if (storage != null) {
|
||||
descriptor.setStorageEngine(storage.value());
|
||||
}
|
||||
|
||||
DbPartition partition = AnnotationUtil.findAnnotationRecursive(cls, DbPartition.class);
|
||||
DbPartition partition = findAnnotationRecursive(cls, DbPartition.class);
|
||||
if (partition != null) {
|
||||
descriptor.setPartitionMeta(new PartitionMeta(partition.mode(), partition.property()));
|
||||
}
|
||||
|
||||
Draftable draftable = AnnotationUtil.findAnnotationRecursive(cls, Draftable.class);
|
||||
Draftable draftable = findAnnotationRecursive(cls, Draftable.class);
|
||||
if (draftable != null) {
|
||||
descriptor.setDraftable();
|
||||
}
|
||||
|
||||
DraftableElement draftableElement = AnnotationUtil.findAnnotationRecursive(cls, DraftableElement.class);
|
||||
DraftableElement draftableElement = findAnnotationRecursive(cls, DraftableElement.class);
|
||||
if (draftableElement != null) {
|
||||
descriptor.setDraftableElement();
|
||||
}
|
||||
|
||||
ReadAudit readAudit = AnnotationUtil.findAnnotationRecursive(cls, ReadAudit.class);
|
||||
ReadAudit readAudit = findAnnotationRecursive(cls, ReadAudit.class);
|
||||
if (readAudit != null) {
|
||||
descriptor.setReadAuditing();
|
||||
}
|
||||
|
||||
History history = AnnotationUtil.findAnnotationRecursive(cls, History.class);
|
||||
History history = findAnnotationRecursive(cls, History.class);
|
||||
if (history != null) {
|
||||
descriptor.setHistorySupport();
|
||||
}
|
||||
|
||||
DbComment comment = AnnotationUtil.findAnnotationRecursive(cls, DbComment.class);
|
||||
DbComment comment = findAnnotationRecursive(cls, DbComment.class);
|
||||
if (comment != null) {
|
||||
descriptor.setDbComment(comment.value());
|
||||
}
|
||||
|
||||
UpdateMode updateMode = AnnotationUtil.findAnnotationRecursive(cls, UpdateMode.class);
|
||||
UpdateMode updateMode = findAnnotationRecursive(cls, UpdateMode.class);
|
||||
if (updateMode != null) {
|
||||
descriptor.setUpdateChangesOnly(updateMode.updateChangesOnly());
|
||||
}
|
||||
|
||||
if (!disableL2Cache) {
|
||||
Cache cache = AnnotationUtil.findAnnotationRecursive(cls, Cache.class);
|
||||
Cache cache = findAnnotationRecursive(cls, Cache.class);
|
||||
if (cache != null) {
|
||||
descriptor.setCache(cache);
|
||||
} else {
|
||||
InvalidateQueryCache invalidateQueryCache = AnnotationUtil.findAnnotationRecursive(cls, InvalidateQueryCache.class);
|
||||
InvalidateQueryCache invalidateQueryCache = findAnnotationRecursive(cls, InvalidateQueryCache.class);
|
||||
if (invalidateQueryCache != null) {
|
||||
descriptor.setInvalidateQueryCache(invalidateQueryCache.region());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (NamedQuery namedQuery : AnnotationUtil.findAnnotationsRecursive(cls, NamedQuery.class)) {
|
||||
for (NamedQuery namedQuery : findAnnotationsRecursive(cls, NamedQuery.class)) {
|
||||
descriptor.addNamedQuery(namedQuery.name(), namedQuery.query());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,17 +19,17 @@ import java.util.UUID;
|
||||
*/
|
||||
public abstract class AnnotationParser extends AnnotationBase {
|
||||
|
||||
protected final DeployBeanInfo<?> info;
|
||||
final DeployBeanInfo<?> info;
|
||||
|
||||
protected final DeployBeanDescriptor<?> descriptor;
|
||||
final DeployBeanDescriptor<?> descriptor;
|
||||
|
||||
protected final Class<?> beanType;
|
||||
final Class<?> beanType;
|
||||
|
||||
protected final boolean validationAnnotations;
|
||||
final boolean validationAnnotations;
|
||||
|
||||
protected final ReadAnnotationConfig readConfig;
|
||||
final ReadAnnotationConfig readConfig;
|
||||
|
||||
public AnnotationParser(DeployBeanInfo<?> info, ReadAnnotationConfig readConfig) {
|
||||
AnnotationParser(DeployBeanInfo<?> info, ReadAnnotationConfig readConfig) {
|
||||
super(info.getUtil());
|
||||
this.readConfig = readConfig;
|
||||
this.validationAnnotations = readConfig.isJavaxValidationAnnotations();
|
||||
@@ -47,7 +47,7 @@ public abstract class AnnotationParser extends AnnotationBase {
|
||||
/**
|
||||
* Read the Id annotation on an embeddedId.
|
||||
*/
|
||||
protected void readIdAssocOne(DeployBeanPropertyAssoc<?> prop) {
|
||||
void readIdAssocOne(DeployBeanPropertyAssoc<?> prop) {
|
||||
prop.setNullable(false);
|
||||
if (prop.isIdClass()) {
|
||||
prop.setImportedPrimaryKey();
|
||||
@@ -61,7 +61,7 @@ public abstract class AnnotationParser extends AnnotationBase {
|
||||
/**
|
||||
* Read the Id annotation on scalar property.
|
||||
*/
|
||||
protected void readIdScalar(DeployBeanProperty prop) {
|
||||
void readIdScalar(DeployBeanProperty prop) {
|
||||
prop.setNullable(false);
|
||||
if (prop.isIdClass()) {
|
||||
prop.setImportedPrimaryKey();
|
||||
@@ -78,7 +78,7 @@ public abstract class AnnotationParser extends AnnotationBase {
|
||||
/**
|
||||
* Helper method to set cascade types to the CascadeInfo on BeanProperty.
|
||||
*/
|
||||
protected void setCascadeTypes(CascadeType[] cascadeTypes, BeanCascadeInfo cascadeInfo) {
|
||||
void setCascadeTypes(CascadeType[] cascadeTypes, BeanCascadeInfo cascadeInfo) {
|
||||
if (cascadeTypes != null && cascadeTypes.length > 0) {
|
||||
cascadeInfo.setTypes(cascadeTypes);
|
||||
}
|
||||
@@ -87,7 +87,7 @@ public abstract class AnnotationParser extends AnnotationBase {
|
||||
/**
|
||||
* Read an AttributeOverrides if they exist for this embedded bean.
|
||||
*/
|
||||
protected void readEmbeddedAttributeOverrides(DeployBeanPropertyAssocOne<?> prop) {
|
||||
void readEmbeddedAttributeOverrides(DeployBeanPropertyAssocOne<?> prop) {
|
||||
|
||||
Set<AttributeOverride> attrOverrides = getAll(prop, AttributeOverride.class);
|
||||
if (!attrOverrides.isEmpty()) {
|
||||
@@ -100,7 +100,7 @@ public abstract class AnnotationParser extends AnnotationBase {
|
||||
|
||||
}
|
||||
|
||||
protected void readColumn(Column columnAnn, DeployBeanProperty prop) {
|
||||
void readColumn(Column columnAnn, DeployBeanProperty prop) {
|
||||
|
||||
if (!isEmpty(columnAnn.name())) {
|
||||
String dbColumn = databasePlatform.convertQuotedIdentifiers(columnAnn.name());
|
||||
@@ -132,14 +132,10 @@ public abstract class AnnotationParser extends AnnotationBase {
|
||||
* Return true if the validation groups are {@link Default} (respectively empty)
|
||||
* can be applied to DDL generation.
|
||||
*/
|
||||
protected boolean isEbeanValidationGroups(Class<?>[] groups) {
|
||||
boolean isEbeanValidationGroups(Class<?>[] groups) {
|
||||
if (!util.isUseJavaxValidationNotNull()) {
|
||||
return false;
|
||||
}
|
||||
if (groups.length == 0
|
||||
|| groups.length == 1 && javax.validation.groups.Default.class.isAssignableFrom(groups[0])) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return groups.length == 0 || groups.length == 1 && Default.class.isAssignableFrom(groups[0]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,22 +4,13 @@ import io.ebean.RawSql;
|
||||
import io.ebeaninternal.server.deploy.TableJoin;
|
||||
import io.ebeaninternal.server.deploy.meta.DeployBeanDescriptor;
|
||||
import io.ebeaninternal.server.deploy.meta.DeployBeanPropertyAssoc;
|
||||
import io.ebeaninternal.server.deploy.meta.DeployTableJoin;
|
||||
import io.ebeaninternal.server.query.SqlJoinType;
|
||||
import io.ebeaninternal.server.rawsql.SpiRawSql;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* Wraps information about a bean during deployment parsing.
|
||||
*/
|
||||
public class DeployBeanInfo<T> {
|
||||
|
||||
/**
|
||||
* Holds TableJoins for secondary table properties.
|
||||
*/
|
||||
private final HashMap<String, DeployTableJoin> tableJoinMap = new HashMap<>();
|
||||
|
||||
private final DeployUtil util;
|
||||
|
||||
private final DeployBeanDescriptor<T> descriptor;
|
||||
@@ -53,25 +44,6 @@ public class DeployBeanInfo<T> {
|
||||
return util;
|
||||
}
|
||||
|
||||
/**
|
||||
* Appropriate TableJoin for a property mapped to a secondary table.
|
||||
*/
|
||||
public DeployTableJoin getTableJoin(String tableName) {
|
||||
|
||||
String key = tableName.toLowerCase();
|
||||
|
||||
DeployTableJoin tableJoin = tableJoinMap.get(key);
|
||||
if (tableJoin == null) {
|
||||
tableJoin = new DeployTableJoin();
|
||||
tableJoin.setTable(tableName);
|
||||
tableJoin.setType(SqlJoinType.INNER);
|
||||
descriptor.addTableJoin(tableJoin);
|
||||
|
||||
tableJoinMap.put(key, tableJoin);
|
||||
}
|
||||
return tableJoin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add named RawSql from ebean.xml.
|
||||
*/
|
||||
|
||||
@@ -138,7 +138,7 @@ public class DeployInheritInfo {
|
||||
/**
|
||||
* Set the sql type of the discriminator.
|
||||
*/
|
||||
public void setColumnType(DiscriminatorType type) {
|
||||
void setColumnType(DiscriminatorType type) {
|
||||
if (type == DiscriminatorType.INTEGER) {
|
||||
this.columnType = Types.INTEGER;
|
||||
} else {
|
||||
@@ -199,9 +199,7 @@ public class DeployInheritInfo {
|
||||
public String getWhere() {
|
||||
|
||||
List<Object> discList = new ArrayList<>();
|
||||
|
||||
appendDiscriminator(discList);
|
||||
|
||||
return buildWhereLiteral(discList);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,6 @@ import io.ebeaninternal.server.type.ScalarTypeArray;
|
||||
import io.ebeaninternal.server.type.ScalarTypeWrapper;
|
||||
import io.ebeaninternal.server.type.SimpleAesEncryptor;
|
||||
import io.ebeaninternal.server.type.TypeManager;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
@@ -34,8 +32,6 @@ import java.sql.Types;
|
||||
*/
|
||||
public class DeployUtil {
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(DeployUtil.class);
|
||||
|
||||
/**
|
||||
* Assumes CLOB rather than LONGVARCHAR.
|
||||
*/
|
||||
@@ -91,26 +87,26 @@ public class DeployUtil {
|
||||
/**
|
||||
* Check that the EncryptKeyManager has been defined.
|
||||
*/
|
||||
public void checkEncryptKeyManagerDefined(String fullPropName) {
|
||||
void checkEncryptKeyManagerDefined(String fullPropName) {
|
||||
if (encryptKeyManager == null) {
|
||||
String msg = "Using encryption on " + fullPropName + " but no EncryptKeyManager defined!";
|
||||
throw new PersistenceException(msg);
|
||||
}
|
||||
}
|
||||
|
||||
public EncryptDeploy getEncryptDeploy(TableName table, String column) {
|
||||
EncryptDeploy getEncryptDeploy(TableName table, String column) {
|
||||
if (encryptDeployManager == null) {
|
||||
return EncryptDeploy.ANNOTATION;
|
||||
}
|
||||
return encryptDeployManager.getEncryptDeploy(table, column);
|
||||
}
|
||||
|
||||
public DataEncryptSupport createDataEncryptSupport(String table, String column) {
|
||||
DataEncryptSupport createDataEncryptSupport(String table, String column) {
|
||||
return new DataEncryptSupport(encryptKeyManager, bytesEncryptor, table, column);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setEnumScalarType(Enumerated enumerated, DeployBeanProperty prop) {
|
||||
void setEnumScalarType(Enumerated enumerated, DeployBeanProperty prop) {
|
||||
|
||||
Class<?> enumType = prop.getPropertyType();
|
||||
if (!enumType.isEnum()) {
|
||||
@@ -159,19 +155,10 @@ public class DeployUtil {
|
||||
Class<?> propType = property.getPropertyType();
|
||||
try {
|
||||
ScalarType<?> scalarType = typeManager.getScalarType(propType, property.getDbType());
|
||||
if (scalarType != null) {
|
||||
if (scalarType != null || property.isTransient()) {
|
||||
return scalarType;
|
||||
}
|
||||
|
||||
String msg = property.getFullBeanName() + " has no ScalarType - type[" + propType.getName() + "]";
|
||||
if (!property.isTransient()) {
|
||||
throw new PersistenceException(msg);
|
||||
|
||||
} else {
|
||||
// this is ok...
|
||||
logger.trace("... transient property {}", msg);
|
||||
return null;
|
||||
}
|
||||
throw new PersistenceException(property.getFullBeanName() + " has no ScalarType - type[" + propType.getName() + "]");
|
||||
} catch (IllegalArgumentException e) {
|
||||
if (property.isTransient()) {
|
||||
// expected for transient properties with unknown/non-mapped types
|
||||
@@ -184,7 +171,7 @@ public class DeployUtil {
|
||||
/**
|
||||
* Map to Postgres HSTORE type (with fallback to JSON storage in VARCHAR).
|
||||
*/
|
||||
public void setDbHstore(DeployBeanProperty prop, DbHstore dbHstore) {
|
||||
void setDbHstore(DeployBeanProperty prop, DbHstore dbHstore) {
|
||||
|
||||
ScalarType<?> scalarType = typeManager.getHstoreScalarType();
|
||||
int dbType = scalarType.getJdbcType();
|
||||
@@ -201,7 +188,7 @@ public class DeployUtil {
|
||||
/**
|
||||
* Set the DbArray type (effectively Postgres only).
|
||||
*/
|
||||
public void setDbArray(DeployBeanProperty prop, DbArray dbArray) {
|
||||
void setDbArray(DeployBeanProperty prop, DbArray dbArray) {
|
||||
|
||||
Class<?> type = prop.getPropertyType();
|
||||
ScalarType<?> scalarType = typeManager.getArrayScalarType(type, dbArray, prop.getGenericType());
|
||||
@@ -227,13 +214,13 @@ public class DeployUtil {
|
||||
/**
|
||||
* This property is marked as a Lob object.
|
||||
*/
|
||||
public void setDbJsonType(DeployBeanProperty prop, DbJson dbJsonType) {
|
||||
void setDbJsonType(DeployBeanProperty prop, DbJson dbJsonType) {
|
||||
|
||||
int dbType = getDbJsonStorage(dbJsonType.storage());
|
||||
setDbJsonType(prop, dbType, dbJsonType.length());
|
||||
}
|
||||
|
||||
public void setDbJsonBType(DeployBeanProperty prop, DbJsonB dbJsonB) {
|
||||
void setDbJsonBType(DeployBeanProperty prop, DbJsonB dbJsonB) {
|
||||
setDbJsonType(prop, DbPlatformType.JSONB, dbJsonB.length());
|
||||
}
|
||||
|
||||
@@ -258,8 +245,6 @@ public class DeployUtil {
|
||||
private int getDbJsonStorage(DbJsonType dbJsonType) {
|
||||
|
||||
switch (dbJsonType) {
|
||||
case JSON:
|
||||
return DbPlatformType.JSON;
|
||||
case JSONB:
|
||||
return DbPlatformType.JSONB;
|
||||
case VARCHAR:
|
||||
@@ -276,7 +261,7 @@ public class DeployUtil {
|
||||
/**
|
||||
* This property is marked as a Lob object.
|
||||
*/
|
||||
public void setLobType(DeployBeanProperty prop) {
|
||||
void setLobType(DeployBeanProperty prop) {
|
||||
|
||||
ScalarType<?> scalarType = prop.getScalarType();
|
||||
|
||||
@@ -303,7 +288,7 @@ public class DeployUtil {
|
||||
return type.equals(String.class);
|
||||
}
|
||||
|
||||
public boolean isUseJavaxValidationNotNull() {
|
||||
boolean isUseJavaxValidationNotNull() {
|
||||
return useJavaxValidationNotNull;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ class ReadAnnotationConfig {
|
||||
return eagerFetchLobs;
|
||||
}
|
||||
|
||||
public boolean isIdGeneratorAutomatic() {
|
||||
boolean isIdGeneratorAutomatic() {
|
||||
return idGeneratorAutomatic;
|
||||
}
|
||||
|
||||
|
||||
@@ -108,13 +108,6 @@ public final class BatchControl {
|
||||
this.batchFlushOnMixed = flushBatchOnMixed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the batchSize.
|
||||
*/
|
||||
public int getBatchSize() {
|
||||
return batchSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the size of batch execution.
|
||||
* <p>
|
||||
@@ -191,7 +184,7 @@ public final class BatchControl {
|
||||
/**
|
||||
* Add the request to the batch and return true if we should flush.
|
||||
*/
|
||||
private boolean addToBatch(PersistRequestBean<?> request) throws BatchedSqlException {
|
||||
private boolean addToBatch(PersistRequestBean<?> request) {
|
||||
|
||||
Object alreadyInBatch = persistedBeans.put(request.getEntityBean(), DUMMY);
|
||||
if (alreadyInBatch != null) {
|
||||
|
||||
@@ -26,7 +26,7 @@ class BatchDepthOrder {
|
||||
|
||||
int count;
|
||||
|
||||
public int increment() {
|
||||
int increment() {
|
||||
return count++;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import java.util.ArrayList;
|
||||
* executed. The lowest depth is executed first.
|
||||
* </p>
|
||||
*/
|
||||
public class BatchedBeanHolder {
|
||||
class BatchedBeanHolder {
|
||||
|
||||
/**
|
||||
* The owning queue.
|
||||
|
||||
@@ -5,9 +5,9 @@ import java.util.ArrayList;
|
||||
/**
|
||||
* Holds a list of bind values for binding to a PreparedStatement.
|
||||
*/
|
||||
public class BindValues {
|
||||
class BindValues {
|
||||
|
||||
final ArrayList<Value> list = new ArrayList<>();
|
||||
private final ArrayList<Value> list = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Create with a Binder.
|
||||
@@ -15,13 +15,6 @@ public class BindValues {
|
||||
public BindValues() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of bind values.
|
||||
*/
|
||||
public int size() {
|
||||
return list.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a bind value with its JDBC datatype.
|
||||
*
|
||||
@@ -53,7 +46,7 @@ public class BindValues {
|
||||
/**
|
||||
* Create the value.
|
||||
*/
|
||||
public Value(Object value, int dbType, String name) {
|
||||
Value(Object value, int dbType, String name) {
|
||||
this.value = value;
|
||||
this.dbType = dbType;
|
||||
this.name = name;
|
||||
|
||||
@@ -124,7 +124,7 @@ public class Binder {
|
||||
/**
|
||||
* Bind the list of positionedParameters in BindParams.
|
||||
*/
|
||||
public String bind(BindParams bindParams, DataBind dataBind) throws SQLException {
|
||||
private String bind(BindParams bindParams, DataBind dataBind) throws SQLException {
|
||||
|
||||
StringBuilder bindLog = new StringBuilder();
|
||||
bind(bindParams, dataBind, bindLog);
|
||||
@@ -142,7 +142,7 @@ public class Binder {
|
||||
/**
|
||||
* Bind the list of parameters..
|
||||
*/
|
||||
public void bind(List<BindParams.Param> list, DataBind dataBind, StringBuilder bindLog) throws SQLException {
|
||||
private void bind(List<BindParams.Param> list, DataBind dataBind, StringBuilder bindLog) throws SQLException {
|
||||
|
||||
CallableStatement cstmt = null;
|
||||
|
||||
@@ -261,7 +261,7 @@ public class Binder {
|
||||
* default is that both are converted to java.sql.Timestamp.
|
||||
* </p>
|
||||
*/
|
||||
public void bindObject(DataBind dataBind, Object data, int dbType) throws SQLException {
|
||||
private void bindObject(DataBind dataBind, Object data, int dbType) throws SQLException {
|
||||
|
||||
if (data == null) {
|
||||
dataBind.setNull(dbType);
|
||||
@@ -298,8 +298,6 @@ public class Binder {
|
||||
try {
|
||||
switch (dataType) {
|
||||
case java.sql.Types.BOOLEAN:
|
||||
b.setBoolean((Boolean) data);
|
||||
break;
|
||||
case java.sql.Types.BIT:
|
||||
// Types.BIT should map to Java Boolean
|
||||
b.setBoolean((Boolean) data);
|
||||
@@ -334,18 +332,12 @@ public class Binder {
|
||||
break;
|
||||
|
||||
case java.sql.Types.FLOAT:
|
||||
case java.sql.Types.DOUBLE:
|
||||
// DB Float in theory maps to Java Double type
|
||||
b.setDouble((Double) data);
|
||||
break;
|
||||
|
||||
case java.sql.Types.DOUBLE:
|
||||
b.setDouble((Double) data);
|
||||
break;
|
||||
|
||||
case java.sql.Types.NUMERIC:
|
||||
b.setBigDecimal((BigDecimal) data);
|
||||
break;
|
||||
|
||||
case java.sql.Types.DECIMAL:
|
||||
b.setBigDecimal((BigDecimal) data);
|
||||
break;
|
||||
@@ -363,14 +355,13 @@ public class Binder {
|
||||
break;
|
||||
|
||||
case java.sql.Types.BINARY:
|
||||
b.setBytes((byte[]) data);
|
||||
break;
|
||||
|
||||
case java.sql.Types.VARBINARY:
|
||||
b.setBytes((byte[]) data);
|
||||
break;
|
||||
|
||||
case DbPlatformType.UUID:
|
||||
case java.sql.Types.JAVA_OBJECT:
|
||||
// Not too sure about this.
|
||||
// native UUID support in H2 and Postgres
|
||||
b.setObject(data);
|
||||
break;
|
||||
@@ -384,11 +375,6 @@ public class Binder {
|
||||
b.setObject(data, dataType);
|
||||
break;
|
||||
|
||||
case java.sql.Types.JAVA_OBJECT:
|
||||
// Not too sure about this.
|
||||
b.setObject(data);
|
||||
break;
|
||||
|
||||
default:
|
||||
String msg = Message.msg("persist.bind.datatype", String.valueOf(dataType), String.valueOf(b.currentPos()));
|
||||
throw new SQLException(msg);
|
||||
@@ -440,12 +426,9 @@ public class Binder {
|
||||
private boolean isLob(int dbType) {
|
||||
switch (dbType) {
|
||||
case Types.CLOB:
|
||||
return true;
|
||||
case Types.LONGVARCHAR:
|
||||
return true;
|
||||
case Types.BLOB:
|
||||
return true;
|
||||
case Types.LONGVARBINARY:
|
||||
case Types.BLOB:
|
||||
case Types.LONGVARCHAR:
|
||||
return true;
|
||||
|
||||
default:
|
||||
|
||||
@@ -267,7 +267,6 @@ public final class DefaultPersister implements Persister {
|
||||
|
||||
final BeanDescriptor<T> desc;
|
||||
final Transaction transaction;
|
||||
final BeanProperty draftDirty;
|
||||
final List<T> draftUpdates = new ArrayList<>();
|
||||
|
||||
/**
|
||||
@@ -288,7 +287,6 @@ public final class DefaultPersister implements Persister {
|
||||
DraftHandler(BeanDescriptor<T> desc, Transaction transaction) {
|
||||
this.desc = desc;
|
||||
this.transaction = transaction;
|
||||
this.draftDirty = desc.getDraftDirty();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1288,8 +1286,8 @@ public final class DefaultPersister implements Persister {
|
||||
return new PersistRequestBean(server, bean, parentBean, mgr, (SpiTransaction) t, persistExecute, type, flags);
|
||||
}
|
||||
|
||||
<T> PersistRequestBean<T> createDeleteRemoved(T bean, Transaction t, PersistRequest.Type type, int flags) {
|
||||
return createDeleteRequest(bean, t, type, Flags.unsetRecurse(flags));
|
||||
<T> PersistRequestBean<T> createDeleteRemoved(T bean, Transaction t, int flags) {
|
||||
return createDeleteRequest(bean, t, PersistRequest.Type.DELETE, Flags.unsetRecurse(flags));
|
||||
}
|
||||
|
||||
private <T> PersistRequestBean<T> createDeleteRequest(EntityBean bean, Transaction t, Type type) {
|
||||
|
||||
@@ -14,6 +14,7 @@ class DeleteIdRequest implements BeanDeleteIdRequest {
|
||||
DeleteIdRequest(SpiEbeanServer server, Transaction transaction, Object id) {
|
||||
this.server = server;
|
||||
this.transaction = transaction;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
void setId(Object id) {
|
||||
|
||||
@@ -39,10 +39,6 @@ class DeleteUnloadedForeignKeys {
|
||||
this.deletePermanent = request.isHardDeleteCascade();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return propList.isEmpty();
|
||||
}
|
||||
|
||||
public void add(BeanPropertyAssocOne<?> prop) {
|
||||
propList.add(prop);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ class MergeContext {
|
||||
|
||||
private final List<EntityBean> deleteBeans = new ArrayList<>();
|
||||
|
||||
private boolean clientGeneratedIds;
|
||||
private final boolean clientGeneratedIds;
|
||||
|
||||
MergeContext(SpiEbeanServer server, SpiTransaction transaction, boolean clientGeneratedIds) {
|
||||
this.server = server;
|
||||
|
||||
@@ -135,7 +135,7 @@ class MergeHandler {
|
||||
static MergeNode createMergeNode(String fullPath, BeanDescriptor<?> targetDesc, String path) {
|
||||
|
||||
BeanProperty prop = targetDesc.getBeanProperty(path);
|
||||
if (prop == null || !(prop instanceof BeanPropertyAssoc)) {
|
||||
if (!(prop instanceof BeanPropertyAssoc)) {
|
||||
throw new PersistenceException("merge path [" + path + "] is not a ToMany or ToOne property of " + targetDesc.getFullName());
|
||||
}
|
||||
if (prop instanceof BeanPropertyAssocMany<?>) {
|
||||
|
||||
@@ -16,9 +16,9 @@ import java.util.Map;
|
||||
*/
|
||||
abstract class MergeNode {
|
||||
|
||||
protected final String fullPath;
|
||||
protected final BeanDescriptor<?> targetDescriptor;
|
||||
protected Map<String,MergeNode> children;
|
||||
private final String fullPath;
|
||||
final BeanDescriptor<?> targetDescriptor;
|
||||
private Map<String,MergeNode> children;
|
||||
|
||||
MergeNode(String fullPath, BeanPropertyAssoc<?> property) {
|
||||
this.fullPath = fullPath;
|
||||
@@ -80,7 +80,7 @@ abstract class MergeNode {
|
||||
/**
|
||||
* Cascade the merge processing if this has child nodes.
|
||||
*/
|
||||
protected void cascade(EntityBean entityBean, EntityBean outlineBean, MergeRequest request) {
|
||||
void cascade(EntityBean entityBean, EntityBean outlineBean, MergeRequest request) {
|
||||
|
||||
if (children != null && !children.isEmpty()) {
|
||||
MergeRequest sub = request.sub(entityBean, outlineBean);
|
||||
|
||||
@@ -41,6 +41,13 @@ abstract class SaveManyBase {
|
||||
*/
|
||||
abstract void save();
|
||||
|
||||
void preElementCollectionUpdate(Object parentId) {
|
||||
if (!insertedParent) {
|
||||
request.preElementCollectionUpdate();
|
||||
server.execute(many.deleteByParentId(parentId, null), transaction);
|
||||
}
|
||||
}
|
||||
|
||||
void resetModifyState() {
|
||||
if (value instanceof BeanCollection<?>) {
|
||||
modifyListenReset((BeanCollection<?>) value);
|
||||
|
||||
@@ -4,7 +4,6 @@ import io.ebean.bean.BeanCollection;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebean.bean.EntityBeanIntercept;
|
||||
import io.ebeaninternal.api.SpiSqlUpdate;
|
||||
import io.ebeaninternal.server.core.PersistRequest;
|
||||
import io.ebeaninternal.server.core.PersistRequestBean;
|
||||
import io.ebeaninternal.server.deploy.BeanCollectionUtil;
|
||||
import io.ebeaninternal.server.deploy.BeanDescriptor;
|
||||
@@ -356,7 +355,7 @@ public class SaveManyBeans extends SaveManyBase {
|
||||
EntityBean eb = (EntityBean) removedBean;
|
||||
if (!eb._ebean_getIntercept().isNew()) {
|
||||
// only delete if the bean was loaded meaning that it is known to exist in the DB
|
||||
persister.deleteRequest(persister.createDeleteRemoved(removedBean, transaction, PersistRequest.Type.DELETE, request.getFlags()));
|
||||
persister.deleteRequest(persister.createDeleteRemoved(removedBean, transaction, request.getFlags()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,6 @@ package io.ebeaninternal.server.persist;
|
||||
|
||||
import io.ebean.SqlUpdate;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.server.core.PersistRequestBean;
|
||||
import io.ebeaninternal.server.deploy.BeanCollectionUtil;
|
||||
import io.ebeaninternal.server.deploy.BeanPropertyAssocMany;
|
||||
@@ -27,26 +26,15 @@ class SaveManyElementCollection extends SaveManyBase {
|
||||
}
|
||||
|
||||
Object parentId = request.getBeanId();
|
||||
SpiEbeanServer server = request.getServer();
|
||||
|
||||
if (!insertedParent) {
|
||||
request.preElementCollectionUpdate();
|
||||
SqlUpdate sqlDelete = many.deleteByParentId(parentId, null);
|
||||
server.execute(sqlDelete, transaction);
|
||||
}
|
||||
preElementCollectionUpdate(parentId);
|
||||
|
||||
transaction.depth(+1);
|
||||
|
||||
String insert = many.insertElementCollection();
|
||||
SqlUpdate sqlInsert = server.createSqlUpdate(insert);
|
||||
|
||||
SqlUpdate sqlInsert = server.createSqlUpdate(many.insertElementCollection());
|
||||
for (Object value : collection) {
|
||||
|
||||
sqlInsert.setNextParameter(parentId);
|
||||
many.bindElementValue(sqlInsert, value);
|
||||
server.execute(sqlInsert, transaction);
|
||||
}
|
||||
|
||||
transaction.depth(-1);
|
||||
resetModifyState();
|
||||
postElementCollectionUpdate();
|
||||
|
||||
@@ -2,7 +2,6 @@ package io.ebeaninternal.server.persist;
|
||||
|
||||
import io.ebean.SqlUpdate;
|
||||
import io.ebean.bean.EntityBean;
|
||||
import io.ebeaninternal.api.SpiEbeanServer;
|
||||
import io.ebeaninternal.server.core.PersistRequestBean;
|
||||
import io.ebeaninternal.server.deploy.BeanCollectionUtil;
|
||||
import io.ebeaninternal.server.deploy.BeanPropertyAssocMany;
|
||||
@@ -29,18 +28,10 @@ class SaveManyElementCollectionMap extends SaveManyBase {
|
||||
}
|
||||
|
||||
Object parentId = request.getBeanId();
|
||||
SpiEbeanServer server = request.getServer();
|
||||
if (!insertedParent) {
|
||||
request.preElementCollectionUpdate();
|
||||
SqlUpdate sqlDelete = many.deleteByParentId(parentId, null);
|
||||
server.execute(sqlDelete, transaction);
|
||||
}
|
||||
preElementCollectionUpdate(parentId);
|
||||
|
||||
transaction.depth(+1);
|
||||
|
||||
String insert = many.insertElementCollection();
|
||||
SqlUpdate sqlInsert = server.createSqlUpdate(insert);
|
||||
|
||||
SqlUpdate sqlInsert = server.createSqlUpdate(many.insertElementCollection());
|
||||
for (Map.Entry<?, ?> entry : entries) {
|
||||
sqlInsert.setNextParameter(parentId);
|
||||
sqlInsert.setNextParameter(entry.getKey());
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package io.ebeaninternal.server.persist.dml;
|
||||
|
||||
import io.ebeaninternal.api.ConcurrencyMode;
|
||||
import io.ebeaninternal.server.persist.dmlbind.Bindable;
|
||||
import io.ebeaninternal.server.persist.dmlbind.BindableId;
|
||||
|
||||
class BaseMeta {
|
||||
|
||||
final BindableId id;
|
||||
final Bindable version;
|
||||
final Bindable tenantId;
|
||||
|
||||
BaseMeta(BindableId id, Bindable version, Bindable tenantId) {
|
||||
this.id = id;
|
||||
this.version = version;
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
|
||||
String appendWhere(GenerateDmlRequest request, ConcurrencyMode conMode) {
|
||||
request.setWhereIdMode();
|
||||
id.dmlAppend(request);
|
||||
if (tenantId != null) {
|
||||
tenantId.dmlAppend(request);
|
||||
}
|
||||
|
||||
if (ConcurrencyMode.VERSION == conMode) {
|
||||
if (version != null) {
|
||||
version.dmlAppend(request);
|
||||
}
|
||||
}
|
||||
|
||||
return request.toString();
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ public class DeleteHandler extends DmlHandler {
|
||||
private final DeleteMeta meta;
|
||||
|
||||
DeleteHandler(PersistRequestBean<?> persist, DeleteMeta meta) {
|
||||
super(persist, meta.isEmptyStringAsNull());
|
||||
super(persist);
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,27 +13,15 @@ import java.sql.SQLException;
|
||||
* Meta data for delete handler. The meta data is for a particular bean type. It
|
||||
* is considered immutable and is thread safe.
|
||||
*/
|
||||
public final class DeleteMeta {
|
||||
final class DeleteMeta extends BaseMeta {
|
||||
|
||||
private final String sqlVersion;
|
||||
private final String sqlNone;
|
||||
private final String sqlDraftVersion;
|
||||
private final String sqlDraftNone;
|
||||
|
||||
private final BindableId id;
|
||||
private final Bindable version;
|
||||
private final Bindable tenantId;
|
||||
|
||||
private final String tableName;
|
||||
|
||||
private final boolean emptyStringAsNull;
|
||||
|
||||
DeleteMeta(boolean emptyStringAsNull, BeanDescriptor<?> desc, BindableId id, Bindable version, Bindable tenantId) {
|
||||
this.emptyStringAsNull = emptyStringAsNull;
|
||||
this.tableName = desc.getBaseTable();
|
||||
this.id = id;
|
||||
this.version = version;
|
||||
this.tenantId = tenantId;
|
||||
DeleteMeta(BeanDescriptor<?> desc, BindableId id, Bindable version, Bindable tenantId) {
|
||||
super(id, version, tenantId);
|
||||
|
||||
String tableName = desc.getBaseTable();
|
||||
this.sqlNone = genSql(ConcurrencyMode.NONE, tableName);
|
||||
@@ -49,17 +37,6 @@ public final class DeleteMeta {
|
||||
}
|
||||
}
|
||||
|
||||
boolean isEmptyStringAsNull() {
|
||||
return emptyStringAsNull;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the table name.
|
||||
*/
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind the request based on the concurrency mode.
|
||||
*/
|
||||
@@ -104,20 +81,7 @@ public final class DeleteMeta {
|
||||
GenerateDmlRequest request = new GenerateDmlRequest();
|
||||
request.append("delete from ").append(table);
|
||||
request.append(" where ");
|
||||
|
||||
request.setWhereIdMode();
|
||||
id.dmlAppend(request);
|
||||
if (tenantId != null) {
|
||||
tenantId.dmlAppend(request);
|
||||
}
|
||||
|
||||
if (ConcurrencyMode.VERSION == conMode) {
|
||||
if (version != null) {
|
||||
version.dmlAppend(request);
|
||||
}
|
||||
}
|
||||
|
||||
return request.toString();
|
||||
return appendWhere(request, conMode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ public final class DmlBeanPersister implements BeanPersister {
|
||||
|
||||
private final DeleteMeta deleteMeta;
|
||||
|
||||
public DmlBeanPersister(DatabasePlatform dbPlatform, UpdateMeta updateMeta, InsertMeta insertMeta, DeleteMeta deleteMeta) {
|
||||
DmlBeanPersister(DatabasePlatform dbPlatform, UpdateMeta updateMeta, InsertMeta insertMeta, DeleteMeta deleteMeta) {
|
||||
this.dbPlatform = dbPlatform;
|
||||
this.updateMeta = updateMeta;
|
||||
this.insertMeta = insertMeta;
|
||||
|
||||
@@ -30,33 +30,30 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
|
||||
/**
|
||||
* The originating request.
|
||||
*/
|
||||
protected final PersistRequestBean<?> persistRequest;
|
||||
final PersistRequestBean<?> persistRequest;
|
||||
|
||||
protected final StringBuilder bindLog;
|
||||
private final StringBuilder bindLog;
|
||||
|
||||
protected final SpiTransaction transaction;
|
||||
final SpiTransaction transaction;
|
||||
|
||||
protected final boolean emptyStringToNull;
|
||||
private final boolean logLevelSql;
|
||||
|
||||
protected final boolean logLevelSql;
|
||||
|
||||
protected final long now;
|
||||
private final long now;
|
||||
|
||||
/**
|
||||
* The PreparedStatement used for the dml.
|
||||
*/
|
||||
protected DataBind dataBind;
|
||||
DataBind dataBind;
|
||||
|
||||
protected BatchedPstmt batchedPstmt;
|
||||
BatchedPstmt batchedPstmt;
|
||||
|
||||
protected String sql;
|
||||
String sql;
|
||||
|
||||
private short batchedStatus;
|
||||
|
||||
protected DmlHandler(PersistRequestBean<?> persistRequest, boolean emptyStringToNull) {
|
||||
DmlHandler(PersistRequestBean<?> persistRequest) {
|
||||
this.now = System.currentTimeMillis();
|
||||
this.persistRequest = persistRequest;
|
||||
this.emptyStringToNull = emptyStringToNull;
|
||||
this.transaction = persistRequest.getTransaction();
|
||||
this.logLevelSql = transaction.isLogSql();
|
||||
if (logLevelSql) {
|
||||
@@ -79,7 +76,7 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
|
||||
/**
|
||||
* Bind to the statement returning the DataBind.
|
||||
*/
|
||||
protected DataBind bind(PreparedStatement stmt) {
|
||||
DataBind bind(PreparedStatement stmt) {
|
||||
return new DataBind(persistRequest.getDataTimeZone(), stmt, transaction.getInternalConnection());
|
||||
}
|
||||
|
||||
@@ -98,7 +95,7 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
|
||||
/**
|
||||
* Check the rowCount.
|
||||
*/
|
||||
protected void checkRowCount(int rowCount) throws OptimisticLockException {
|
||||
void checkRowCount(int rowCount) throws OptimisticLockException {
|
||||
try {
|
||||
persistRequest.checkRowCount(rowCount);
|
||||
persistRequest.postExecute();
|
||||
@@ -132,14 +129,6 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the bind log.
|
||||
*/
|
||||
@Override
|
||||
public String getBindLog() {
|
||||
return bindLog == null ? "" : bindLog.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Id value that was bound. This value is used for logging summary
|
||||
* level information.
|
||||
@@ -152,7 +141,7 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
|
||||
/**
|
||||
* Log the sql to the transaction log.
|
||||
*/
|
||||
protected void logSql(String sql) {
|
||||
void logSql(String sql) {
|
||||
if (logLevelSql) {
|
||||
switch (batchedStatus) {
|
||||
case BATCHED_FIRST: {
|
||||
@@ -185,7 +174,7 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
|
||||
} else {
|
||||
String sval = value.toString();
|
||||
if (sval.length() > 50) {
|
||||
bindLog.append(sval.substring(0, 47)).append("...");
|
||||
bindLog.append(sval, 0, 47).append("...");
|
||||
} else {
|
||||
bindLog.append(sval);
|
||||
}
|
||||
@@ -244,7 +233,7 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
|
||||
/**
|
||||
* Check with useGeneratedKeys to get appropriate PreparedStatement.
|
||||
*/
|
||||
protected PreparedStatement getPstmt(SpiTransaction t, String sql, boolean genKeys) throws SQLException {
|
||||
PreparedStatement getPstmt(SpiTransaction t, String sql, boolean genKeys) throws SQLException {
|
||||
|
||||
Connection conn = t.getInternalConnection();
|
||||
if (genKeys) {
|
||||
@@ -261,7 +250,7 @@ public abstract class DmlHandler implements PersistHandler, BindableRequest {
|
||||
/**
|
||||
* Return a prepared statement taking into account batch requirements.
|
||||
*/
|
||||
protected PreparedStatement getPstmt(SpiTransaction t, String sql, PersistRequestBean<?> request, boolean genKeys) throws SQLException {
|
||||
PreparedStatement getPstmt(SpiTransaction t, String sql, PersistRequestBean<?> request, boolean genKeys) throws SQLException {
|
||||
|
||||
BatchedPstmtHolder batch = t.getBatchControl().getPstmtHolder();
|
||||
batchedPstmt = batch.getBatchedPstmt(sql, request);
|
||||
|
||||
@@ -5,8 +5,6 @@ package io.ebeaninternal.server.persist.dml;
|
||||
*/
|
||||
public class GenerateDmlRequest {
|
||||
|
||||
private static final String IS_NULL = " is null";
|
||||
|
||||
private final StringBuilder sb = new StringBuilder(100);
|
||||
|
||||
private StringBuilder insertBindBuffer;
|
||||
@@ -57,11 +55,11 @@ public class GenerateDmlRequest {
|
||||
}
|
||||
}
|
||||
|
||||
public int getBindColumnCount() {
|
||||
int getBindColumnCount() {
|
||||
return bindColumnCount;
|
||||
}
|
||||
|
||||
public String getInsertBindBuffer() {
|
||||
String getInsertBindBuffer() {
|
||||
return insertBindBuffer.toString();
|
||||
}
|
||||
|
||||
@@ -70,19 +68,19 @@ public class GenerateDmlRequest {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public void setWhereIdMode() {
|
||||
void setWhereIdMode() {
|
||||
this.prefix = "";
|
||||
this.prefix2 = " and ";
|
||||
}
|
||||
|
||||
public void setInsertSetMode() {
|
||||
void setInsertSetMode() {
|
||||
this.insertBindBuffer = new StringBuilder(100);
|
||||
this.insertMode = 1;
|
||||
this.prefix = "";
|
||||
this.prefix2 = ", ";
|
||||
}
|
||||
|
||||
public void setUpdateSetMode() {
|
||||
void setUpdateSetMode() {
|
||||
this.prefix = "";
|
||||
this.prefix2 = ", ";
|
||||
}
|
||||
|
||||
@@ -64,12 +64,12 @@ class GeneratedProperties {
|
||||
this.generatedProperty = property.getGeneratedProperty();
|
||||
}
|
||||
|
||||
public void preInsert(EntityBean bean, long now) {
|
||||
void preInsert(EntityBean bean, long now) {
|
||||
Object value = generatedProperty.getInsertValue(property, bean, now);
|
||||
property.setValue(bean, value);
|
||||
}
|
||||
|
||||
public void preUpdate(EntityBean bean, long now) {
|
||||
void preUpdate(EntityBean bean, long now) {
|
||||
Object value = generatedProperty.getUpdateValue(property, bean, now);
|
||||
property.setValue(bean, value);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class GeneratedPropertyCollector {
|
||||
return new GeneratedProperties(preInsert, preUpdate);
|
||||
}
|
||||
|
||||
void add(BeanProperty prop) {
|
||||
private void add(BeanProperty prop) {
|
||||
GeneratedProperty gen = prop.getGeneratedProperty();
|
||||
if (gen != null) {
|
||||
if (gen.includeInInsert()) {
|
||||
|
||||
@@ -45,7 +45,7 @@ public class InsertHandler extends DmlHandler {
|
||||
* Create to handle the insert execution.
|
||||
*/
|
||||
public InsertHandler(PersistRequestBean<?> persist, InsertMeta meta) {
|
||||
super(persist, meta.isEmptyStringToNull());
|
||||
super(persist);
|
||||
this.meta = meta;
|
||||
this.concatinatedKey = meta.isConcatenatedKey();
|
||||
}
|
||||
@@ -106,7 +106,7 @@ public class InsertHandler extends DmlHandler {
|
||||
* Check with useGeneratedKeys to get appropriate PreparedStatement.
|
||||
*/
|
||||
@Override
|
||||
protected PreparedStatement getPstmt(SpiTransaction t, String sql, boolean useGeneratedKeys) throws SQLException {
|
||||
PreparedStatement getPstmt(SpiTransaction t, String sql, boolean useGeneratedKeys) throws SQLException {
|
||||
Connection conn = t.getInternalConnection();
|
||||
if (useGeneratedKeys) {
|
||||
return conn.prepareStatement(sql, meta.getIdentityDbColumns());
|
||||
|
||||
@@ -16,7 +16,7 @@ import java.sql.SQLException;
|
||||
* Meta data for insert handler. The meta data is for a particular bean type. It
|
||||
* is considered immutable and is thread safe.
|
||||
*/
|
||||
public final class InsertMeta {
|
||||
final class InsertMeta {
|
||||
|
||||
private final String sqlNullId;
|
||||
private final String sqlWithId;
|
||||
@@ -44,11 +44,7 @@ public final class InsertMeta {
|
||||
|
||||
private final String[] identityDbColumns;
|
||||
|
||||
private final boolean emptyStringToNull;
|
||||
|
||||
public InsertMeta(DatabasePlatform dbPlatform, BeanDescriptor<?> desc, Bindable shadowFKey, BindableId id, BindableList all) {
|
||||
|
||||
this.emptyStringToNull = dbPlatform.isTreatEmptyStringsAsNull();
|
||||
InsertMeta(DatabasePlatform dbPlatform, BeanDescriptor<?> desc, Bindable shadowFKey, BindableId id, BindableList all) {
|
||||
this.discriminator = getDiscriminator(desc);
|
||||
this.id = id;
|
||||
this.all = all;
|
||||
@@ -57,7 +53,6 @@ public final class InsertMeta {
|
||||
|
||||
String tableName = desc.getBaseTable();
|
||||
String draftTableName = desc.getDraftTable();
|
||||
|
||||
this.sqlWithId = genSql(false, tableName, false);
|
||||
this.sqlDraftWithId = desc.isDraftable() ? genSql(false, draftTableName, true) : sqlWithId;
|
||||
|
||||
@@ -90,28 +85,17 @@ public final class InsertMeta {
|
||||
|
||||
private static Bindable getDiscriminator(BeanDescriptor<?> desc) {
|
||||
InheritInfo inheritInfo = desc.getInheritInfo();
|
||||
if (inheritInfo != null) {
|
||||
return new BindableDiscriminator(inheritInfo);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if empty strings should be treated as null.
|
||||
*/
|
||||
public boolean isEmptyStringToNull() {
|
||||
return emptyStringToNull;
|
||||
return inheritInfo != null ? new BindableDiscriminator(inheritInfo) : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this is a concatenated key.
|
||||
*/
|
||||
public boolean isConcatenatedKey() {
|
||||
boolean isConcatenatedKey() {
|
||||
return concatinatedKey;
|
||||
}
|
||||
|
||||
public String[] getIdentityDbColumns() {
|
||||
String[] getIdentityDbColumns() {
|
||||
return identityDbColumns;
|
||||
}
|
||||
|
||||
@@ -119,7 +103,7 @@ public final class InsertMeta {
|
||||
* Return true if we should use a SQL query to return the generated key.
|
||||
* This can not be used with JDBC batch mode.
|
||||
*/
|
||||
public boolean supportsSelectLastInsertedId() {
|
||||
boolean supportsSelectLastInsertedId() {
|
||||
return supportsSelectLastInsertedId;
|
||||
}
|
||||
|
||||
@@ -127,14 +111,14 @@ public final class InsertMeta {
|
||||
* Return true if getGeneratedKeys is supported by the underlying jdbc
|
||||
* driver and database.
|
||||
*/
|
||||
public boolean supportsGetGeneratedKeys() {
|
||||
boolean supportsGetGeneratedKeys() {
|
||||
return supportsGetGeneratedKeys;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the Id can be derived from other property values.
|
||||
*/
|
||||
public boolean deriveConcatenatedId(PersistRequestBean<?> persist) {
|
||||
boolean deriveConcatenatedId(PersistRequestBean<?> persist) {
|
||||
return id.deriveConcatenatedId(persist);
|
||||
}
|
||||
|
||||
@@ -177,8 +161,12 @@ public final class InsertMeta {
|
||||
request.setInsertSetMode();
|
||||
|
||||
request.append("insert into ").append(table);
|
||||
request.append(" (");
|
||||
if (nullId && noColumnsForInsert(draftTable)) {
|
||||
request.append(" default values");
|
||||
return request.toString();
|
||||
}
|
||||
|
||||
request.append(" (");
|
||||
if (!nullId) {
|
||||
id.dmlAppend(request);
|
||||
}
|
||||
@@ -200,8 +188,16 @@ public final class InsertMeta {
|
||||
request.append(") values (");
|
||||
request.append(request.getInsertBindBuffer());
|
||||
request.append(")");
|
||||
|
||||
return request.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the insert actually contains no columns.
|
||||
*/
|
||||
private boolean noColumnsForInsert(boolean draftTable) {
|
||||
return shadowFKey == null
|
||||
&& discriminator == null
|
||||
&& (draftTable ? all.isEmpty() : allExcludeDraftOnly.isEmpty());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.List;
|
||||
/**
|
||||
* Factory for creating InsertMeta UpdateMeta and DeleteMeta.
|
||||
*/
|
||||
public class MetaFactory {
|
||||
class MetaFactory {
|
||||
|
||||
private final FactoryBaseProperties baseFact;
|
||||
private final FactoryEmbedded embeddedFact;
|
||||
@@ -39,16 +39,11 @@ public class MetaFactory {
|
||||
|
||||
private final DatabasePlatform dbPlatform;
|
||||
|
||||
private final boolean emptyStringAsNull;
|
||||
|
||||
MetaFactory(DatabasePlatform dbPlatform) {
|
||||
this.dbPlatform = dbPlatform;
|
||||
this.emptyStringAsNull = dbPlatform.isTreatEmptyStringsAsNull();
|
||||
|
||||
// to bind encryption data before or after the encryption key
|
||||
DbEncrypt dbEncrypt = dbPlatform.getDbEncrypt();
|
||||
boolean bindEncryptDataFirst = dbEncrypt == null || dbEncrypt.isBindEncryptDataFirst();
|
||||
|
||||
this.baseFact = new FactoryBaseProperties(bindEncryptDataFirst);
|
||||
this.embeddedFact = new FactoryEmbedded(bindEncryptDataFirst);
|
||||
}
|
||||
@@ -75,7 +70,7 @@ public class MetaFactory {
|
||||
|
||||
BindableList setBindable = new BindableList(setList);
|
||||
|
||||
return new UpdateMeta(emptyStringAsNull, desc, setBindable, id, version, tenantId);
|
||||
return new UpdateMeta(desc, setBindable, id, version, tenantId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,8 +81,7 @@ public class MetaFactory {
|
||||
BindableId id = idFact.createId(desc);
|
||||
Bindable version = versionFact.createForDelete(desc);
|
||||
Bindable tenantId = versionFact.createTenantId(desc);
|
||||
|
||||
return new DeleteMeta(emptyStringAsNull, desc, id, version, tenantId);
|
||||
return new DeleteMeta(desc, id, version, tenantId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,12 +5,7 @@ import java.sql.SQLException;
|
||||
/**
|
||||
* Implementation API for insert update and delete handlers.
|
||||
*/
|
||||
public interface PersistHandler {
|
||||
|
||||
/**
|
||||
* Return the bind log.
|
||||
*/
|
||||
String getBindLog();
|
||||
interface PersistHandler {
|
||||
|
||||
/**
|
||||
* Get the sql and bind the statement.
|
||||
|
||||
@@ -18,7 +18,7 @@ public class UpdateHandler extends DmlHandler {
|
||||
private boolean emptySetClause;
|
||||
|
||||
UpdateHandler(PersistRequestBean<?> persist, UpdateMeta meta) {
|
||||
super(persist, meta.isEmptyStringAsNull());
|
||||
super(persist);
|
||||
this.meta = meta;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,49 +17,22 @@ import java.util.List;
|
||||
* Meta data for update handler. The meta data is for a particular bean type. It
|
||||
* is considered immutable and is thread safe.
|
||||
*/
|
||||
public final class UpdateMeta {
|
||||
final class UpdateMeta extends BaseMeta {
|
||||
|
||||
private final BindableList set;
|
||||
private final BindableId id;
|
||||
private final Bindable version;
|
||||
private final Bindable tenantId;
|
||||
|
||||
private final String tableName;
|
||||
|
||||
private final UpdatePlan modeNoneUpdatePlan;
|
||||
private final UpdatePlan modeVersionUpdatePlan;
|
||||
|
||||
private final boolean emptyStringAsNull;
|
||||
|
||||
UpdateMeta(boolean emptyStringAsNull, BeanDescriptor<?> desc, BindableList set, BindableId id, Bindable version, Bindable tenantId) {
|
||||
this.emptyStringAsNull = emptyStringAsNull;
|
||||
this.tableName = desc.getBaseTable();
|
||||
UpdateMeta(BeanDescriptor<?> desc, BindableList set, BindableId id, Bindable version, Bindable tenantId) {
|
||||
super(id, version, tenantId);
|
||||
this.set = set;
|
||||
this.id = id;
|
||||
this.version = version;
|
||||
this.tenantId = tenantId;
|
||||
|
||||
String sqlNone = genSql(ConcurrencyMode.NONE, set, desc.getBaseTable());
|
||||
String sqlVersion = genSql(ConcurrencyMode.VERSION, set, desc.getBaseTable());
|
||||
|
||||
this.modeNoneUpdatePlan = new UpdatePlan(ConcurrencyMode.NONE, sqlNone, set);
|
||||
this.modeVersionUpdatePlan = new UpdatePlan(ConcurrencyMode.VERSION, sqlVersion, set);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if empty strings should be treated as null.
|
||||
*/
|
||||
boolean isEmptyStringAsNull() {
|
||||
return emptyStringAsNull;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the base table name.
|
||||
*/
|
||||
public String getTableName() {
|
||||
return tableName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bind the request based on the concurrency mode.
|
||||
*/
|
||||
@@ -135,7 +108,6 @@ public final class UpdateMeta {
|
||||
|
||||
GenerateDmlRequest request = new GenerateDmlRequest();
|
||||
request.append("update ").append(tableName).append(" set ");
|
||||
|
||||
request.setUpdateSetMode();
|
||||
bindableList.dmlAppend(request);
|
||||
|
||||
@@ -146,19 +118,7 @@ public final class UpdateMeta {
|
||||
}
|
||||
|
||||
request.append(" where ");
|
||||
|
||||
request.setWhereIdMode();
|
||||
id.dmlAppend(request);
|
||||
if (tenantId != null) {
|
||||
tenantId.dmlAppend(request);
|
||||
}
|
||||
if (ConcurrencyMode.VERSION == conMode) {
|
||||
if (version != null) {
|
||||
version.dmlAppend(request);
|
||||
}
|
||||
}
|
||||
|
||||
return request.toString();
|
||||
return appendWhere(request, conMode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import java.sql.SQLException;
|
||||
/**
|
||||
* Plan for executing bean updates for a given set of changed properties.
|
||||
*/
|
||||
public class UpdatePlan implements SpiUpdatePlan {
|
||||
class UpdatePlan implements SpiUpdatePlan {
|
||||
|
||||
private final String key;
|
||||
|
||||
|
||||
@@ -14,9 +14,9 @@ import java.util.List;
|
||||
*/
|
||||
class BindableAssocOne implements Bindable {
|
||||
|
||||
protected final BeanPropertyAssocOne<?> assocOne;
|
||||
final BeanPropertyAssocOne<?> assocOne;
|
||||
|
||||
protected final ImportedId importedId;
|
||||
final ImportedId importedId;
|
||||
|
||||
BindableAssocOne(BeanPropertyAssocOne<?> assocOne) {
|
||||
this.assocOne = assocOne;
|
||||
@@ -55,7 +55,7 @@ class BindableAssocOne implements Bindable {
|
||||
/**
|
||||
* Bind and register a deferred relationship value.
|
||||
*/
|
||||
void registerDeferred(BindableRequest request, EntityBean bean, EntityBean assocBean) throws SQLException {
|
||||
private void registerDeferred(BindableRequest request, EntityBean bean, EntityBean assocBean) throws SQLException {
|
||||
Object boundValue = importedId.bind(request, assocBean);
|
||||
if (boundValue == null && assocBean != null) {
|
||||
// this is the scenario for a derived foreign key
|
||||
|
||||
@@ -4,7 +4,6 @@ import io.ebean.bean.EntityBean;
|
||||
import io.ebeaninternal.server.core.PersistRequestBean;
|
||||
import io.ebeaninternal.server.persist.dml.GenerateDmlRequest;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
public class BindableIdEmpty implements BindableId {
|
||||
@@ -30,7 +29,7 @@ public class BindableIdEmpty implements BindableId {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
|
||||
public void dmlBind(BindableRequest request, EntityBean bean) {
|
||||
// nothing
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,10 @@ public class BindableList implements Bindable {
|
||||
return new BindableList(copy);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return items.length == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDraftOnly() {
|
||||
return false;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user