Giter Site home page Giter Site logo

Create a builder API about mongo-emf HOT 16 CLOSED

bryanhunt avatar bryanhunt commented on July 28, 2024
Create a builder API

from mongo-emf.

Comments (16)

BryanHunt avatar BryanHunt commented on July 28, 2024

Would you expect this API to abstract away the reserved keys like _eClass, or would that still be managed by the base algorithm?

from mongo-emf.

dlaidlaw avatar dlaidlaw commented on July 28, 2024

I don't really mind the eClass name and can't think of any reason I would
need to abstract it away. But I suppose someday it might be required.

Don Laidlaw | Sr Research Eng. | Infor | Cell +1-902-401-6771 | Home
Office +1-902-576-5185

On 12/16/11 2:41 AM, "Bryan Hunt"
<reply+i-2525494-bd16df7ddb3415bfc5f20934f264ea990eeb9cd2-124929@reply.gith
ub.com> wrote:

Would you expect this API to abstract away the reserved keys like
_eClass, or would that still be managed by the base algorithm?


Reply to this email directly or view it on GitHub:
#9 (comment)

from mongo-emf.

jconlon avatar jconlon commented on July 28, 2024

Great framework!

Have attributes longitude and latitude in my model and would like to persist this to MongoDB in a geo-spatial friendly form so I can index it with 2d, something like
{ .... location: { longitude : 40.93907, latitude : 73.9923} ....}

Can I do this now with the current code, or must I wait for this issue's resolution? If I must wait for resolution, do you have any ideas when you may get to this?
thanks...

from mongo-emf.

BryanHunt avatar BryanHunt commented on July 28, 2024

I have yet to work on this issue. It will be part of the upcoming 0.5.0 release. I think I have just this issue and one other feature left before the 0.5.0 release, but given my current schedule, it may be a few more weeks before I get the release out. Contributions are always welcome if you "need it now".

from mongo-emf.

BryanHunt avatar BryanHunt commented on July 28, 2024

Here is the first attempt at an API. It will definitely change as I refactor the code, but it gives you an idea as to where I'm headed.

public class EObjectBuilder
{
  public EObject buildEObject(DBCollection collection, DBObject dbObject, Resource resource, XMLResource.URIHandler uriHandler, boolean isProxy);

  /**
   * @param collection
   * @param dbObject
   * @param resource
   * @param uriHandler
   * @param resourceSet
   * @param eObject
   * @param attribute
   */
  protected void buildEObjectAttribute(DBCollection collection, DBObject dbObject, Resource resource, XMLResource.URIHandler uriHandler, ResourceSet resourceSet, EObject eObject, EAttribute attribute);

  /**
   * @param collection
   * @param dbObject
   * @param resource
   * @param uriHandler
   * @param eObject
   * @param reference
   */
  protected void buildEObjectReference(DBCollection collection, DBObject dbObject, Resource resource, XMLResource.URIHandler uriHandler, EObject eObject, EReference reference);

  protected EObject buildEObjectReference(DBCollection collection, DBObject dbReference, Resource resource, XMLResource.URIHandler uriHandler, boolean referenceResolvesProxies);

  /**
   * This function builds an EMF proxy object from the reference DBObject
   * 
   * @param collection the collection containing the referencing object
   * @param dbReference the MongoDB reference - must be of the form { ECLASS_KEY : eClassURI, PROXY_KEY : proxyURI }
   * @param resourceSet the resource set to use for building the proxy
   * @param uriHandler the resource URI handler used to resolve the relative proxy URI
   * @param referenceResolvedProxies flag indicating that the reference resolves proxies
   * @return the proxy object when referenceResolvedProxies is true, the resolved object otherwise
   */
  protected EObject buildProxy(DBCollection collection, DBObject dbReference, ResourceSet resourceSet, XMLResource.URIHandler uriHandler, boolean referenceResolvedProxies);

  /**
   * This function converts the raw value read from MongoDB into the correct type for
   * the given datatype.
   * 
   * @param eDataType the EMF datatype to convert to
   * @param value the raw MongoDB value to convert from
   * @return the converted value
   */
  protected Object convertMongoDBValueToEMFValue(EDataType eDataType, Object value)

  /**
   * This function creates an empty EObject from the given DBObject. The actual instance created
   * is determined by the EClass specified in the DBObject by the ECLASS_KEY. This function also
   * maintains a static cache of EClass URI to EClass for improved performance.
   * 
   * @param dbObject the object read from MongoDB
   * @param resourceSet the resourceSet that will be used to locate the EClass if it is not cached
   * @return the newly created object of type as specified by the data read from MongoDB
   */
  protected EObject createEObject(DBObject dbObject, ResourceSet resourceSet);
}
public class DBObjectBuilder
{
  public DBObject buildDBObject(DB db, EObject eObject, XMLResource.URIHandler uriHandler) throws IOException;

  protected Object buildDBReference(DB db, EReference eReference, EObject targetObject, XMLResource.URIHandler uriHandler) throws IOException;

  protected Object getDBAttributeValue(EAttribute attribute, Object rawValue);
}

from mongo-emf.

BryanHunt avatar BryanHunt commented on July 28, 2024

I've started working on the refactoring and I have pushed the latest changes to the builders branch. Much more refactoring to come.

from mongo-emf.

BryanHunt avatar BryanHunt commented on July 28, 2024

I believe the refactoring of the code into builders is complete. There may still be some minor refactoring of the MongoDBURIHandlerImpl, MongoDBInputStream, and MongoDBOutputStream. These changes have been pushed to the builders branch.

from mongo-emf.

BryanHunt avatar BryanHunt commented on July 28, 2024

I've refactored MongoDBURIHandlerImpl, MongoDBInputStream, and MongoDBOutputStream. I believe this completes the refactoring.

I would appreciate it if the design could be reviewed before the next release which I hope to have complete in a week or two.

All code is available in the builders branch.

from mongo-emf.

jconlon avatar jconlon commented on July 28, 2024

So the way I understand it is to extend the DBObjectBuilder and the EObjectBuilder and to tie these extensions in is by also extending the MongoDBInputStream & MongoDBOutputStream and overriding the createBuilder methods. Then of course to get these two extensions in I would also extend the MongoDBURIHandlerImpl.

Am I missing something? Is there a cleaner way to do this?

from mongo-emf.

BryanHunt avatar BryanHunt commented on July 28, 2024

That sounds about right. I'm open to suggestions for a cleaner implementation. I suppose I could use a factory class pattern, but is that any cleaner?

from mongo-emf.

jconlon avatar jconlon commented on July 28, 2024

Right or you can pass the builders into a static factory method, or pass them in the constructor of MongoDBURIHandlerImpl.

Or ... Why not follow the pattern you already have in place for the converters?

MongoDBURIHandlerImpl handler = new MongoDBURIHandlerImpl();
handler.getConverterService().addConverter(new MyMongoEmfConverter());
//so to add builders
handler.getBuilderService().addBuilders(new MyEObjectBuilder(), new MyDBObjectBuilder());

from mongo-emf.

jconlon avatar jconlon commented on July 28, 2024

In order to override the framework classes, I will need changes to access some fields:

MongoDBOutputStream:
protected IConverterService converterService;

MongoDBInputStream:
protected HashMap<String, EClass> eClassCache = ...

MongoDBURIHandlerImpl:
protected IMongoEmfQueryEngine queryEngine;
protected IConverterService converterService;

from mongo-emf.

BryanHunt avatar BryanHunt commented on July 28, 2024

I've pushed some API changes to the builders branch. I now use the factory pattern for all of the sub components. Please have a look and let me know if this works for you. I'd like to get it merged into master and released this week.

from mongo-emf.

jconlon avatar jconlon commented on July 28, 2024

This works fine and is much cleaner than before - thanks.

from mongo-emf.

BryanHunt avatar BryanHunt commented on July 28, 2024

I've added the appropriate javadocs and I've merged all changes into master.

from mongo-emf.

jconlon avatar jconlon commented on July 28, 2024

Looks good - thanks!

from mongo-emf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.