Skip to content

Commit 7845c21

Browse files
committed
Made major changes to only depend on fields, split long strings to multi-attributes, added OFFSET keyword support, and serialize objects to Base64.
WARNING: Had to comment out foreign key and lobkey support due to its dependencies on beans and enhancers. Will re-add them when I have time to do it without beans and enhancers. WARNING: core/tests will have some commented/removed code, will add proper tests concerning the major changes. Removed most dependencies on get/set methods, beans, and enhancers. (There are still some enhancers and beans somewhere, but most of them shouldn't be used) Long strings get split to multiple attribute/value pairs (most code from appoxy#5 , adapted for more recent changes in SimpleJPA) Any serializable objects in members will be serialized into Base64 string (uses long strings split change). Added OFFSET keyword support, which does a count query and uses the next token to get wanted items (as suggested by AWS people). Added utility constructor in EntityManagerFactoryImp. SimpleJPA should ignore static fields now. Updated README.markdown (and fixed some stuff so it's actually readable). Signed-off-by: jayther <jayther@gmail.com>
1 parent 94af6be commit 7845c21

23 files changed

+487
-189
lines changed

README.markdown

Lines changed: 71 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
#Jayther's SimpleJPA Fork#
2+
**Note**: this is more for myself so it's easy for me to work with JPA-style configurations.
3+
4+
Improvements include only depending on member fields, splitting long strings to multiple attribute/value pairs (from https://github.com/appoxy/simplejpa/pull/5 , adapted to work in SimpleJPA's more recent changes), and serialize objects into Base64 strings (which also use the long string split feature).
5+
6+
**WARNING**: Foreign keys and Lobs support are removed for now to remove dependencies on beans and enhancers. Will re-add support when I have time.
7+
8+
**WARNING**: There are some commented/removed code in the tests. Will add proper tests for the major changes.
9+
110
#SimpleJPA's new home.#
211

312
Discussion Group: http://groups.google.com/group/simplejpa
@@ -8,42 +17,45 @@ Here's how to get started using SimpleJPA.
817
##Dependencies##
918
Starting with version 1.5 SimpleJPA switched to use Amazon's Java SDK. Use the latest releases of (I'll try to package these up into the release if I can figure out the licensing compatability):
1019

11-
commons-lang - You can grab all commons libs at http://commons.apache.org/downloads/index.html
12-
commons-collections
13-
commons-logging
14-
commons-codec
15-
cglib-nodep
16-
kitty-cache
17-
ehcache
18-
scannotation
19-
javassist (required for scannotation)
20-
ejb3-persistence-api
21-
AWS SDK for Java
22-
Apache HttpClient
20+
* commons-lang - You can grab all commons libs at http://commons.apache.org/downloads/index.html
21+
* commons-collections
22+
* commons-logging
23+
* commons-codec
24+
* cglib-nodep
25+
* kitty-cache
26+
* ehcache
27+
* scannotation
28+
* javassist (required for scannotation)
29+
* ejb3-persistence-api
30+
* AWS SDK for Java
31+
* Apache HttpClient
32+
2333
When building from source and using the Maven pom.xml file Kitty-cache will need to be added explicitly as a reference.
2434

2535
Dependencies for versions pre 1.5
26-
commons-lang - You can grab all commons libs at http://commons.apache.org/downloads/index.html
27-
commons-beanutils
28-
commons-collections
29-
commons-logging (required for jets3t)
30-
commons-codec (required for jets3t)
31-
Apache HttpClient - (required for jets3t)
32-
typica
33-
jets3t
34-
cglib-nodep - http://sourceforge.net/project/showfiles.php?group_id=56933
35-
ejb3-persistence-api - http://mirrors.ibiblio.org/pub/mirrors/maven2/org/hibernate/ejb3-persistence/1.0.2.GA/
36-
scannotation - http://scannotation.sourceforge.net/
37-
javassist (scannotation) - http://www.csg.is.titech.ac.jp/~chiba/javassist/
38-
kitty-cache - http://code.google.com/p/kitty-cache/
39-
ehcache - http://ehcache.org/
36+
37+
* commons-lang - You can grab all commons libs at http://commons.apache.org/downloads/index.html
38+
* commons-beanutils
39+
* commons-collections
40+
* commons-logging (required for jets3t)
41+
* commons-codec (required for jets3t)
42+
* Apache HttpClient - (required for jets3t)
43+
* typica
44+
* jets3t
45+
* cglib-nodep - http://sourceforge.net/project/showfiles.php?group_id=56933
46+
* ejb3-persistence-api - http://mirrors.ibiblio.org/pub/mirrors/maven2/org/hibernate/ejb3-persistence/1.0.2.GA/
47+
* scannotation - http://scannotation.sourceforge.net/
48+
* javassist (scannotation) - http://www.csg.is.titech.ac.jp/~chiba/javassist/
49+
* kitty-cache - http://code.google.com/p/kitty-cache/
50+
* ehcache - http://ehcache.org/
4051

4152

4253
##Setup##
4354
Create a file called simplejpa.properties and put on the classpath. Add your Amazon access key and secret key like:
4455

45-
accessKey = AAAAAAAAAAAAAAAAAAAAAAA
46-
secretKey = SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
56+
accessKey = AAAAAAAAAAAAAAAAAAAAAAA
57+
secretKey = SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
58+
4759
For more configuration options, see Configuration.
4860

4961
Now the Code
@@ -56,48 +68,49 @@ EntityManager em = factory.createEntityManager();
5668
##Persisting an object##
5769
Lets create a very simple object to store.
5870

59-
@Entity
60-
public class MyTestObject {
61-
private String id;
62-
private String name;
63-
64-
@Id
65-
public String getId() {
66-
return id;
67-
}
68-
69-
public void setId(String id) {
70-
this.id = id;
71-
}
72-
73-
public void setName(String name) {
74-
this.name = name;
75-
}
76-
77-
public String getName() {
78-
return name;
79-
}
80-
81-
}
71+
@Entity
72+
public class MyTestObject {
73+
@Id
74+
private String id;
75+
private String name;
76+
77+
public String getId() {
78+
return id;
79+
}
80+
81+
public void setId(String id) {
82+
this.id = id;
83+
}
84+
85+
public void setName(String name) {
86+
this.name = name;
87+
}
88+
89+
public String getName() {
90+
return name;
91+
}
92+
93+
}
8294
Now to persist it:
8395

84-
MyObject ob = new MyObject();
85-
ob.setName("Scooby doo");
86-
em.persist(ob);
96+
MyObject ob = new MyObject();
97+
ob.setName("Scooby doo");
98+
em.persist(ob);
99+
87100
That's it!
88101

89102
##Querying##
90103
See JPAQuery
91104

92105
##Deleting##
93-
MyObject ob...
94-
em.remove(ob);
106+
MyObject ob...
107+
em.remove(ob);
95108
Close the EntityManager when you're done
96109
This is done after you've completed a set of tasks, such as displaying a web page. It ensures that caches get cleaned up and no memory gets wasted.
97110

98-
em.close();
111+
em.close();
99112
Close the EntityManagerFactory before you shutdown your app
100-
factory.close();
113+
factory.close();
101114
##What Next?##
102115
See all the JPA features currently supported.
103116
Cast your EntityManager to SimpleEntityManager to get more advanced features like asynchronous operations.

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<modelVersion>4.0.0</modelVersion>
33
<groupId>SimpleJPA</groupId>
44
<artifactId>SimpleJPA</artifactId>
5-
<version>1.6-SNAPSHOT-aldrinleal</version>
5+
<version>1.6.1-SNAPSHOT-gm</version>
66
<name>SimpleJPA</name>
77
<dependencies>
88
<dependency>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Class-Path:
3+

core/src/main/java/com/spaceprogram/simplejpa/AnnotationInfo.java

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
public class AnnotationInfo {
1818

1919
private Annotation[] classAnnotations;
20-
private PersistentProperty idMethod;
20+
private PersistentProperty idProperty;
2121
private Map<String, PersistentProperty> persistentProperties = new HashMap();
2222
private String discriminatorValue;
2323
private String domainName;
@@ -30,7 +30,7 @@ public void setClassAnnotations(Annotation[] classAnnotations) {
3030
}
3131

3232
public void setIdProperty(PersistentProperty property) {
33-
this.idMethod = property;
33+
this.idProperty = property;
3434
}
3535

3636
public void setDomainName(String domainName) {
@@ -41,24 +41,15 @@ public Annotation[] getClassAnnotations() {
4141
return classAnnotations;
4242
}
4343

44-
public PersistentProperty getIdMethod() {
45-
return idMethod;
44+
public PersistentProperty getIdProperty() {
45+
return idProperty;
4646
}
4747

4848
public String getDomainName()
4949
{
5050
return domainName;
5151
}
5252

53-
public PersistentProperty addGetter(Method method) {
54-
PersistentMethod persistentMethod = new PersistentMethod(method);
55-
// if we already have an accessor in the list, don't overwrite it
56-
if (persistentProperties.containsKey(persistentMethod.getFieldName())) return persistentProperties.get(persistentMethod.getFieldName());
57-
persistentProperties.put(persistentMethod.getFieldName(), persistentMethod);
58-
if (persistentMethod.isId()) setIdProperty(persistentMethod);
59-
return persistentMethod;
60-
}
61-
6253
public PersistentProperty addField(Field field) {
6354
PersistentField persistentField = new PersistentField(field);
6455
// if we already have an accessor in the list, don't overwrite it

core/src/main/java/com/spaceprogram/simplejpa/AnnotationManager.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.lang.reflect.Field;
55
import java.lang.reflect.InvocationTargetException;
66
import java.lang.reflect.Method;
7+
import java.lang.reflect.Modifier;
78
import java.util.ArrayList;
89
import java.util.Arrays;
910
import java.util.HashMap;
@@ -80,13 +81,19 @@ public AnnotationInfo getAnnotationInfo(Class c) {
8081

8182
private AnnotationInfo getAnnotationInfo(String className) {
8283
AnnotationInfo ai = getAnnotationMap().get(className);
84+
if (ai == null) {
85+
ai = putAnnotationInfo(getClass(className, null));
86+
}
8387
return ai;
8488
}
8589

8690
// I could have used the getAnnotationInfo() method but I am not sure how it will evolve.
8791
// I found that the meaning was more visible using another method.
8892
public AnnotationInfo getAnnotationInfoUsingFullClassName(String fullClassName) {
8993
AnnotationInfo ai = getAnnotationMap().get(fullClassName);
94+
if (ai == null) {
95+
ai = putAnnotationInfo(getClass(fullClassName, null));
96+
}
9097
return ai;
9198
}
9299

@@ -199,7 +206,7 @@ public AnnotationInfo putAnnotationInfo(Class c) {
199206
putTableDeclaration(ai, c);
200207
putProperties(ai, c);
201208
putMethods(ai, c);
202-
if (ai.getIdMethod() == null) {
209+
if (ai.getIdProperty() == null) {
203210
throw new PersistenceException("No ID method specified for: " + c.getName());
204211
}
205212
putEntityListeners(ai, c);
@@ -209,6 +216,7 @@ public AnnotationInfo putAnnotationInfo(Class c) {
209216
}
210217

211218
private void putMethods(AnnotationInfo ai, Class c) {
219+
/*
212220
Method[] methods = c.getDeclaredMethods();
213221
for (Method method : methods) {
214222
// logger.fine("method=" + method.getName());
@@ -221,6 +229,7 @@ private void putMethods(AnnotationInfo ai, Class c) {
221229
if (transientM != null) continue; // we don't save this one
222230
ai.addGetter(method);
223231
}
232+
*/
224233
}
225234

226235

@@ -239,9 +248,14 @@ private void putProperties(AnnotationInfo ai, Class c) {
239248

240249
private void parseProperty(AnnotationInfo ai, Class c, Field field) {
241250
// TODO add support for OneToOne
251+
/*
242252
if (!field.isAnnotationPresent(Transient.class) && (field.isAnnotationPresent(ManyToMany.class) || field.isAnnotationPresent(OneToMany.class) || field.isAnnotationPresent(ManyToOne.class) || field.isAnnotationPresent(Id.class))) {
243253
ai.addField(field);
244254
}
255+
*/
256+
if (!field.isAnnotationPresent(Transient.class) && (field.getModifiers() & Modifier.STATIC) == 0) {
257+
ai.addField(field);
258+
}
245259
}
246260

247261
private void putTableDeclaration(AnnotationInfo ai, Class<?> c)

core/src/main/java/com/spaceprogram/simplejpa/EntityManagerFactoryImpl.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,21 @@ public EntityManagerFactoryImpl(String persistenceUnitName, Map props) {
171171
this(persistenceUnitName, props, null, null);
172172
}
173173

174+
/**
175+
* Use this one in web applications, see:
176+
* http://code.google.com/p/simplejpa/wiki/WebApplications
177+
*
178+
* @param persistenceUnitName
179+
* used to prefix the SimpleDB domains
180+
* @param props
181+
* should have accessKey and secretKey
182+
* @param libsToScan
183+
* a set of
184+
*/
185+
public EntityManagerFactoryImpl(String persistenceUnitName, Map props, Set<String> libsToScan) {
186+
this(persistenceUnitName, props, libsToScan, null);
187+
}
188+
174189
/**
175190
* Use this one in web applications, see:
176191
* http://code.google.com/p/simplejpa/wiki/WebApplications

0 commit comments

Comments
 (0)