Skip to content

Commit abebad4

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 abebad4

23 files changed

+486
-189
lines changed

README.markdown

Lines changed: 70 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
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+
**WARNING**: There are some commented/removed code in the tests. Will add proper tests for the major changes.
8+
19
#SimpleJPA's new home.#
210

311
Discussion Group: http://groups.google.com/group/simplejpa
@@ -8,42 +16,45 @@ Here's how to get started using SimpleJPA.
816
##Dependencies##
917
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):
1018

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
19+
* commons-lang - You can grab all commons libs at http://commons.apache.org/downloads/index.html
20+
* commons-collections
21+
* commons-logging
22+
* commons-codec
23+
* cglib-nodep
24+
* kitty-cache
25+
* ehcache
26+
* scannotation
27+
* javassist (required for scannotation)
28+
* ejb3-persistence-api
29+
* AWS SDK for Java
30+
* Apache HttpClient
31+
2332
When building from source and using the Maven pom.xml file Kitty-cache will need to be added explicitly as a reference.
2433

2534
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/
35+
36+
* commons-lang - You can grab all commons libs at http://commons.apache.org/downloads/index.html
37+
* commons-beanutils
38+
* commons-collections
39+
* commons-logging (required for jets3t)
40+
* commons-codec (required for jets3t)
41+
* Apache HttpClient - (required for jets3t)
42+
* typica
43+
* jets3t
44+
* cglib-nodep - http://sourceforge.net/project/showfiles.php?group_id=56933
45+
* ejb3-persistence-api - http://mirrors.ibiblio.org/pub/mirrors/maven2/org/hibernate/ejb3-persistence/1.0.2.GA/
46+
* scannotation - http://scannotation.sourceforge.net/
47+
* javassist (scannotation) - http://www.csg.is.titech.ac.jp/~chiba/javassist/
48+
* kitty-cache - http://code.google.com/p/kitty-cache/
49+
* ehcache - http://ehcache.org/
4050

4151

4252
##Setup##
4353
Create a file called simplejpa.properties and put on the classpath. Add your Amazon access key and secret key like:
4454

45-
accessKey = AAAAAAAAAAAAAAAAAAAAAAA
46-
secretKey = SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
55+
accessKey = AAAAAAAAAAAAAAAAAAAAAAA
56+
secretKey = SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
57+
4758
For more configuration options, see Configuration.
4859

4960
Now the Code
@@ -56,48 +67,49 @@ EntityManager em = factory.createEntityManager();
5667
##Persisting an object##
5768
Lets create a very simple object to store.
5869

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-
}
70+
@Entity
71+
public class MyTestObject {
72+
@Id
73+
private String id;
74+
private String name;
75+
76+
public String getId() {
77+
return id;
78+
}
79+
80+
public void setId(String id) {
81+
this.id = id;
82+
}
83+
84+
public void setName(String name) {
85+
this.name = name;
86+
}
87+
88+
public String getName() {
89+
return name;
90+
}
91+
92+
}
8293
Now to persist it:
8394

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

89101
##Querying##
90102
See JPAQuery
91103

92104
##Deleting##
93-
MyObject ob...
94-
em.remove(ob);
105+
MyObject ob...
106+
em.remove(ob);
95107
Close the EntityManager when you're done
96108
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.
97109

98-
em.close();
110+
em.close();
99111
Close the EntityManagerFactory before you shutdown your app
100-
factory.close();
112+
factory.close();
101113
##What Next?##
102114
See all the JPA features currently supported.
103115
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)