Commit Graph

31 Commits

Author SHA1 Message Date
Michael Bayne fc4cda9260 Allow multiple join clauses. Added a clone() method for reusing partially
configured queries.
2010-12-08 00:41:06 +00:00
Michael Bayne 355b084292 Further QueryBuilder improvements. In any case where you may want a specially
configured clause, allow adding the clause directly. Removed some repetition by
using said methods from factory versions. Other tidying.
2010-12-08 00:23:15 +00:00
Michael Bayne fca5cb2386 Added QueryBuilder.delete() along with a bunch of sanity checking. I considered
having a separate deleteFrom(record).where(...).delete() builder, but
from(record).where(...).delete() was so much nicer that I decided that
preventing the specification of invalid clauses could be deferred from compile
to runtime.

I could do some fiddly things with return types and have from() return a
builder that then subsequently pigeon-holed you into deletability or not
depending on whether you called things like orderBy(), but to do so in Java
would require that I override every method to specialize its return type, which
presents something of a maintenance annoyance.
2010-12-07 23:41:27 +00:00
Michael Bayne 1e86fba829 Added a limit that takes only a count. 2010-12-07 23:14:29 +00:00
Michael Bayne f48a688d99 Scratch the FluentRepository, let's do things properly with a QueryBuilder.
With this you can write queries like:

  MaxPointsRecord max = from(MaxPointsRecord.class).
      override(DailyScoreRecord.class),
      where(DailyScoreRecord.KEY.eq(key)).load();

  List<DailyLeaderRecord> top = from(DailyLeaderRecord.class).
      override(DailyScoreRecord.class).
      join(DailyScoreRecord.KNIGHT_ID, KnightRecord.KNIGHT_ID).
      where(DailyScoreRecord.KEY.eq(key),
            DailyScoreRecord.POINTS.eq(max.maxPoints)).
      select();

After configuring your query, you can load(), you can select(), you can
selectKeys() and you can selectCount(). Other improvements include configuring
cache behavior (from(FooRecord.class).noCache().where(...).select()).

random() became randomOrder() because I think that seeing random() stuffed in
the middle of a query is insufficiently communicative.

Next, I'm going to look into extending the query builder to allow things like:

   from(MemberRecord.class).
       where(MemberRecord.CREATED.greaterThan(date)).
       select(MemberRecord.AVATAR_ID, MemberRecord.HOME_SCENE_ID);
   // yields List<Tuple2<Integer, Integer>>

which will require adding types to ColumnExp, which I hope to do in a
moderately backwards compatible way. If I can, I may use those types to enforce
type correctness and turn things like the following into a compiler error:

   MemberRecord.MEMBER_ID.greaterThan("bob")

If I had a more sophisticated type system, I could even make an attempt to call
greaterThan() on a ColumnExp<String> a compilation error.

If the above doesn't turn out to be a rabbit hole extraordinairre (it probably
will), I'd like to look into obviating the need for most of the FieldOverride
and FromOverride fiddling, and support things like:

   from(MemberRecord.class).
       where(MemberRecord.CREATED.greaterThan(date)).
       select(Exps.max(MemberRecord.SESSIONS));
   // yields List<Integer>

which would take Depot in the direction of being a (somewhat) type safe wrapper
around SQL. This would go a long way toward bridging the conceptual gap between
"the SQL I know I want to write" and "how the fuck do I do this with this Java
API".

I don't think I'm going to be able to get too far with the type-safe wrapper
approach without propagating types all over the place, which may result in
backwards compatibility breakage. If things get really bad, I may just have to
pinch off the Depot 1.x series and venture into the green fields of Depot 2.x.
I'll see how far I can get before taking such drastic action, however.
2010-12-07 22:49:28 +00:00
Michael Bayne 44a8fccc86 Added FluentRepository, which provides helper methods for creating all of the
various query clauses.

Something like this:

   MaxPointsRecord max = load(MaxPointsRecord.class,
       new FromOverride(DailyScoreRecord.class),
       new Where(DailyScoreRecord.KEY.eq(key)));

   List<DailyLeaderRecord> top = findAll(DailyLeaderRecord.class,
       new FromOverride(DailyScoreRecord.class),
       DailyScoreRecord.KNIGHT_ID.join(KnightRecord.KNIGHT_ID),
       new Where(Ops.and(DailyScoreRecord.KEY.eq(key),
           DailyScoreRecord.POINTS.eq(max.maxPoints))));

becomes this:

   MaxPointsRecord max = load(MaxPointsRecord.class,
       from(DailyScoreRecord.class),
       where(DailyScoreRecord.KEY.eq(key)));

   List<DailyLeaderRecord> top = findAll(DailyLeaderRecord.class,
       from(DailyScoreRecord.class),
       join(DailyScoreRecord.KNIGHT_ID, KnightRecord.KNIGHT_ID),
       where(DailyScoreRecord.KEY.eq(key),
             DailyScoreRecord.POINTS.eq(max.maxPoints)));

and the imports for Where and FromOverride go away. It's a modest improvement
in readability.

Both COL.join(OCOL) and join(COL, OCOL) are supported; one can choose based on
the aesthetic demands of an individual query.
2010-12-07 21:05:42 +00:00
Michael Bayne 569cce8276 Whitespace fix. 2010-12-07 20:58:41 +00:00
Ray Greenwell 7a1f87f2a0 IntArrayMarshaller was doing things in the wrong places to work
as a delegate for a TransformingMarshaller.
2010-12-01 20:59:12 +00:00
Michael Bayne 52f432270d Added a test for using an Enum as a record key, observed brokitude, fixed
brokitude, but did not take the opportunity to do so in a non-hacky way.
2010-12-01 19:53:03 +00:00
Michael Bayne eaadb3228a Added support for non-ByteEnum enums, which are stored using their string name. 2010-12-01 19:36:01 +00:00
Michael Bayne 6365f290d9 Put our templates in src/main/resources. 2010-11-20 02:50:38 +00:00
Charlie Groves c70cf7c1c6 Fix column indices in hsqldb. Like mysql, it can't handle parenthesis around its index column expressions. 2010-11-18 00:48:20 +00:00
Michael Bayne 2db4506a2b Nixed extra space. 2010-10-25 20:15:55 +00:00
Michael Bayne c7b60a1de8 No value in having the transforming marshaller be a named class. Switch to
slightly more concise code.
2010-10-25 20:09:37 +00:00
Michael Bayne 5046c1d906 Unused import trimming. Type parameter cleanup. 2010-10-25 19:55:27 +00:00
Michael Bayne ec04d618c4 Nixed vestigial methods. 2010-10-25 19:53:34 +00:00
Charlie Groves a649efac99 Missing @Overrides, extra imports 2010-10-19 00:33:31 +00:00
Charlie Groves 9368da4ebf Skip classes in GenRecordTask if they have @GeneratedValue on a field without @Id. I'd rather stop
the build, but other errors in class processing seem to lead to skipping, so I'm not rocking the
boat.

If @GeneratedValue is on a field without an @Id, depot creates the necessary indices to generate the
value, but it doesn't actually do the generation on insertion.  Rather than making it work without a
good use case for it, I'm adding this check to keep people from stumbling into a broken design.
2010-10-19 00:29:31 +00:00
Ray Greenwell dcd4046c60 Transformer rejigger.
Transformer is now an abstract class with a default init() method.
The Type parameter has been removed from fromPersistent().
The Transformer annotation now has some new attributes that
can be used to hint whether you want a result that is immutable or interned,
the meaning and support of both is completely up to the Transformer.
Brought back my uber Iterable<String> transformers, with immutable/intern
support in a single Transformer.
 - interning will intern the strings
 - immutable will wrap the collections in Collections.unmodifiable*
   (using a guava Immutable collection ends up creating a temporary
    builder collection and then copying the elements)
 - if immutable AND interning then the collection itself is
   "interned".
At some point I'll add support for nearly any Iterable
of an otherwise supported type, so that our Records can have
List<Integer> and other such fields.
2010-10-12 19:35:07 +00:00
Ray Greenwell 2ff3bac12d Look for any worthy method, even in superclasses. 2010-10-01 01:29:46 +00:00
Ray Greenwell c7eb6f56ef Roll this back until I do some more testing.. :( 2010-09-30 22:25:16 +00:00
Ray Greenwell 89bec13aa2 Added Transformers that will always return immutable collections,
interned Strings, or both.
I may rework this into attributes that can be specified for any
@Transformer annotation, and leave it up to each Transformer
whether they are honored (and how).
2010-09-30 21:30:59 +00:00
Ray Greenwell 9fafebd487 Support creating arrays of java.sql.Date. 2010-09-29 18:31:31 +00:00
Ray Greenwell 020d33c8aa Was looking at how some things work and made a few drive-by optimizations
to FindAllQuery.
- We don't need to destructively modify the Set of keys to fetch if we hold
  on to one iterator.
- We can create an ArrayList that won't need to grow if our keys Iterable
  happens to be a Collection.
- And, just generally prefer Lists factories to specific constructors.
2010-09-20 23:21:06 +00:00
Andrzej Kapolka 8c5f333f73 Is there a reason why this didn't return TIME? It seems to work. 2010-09-17 02:46:17 +00:00
Michael Bayne 07e4bdec4a Move overview.html to a place where Maven's javadoc plugin will find it. 2010-09-09 20:31:51 +00:00
Michael Bayne 33f6351af5 Add link to project website to docs. 2010-09-09 20:28:34 +00:00
Michael Bayne 0fea1dfb07 Nix link since we're not including protected bits in the docs. 2010-09-09 20:27:18 +00:00
Michael Bayne 5fe094a804 Import needed for Javadoc comment. 2010-09-09 05:26:16 +00:00
Michael Bayne 3f7a7be9da Some Javadoc fixing. Though it's very annoying that I have to use &#064;
instead of @. Thanks for making things totally unreadable in the source file
javadoc. How about \@ instead?
2010-08-27 18:11:22 +00:00
Michael Bayne 28f9439b5f More layout standardizing. 2010-08-27 17:49:18 +00:00