--- /dev/null
+/*
+ * Copyright 2005-2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.persistence;
+
+/**
+ * Abstraction for accessing fields or properties of an object.
+ *
+ * @author Erik Brakkee
+ *
+ * @param <T>
+ */
+public interface Accessor<T> {
+ /**
+ * Sets the value.
+ * @param aObject Object.
+ * @param aValue Value.
+ */
+ void set(Object aObject, T aValue);
+
+ /**
+ * Gets the value.
+ * @param aObject Object
+ * @return Value
+ */
+ T get(Object aObject);
+}
+
--- /dev/null
+/*
+ * Copyright 2005-2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.persistence;
+
+import java.lang.reflect.Field;
+
+/**
+ * Utility for interfacing to a field of an object.
+ *
+ * @author Erik Brakkee
+ *
+ * @param <T> Type of the field.
+ */
+class FieldAccessor<T> implements Accessor<T> {
+ private Field field;
+
+ /**
+ * Constructs the accessor.
+ * @param aField Field.
+ */
+ public FieldAccessor(Field aField) {
+ field = aField;
+ field.setAccessible(true);
+ }
+
+ @Override
+ public T get(Object aEntity) {
+ try {
+ T value = (T) field.get(aEntity);
+ return value;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void set(Object aEntity, T aValue) {
+ try {
+ field.set(aEntity, aValue);
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(e.getMessage(), e);
+ }
+ }
+
+ /**
+ * Gets the field.
+ * @return Field.
+ */
+ public Field getField() {
+ return field;
+ }
+}
\ No newline at end of file
*/
private static Map<String, EntityAccessor> CACHE = new ConcurrentHashMap<String, EntityAccessor>();
- public static interface Accessor<T> {
- void set(Object aEntity, T aValue);
-
- T get(Object aEntity);
- }
-
- static class FieldAccessor<T> implements Accessor<T> {
- private Field field;
-
- public FieldAccessor(Field aField) {
- field = aField;
- field.setAccessible(true);
- }
-
- @Override
- public T get(Object aEntity) {
- try {
- T value = (T) field.get(aEntity);
- return value;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public void set(Object aEntity, T aValue) {
- try {
- field.set(aEntity, aValue);
- } catch (IllegalAccessException e) {
- throw new RuntimeException(e.getMessage(), e);
- }
- }
-
- public Field getField() {
- return field;
- }
- }
-
- static class PropertyAccessor<T> implements Accessor<T> {
- private Method getter;
- private Method setter;
-
- public PropertyAccessor(Method aGetter, Method aSetter) {
- getter = aGetter;
- setter = aSetter;
- getter.setAccessible(true);
- setter.setAccessible(true);
- }
-
- @Override
- public T get(Object aEntity) {
- try {
- return (T) getter.invoke(aEntity);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- @Override
- public void set(Object aEntity, T aValue) {
- try {
- setter.invoke(aEntity, aValue);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- public Method getGetter() {
- return getter;
- }
-
- public Method getSetter() {
- return setter;
- }
- }
-
static class EntityAccessor {
private Accessor pk;
private Accessor version;
--- /dev/null
+/*
+ * Copyright 2005-2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.persistence;
+
+import java.lang.reflect.Method;
+
+/**
+ * Accessing a property of an object.
+ *
+ * @author Erik Brakkee
+ *
+ * @param <T> Type of the property.
+ */
+class PropertyAccessor<T> implements Accessor<T> {
+ private Method getter;
+ private Method setter;
+
+ /**
+ * Constructs the accessor.
+ * @param aGetter Getter method.
+ * @param aSetter Setter method.
+ */
+ public PropertyAccessor(Method aGetter, Method aSetter) {
+ getter = aGetter;
+ setter = aSetter;
+ getter.setAccessible(true);
+ setter.setAccessible(true);
+ }
+
+ @Override
+ public T get(Object aEntity) {
+ try {
+ return (T) getter.invoke(aEntity);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Override
+ public void set(Object aEntity, T aValue) {
+ try {
+ setter.invoke(aEntity, aValue);
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * @return The getter.
+ */
+ public Method getGetter() {
+ return getter;
+ }
+
+ /**
+ * @return The setter.
+ */
+ public Method getSetter() {
+ return setter;
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2005-2010 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.wamblee.reflection;
+
+/**
+ * Utlities for working with annotations.
+ *
+ * @author Erik Brakkee
+ *
+ */
+public class AnnotationUtils {
+
+}
import javax.persistence.Version;
import org.junit.Test;
-import org.wamblee.persistence.PersistentFactory.Accessor;
import org.wamblee.persistence.PersistentFactory.EntityAccessor;
import org.wamblee.persistence.PersistentFactory.EntityObjectAccessor;
-import org.wamblee.persistence.PersistentFactory.FieldAccessor;
-import org.wamblee.persistence.PersistentFactory.PropertyAccessor;
public class PersistentFactoryTest {