Commit Graph

92 Commits

Author SHA1 Message Date
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
Michael Bayne 71d3577074 Ur doin it wrong. The transforming field marshaller needs to operate on F (the
non-persistent type), and transform in getFromSet/writeToStatement, rather than
operate on T (the persistent type) and transform in
getFromObject/writeToObject.

This makes the newly added test in TransformTest work, rather than fail, as it
did previously.
2011-02-04 18:14:15 +00:00
Michael Bayne ea676d5b9e Added Tuple2.toMap for those times when you really want a map from a to b
rather than a list of (a, b).
2011-01-31 17:50:18 +00:00
Ray Greenwell f4b25369ff Bugfix. 2011-01-18 21:52:47 +00:00
Ray Greenwell 8e3a690b79 Fixed one little thing that bothered me: null enum values could
safely be stored, but if rehydrated into a Set then an EnumSet would
be created and that can't store nulls.
So, check to see if the encoded String has any nulls in it and
have the builder create a HashSet instead.
2011-01-18 21:37:38 +00:00
Ray Greenwell b32c6753c1 Added EnumIterable, which can be used to transform an Iterable
containing Enums. It extends StringBase, so the enums are stored
similarly to how a Set<String> is stored, and not based on ordinal.
2011-01-17 22:20:25 +00:00
Charlie Groves 63816b421c Don't complain that indices created by hsqldb are stale 2011-01-05 20:24:29 +00:00
Michael Bayne 1b21df9994 Added Funcs.countStar() because it's such a common SQL operation. 2010-12-18 18:01:57 +00:00
Michael Bayne 5dc96f1ac0 We need to ascend or descend on a particular column. 2010-12-18 17:47:31 +00:00
Michael Bayne 2796b3992d Stop calling me Shirley. 2010-12-18 17:37:23 +00:00
Michael Bayne 5809a5e8c6 New deal: every time you call a builder method, a copy of the Query is created,
so that partially constructed queries can be reused without any special care
being taken by the caller. I also switched to the use of a functional list
internally to make this whole process more pleasant and efficient.
2010-12-18 17:32:31 +00:00
Par Winzell 0fd6f66181 This was very confused. Unique columns are automatically indexed. Thus we should certainly not create an explicit index when we encounter a unique column, as we were doing, and we will even go so far as to forbid an explicit index. 2010-12-15 03:25:40 +00:00
Par Winzell f81b338cd9 Check for stale indexes, too. Use our knowledge of full text indexes to better decide if a column or index is internal to Depot's or the DB's workings. Finally, allow com.samskivert.depot.verifyschema to be set, forcing a staleness check (which slows down initialization somewhat). 2010-12-15 02:58:55 +00:00
Michael Bayne 367c10cc52 Javadoc fixes. 2010-12-14 17:09:43 +00:00
Michael Bayne d0919f8239 Correctify the documentation for selectInto(). 2010-12-14 16:41:16 +00:00
Ray Greenwell 5455490fcf PECS.
Even if the columns are String, Integer, and Boolean; it's not unreasonable
to accept a Builder that consumes Object, Number, and Comparable.
2010-12-13 19:48:46 +00:00
Michael Bayne 5e10393463 Added a totally type-safe mechanism for selecting ad-hoc query results into
pojos which hold the results of the query. The caller can decide if they want
to use the magic of selectInto(), and be careful not to screw up the types and
order of their pojo fields, or they can boil up some plates and create a
builder for their pojo, which will be type-checked, soup to nuts.
2010-12-13 19:29:50 +00:00
Michael Bayne 90b04e68b8 Prevent confusion if someone uses selectCount() (which returns int) on a
grouped query. They should be using select(Funcs.count(Exps.literal("*")))
(which returns List<Integer>) in such cases.
2010-12-13 17:50:50 +00:00
Charlie Groves 881a36bdca Log processed and skipped classes to ant's verbose logger to give some visibility into what's
happening if run with -v.
2010-12-11 00:10:15 +00:00
Charlie Groves fa94063dc7 Missing @Overrides 2010-12-10 21:40:35 +00:00
Michael Bayne 4b59373559 Added a mechanism for selecting results into a simple result class that relies
only on a matching public constructor. This version is not type-safe, but I'll
also be adding an additional mechanism to do selections like this that uses a
type-safe builder approach, which comes at the cost of a healthy dose of
boilerplate code.
2010-12-10 21:12:57 +00:00
Michael Bayne dd6dec7b9a Handle arrays (potentially of nested types). Ray's got some crazy shit over in
PX land.
2010-12-10 04:50:26 +00:00
Michael Bayne b6088302d5 Added a bunch of tests for the various functions appearing in a projection.
This uncovered a lot of loose geese as far as the database was concerned, which
necessitated turning a bunch of functions which had specific type into
functions which have type Number.

In general, I made the Funcs/StringFuncs/MathFuncs factory methods provide an
expression typed Number and I left the underlying SQLExpression derivations
able to be more precisely typed. So if you know that your database does not
magically promote an integer column to long when calling sum() on it, you can
force a more specific type. But really, I don't see why you would go to the
trouble. You can just call intValue() on your result and get the int you were
looking for regardless of what the database thought it would be fun to provide.

I also fixed a few HSQLDB variants (average -> avg, round(a) -> round(a, 0),
etc.) and made notes about a few things that just plain don't work in HSQLDB.
Awesome! Fortunately they're things like log-base-10, rather than more critical
functionality.
2010-12-10 00:48:52 +00:00
Michael Bayne fc94473ec4 The beans were above the frank. 2010-12-10 00:35:23 +00:00
Michael Bayne f2842f87da QueryBuilder -> Query. 2010-12-09 23:09:24 +00:00
Michael Bayne a0a9acbf16 Query -> Fetcher because I want to next change QueryBuilder -> Query so that it
looks nicer when you keep partially constructed queries around.
2010-12-09 23:05:43 +00:00
Michael Bayne 1b2df7b583 Return null from a load() with no matches, rather than throwing a NoSuchElement
exception. I'm tempted to reinstate the NoSuchElement exception for a load()
that attempts to project fields from the selected rows, but I think it makes
more sense for a load() which aggregates over zero rows to return null than to
throw a NoSuchElement exception.
2010-12-09 22:55:49 +00:00
Charlie Groves d93db7a0f7 Specify the types on Tuple.newTuple to make the captures line up 2010-12-09 21:53:49 +00:00
Michael Bayne 84738f9c57 Roll everything on up to Tuple5. We boil the plates so that you don't have to! 2010-12-09 01:44:27 +00:00
Michael Bayne 780d25866c Holy plans coming together Batman, selecting computed expressions is working.
Some examples:

int max = _repo.from(TestRecord.class).load(Funcs.max(TestRecord.RECORD_ID));

List<Tuple2<String,Integer>> data = _repo.from(EnumKeyRecord.class).
    groupBy(EnumKeyRecord.NAME).ascending(EnumKeyRecord.NAME).
    select(EnumKeyRecord.NAME, Funcs.count(EnumKeyRecord.TYPE));

Still no caching integration, but the ratio of utility over boilerplate is
high.
2010-12-09 01:14:21 +00:00
Michael Bayne 800c566fc6 Use DepotTypes to keep track of the types in our query. That's it's whole
purpose in life.
2010-12-09 00:42:34 +00:00
Michael Bayne f629b267ba I'd like to be able to require that you at least can only call greatest and
least on something that was Comparable, but unfortunately, the numeric type's
only shared supertype is Number and that is not comparable.

If I require Number, then you can't do greatest(timestamp, timestamp), and if I
require Comparable, then you can't do greatest(int, double) because the
compiler can't unify those types to something that is Comparable.

I could require that you only compare apples with apples (i.e. greatest(int,
int) or greatest(double, double)), but databases will happily compare
greatest(int, double) and people are going to want to do that. I could
introduce some sort of numeric conversion expressions, but I think that's
getting too deeply into the realm of type safety for type safety's sake.
2010-12-09 00:21:44 +00:00