Commit Graph

753 Commits

Author SHA1 Message Date
Ray Greenwell 2b71609148 I should change the name of this test... 2010-07-05 22:36:18 +00:00
Ray Greenwell 48279471e1 Updated tests. 2010-07-05 22:34:15 +00:00
Ray Greenwell eef66bcaee Changed my String[] Transformer:
- continue to terminate Strings with a newline
- turn newlines inside a String into "\n"
- turn null elements into "\0".

This is one additional character when encoding nulls, but
I think it may improve readability..
2010-07-05 22:10:56 +00:00
Michael Bayne 0e82904696 Provide the Transformer with the field's Type rather than it's Class. The Type
contains generic type information which would allow a transformer to do the
right thing with a field of, say, type Set<Integer>.

If we had unit tests for StringIterable, I'd know that I didn't just break it.
I'd also know that it worked in the first place. :)
2010-07-05 21:43:10 +00:00
Ray Greenwell a5fee01354 Maybe I can generalize this into a rule: if either of operands 2 or 3
to the ternary operator are boolean constants, don't use the ternary operator.

a ? true : x   ==  a || x
a ? x : true   ==  !a || x
a ? false : x  ==  !a && x
a ? x : false  ==  a && x
2010-07-05 21:32:28 +00:00
Ray Greenwell f2f995766b A demonstration of the failing of the current String[] transformer.
I'll do some more tests and nix this one today.
2010-07-05 14:16:00 +00:00
Ray Greenwell ce1d06e82b I was trying to be clever with newline and save a character,
but I forgot about that cleverness in fromPersistent, so skip it for now.
2010-07-02 03:56:26 +00:00
Ray Greenwell f4c7b7fef4 Better String[] Transformer, RFC. 2010-07-02 03:49:43 +00:00
Par Winzell 846ea920b6 Make the adapter configurable, as was always the intention. 2010-07-01 17:15:32 +00:00
Par Winzell a0e8c602ed Maintain correct record counts for cacheless finds. 2010-06-24 18:15:40 +00:00
Michael Bayne 75a22f5584 Nix joiner. 2010-06-19 18:05:46 +00:00
Michael Bayne 728159dc48 Replace the CommaSeparatedString transformer with an escaping
TabSeparatedString transformer. Maybe I should just use StringUtil methods...
2010-06-19 18:05:23 +00:00
Michael Bayne f4cc4f2bee Move the repository south to match AllTypesTest. 2010-06-19 17:52:52 +00:00
Michael Bayne 978bf81acb Added support for boxed booleans. I have to admit that adding it to the test
case, seeing it fail, then adding the code to handle it was rather satisfying.

I'm not jumping on the TDD bandwagon or anything, but libraries like Depot are
clear cases where vigorous unit testing is a big win.
2010-06-19 17:48:51 +00:00
Michael Bayne 9d9ba71c97 Import tidying. 2010-06-19 17:45:28 +00:00
Michael Bayne d0dd828925 Comment our workarounds. 2010-06-19 17:44:55 +00:00
Michael Bayne 45ec7cf77c Implemented the ColumnTyper interface for our various builders. 2010-06-19 17:41:10 +00:00
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