Commit Graph

768 Commits

Author SHA1 Message Date
Michael Bayne 872b2d9ef3 Some robustness bits.
It's not clear what the right thing to do is if the database connection fails
during the middle of a transaction. In general, one can't talk to the database
after that, so I'm assuming the transaction is aborted (or eventually aborted)
and rolled back, and everything has to be retried.

I'm not currently tracking state inside a Transaction, which means that I don't
freak out if you call commit() then call rollback(), I just ignore the latter
call, and it's also possible to do something stupid like:

  Transaction tx = Transaction.start(ctx);
  try {
    _somRepo.doOp(..);
  } catch (DatabaseException de) {
    // no problem!, keep on keepin' on
  }
  _someRepo.doAnotherOp(...);
  tx.commit();

If the first repo op fails due to a database connection failure, the
transaction will get a new database connection for the second op and do the
last half of the op in a new connection.

I guess I'll have to do some state tracking, because stupid as the above code
is, I'm sure some circumstance will arise where it seems like a reasonable
thing to do, and hilarity will ensue. Blah.
2014-10-01 14:27:55 -07:00
Michael Bayne d676847c24 Initial pass at transaction support.
Now to test it!
2014-10-01 14:16:48 -07:00
Michael Bayne 63f69eb843 Tweaky tweak. 2014-10-01 11:25:16 -07:00
Michael Bayne 9874be4034 Added special update() provided by Ray.
This allows one to update a record iff some additional criteria are met.
2014-10-01 11:19:21 -07:00
Michael Bayne 1d826d903f Beans/frank.
I should probably add a test for this. Ha!
2014-06-26 11:50:45 -07:00
Michael Bayne 44091660ea Migrated to Github. 2014-06-25 15:39:13 -07:00
Michael Bayne c60d8e2dde A bunch of Javadoc fixes. 2014-06-25 21:49:09 +00:00
Michael Bayne 97b404c236 Provide a modicum of thread safety for marshaller init.
The _marshallers table must be guarded as computed marshallers can be created
at any time, and marshaller initialization itself must be guarded for the same
reason.

Thanks to Ray for pointing this out.
2014-06-25 21:48:50 +00:00
Michael Bayne 3906c69a88 Liaison now handles exceptioning for us. 2014-05-02 20:46:36 +00:00
Michael Bayne f2be63ec19 Choke usefully if we can't obtain last inserted id. 2014-05-02 20:14:43 +00:00
Ray Greenwell 800add9667 Clean up imports. 2014-05-02 18:28:50 +00:00
Michael Bayne 9ebd2c677c Use new smarter DatabaseLiaison.lastInsertedId. 2014-05-02 18:19:51 +00:00
Ray Greenwell 2cf224dd18 Whoops! My last edit didn't actually work, it ended up falling back.
This works, but mdb is going to move the special caseyness inside the Liaison.
2014-05-02 18:12:46 +00:00
Ray Greenwell 1a9fc404ba Ok, this works on both mysql and postgres.
On mysql the column name ends up being "GENERATED_KEY".
2014-05-02 01:31:58 +00:00
Ray Greenwell e2a9702c46 This getGeneratedKeys business doesn't seem to work for us on mysql.
Trying a catch/fallback. This should at least provide a workaround for now...
2014-05-01 23:01:55 +00:00
Michael Bayne e08911369e Only use RETURN_GENERATED_KEYS on inserts.
This works around "unsophisticated" Postgres JDBC drivers which blindly tack
"RETURNING *" onto a query if RETURN_GENERATED_KEYS is supplied.
2013-11-20 19:45:24 +00:00
Michael Bayne ca4ec1f4d3 Reverse order in addAll(List,Cons).
This causes the elements of the list to match the original order they were
added to the cons list (which stores elements "backwards").

This order matters for joins, as Ray discovered.
2013-10-10 22:06:34 +00:00
Michael Bayne 99a4d7a18e Only rewrite record file if it changed. 2013-09-17 19:07:19 +00:00
Michael Bayne bc8a18dec5 Factor the logic of genrecord from the Ant harness. 2013-09-17 19:07:16 +00:00
Michael Bayne 58ede042a6 Fixed some use of wrong log helper. 2013-05-24 18:45:26 +00:00
Michael Bayne 8a74276caf Various tidyings. 2013-05-24 18:30:57 +00:00
Michael Bayne 952d01c55b Info -> debug for initial version record message.
It's not that important. We already log a message indicating that we created
the table for the first time, which will always follow this message.
2013-05-24 18:30:53 +00:00
Michael Bayne 1bee1d0351 Revamp identity value generator to use Statement getGeneratedKeys.
Most JDBC drivers have supported this for ages. No longer do we need the
hackery of turning around and doing another query to obtain generated key
values.
2013-05-16 18:42:16 +00:00
Michael Bayne 81c24f56bf Fix rawtypes. 2013-05-16 18:42:13 +00:00
Michael Bayne 0b5369fd11 Do this cast in a way that Java 7 doesn't complain about. 2013-05-16 18:42:09 +00:00
Michael Bayne 0c26a26ce0 Bump HSQLDB to 2.9, fix test that assumed count(*) returned int. 2013-05-16 18:42:05 +00:00
Ray Greenwell 4af2b7c95d More inline comments explaining why we don't just drop the DKE. 2013-05-07 00:41:17 +00:00
Ray Greenwell ce3a340199 Bugfix: store() should never throw a DuplicateKeyException.
It would be extremely rare, but if two nodes were trying to simultaneously
store() the same record with the same Key, one could fail with a DKE.

Attempt a second 'update' if the insert fails.
2013-05-07 00:03:05 +00:00
Michael Bayne c63ce0c10e Out with arrays, in with collections. 2013-05-06 18:19:31 +00:00
Michael Bayne a625c831ae Updates to work with HSQLDB 2.2.4.
We need the HsqldbLiaison fixes from samskivert 1.8-SNAPSHOT and we have to nix
some hardcoded bogosity in our own tests.
2013-05-06 17:38:16 +00:00
Ray Greenwell 9614fc02b9 This note has been obsolete since r376. Removed. 2012-08-13 17:56:37 +00:00
Michael Bayne 7f839f8ddd Patch from Mike T to support parameterized types in genrecord. 2012-07-25 16:38:43 +00:00
Par Winzell 42e8d6e75e According to Javadoc, getColumnLabel is the method that is meant to respect the 'as foo' construct we rely on. 2012-07-03 23:38:35 +00:00
Michael Bayne f7d7c586c0 Make GenRecordTask only honor @Transient, like DepotMarshaller.
We've chosen not to conflate Java transience with Depot non-persistence. It's a
little wonky to have to choose a particular memory model behavior just to have
a field not persisted in your record.
2012-06-27 18:22:36 +00:00
Michael Bayne 4734156b31 Nix unused import. 2012-04-13 18:12:51 +00:00
Michael Bayne d254148fd0 Use ImmutableMap. I mistakenly thought we didn't use Gauva in Depot. 2012-04-13 18:12:34 +00:00
Michael Bayne 781564f9e0 A swipe of Occam's razor. 2012-04-13 16:09:02 +00:00
Michael Bayne 90d01ce58d Revamp stock marshaller creation, use to further optimize @Transform search. 2012-04-13 16:00:51 +00:00
Michael Bayne 6d8eabce93 Improve the semantics of @Transform handling.
@Transform is first sought on the field itself, which overrides any other
handling. Next it is sought on the class that represents the field (i.e. if the
field is type Foo we look for an @Transform annotation on class Foo). We avoid
doing this somewhat expensive search if the field has a type that we know
cannot have an @Transform annotation. If we've still found no @Transform
annotation (which is unfortunately the overwhelmingly common case), we then
create a stock marshaller.
2012-04-13 16:00:46 +00:00
Michael Bayne 946f05d3a0 Resolve our migration record during initRepos.
Otherwise, if a data migration is registered and run after the initialization
process, we'll end up warning that this record has not yet been initialized.

In theory, you should register your data migrations prior to calling initRepos,
but I don't want to be too draconian about that. Unlike schema migrations, you
*could* conceivably mean to start your app up and let it run before running
data migrations.
2012-04-05 22:21:37 +00:00
Michael Bayne 5984dbba80 Make it possible to register migrations outside a repository. 2012-04-04 18:46:46 +00:00
Par Winzell 73346e9fd0 Add the actual Distinct class; fix bugs. 2012-02-03 21:39:12 +00:00
Par Winzell cf47c335a0 Implement SELECT DISTINCT [ON <exp>] as a QueryClause. 2012-02-03 21:29:16 +00:00
Michael Bayne 03ee53194b Oops, ended up passing that to the ctor rather than a toggly method. 2012-02-02 18:30:56 +00:00
Michael Bayne 020e7911ba Added support for disabling schema migrations for a PersistenceContext.
This allows two separate services which share a database to assign "control" of
the schema to one of the services. The non-controlling service can be
configured to simply fail if new code is deployed to said service before new
code is deployed to the controlling service, rather than have the
non-controlling service migrate the schema out from under the controlling
service.
2012-02-02 18:27:58 +00:00
Michael Bayne 2d998ac23a As Jamie points out, we should use pe as the cause, rather than writing them
out of the (chain of exception) inheritance.
2012-01-14 02:39:33 +00:00
Michael Bayne dbf0684567 If we're creating a table the first time, note that we now expect the current
version to be 0, not -1.
2012-01-13 18:35:29 +00:00
Michael Bayne 55a866842b Report the identity of the connection we're trying to establish.
This is more useful than parroting the lower level exception message, which
will already be shown in the full stack dump anyway.
2012-01-13 17:15:10 +00:00
Ray Greenwell fa66796863 When grabbing the schema migration lock, ensure that the current
version is set to what we expect it to be.

Otherwise if one node reads an old value for the schema version, it will
be able to grab the migration lock as long as another node has already
completed the migration.
2012-01-05 20:35:55 +00:00
Ray Greenwell 73c111c20b Update to Guava 11, change MapMaker/ConcurrentMap -> CacheBuilder/LoadingCache. 2012-01-05 20:34:14 +00:00