Add Period support via CompoundTypePeriod, rename server/reflect to server/properties

This commit is contained in:
rbygrave committed 2014-11-18 23:09:26 +13:00
1 parent 98f6e1e6af
commit 07cdb69a5b
27 files changed
+501 -333

No files matched your search

@@ -14,40 +14,41 @@ import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
*/
public class BindableCompound implements Bindable {
private final Bindable[] items;
private final BindableProperty[] items;
private final BeanPropertyCompound compound;
private final BeanPropertyCompound compound;
public BindableCompound(BeanPropertyCompound embProp, List<Bindable> list) {
this.compound = embProp;
this.items = list.toArray(new Bindable[list.size()]);
public BindableCompound(BeanPropertyCompound embProp, List<BindableProperty> list) {
this.compound = embProp;
this.items = list.toArray(new BindableProperty[list.size()]);
}
public String toString() {
return "BindableCompound " + compound + " items:" + Arrays.toString(items);
}
public void dmlAppend(GenerateDmlRequest request) {
for (int i = 0; i < items.length; i++) {
items[i].dmlAppend(request);
}
}
public String toString() {
return "BindableCompound " + compound + " items:" + Arrays.toString(items);
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
if (request.isAddToUpdate(compound)) {
list.add(this);
}
}
public void dmlAppend(GenerateDmlRequest request) {
public void dmlBind(BindableRequest bindRequest, EntityBean bean) throws SQLException {
for (int i = 0; i < items.length; i++) {
items[i].dmlAppend(request);
}
}
// get the compound type value
Object valueObject = compound.getValue(bean);
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
if (request.isAddToUpdate(compound)) {
list.add(this);
}
}
public void dmlBind(BindableRequest bindRequest, EntityBean bean) throws SQLException {
throw new RuntimeException("This is broken, need to break out the scalar values!!");
//Object valueObject = compound.getValue(bean);
//for (int i = 0; i < items.length; i++) {
// items[i].dmlBind(bindRequest, valueObject);
//}
// bind each of the underlying scalar values for this compound type
for (int i = 0; i < items.length; i++) {
items[i].dmlBindObject(bindRequest, valueObject);
}
}
}
@@ -13,33 +13,47 @@ import com.avaje.ebeaninternal.server.persist.dml.GenerateDmlRequest;
*/
public class BindableProperty implements Bindable {
protected final BeanProperty prop;
protected final BeanProperty prop;
public BindableProperty(BeanProperty prop) {
this.prop = prop;
public BindableProperty(BeanProperty prop) {
this.prop = prop;
}
public String toString() {
return prop.toString();
}
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
if (request.isAddToUpdate(prop)) {
list.add(this);
}
}
public String toString() {
return prop.toString();
public void dmlAppend(GenerateDmlRequest request) {
request.appendColumn(prop.getDbColumn());
}
/**
* Normal binding of a property value from the bean.
*/
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
Object value = null;
if (bean != null) {
value = prop.getValue(bean);
}
request.bind(value, prop, prop.getName());
}
public void addToUpdate(PersistRequestBean<?> request, List<Bindable> list) {
if (request.isAddToUpdate(prop)) {
list.add(this);
}
}
/**
* For compound types bind one of the underlying scalar values for a compound type.
*/
public void dmlBindObject(BindableRequest request, Object bean) throws SQLException {
public void dmlAppend(GenerateDmlRequest request) {
request.appendColumn(prop.getDbColumn());
}
public void dmlBind(BindableRequest request, EntityBean bean) throws SQLException {
Object value = null;
if (bean != null) {
value = prop.getValue(bean);
}
// value = prop.getDefaultValue();
request.bind(value, prop, prop.getName());
Object value = null;
if (bean != null) {
value = prop.getValueObject(bean);
}
request.bind(value, prop, prop.getName());
}
}
@@ -16,49 +16,52 @@ import com.avaje.ebeaninternal.server.persist.dml.DmlMode;
*/
public class FactoryBaseProperties {
private final FactoryProperty factoryProperty;
public FactoryBaseProperties(boolean bindEncryptDataFirst) {
factoryProperty = new FactoryProperty(bindEncryptDataFirst);
}
private final FactoryProperty factoryProperty;
/**
* Add Bindable for the base properties to the list.
*/
public void create(List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode, boolean withLobs) {
add(desc.propertiesBaseScalar(), list, desc, mode, withLobs);
public FactoryBaseProperties(boolean bindEncryptDataFirst) {
factoryProperty = new FactoryProperty(bindEncryptDataFirst);
}
BeanPropertyCompound[] compoundProps = desc.propertiesBaseCompound();
for (int i = 0; i < compoundProps.length; i++) {
BeanProperty[] props = compoundProps[i].getScalarProperties();
/**
* Add Bindable for the base properties to the list.
*/
public void create(List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode, boolean withLobs) {
ArrayList<Bindable> newList = new ArrayList<Bindable>(props.length);
add(props, newList, desc, mode, withLobs);
BindableCompound compoundBindable = new BindableCompound(compoundProps[i], newList);
add(desc.propertiesBaseScalar(), list, desc, mode, withLobs);
list.add(compoundBindable);
}
}
BeanPropertyCompound[] compoundProps = desc.propertiesBaseCompound();
for (int i = 0; i < compoundProps.length; i++) {
BeanProperty[] props = compoundProps[i].getScalarProperties();
private void add(BeanProperty[] props, List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode, boolean withLobs) {
List<BindableProperty> newList = new ArrayList<BindableProperty>(props.length);
addCompound(props, newList, desc, mode, withLobs);
for (int i = 0; i < props.length; i++) {
BindableCompound compoundBindable = new BindableCompound(compoundProps[i], newList);
// if(DmlMode.WHERE.equals(mode) && !withLobs && !props[i].isDbUpdatable()) {
// // skip non-updatable column from where clause
// } else {
Bindable item = factoryProperty.create(props[i], mode, withLobs);
if (item != null) {
list.add(item);
} else {
// null where readOnly (Secondary tables) or Lob exclusion
}
// }
}
list.add(compoundBindable);
}
}
private void add(BeanProperty[] props, List<Bindable> list, BeanDescriptor<?> desc, DmlMode mode, boolean withLobs) {
for (int i = 0; i < props.length; i++) {
Bindable item = factoryProperty.create(props[i], mode, withLobs);
if (item != null) {
list.add(item);
}
}
}
private void addCompound(BeanProperty[] props, List<BindableProperty> list, BeanDescriptor<?> desc, DmlMode mode, boolean withLobs) {
for (int i = 0; i < props.length; i++) {
BindableProperty item = (BindableProperty) factoryProperty.create(props[i], mode, withLobs);
if (item != null) {
list.add(item);
}
}
}
}