Permalink
Browse files

updated copyrights

added readme and examples
  • Loading branch information...
jacum committed Sep 20, 2011
1 parent 56cc3d3 commit af95dbe5422e70d4de7c95c9cd7ddc04dfa7eaa4
Showing with 869 additions and 288 deletions.
  1. +25 −0 LICENSE
  2. +101 −0 README.md
  3. +31 −12 src/main/java/net/karmafiles/ff/core/tool/Assert.java
  4. +31 −18 src/main/java/net/karmafiles/ff/core/tool/IdGenerator.java
  5. +32 −13 src/main/java/net/karmafiles/ff/core/tool/dbutil/ConnectionImpl.java
  6. +31 −0 src/main/java/net/karmafiles/ff/core/tool/dbutil/MongoConnection.java
  7. +31 −12 src/main/java/net/karmafiles/ff/core/tool/dbutil/converter/BaseProxy.java
  8. +40 −18 src/main/java/net/karmafiles/ff/core/tool/dbutil/converter/BeanDescription.java
  9. +34 −13 src/main/java/net/karmafiles/ff/core/tool/dbutil/converter/Converter.java
  10. +31 −3 src/main/java/net/karmafiles/ff/core/tool/dbutil/converter/MapClasses.java
  11. +31 −12 src/main/java/net/karmafiles/ff/core/tool/dbutil/converter/bean/BeanEnhancer.java
  12. +33 −18 src/main/java/net/karmafiles/ff/core/tool/dbutil/converter/bean/BeanMethodInterceptor.java
  13. +31 −12 src/main/java/net/karmafiles/ff/core/tool/dbutil/converter/dbobject/DBObjectArrayProxy.java
  14. +36 −19 src/main/java/net/karmafiles/ff/core/tool/dbutil/converter/dbobject/DBObjectIterableProxy.java
  15. +32 −13 src/main/java/net/karmafiles/ff/core/tool/dbutil/converter/dbobject/DBObjectMapProxy.java
  16. +36 −24 src/main/java/net/karmafiles/ff/core/tool/dbutil/converter/dbobject/DBObjectProxy.java
  17. +33 −14 src/main/java/net/karmafiles/ff/core/tool/dbutil/daohelper/BaseDaoHelper.java
  18. +31 −12 src/main/java/net/karmafiles/ff/core/tool/dbutil/daohelper/DaoException.java
  19. +32 −14 src/main/java/net/karmafiles/ff/core/tool/dbutil/daohelper/DaoHelper.java
  20. +31 −12 src/main/java/net/karmafiles/ff/core/tool/dbutil/daohelper/DaoHelperFilter.java
  21. +31 −12 src/main/java/net/karmafiles/ff/core/tool/dbutil/daohelper/DaoHelperTemplate.java
  22. +31 −0 src/main/java/net/karmafiles/ff/core/tool/dbutil/daohelper/EntityFilter.java
  23. +31 −12 src/main/java/net/karmafiles/ff/core/tool/dbutil/daohelper/FieldValueChecker.java
  24. +31 −12 src/main/java/net/karmafiles/ff/core/tool/dbutil/daohelper/FieldValueProvider.java
  25. +32 −13 src/main/java/net/karmafiles/ff/core/tool/dbutil/daohelper/SimpleCriteria.java
View
25 LICENSE
@@ -0,0 +1,25 @@
+Copyright 2011 Dadastream. All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are
+permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice, this list of
+ conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ of conditions and the following disclaimer in the documentation and/or other materials
+ provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY DADASTREAM ''AS IS'' AND ANY EXPRESS OR IMPLIED
+WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DADASTREAM OR
+CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+The views and conclusions contained in the software and documentation are those of the
+authors and should not be interpreted as representing official policies, either expressed
+or implied, of Dadastream.
View
101 README.md
@@ -0,0 +1,101 @@
+MongoMapper
+===========
+
+This library provides clean and powerful mapping between Java POJOs and MongoDB DBObject.
+
+Features
+--------
+
+* Just 2 methods of API for mapping to and from
+* No annotations, no factories, just POJOs all the way
+* Full support of Java collections: Maps, Lists, Sets
+* Full support of polymorphism: generified collections containing different subclasses, complex beans containing polymorphic attributes
+* Convenient template for DAO classes
+
+Using raw converter API
+-----------------------
+
+ import com.mongodb.*;
+ import net.karmafiles.ff.core.tool.dbutil.converter.Converter;
+
+ ...
+
+ MyTopLevelEntity entity = ...
+ // here the graph of objects is created, starting from top-level entity
+
+ Mongo m = new Mongo("localhost", 27017);
+ DB db = m.getDB("mydb1");
+ DBCollection coll = db.getCollection("testCollection");
+
+ // convert entitiy to MongoDB DBObject
+
+ DBObject dbObject = Converter.toDBObject(entity);
+ coll.save(dbObject);
+
+ // restore entity from MongoDB DBObject
+ DBObject newDbObject = coll.findOne();
+ MyTopLevelEntity newEntity = Converter.toObject(MyTopLevelEntity.class, newDbObject);
+
+More examples in test directory under ...converter.test package.
+
+Using DAO template
+------------------
+
+ import net.karmafiles.ff.core.tool.dbutil.ConnectionImpl;
+ import net.karmafiles.ff.core.tool.dbutil.daohelper.DaoHelper;
+
+ import java.util.Date;
+
+ public class JobDao<T> extends DaoHelper<T> {
+
+ // provide some method of getting a connection to MongoDB
+ // e.g. Spring @Autowire
+
+ private ConnectionImpl connection;
+
+ public ConnectionImpl getConnection() {
+ return connection;
+ }
+
+ public void setConnection(ConnectionImpl connection) {
+ this.connection = connection;
+ }
+
+
+ // custom find method
+ public List<Job> findNewJobs() {
+
+ BasicDBObject query = new BasicDBObject();
+ query.put("state", JobState.NOT_STARTED.toString());
+ DBCursor c = getDbCollection().find(query);
+
+ List<Job> jobs = new ArrayList<Job>();
+ while (c.hasNext()) {
+ jobs.add(Converter.toObject(Job.class, c.next()));
+ }
+ return jobs;
+
+ }
+
+ // custom update method
+ public Job update(Job entity) {
+ Job oldJob = get(entity.get_id());
+ if (oldJob.getModified().after(entity.getModified())) {
+ throw new IllegalStateException("Job " + entity.get_id() + " copy in the database is newer than in request, can't update");
+ }
+ return super.update(entity);
+ }
+
+
+ }
+
+More examples in TestEntityDaoTest.
+
+Caveats
+-------
+
+In order to prevent endless looping in some polymorhpic cases, Converter.toObject() creates a clean bean copy:
+
+ PropertyUtils.copyProperties(copyObject, newObject);
+
+This is rather a kludge than a proper solution.
@@ -1,19 +1,38 @@
+/*
+ * Copyright 2011 Dadastream. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY DADASTREAM ''AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DADASTREAM OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of Dadastream.
+ *
+ * @author Ilya Brodotsky
+ * @author Timur Evdokimov
+ */
+
package net.karmafiles.ff.core.tool;
import java.util.Collection;
-/**
- * Created by Ilya Brodotsky
- * Date: 14.10.2010
- * Time: 19:19:17
- * <p/>
- * All rights reserved.
- * <p/>
- * Contact me:
- * email, jabber: ilya.brodotsky@gmail.com
- * skype: ilya.brodotsky
- */
-
public final class Assert {
private Assert() {
@@ -1,12 +1,41 @@
+/*
+ * Copyright 2011 Dadastream. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY DADASTREAM ''AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DADASTREAM OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of Dadastream.
+ *
+ * @author Ilya Brodotsky
+ * @author Timur Evdokimov
+ */
+
package net.karmafiles.ff.core.tool;
import org.apache.commons.codec.binary.Base64;
import java.math.BigInteger;
import java.net.InetAddress;
import java.net.UnknownHostException;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.concurrent.atomic.AtomicLong;
@@ -16,17 +45,10 @@
private static SecureRandom mySecureRand;
- private static String s_id;
-
static {
atomicLong = new AtomicLong();
mySecureRand = new SecureRandom();
- try {
- s_id = InetAddress.getLocalHost().toString();
- } catch (UnknownHostException e) {
- e.printStackTrace();
- }
}
@@ -35,15 +57,6 @@ private IdGenerator() {
}
private String getRandomGUID() {
- MessageDigest md5 = null;
- StringBuffer sbValueBeforeMD5 = new StringBuffer();
-
- try {
- md5 = MessageDigest.getInstance("MD5");
- } catch (NoSuchAlgorithmException e) {
- System.out.println("Error: " + e);
- }
-
try {
long time = System.currentTimeMillis();
long rand = mySecureRand.nextLong();
@@ -1,3 +1,34 @@
+/*
+ * Copyright 2011 Dadastream. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY DADASTREAM ''AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DADASTREAM OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of Dadastream.
+ *
+ * @author Ilya Brodotsky
+ * @author Timur Evdokimov
+ */
+
package net.karmafiles.ff.core.tool.dbutil;
import com.mongodb.DB;
@@ -11,21 +42,8 @@
import java.util.ArrayList;
import java.util.List;
-/**
- * Created by Ilya Brodotsky
- * Date: 16.10.2010
- * Time: 3:12:06
- * <p/>
- * All rights reserved.
- * <p/>
- * Contact me:
- * email, jabber: ilya.brodotsky@gmail.com
- * skype: ilya.brodotsky
- */
-
public class ConnectionImpl implements MongoConnection {
- private Mongo mongo;
private DB db;
private String connectionHost;
@@ -56,6 +74,7 @@ public void setConnectionDescriptor(String connectionDescriptor) {
@PostConstruct
public void connect() {
try {
+ Mongo mongo;
if (connectionDescriptor != null) {
String[] hosts = connectionDescriptor.split(",");
List<ServerAddress> addr = new ArrayList<ServerAddress>();
@@ -1,3 +1,34 @@
+/*
+ * Copyright 2011 Dadastream. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY DADASTREAM ''AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL DADASTREAM OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of Dadastream.
+ *
+ * @author Ilya Brodotsky
+ * @author Timur Evdokimov
+ */
+
package net.karmafiles.ff.core.tool.dbutil;
import com.mongodb.DBCollection;
Oops, something went wrong.

0 comments on commit af95dbe

Please sign in to comment.