Commit Graph

289 Commits

Author SHA1 Message Date
Michael Bayne 05f499736e Nixed unused import, commented out others that go with commented out code. 2008-11-01 05:39:27 +00:00
Michael Bayne 8ec25c5a6d Make the 1.5 compiler happy. 2008-10-31 00:42:53 +00:00
Michael Bayne 2b8bc0c97f When we can switch entirely to 1.6 we can use Postgres's value = any(?::int[])
form to pass as many damned keys we want in a giant array. At that time we can
nix all the >32,768 key fiddly business.
2008-10-31 00:17:36 +00:00
Michael Bayne ec76d4d29f Oops, avoid introducing a bug when nulls == zeros == values.length. We want to
return null in that case.
2008-10-24 05:18:50 +00:00
Michael Bayne 2309c490f7 Compromise on our 0 == null stance for primary key columns. See the code
comments for further details.
2008-10-24 05:13:28 +00:00
Michael Bayne ba97743754 Make sure we use the up to date metadata when doing our stale column check. 2008-10-22 01:09:22 +00:00
Michael Bayne 19287550f4 More javadoc cleanup. 2008-09-30 00:23:57 +00:00
Michael Bayne 4c94296b67 Javadoc fixes. 2008-09-30 00:12:08 +00:00
Michael Bayne fee6be6c2d Added support for data migrations, which are run after all schema migrations
have been run and are also coordinated between disparate processes by an
in-database lock system.
2008-09-25 23:40:01 +00:00
Michael Bayne 2b21105dc1 Call EntityMigration SchemaMigration because that's what it's for and I want to
add a new DataMigration mechanism so that people can stop using schema
migrations to do data migration.
2008-09-25 22:27:58 +00:00
Michael Bayne 2c9c9b47c1 Let's preserve the ability for callers with uncomplicated needs to create and
initialize a persistence context in one fell swoop.
2008-09-24 19:09:17 +00:00
Michael Bayne 0e68c8a599 Change the way initialization is handled (a bit). It is now possible to create
a PersistenceContext and give it out to all of your repositories and delay
activating the context until you are ready for everyone to start talking to the
database. In this way you can enforce that no one does any database fooling
around before it's OK.

I also introduced DepotRepository.init() where database fooling around is OK.
The general idea is that you register schema migrations in your constructor and
then if you have data migrations to be done (or initialization that requires
reading things from the database), you do that in init().
2008-09-24 18:33:25 +00:00
Michael Bayne 81c25ae4f1 Properly handle int[] fields when encountered as unassociated values. We
already do the right thing when we process them as fields of persistent
records.
2008-09-23 17:18:23 +00:00
Michael Bayne f33a376f7e Formatting tweaks. 2008-09-23 17:17:05 +00:00
Michael Bayne d7f864dfe4 Don't try to manage the cache manager. Push that burden out to the caller who
may have their own needs and arrangements.
2008-09-20 03:30:49 +00:00
Michael Bayne 3e8ac68af6 Properly handle @GeneratedValue(strategy=GenerationType.IDENTITY,
initialValue=N) for non-zero values of N. This is complicated. Depot used to
"initialize" value generators pretty much every time a table schema was
migrated. For TableValueGenerator it could just NOOP if the proper row was in
the sequence table. IdentityValueGenerator was just broken and ignored any
request to configure an initialValue, so it never did anything.

First I looked into preserving this frequent reinitialization behavior, but it
turns out that it's not possible to read the current value of a sequence in
Postgres without modifying it. So trying to do something like:

SELECT setval('"FooRecord_fooId_seq"', max(currval('"FooRecord_fooId_seq"'),
                                           cast(initialValue as bigint)));

doesn't work because you can't call currval() without first having called
nextval() (and furthermore when you do that, the Postgres client grabs a block
of sequence values for this client so that multiple clients can add rows to a
table without having to coordinate with the server and one another to assign a
new value every time a row is inserted).

So I changed Depot around to not reinitialize value generators unless it really
believes that the column in question is newly added. We can't rely on our own
auto-column creation because it's possible for someone to create a column
through a custom entity migration, so instead we just keep track of what
columns we had before we started all of our migrations (automatic and custom)
and check to see if there are any new columns after all is said and done and if
any of those have value generators, we "create" them.

This allows us to just setval() the sequence to the desired initial value
without first reading it.

This all fails if someone renames a column with a value generator. The column
will appear to Depot to be new and it will try to recreate the value generator
on that column. For TableValueGenerators that will basically NOOP and
everything will be just like it was before. For IdentityValueGenerators,
because of the way that Postgres magically creates a tablename_columnname_seq
sequence for identity value generation, when the column is renamed, the
sequence will retain the old column name and when Depot goes to try to setval()
the sequence based on the new column name, it won't exist and the migration
will fail. So at least we're not silently reinitializing the value generator to
its initial value when a column (with an identity value generator) is renamed.
We also don't try to do anything if the initialValue is not 1 (the default). So
we avoid failing or doing anything wrong if those kinds of columns are renamed.

So we only fail if someone renames a column with an identity value generator
with a non-default initial value. Since one can only put a value generator on a
primary key field and an identity value generator generally means you have
something simple like FooRecord with fooId. This means someone is renaming
their simple auto incrementing primary key field which seems extremely unlikely
because those columns usually have an obvious name that you're never going to
change. No problem!

I also haven't fixed this problem for MySQL yet. I can only handle so much
database befuckaroundery in one go.
2008-09-17 19:09:08 +00:00
Michael Bayne 5ac15a99ca Use varying size blobs for int[] columns like we do byte[]. 2008-09-16 22:51:59 +00:00
Michael Bayne b64658fd83 Handle conversion from int[] to byte[] manually rather than relying on the JDBC
driver to know how to do it.
2008-09-16 22:49:11 +00:00
Michael Bayne 9112b3c7e2 Javadoc fix from Dave. 2008-09-16 21:54:21 +00:00
Michael Bayne 84dd3c6b5f Amazingly, we had apparently never tried to insert a preconfigured row into a
table that had field generators on its primary key. The code just blindly
overwrite the supplied primary key and ran the generators anyway.

We now only run the generators if the record has no primary key. This means we
can't use field generators on non-primary-key fields, but I'm not sure we ever
meant to support that in the first place.
2008-09-16 21:33:22 +00:00
Michael Bayne e25aa25bd6 Nixed unused imports. 2008-09-16 02:01:19 +00:00
Michael Bayne 2b1b2e8334 Missed a spot. 2008-09-15 18:46:48 +00:00
Michael Bayne 759fb587dc Name things a bit more clearly to indicate that we're manipulating field
definitions, not necessarily field overrides.
2008-09-15 18:42:12 +00:00
Michael Bayne a507308c2b Zell reminds me that I want to use FieldDefinition rather than FieldOverride
which is meant to be used only in certain circumstances.
2008-09-15 18:37:04 +00:00
Michael Bayne 7e8c7fadcb Don't log a warning if we don't get a result for every primary key provided
when we're doing a query with primary keys provided by a random caller. We have
know idea where they got those keys or where they have been before we got our
filthy mitts on them.
2008-09-15 18:33:21 +00:00
Michael Bayne 2f57697c32 We're going to allow FieldOverride on @Computed records, just not on @Computed
fields. Maybe Zell will remind me why this was disallowed, but it seems that to
disallow this is to make FieldOverride useless.
2008-09-15 18:22:18 +00:00
Michael Bayne 98ac644ad9 Ah, entities.keySet() is misleading because it contains records that were found
in the cache as well as records loaded from earlier passes in cases where we
split our query up to avoid database breaking in() clause sizes. Now we track
exactly what we got this time around and report that.
2008-09-12 01:55:54 +00:00
Michael Bayne 2611a1076b Let's have a stack trace here because these mismatches are just plain bizarre. 2008-09-12 01:49:06 +00:00
Michael Bayne d47e85fe9f If we're going to magically convert ByteEnum to an integer type, then we should
magically assign it a default value of 0 like we do for our other integer types.
2008-09-12 00:24:14 +00:00
Michael Bayne 96bd8b56a0 We're seeing some weirdness here, so let's log the original statement along
with the actual set of wanted and obtained keys when we have a mismatch.
2008-09-10 18:09:23 +00:00
Michael Bayne 27b619d59b Let's log a stack trace on lazy initialization so that we can see who the
culprit is.
2008-09-10 18:01:24 +00:00
Michael Bayne c4ddf1853c Created an explicit EntityMigration.Add for when you want to add a column to a
database and need to provide a defaultValue at the time that you add it, but
don't want to have to define a permanent default value on the field.
2008-09-10 02:00:19 +00:00
Michael Bayne 00d6ae5492 Don't try to do the primary key lookup on delete for records that define no
primary key.
2008-09-08 19:01:30 +00:00
Michael Bayne ffeb6534c4 Cope with the goddamned broken generics implementation in JDK 1.5. 2008-09-08 18:58:12 +00:00
Michael Bayne f1dd34e4b3 We need Key to export a Key.Expression which we can use inside the SQL for a
KeySet so that the "where" keyword is not repeated every time we bind a key.
2008-09-08 17:54:11 +00:00
Michael Bayne 56c4394b29 Beans/frank. 2008-09-08 16:48:32 +00:00
Michael Bayne d5619a3b28 Automatically add the shadow to our type set for @Computed(shadowOf=FooRecord)
record classes.
2008-09-06 02:38:20 +00:00
Michael Bayne 9a7a78080c We need to set up our _builder in WithKeys. Also moved loadRecords() down below
loadAndResolve().
2008-09-06 02:27:53 +00:00
Michael Bayne 2f335c4dc8 Actually, if we use Key we don't need to specify the type. It's already in the
keys. So we can have loadAll(Class,Collection<Comparable>) and
loadAll(Collection<Key>) and not run into type erasure problems. Yay!
2008-09-06 02:06:44 +00:00
Michael Bayne 9a21071c82 Type jockeying. 2008-09-06 01:59:52 +00:00
Michael Bayne 35f654a8c1 Added loadAll() which takes a collection of primary keys. Since we've already
got the primary keys, this goes right to phase two wherein we check the cache
for hits and load the remaining records by primary key (and cache them).
2008-09-06 01:54:08 +00:00
Michael Bayne 52de64001d Allow the cache to be explicitly bypassed. 2008-09-06 00:34:29 +00:00
Michael Bayne 089706427e Be sure to report that we throw DatabaseException for documentation purposes. 2008-09-06 00:30:25 +00:00
Michael Bayne fe1aff3842 Tidying. 2008-09-06 00:17:52 +00:00
Michael Bayne 84c32cc5e3 We need to use the key in our or clause, not its non-existent where expression. 2008-09-06 00:13:05 +00:00
Michael Bayne 263529c929 Use the SelectClause to obtain our types so that the main record class is
always properly added. Also made SelectClause freak out if it's provided with
bogus clauses.
2008-09-05 23:17:37 +00:00
Michael Bayne 8b6f575af8 Nixed unused import. 2008-09-05 23:03:49 +00:00
Michael Bayne ae9e0acef8 We need to let you express whether or not you want your keys from the master
server or if it's OK to get them from a (potentially slightly out of date)
replica. If you're going to modify rows based on the results of findAllKeys(),
you should probably get them from the master server, if you're just reading
data, you can talk to a replica.
2008-09-05 23:03:08 +00:00
Michael Bayne 2e4decf18a Added findAllKeys() for when you only need the keys. 2008-09-05 22:58:05 +00:00
Michael Bayne 95d316d28e One more unused import. 2008-09-05 22:43:38 +00:00