Commit Graph

123 Commits

Author SHA1 Message Date
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
Ray Greenwell 9838e4922c Added OrderBy.Order.NULL.
"order by null" can be used in a query with a "group by" in it to tell
the database to suppress the overhead of sorting the results.
(Supported in postgres and mysql.)

Changed the build visitors to have a whitelist of supported
Orders, and to NPE on a null value for the Order enum.

Note that previously "order by null" could be accomplished by passing
a null value to your OrderBy, but now the enum constant must be used.
I can change that if this disrupts anything.
2011-12-06 19:26:53 +00:00
Ray Greenwell acbdfc4044 Added two new Order constants: ASC_NULLS_FIRST and DESC_NULLS_LAST.
Only supported on postgres. If needed we could allow for fallbacks
for other databases.
2011-12-03 22:06:08 +00:00
Michael Bayne fb0a5f2884 Improve the documentation here. 2011-11-23 03:06:14 +00:00
Michael Bayne 33615067d9 Fail early. 2011-10-24 21:13:25 +00:00
Michael Bayne 3fbd5f4993 Made log message less terrifying.
I don't like to see the words "Aborting creation." when I'm in the middle of
creating databases. If we're not creating the index, fine, but don't give me
the idea that we're aborting the entire creation of the table.
2011-10-20 20:10:59 +00:00
Par Winzell 710d2ffaf2 From Bruno Garcia: Add a mode for FullText to search for rows that match all the words in a query rather than any of them. 2011-08-24 15:04:43 +00:00
Michael Bayne 3f8f15af9f Added support for clearing caches. 2011-06-27 21:08:01 +00:00
Ray Greenwell c26d9b29fb Had this laying around...
- Added an IntegerIterable Transformer.
- Document that these *Iterable transformers work with List/Set/Collection...
  In case it wasn't clear.
- Added a sizeHint argument to the createCollectionBuilder method, take
  advantage of that in the IntegerIterable since we don't need to do any
  work to find the size.
2011-06-24 20:17:02 +00:00
Charlie Groves cef1461109 Warning cleanup 2011-06-24 19:47:18 +00:00
Charlie Groves 7ba475e61c Use default values for the values section of an insert statement for hsqldb as well as postgres
It blows up expecting a column name in the values parenthesis, but the default values string that
postgres was working seems to work. It's not in http://hsqldb.org/doc/guide/ch09.html, but so it
goes.
2011-06-24 19:25:57 +00:00
Michael Bayne e3ff96745d Added support for limit to deleteAll.
I would have prefered to only add this support to the Query interface, and not
clutter up DepotRepository with two additional overloaded methods. However,
that would not have been possible without duplicating a bunch of logic from
DepotRepository. Yet another reason why the Query builder approach is awesome
and the fuckloads of overloaded methods approach isn't.
2011-06-23 22:12:47 +00:00
Ray Greenwell eb6d48d054 Changed selectCount() to not alter the state of the Query,
so that I can select a count of matching rows and then go on
to add an ordering and limit and select a particular page of results.
2011-05-13 16:43:31 +00:00
Andrzej Kapolka 5d9a584e4c Because MySQL can't abide parentheses around its intervals, let's put
them around the entire expression rather than around the operands
(which matches the behavior of the binary operator method).
2011-05-12 01:48:24 +00:00
Michael Bayne 607f63a7a1 Fixed a problem where the Postgres JDBC driver would call toString() on an
enum, when we need it to be using name() instead. We just take care to send it
the results of name() instead of the enum value itself.

It would be nice to share this code with BuildVisitor.bindValue, but that would
require yet further twisting and factoring of the code, obscuring it even more.
We'll just hope that special cases like Enum and ByteEnum aren't going to keep
cropping up.
2011-05-05 19:02:38 +00:00
Michael Bayne 4c1864ddd6 This is exactly the sort of place where it's useful to *not* turn a complex
value into a string and then throw it away when doing debug logging.
2011-05-05 18:56:33 +00:00
Michael Bayne e53288b7c4 Compactified header, extracted copyright and license bits into LICENSE. 2011-05-05 18:35:14 +00:00
Michael Bayne 72c4782b3c We need to quote identifiers in MySQL so that we can handle columns with names
like group.
2011-05-04 18:40:24 +00:00
Michael Bayne fd4be08c78 None would be best in this case. 2011-04-30 23:21:35 +00:00
Andrzej Kapolka 531b9a3234 Some changes to allow the ability to subclass the stats class and
record more extensive, per-table stats.
2011-04-01 04:44:04 +00:00
Charlie Groves e41e3c9961 Match the SQLBuilder changes in HSQLBuilder to fix the build 2011-03-29 19:36:35 +00:00
Ray Greenwell 903bb5181b From Mark Johnson: support long autogenerated fields. 2011-03-29 03:42:24 +00:00
Ray Greenwell 07e5b934b5 Patch from Mark Johnson: support long[] field types. 2011-03-29 01:52:59 +00:00
Charlie Groves 1a2967b31f yohoho no longer cares if depot is built with 1.6, so build with that since we're using 1.6's Connection.createArrayOf in PostgreSQL4Builder. Sneak a ooo-buildification in with the compiler version bump. 2011-03-23 20:42:00 +00:00
Charlie Groves 2dbfaa0ee6 Remove an @Override from an interface as that isn't 1.5 compatible, and remove some unused imports 2011-03-23 01:43:52 +00:00
Michael Bayne ad4f2c9970 Changed expressions that deal with count() results to Number because Postgres
in its burning desire to support the amazing four hundred billion rows, returns
a Long for count expressions.

Clients using selectCount() won't be impacted, but clients doing more complex
counting are going to have to sprinkle in some .intValue() calls.
2011-02-28 22:58:38 +00:00
Michael Bayne 677de3da03 Added notNull() at Ray's request. 2011-02-28 19:12:52 +00:00
Andrzej Kapolka 89927523bc Let byte enum columns be nullable. 2011-02-21 20:58:34 +00:00
Michael Bayne 687de42168 Added needed import. 2011-02-18 18:24:40 +00:00
Michael Bayne 2565a292d1 Have the trivial fetcher do no stats updating by default. 2011-02-18 01:53:23 +00:00
Michael Bayne e59b20dd56 Report the pkName in both cases, and do so using valid Java code. 2011-02-18 00:40:48 +00:00
Michael Bayne adf914e156 Wired up handling of primary key changes (with some reorganization of a patch
from Nathan). If we need to add our primary key, we do so, if we need to remove
it, we do so, and only then do we consider whether we need to migrate it (in
which case we drop and re-add it).
2011-02-18 00:35:58 +00:00
Michael Bayne 8670d0e109 Support creation of arrays of stock enum values (which are turned into
strings). From Jamie.
2011-02-16 02:13:35 +00:00
Par Winzell 10e97b55c9 PostgreSQL gets very confused when date_part() is used in a GROUP BY and the part bit isn't a constant. It doesn't recognize the selected values as being identical to the grouped-by values, and throws an error. So we use a literal here. 2011-02-15 23:21:11 +00:00
Michael Bayne 6603fb7d81 Patches from Jamie:
1. DateFuncs.dayOfWeek and dayOfMonth can now be used on Timestamp. +FromDate
variants exist for using on Date.

2. hour, minute, second, etc. are now typed Number to cope with differing
opinions on the part of the underlying SQL drivers as to whether to return
Double, Long, Integer or something else.
2011-02-15 22:20:53 +00:00
Michael Bayne 51aa221606 Use the platform's line separator when generating code from templates. This
assumes that the depot.jar in question was created on a LF-only platform, but
that's probably a safe bet.
2011-02-12 00:26:56 +00:00
Ray Greenwell d59717d025 No longer lazily initialized. 2011-02-10 17:28:39 +00:00
Par Winzell 5c52a84916 I can think of no reason why this was ever allowed to be null. 2011-02-10 17:21:06 +00:00
Michael Bayne b8fec6cab5 Fixed a problem with binding transformed values in updatePartial.
When we go to bind values in an update statement, we either have:

- field names and a pojo from which to extract them, in which case
  transformation happens naturally when we extract the current value from the
  pojo

- value expressions (like 1, or "bob") which we were previously just binding
  directly to the statement, which was wrong because they need to first be
  transformed in the case where the field in question has an @Transform
  annotation; now we get the field marshaller for the field in question and
  pass the raw value to it, so that it can do the necessary transformations in
  writeToStatement()

- other expressions (like LiteralExp("true") or or IntervalExp or anything else
  where the database is involved in computing the final value to be assigned to
  the column).

This last case still holds the potential for badness with regard to transformed
fields. We can't magically transform the value to be stored into a field if the
database is computing the ultimate value. Say, for a contrived example, that
you had a record where you stored an int column as a String for shits and
giggles:

public class MyRecord {
    @Transform(IntToStringTransformer.class)
    public int someValue;
}

someValue will be a string column in the database, owing to the
IntToStringTransformer converting the int to a String.

Now you come along and think to yourself, "Hey, I want to store the current
minute in my  'int' field." and you write something like:

updatePartial(MyRecord.class, MyRecord.SOME_VALUE,
    DateFuncs.minute(Exps.literal(new Timestamp(System.currentTimeMillis()))));

Well, that's going to end up trying to stuff an int-valued expression (computed
by the database) into a String field, and the shit will hit the fan.

I can't really think of a non-contrived situation where this is likely to bite
us in the ass, but I don't especially like grass covered pits like this lying
around, waiting for someone to unsuspectingly step into them.

I could fail if you try to update a transformed field with anything other than
a ValueExp (or the current value from a pojo), but that would prevent you from
doing something potentially useful and safe like copying one field to another,
which both use the same transformation.
2011-02-05 00:22:53 +00:00
Michael Bayne 6c9d372510 Removed a final annotation that I had slipped in for testing. 2011-02-04 18:14:45 +00:00