Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't use properties through the element values #62

Merged
merged 30 commits into from
May 10, 2016

Conversation

laughedelic
Copy link
Member

I've already started some changes in master accidentally. Starting from what we had before the #58:

  • I've changed relationship between Vertex and VertexType:
    • before the idea was to define User as a unique VertexType and then have its "value type" as Vertex<User>
    • but actually we want the opposite: to define a unique type for the user Vertex (because we are going to refer to this as a type) and also have a value reference to its VertexType which only needs to have a fromRaw factory method returning a value of that User type
  • now with this situation the only thing that makes us extending VertexType is that we would normally store properties in it and refer to them as g.user.name, g.posted.date.
  • here comes the idea developed in the Experimenting with element/its type relationship #61 experiment:

We can add properties as the members of the User value-type and add setter/getter methods, then the syntax for working with them would change from

Tweetter<RV,RE>.User bob =
  g.addVertex(g.user)
   .set(g.user.name, "Bob");

String name = bob.get(g.user.name);

bob.set(g.user.age, 42);

to

Tweetter<RV,RE>.User bob =
  g.addVertex(g.user)
   .name.set("Bob");

String name = bob.name.get();

bob.age.set(42);

which doesn't look too bad and is more concise than the old one. Btw, I've tried to make them instances of Supplier<X> (for the .get() method) and Function<V,X> (for .apply()) hoping that it will allow for syntax like bob.name("Bob") instead of bob.name.apply("Bob"), but it seems that Java doesn't have any shortcuts "( 👎

The schema definition becomes much more clear than before and almost doesn't have boilerplate code:

public final class User extends Vertex<User> {
  @Override public final User self() { return this; }
  private User(RV raw) { super(raw, user); }

  public final Property<String> name = property("name", String.class);
  public final Property<Integer> age = property("age", Integer.class);
}

public final VertexType<User> user = new VertexType<>(User::new);

No any significant changes to the inner code needed. Only the GraphSchema class.

…be unique and can take advantage of the lambda syntax for fromRaw override
@laughedelic
Copy link
Member Author

@eparejatobes please, take a look 🙏

After all my suffering in #58 and #60 and experimenting with things in #61 and some other branches that don't worth to be pushed here, I can say that what I have here is the best option I can get (again, I was trying really hard, you know 😐).

Using inner classes as in #58 doesn't help to simplify the API and it has a major disadvantage: it's hard to override methods in them. I'm even not sure if it's possible to do in any reasonable way, because if you subclass and have a more precise User.Vertex type, all its non-overriden API methods still return the type of the inner class from its parent.

Therefore I think it's better to use inner classes only on the level of the schema definition (i.e. VertexType/EdgeType inside of a TypedGraph/GraphSchema).

Putting all things in one file doesn't help anything, see #60 (comment).

So, what we have here:

  • API split on Vertex/Edge-related interfaces in separate files
  • simple schema definition almost without boilerplate (only the self() thing)
  • easy way to override things in a particular graph's Vertex/Edge class, or its concrete instance

If you are fine with this approach, I will cherry-pick good things from #58, especially the auto-schema-related stuff from #59.

We can already try this with some Bio4j graph. The Titan implementation should work (modulo the schema creation).

UPD: currently angulillos-titan compiles without any changes.

@eparejatobes
Copy link
Member

@laughedelic I'm going to look at this tonight/tomorrow morning.

@laughedelic laughedelic changed the title Use properties through the element values Don't use properties through the element values Apr 28, 2016
@laughedelic
Copy link
Member Author

laughedelic commented May 5, 2016

What I'm working on here:

  • untyped schema creation
  • indexes
  • SimpleGraph and LinkGraph traits

* Added no-parameters Any-traits for all type-interfaces
* Implemented automatic graph schema creation method
@laughedelic
Copy link
Member Author

laughedelic commented May 9, 2016

  • change UntypedGraph interface to use Any-types instead of strings
  • add inEdges/outEdges sets to the AnyVertexType interface

@laughedelic
Copy link
Member Author

I'm merging and releasing it as v0.7.0

This was referenced May 10, 2016
@laughedelic laughedelic merged commit ba2f17d into master May 10, 2016
@laughedelic laughedelic deleted the experiment/properties-in-elements branch May 10, 2016 18:38
laughedelic added a commit that referenced this pull request May 10, 2016
* A lot of general code refactoring (most of it in #62):
    - Setters return the subject for chaining calls
    - Added arity-specific methods in/out-E/V methods with default implementations
    - Moved all the methods from TypedGraph to the elements interfaces
    - Split Arity on two: From/To; Added FromArity to Property
    - Added Unique and NonUnique Property types to fix the arity
    - Added vertex/edge types list to the typed graph and properties list to each typed element
    - Added UntypedGraphSchema interface for automatic schema creation
* See also #46, #51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants