Skip to content

Commit

Permalink
Merge branch 'master-rob' into master-new
Browse files Browse the repository at this point in the history
  • Loading branch information
rPraml committed Aug 11, 2023
2 parents 14e8af4 + 1ca73ca commit b83bba0
Show file tree
Hide file tree
Showing 11 changed files with 262 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ public enum EntityType {
private final EntityBean prototypeEntityBean;

private final IdBinder idBinder;
private final String idSelect;
private String idBinderInLHSSql;
private String idBinderIdSql;
private String deleteByIdSql;
Expand Down Expand Up @@ -355,23 +354,11 @@ public BeanDescriptor(BeanDescriptorMap owner, DeployBeanDescriptor<T> deploy) {
propertiesIndex[i] = propMap.get(ebi.property(i));
}
}
idSelect = initIdSelect();
}

String initIdSelect() {
if (idProperty != null && !idProperty.name().equals("_idClass")) {
return idProperty.name();
} else if (entityType == EntityType.EMBEDDED) {
return null;
} else {
StringJoiner sj = new StringJoiner(",");
for (BeanProperty prop : propertiesNonMany) {
if (prop.isImportedPrimaryKey()) {
sj.add(prop.name());
}
}
return sj.toString().intern();
}
public String idSelect() {
if (idBinder == null) throw new UnsupportedOperationException();
return idBinder.idSelect();
}

public boolean isJacksonCorePresent() {
Expand Down Expand Up @@ -2436,9 +2423,13 @@ public BeanProperty findProperty(String propName) {

BeanProperty _findBeanProperty(String propName) {
BeanProperty prop = propMap.get(propName);
if (prop == null && inheritInfo != null) {
// search in sub types...
return inheritInfo.findSubTypeProperty(propName);
if (prop == null) {
if ("_idClass".equals(propName)) {
return idProperty;
} else if (inheritInfo != null) {
// search in sub types...
return inheritInfo.findSubTypeProperty(propName);
}
}
return prop;
}
Expand Down Expand Up @@ -3043,10 +3034,6 @@ public BeanProperty idProperty() {
return idProperty;
}

public String idSelect() {
return idSelect;
}

/**
* Return true if this bean should be inserted rather than updated.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@ abstract class BeanDescriptorElement<T> extends BeanDescriptor<T> {
this.elementHelp = elementHelp;
}

@Override
String initIdSelect() {
return null;
}

private String shortName(String name) {
int pos = name.lastIndexOf('.');
if (pos > 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public interface IdBinder {
*/
void initialise();

String idSelect();

/**
* Return true if this is a compound key and must use expanded and or form.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public void initialise() {
this.idInValueSql = idInExpandedForm ? idInExpanded() : idInCompressed();
}

@Override
public String idSelect() {
return embIdProperty.name();
}

@Override
public boolean isIdInExpandedForm() {
return idInExpandedForm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import io.ebean.bean.EntityBean;
import io.ebeaninternal.api.SpiExpressionRequest;
import io.ebeaninternal.server.bind.DataBind;
import io.ebeaninternal.server.core.DefaultSqlUpdate;
import io.ebeaninternal.server.deploy.BeanProperty;
import io.ebeaninternal.server.deploy.DbReadContext;
import io.ebeaninternal.server.deploy.DbSqlContext;
import io.ebeaninternal.server.bind.DataBind;

import java.io.DataInput;
import java.io.DataOutput;
Expand All @@ -27,6 +27,11 @@ public IdBinderEmpty() {
public void initialise() {
}

@Override
public String idSelect() {
return "";
}

@Override
public boolean isIdInExpandedForm() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public void initialise() {
// do nothing
}

@Override
public String idSelect() {
return idProperty.name();
}

@Override
public boolean isIdInExpandedForm() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,36 @@
public class CEPProductCategoryId {

// primitive id values as part of an EmbeddedId (NPE #1722)
private long customerId;
private long addressId;
private long categoryId;
private long productId;

public long getCustomerId() {
return customerId;
public long getCategoryId() {
return categoryId;
}

public void setCustomerId(long customerId) {
this.customerId = customerId;
public void setCategoryId(long categoryId) {
this.categoryId = categoryId;
}

public long getAddressId() {
return addressId;
public long getProductId() {
return productId;
}

public void setAddressId(long addressId) {
this.addressId = addressId;
public void setProductId(long productId) {
this.productId = productId;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CEPProductCategoryId that = (CEPProductCategoryId) o;
return customerId == that.customerId &&
addressId == that.addressId;
return categoryId == that.categoryId &&
productId == that.productId;
}

@Override
public int hashCode() {
return Objects.hash(customerId, addressId);
return Objects.hash(categoryId, productId);
}
}
53 changes: 53 additions & 0 deletions ebean-test/src/test/java/org/tests/cache/embeddedid/Concept.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.tests.cache.embeddedid;

import javax.persistence.*;
import java.util.List;

@Entity
@IdClass(ConceptId.class)
@SuppressWarnings("unused")
public class Concept {
@Id
private String id;

@Id
private String networkId;

private String label;

@OneToMany(mappedBy = "from", cascade = {CascadeType.ALL})
private List<Connection> outgoingConnections;

@OneToMany(mappedBy = "to", cascade = {CascadeType.ALL})
private List<Connection> incomingConnections;

public Concept(String networkId, String id, String label) {
this.networkId = networkId;
this.id = id;
this.label = label;
}

public String id() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String networkId() {
return networkId;
}

public void setNetworkId(String networkId) {
this.networkId = networkId;
}

public String label() {
return label;
}

public void setLabel(String label) {
this.label = label;
}
}
31 changes: 31 additions & 0 deletions ebean-test/src/test/java/org/tests/cache/embeddedid/ConceptId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.tests.cache.embeddedid;

import javax.persistence.Embeddable;

@Embeddable
public class ConceptId {
private final String networkId;
private final String id;

public ConceptId(String networkId, String id) {
this.networkId = networkId;
this.id = id;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

ConceptId conceptId = (ConceptId) o;
if (!id.equals(conceptId.id)) return false;
return networkId.equals(conceptId.networkId);
}

@Override
public int hashCode() {
int result = id.hashCode();
result = 31 * result + networkId.hashCode();
return result;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package org.tests.cache.embeddedid;

import javax.persistence.*;

@Entity
@IdClass(ConceptId.class)
@SuppressWarnings("unused")
public class Connection {
@Id
private String id;

@Id
private String networkId;

private String label;

@ManyToOne(optional = false)
@JoinColumns({
@JoinColumn(name = "from_conc", referencedColumnName = "id", nullable = false),
@JoinColumn(
name = "network_id", referencedColumnName = "network_id",
nullable = false, insertable = false, updatable = false
)
})
private Concept from;

@ManyToOne(optional = false)
@JoinColumns({
@JoinColumn(name = "to_conc", referencedColumnName = "id", nullable = false),
@JoinColumn(
name = "network_id", referencedColumnName = "network_id",
nullable = false, insertable = false, updatable = false
)
})
private Concept to;

public Connection(
String networkId, String id, String label,
Concept from, Concept to
) {
this.networkId = networkId;
this.id = id;
this.label = label;
this.from = from;
this.to = to;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getNetworkId() {
return networkId;
}

public void setNetworkId(String networkId) {
this.networkId = networkId;
}

public String getLabel() {
return label;
}

public void setLabel(String label) {
this.label = label;
}

public Concept from() {
return from;
}

public void setFrom(Concept from) {
this.from = from;
}

public Concept to() {
return to;
}

public void setTo(Concept to) {
this.to = to;
}
}
Loading

0 comments on commit b83bba0

Please sign in to comment.