Commit Graph

786 Commits

Author SHA1 Message Date
Michael Bayne 5587d134bd Request the appropriate length for int arrays. 2010-06-19 17:40:03 +00:00
Michael Bayne ff53b67e3d Test that @Transform works in its various supported use cases, and fails as
early as possible in situations where the developer is fucking up.
2010-06-19 17:36:04 +00:00
Michael Bayne 7f9bf7b589 Determined that we need to pass the field type into the fromPersistent() to
support use cases like ByteEnum. (Even though I'm leaving ByteEnum support
hard-coded for the time being.)
2010-06-19 17:35:05 +00:00
Michael Bayne 1d9a19e502 Unit tests for all supported field types (including null versions). 2010-06-19 17:34:21 +00:00
Michael Bayne 06c36fbed2 - Added support for @Transform annotation.
- Revamped column type determination to use a mechanism that supports
  delegation and does not rely on a heap of instanceof calls (which results in
  runtime failure rather than compile time failure when a new column type is
  added)
- Discovered that HSQLDB (at least) does not handle Byte, Short and Float
  correctly. It returns them as Integer, Integer and Double respectively, which
  then causes failure when trying to write those values back to the fields. We
  work around this by converting non-null results to the correct type after we
  get them back from the JDBC driver.
2010-06-19 17:33:55 +00:00
Michael Bayne a4e7f3fb47 Make "ant -Ddebug=true tests" run the tests with SQL debugging on. 2010-06-18 23:49:32 +00:00
Michael Bayne 6fd404587f Allow a specific test to be run with "ant -Dtest=Foo tests". 2010-06-18 23:12:27 +00:00
Michael Bayne 5e77d29c47 Test good and bad byte enum marshaller creation. 2010-06-18 22:49:02 +00:00
Michael Bayne 0950fdd4ea Transformers: more than meets the eye.
This is an unimplemented proposal for handling non-basic types in Depot in an
extensible way, instead of continuing down the road of the ByteEnum-style
hackery that we've been doing to date. The basic design is as follows:

Annotate either a field or a class with @Transform and specify the classname of
a Transformer in that annotation. For example:

 public class MyRecord extends PersistentRecord {
     @Transform(Transformers.CommaSeparatedString.class)
     public String[] cities;
 }

will cause "cities" to be combined into a single string (comma separated)
before storing in the database, and split back into a string array from the
single string when read from the database.

Alternatively, one can annotate a type:

 @Transform(ByteEnumTransformer.class)
 public interface ByteEnum { ... }

If Depot sees a field of non-basic type, it will look for a @Transform
annotation on the field's type (and any interfaces implemented by that type or
its parent types, which is not auto-magic). If it finds one, it will use it.
Otherwise it will fall back to what it does now (which I think is to just foist
the object off to JDBC and hope for the best).

Comments and suggestions are invited.
2010-06-17 19:11:35 +00:00
Michael Bayne f722d1b2df There must be a way to have svn magically put in the current year. 2010-06-17 19:05:21 +00:00
Par Winzell 2125367297 Automatically handle changes to primary key by dropping the old one (which triggers the creation of the new one). 2010-05-06 14:38:52 +00:00
Par Winzell f54c74e385 Abstract records should never be directly referenced; fail as early as possible and explain what's going on. 2010-05-06 14:37:18 +00:00
Ray Greenwell 743ca150cf Patch from Jamie Doornbos: update Eclipse file to match the move to guava, in r600. 2010-04-16 16:40:29 +00:00
Michael Bayne 70a16d64ad Back to the freakoutery. Nathan's going to use the existing (if somewhat
verbose) mechanisms to accomodate his needs. We freak out as early as possible
to save the developer a time wasting debugging session in situations where they
update only one or the other of the persistent and runtime class, or make a
typo, or get the types wrong, etc.
2010-04-10 00:28:26 +00:00
Ray Greenwell a23cb7e4d8 Patch from Nathan Curtis: gracefully ignore any field contained in the
runtime class that's not in the persistent class.
2010-04-09 20:38:33 +00:00
Par Winzell 26ece1f2c0 Ray points out these should be FluentExp's. 2010-04-07 18:34:23 +00:00
Par Winzell 31f5d593e5 Move in() and like() into FluentExp (they can certainly operate on an expression), and add notLike() variants. 2010-04-07 16:24:18 +00:00
Ray Greenwell 40d596509d Added a note about the @Generated annotation, which we're declining to use. 2010-03-30 20:07:07 +00:00
Ray Greenwell 704476323e Faster Key construction via the generated getKey() factory.
A little bit back Mike added a fast-path for Key construction for keys with
one Comparable. Keys with multiple values would still validate the order
every time. This was necessary even when using the generated factory
because Class' getFields() does not guarantee any order. In practice,
the Sun JVM seems to return them in declared order, but apparently other
JVMs may not. The arguments to getKey() are determined when 'genrecord'
is run, but the field order used during runtime is computed at runtime.

This change generates code that stashes the key fields in an order
deteremined at the time 'genrecord' is run and that is guaranteed to
match the argument order to each PersistentRecord subclass' getKey().
Thus, getKey() can now directly construct a key with minimal overhead.

The field order is still computed at runtime as a fallback for
PersistentRecord classes that haven't yet been updated.

The ordering of getFields() is still being relied upon at 'genrecord'
time, but Mike may introduce a patch that will guarantee that ordering
matches declaration order. In the meantime, it's no worse than before
and if somehow someone does run 'genrecord' with an alternate JVM
they should immediately notice the discrepency in their diffs.

The Key constructor utilized is still public because it is used by
DepotUtil. A nice change would be to make it package-private.
2010-03-24 19:51:56 +00:00
Michael Bayne 55b0d2e3ea Behold, the power of Guava. 2010-03-16 23:56:30 +00:00
Michael Bayne 8b871dcf19 Look ma, unit tests that run against HSQLDB. 2010-03-16 04:57:52 +00:00
Ray Greenwell aae3d909a2 Via Charlie Groves, some bits that Eclipse noticed. 2010-03-04 21:41:32 +00:00
Michael Bayne 1e2f88ac77 Factor out the canonical order generation as we'll still need this for the
static newKey() methods even if we revamp this whole business.
2010-03-04 07:01:49 +00:00
Michael Bayne 21132b4edb Be stricter about our primary key requirements here. 2010-03-04 07:01:07 +00:00
Michael Bayne a970856aae Well, we can at least write a unit test for this super special business.
However, I started making HSQL work a long time ago so that we could have real
unit tests that did real meaningful things, and Zell was kind enough to finish
making HSQL work, so we should be able to do some real end-to-end testing. I
just need to set up the necessary scaffolding. On the list!
2010-03-04 02:57:49 +00:00
Michael Bayne c017ec5bd1 Provide a fast path for key construction in the rather common case of a
non-composite key (where ordering cannot be a problem). Boy I really wish I had
unit tests...
2010-03-04 02:45:42 +00:00
Ray Greenwell 57e3cce8d0 Return this until/unless I tackle field sorting. 2010-03-03 17:04:16 +00:00
Ray Greenwell 37c348a305 I might get my head chopped off for this one, but presumably the generated
Key construction code "knows what it's doing" and can call the optimized
Key constructor. We can rollback if I'm missing something.
2010-03-03 03:59:02 +00:00
Ray Greenwell 96e858070a This static shared map should really be a ConcurrentMap. 2010-03-03 03:57:54 +00:00
Ray Greenwell 93d90083a1 Use single quotes around the truncation parameter.
(Assume future enums in DateTruncate will correspond to the postgres args).
2010-03-02 21:36:29 +00:00
Andrzej Kapolka cb86b6def4 If we're shadowing a field, let's try using the shadowed column's name. 2010-03-02 21:30:20 +00:00
Ray Greenwell 42d99f90ca Some language about the proper usage of Sequence. 2010-02-25 23:17:06 +00:00
Ray Greenwell 0b51d1e62f Formatting. 2010-02-25 22:35:15 +00:00
Par Winzell 4b1ffe3df9 We need to specify that we want to call the varargs version, not the Iterables version. Screw Java. 2010-02-25 18:48:54 +00:00
Par Winzell 6930ed5b40 Bring back this test: WithKeys's constructor begins with iterator().next().getClass() and it's not obvious to me that it can made to elegantly not knowing that class. 2010-02-25 18:48:24 +00:00
Par Winzell 0b8be77564 Unused import. 2010-02-25 18:47:17 +00:00
Michael Bayne aa4ac73e5d Fixed some javadoc bugs. 2010-02-25 06:52:07 +00:00
Michael Bayne b5e7ba8642 Whitespace patrol. 2010-02-25 06:49:07 +00:00
Michael Bayne b8d957ce4c Accept Iterable rather than Collection everywhere we reasonably can.
Note one potentially consequential diff in DepotRepository:

-        return keys.isEmpty() ? Collections.<T>emptyList() :
-            _ctx.invoke(new FindAllQuery.WithKeys<T>(_ctx, keys));
+        return _ctx.invoke(new FindAllQuery.WithKeys<T>(_ctx, keys));

This should not actually impact anything. FindAllQuery.WithKeys first checks
for keys that are cached, coping with a potentially empty set (there will be
none), then if there are keys that remain to be loaded from the database, it
loads them. The first check will NOOP as will the second check. So this should
just be a slightly more circuitous path to getting back an empty collection. It
should not result in a zero row matching query being sent to the database.

With that in mind, it seemed inelegant to prematurely optmize the return of an
empty collection.
2010-02-25 06:48:27 +00:00
Michael Bayne 950653960b Separate SeqImpl out of Sequence, hiding it away in our impl package tree. Make
Sequence an interface.

We're going to change all of the places in Depot where we take a Collection as
an argument and take an Iterable instead. We invariably just turn the
Collection to an array, and we can just as well do that with an Iterable and be
more flexible about what we accept. Iterables.toArray has a fast path for
Iterable instances that also implement Collection, so we make SeqImpl implement
Collection under the hood even though we don't advertise that in the Sequence
interface because we don't want people using these as collections.

What we really want is something in between Iterable and Collection that knows
its size but otherwise does not allow mutation or containment checks.
2010-02-25 06:30:12 +00:00
Ray Greenwell 503f3893cb XList is now an ex-List. 2010-02-25 06:12:22 +00:00
Ray Greenwell e972ebc72b Added toSet(). 2010-02-24 22:01:25 +00:00
Ray Greenwell 6255819745 Twice now I've blown this comment. 2010-02-24 17:34:03 +00:00
Ray Greenwell 17a6cb3332 Comment pedantry.
Considered adding a note that toArray() is generally not safe, but the
Collections run through here in normal depot usage will be safe to use.
Check out the implementation of AbstractCollection's toArray(T[]).
2010-02-24 02:07:36 +00:00
Ray Greenwell 9444cad7d8 Check our preconditions for fast failure, and added toArray(). 2010-02-23 22:27:30 +00:00
Michael Bayne e251cd9944 This guy needs also to be marked deprecated to let the compiler know that I
know that it's implementing a deprecated interface method.
2010-02-23 08:54:54 +00:00
Michael Bayne 54b7bf9e99 Bring on the deprecation warnings. 2010-02-23 08:47:46 +00:00
Michael Bayne b022382231 XList is going away. To be replaced with this, still somewhat out of place in a
database library but at least slightly more ignorable, bit of functional
helpfulness.
2010-02-23 08:35:30 +00:00
Michael Bayne 152ff056d9 Charlie has convinced me that the database manipulation operations should be
public and I should not force everyone who wants to use Depot to route all
database accesses through custom public methods that hide all of the underlying
Depot business behind application specific APIs.

I still think this is the best way to use Depot, but I acknowledge that there
are certain valid use cases (like generic code that operates on records in
arbitrary repositories) which are precluded by this scheme. So instead I'll
just strongly suggest that Depot be used in the way I think it should, and
frown sternly at anyone who deviates from The Way.
2010-02-23 07:30:58 +00:00
Par Winzell 1fe2c451f8 Both In() and IsNull() will work on general expressions, not just columns. 2010-02-22 18:58:57 +00:00