#919 - io.ebean package initial

This commit is contained in:
Rob Bygrave
2016-12-11 23:23:22 +13:00
parent 5821dc96b9
commit 971e2dc91b
2134 changed files with 10721 additions and 8652 deletions
@@ -0,0 +1,45 @@
package io.ebeaninternal.server.properties;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
/**
* Determines the properties on a given bean.
*/
public class BeanPropertiesReader {
private final Map<String, Integer> propertyIndexMap = new HashMap<>();
private final String[] props;
public BeanPropertiesReader(Class<?> clazz) {
this.props = getProperties(clazz);
for (int i = 0; i < props.length; i++) {
propertyIndexMap.put(props[i], i);
}
}
public String[] getProperties() {
return props;
}
public String toString() {
return Arrays.toString(props);
}
public Integer getPropertyIndex(String property) {
return propertyIndexMap.get(property);
}
private String[] getProperties(Class<?> clazz) {
try {
Field field = clazz.getField("_ebean_props");
return (String[]) field.get(null);
} catch (Exception e) {
throw new IllegalStateException("Error getting _ebean_props field on type " + clazz, e);
}
}
}
@@ -0,0 +1,17 @@
package io.ebeaninternal.server.properties;
/**
* Provides getter setter methods for beans.
*/
public interface BeanPropertyAccess {
/**
* Return the getter for a given bean property.
*/
BeanPropertyGetter getGetter(int position);
/**
* Return the setter for a given bean property.
*/
BeanPropertySetter getSetter(int position);
}
@@ -0,0 +1,17 @@
package io.ebeaninternal.server.properties;
import io.ebean.bean.EntityBean;
/**
* The getter implementation for a given bean property.
*/
public interface BeanPropertyGetter {
/**
* Return the value of a given bean property.
*/
Object get(EntityBean bean);
Object getIntercept(EntityBean bean);
}
@@ -0,0 +1,23 @@
package io.ebeaninternal.server.properties;
import io.ebean.bean.EntityBean;
/**
* The setter for a given bean property.
*/
public interface BeanPropertySetter {
/**
* Set the property value of a bean.
*/
void set(EntityBean bean, Object value);
/**
* Set the property value of a bean with interception checks.
* <p>
* This could invoke lazy loading and or oldValues creation.
* </p>
*/
void setIntercept(EntityBean bean, Object value);
}
@@ -0,0 +1,82 @@
package io.ebeaninternal.server.properties;
import io.ebean.bean.EntityBean;
/**
* Returns Getter and Setter methods based on EntityBean enhancement and field position.
*/
public final class EnhanceBeanPropertyAccess implements BeanPropertyAccess {
private static final int CACHE_SIZE = 30;
private final BeanPropertyGetter[] getters = initGetters(CACHE_SIZE);
private final BeanPropertySetter[] setters = initSetters(CACHE_SIZE);
public EnhanceBeanPropertyAccess() {
}
private BeanPropertyGetter[] initGetters(int count) {
BeanPropertyGetter[] getters = new BeanPropertyGetter[count];
for (int i = 0; i < count; i++) {
getters[i] = new Getter(i);
}
return getters;
}
private BeanPropertySetter[] initSetters(int count) {
BeanPropertySetter[] setters = new BeanPropertySetter[count];
for (int i = 0; i < count; i++) {
setters[i] = new Setter(i);
}
return setters;
}
public BeanPropertyGetter getGetter(int position) {
if (position < CACHE_SIZE) {
return getters[position];
}
return new Getter(position);
}
public BeanPropertySetter getSetter(int position) {
if (position < CACHE_SIZE) {
return setters[position];
}
return new Setter(position);
}
private static final class Getter implements BeanPropertyGetter {
private final int fieldIndex;
Getter(int fieldIndex) {
this.fieldIndex = fieldIndex;
}
public Object get(EntityBean bean) {
return bean._ebean_getField(fieldIndex);
}
public Object getIntercept(EntityBean bean) {
return bean._ebean_getFieldIntercept(fieldIndex);
}
}
private static final class Setter implements BeanPropertySetter {
private final int fieldIndex;
Setter(int fieldIndex) {
this.fieldIndex = fieldIndex;
}
public void set(EntityBean bean, Object value) {
bean._ebean_setField(fieldIndex, value);
}
public void setIntercept(EntityBean bean, Object value) {
bean._ebean_setFieldIntercept(fieldIndex, value);
}
}
}
@@ -0,0 +1,15 @@
<HTML>
<HEAD>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=iso-8859-1">
<TITLE>Bean Reflection</TITLE>
</HEAD>
<Body BGCOLOR="#ffffff">
Bean reflection Implementation
<p>
Abstracts the bean property getter and setter methods.
Allows Code generation or reflection to be used.
</p>
</Body>
</HTML>