Commit Graph

610 Commits

Author SHA1 Message Date
samskivert d1ef556a55 No using raw types. Also no annotating whole methods
@SuppressWarnings("unchecked") even if they're simple.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2437 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-18 17:23:56 +00:00
samskivert 52f5b41f44 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.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2436 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-17 19:09:08 +00:00
andrzej@threerings.net f1a2723292 Added shared true and false predicate instances, with type-safe
accessors (a la Collections.emptyList).


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2435 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-17 01:15:48 +00:00
samskivert 6245c3dd44 Use varying size blobs for int[] columns like we do byte[].
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2434 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-16 22:51:59 +00:00
samskivert ed224ab0cb Handle conversion from int[] to byte[] manually rather than relying on the JDBC
driver to know how to do it.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2433 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-16 22:49:11 +00:00
samskivert 534b224489 Javadoc fix from Dave.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2432 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-16 21:54:21 +00:00
samskivert 129120794a 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.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2431 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-16 21:33:22 +00:00
samskivert a5eff55b9f Nixed unused imports.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2430 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-16 02:01:19 +00:00
samskivert f7025032c2 Missed a spot.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2429 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-15 18:46:48 +00:00
samskivert 067e4ebdb6 Name things a bit more clearly to indicate that we're manipulating field
definitions, not necessarily field overrides.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2428 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-15 18:42:12 +00:00
samskivert 58d2b7d2fe Zell reminds me that I want to use FieldDefinition rather than FieldOverride
which is meant to be used only in certain circumstances.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2427 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-15 18:37:04 +00:00
samskivert 9739e50761 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.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2426 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-15 18:33:21 +00:00
samskivert bc98a28af8 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.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2425 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-15 18:22:18 +00:00
samskivert 610b03df80 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.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2417 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-12 01:55:54 +00:00
samskivert 63f3e00279 Let's have a stack trace here because these mismatches are just plain bizarre.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2416 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-12 01:49:06 +00:00
samskivert b82bf914d9 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.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2415 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-12 00:24:14 +00:00
samskivert 193e2e5853 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.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2412 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-10 18:09:23 +00:00
samskivert f4ff354621 Let's log a stack trace on lazy initialization so that we can see who the
culprit is.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2411 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-10 18:01:24 +00:00
samskivert 845f1f47b6 Some invoker jockeying requested by Charlie.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2410 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-10 02:13:57 +00:00
samskivert d45da29c7b 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.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2409 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-10 02:00:19 +00:00
samskivert e0d3f6b2c9 Don't try to do the primary key lookup on delete for records that define no
primary key.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2408 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-08 19:01:30 +00:00
samskivert ae552d1696 Cope with the goddamned broken generics implementation in JDK 1.5.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2407 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-08 18:58:12 +00:00
samskivert 155a188da2 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.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2406 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-08 17:54:11 +00:00
samskivert 35c90b8926 Beans/frank.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2405 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-08 16:48:32 +00:00
samskivert 5b6d4895e8 Automatically add the shadow to our type set for @Computed(shadowOf=FooRecord)
record classes.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2404 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-06 02:38:20 +00:00
samskivert e1f211dc8e We need to set up our _builder in WithKeys. Also moved loadRecords() down below
loadAndResolve().


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2403 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-06 02:27:53 +00:00
samskivert 9ee3f47e3e 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!


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2402 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-06 02:06:44 +00:00
samskivert 367e118bd5 Type jockeying.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2401 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-06 01:59:52 +00:00
samskivert 8972c0089e 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).


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2400 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-06 01:54:08 +00:00
samskivert 4b4fccc62a Allow the cache to be explicitly bypassed.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2399 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-06 00:34:29 +00:00
samskivert 8d490b3b2e Be sure to report that we throw DatabaseException for documentation purposes.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2398 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-06 00:30:25 +00:00
samskivert 315ea2d87a Tidying.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2397 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-06 00:17:52 +00:00
samskivert f8fd195327 We need to use the key in our or clause, not its non-existent where expression.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2396 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-06 00:13:05 +00:00
samskivert 1066186765 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.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2395 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-05 23:17:37 +00:00
samskivert 8eeff2c670 Nixed unused import.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2394 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-05 23:03:49 +00:00
samskivert 018f4e96d3 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.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2393 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-05 23:03:08 +00:00
samskivert 2d98053b6b Added findAllKeys() for when you only need the keys.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2392 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-05 22:58:05 +00:00
samskivert 8accd6b495 One more unused import.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2391 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-05 22:43:38 +00:00
samskivert d37e8079a8 Unused import patrol.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2390 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-05 22:43:06 +00:00
samskivert ed70e30023 Some method ordering.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2389 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-05 22:37:23 +00:00
samskivert 4ba1d015c9 We're handling Key query construction directly instead of letting it look like
a WhereClause, so we need to add our own where.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2388 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-05 22:36:53 +00:00
samskivert 741f868cc5 PrimaryKeySet -> KeySet.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2387 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-05 22:16:55 +00:00
samskivert 5e68665b34 Now we don't have to provide our values as an ArrayList.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2386 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-05 20:07:43 +00:00
samskivert 90bf8e0e68 Ah, Key actually is PrimaryKey and does not in fact keep the primary key
columns around. Cleaned some things up along those lines.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2385 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-05 20:05:44 +00:00
samskivert 6ac58edef3 Formalized the two-phase "get primary keys that match an arbitrary query, then
load or modify the rows that match those keys" pattern so that we can almost
always just magically do the right thing with regard to the cache. Added a
version of deleteAll() that makes use of this.

Also nixed a bunch of checked exception tomfoolery which was almost entirely
unnecessary and now with DatabaseException is completely unnecessary.

A few things remain to be done:

- PrimaryKeySet tries to be "smart" if its passed 0 keys and use
LiteralExp("false") but that causes things to freak out because Depot then
doesn't know what primary class it's dealing with. I'm probably going to make
All and None expressions that match all and none of the records in a table
respectively.

- deleteAll() doesn't currently split its keys into chunks small enough to be
digestible by the database if we match more than 32,768 rows. I'll see if I
can't abstract out that code from FindAllQuery so that we can easily use it
everywhere. It would be cool to handle that a a lower level and allow the
WhereClause to say that it needs to be run in phases, but that would probably
complicate the crap out of the low-level code.

- I need to create PrimaryKey to go between Key and PrimaryKeySet so that we
can avoid duplicating the primary key columns thousands of times in a large
PrimaryKeySet.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2384 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-05 19:39:08 +00:00
samskivert c02372cad6 Export our samskivert code as a module as well.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2382 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-05 17:05:37 +00:00
samskivert 5facd275b1 Nix dependence on StringUtil.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2381 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-05 01:19:43 +00:00
samskivert 9c071fd67f Widening, removal of MessageFormat import just for the javadoc since that
breaks GWT.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2380 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-05 01:16:57 +00:00
samskivert 1a0c3cc241 Changed Depot to throw a RuntimeException on unexpected database error instead
of a checked exception. Invariably, we don't do anything with our
PersistenceExceptions except let them percolate all the way to the top and then
log a warning. We can probably automate the process of logging a warning with
useful information and save ourselves the trouble of doing it manually
everywhere.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@2376 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-03 16:10:06 +00:00
samskivert 79a466c42a Any collection of anything that extends QueryClause is generally all we need.
git-svn-id: https://samskivert.googlecode.com/svn/trunk@2375 6335cc39-0255-0410-8fd6-9bcaacd3b74c
2008-09-03 00:55:07 +00:00