Use ImmutableMap. I mistakenly thought we didn't use Gauva in Depot.
This commit is contained in:
@@ -19,6 +19,9 @@ import java.sql.SQLException;
|
|||||||
import java.sql.Time;
|
import java.sql.Time;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
|
||||||
import com.samskivert.depot.DatabaseException;
|
import com.samskivert.depot.DatabaseException;
|
||||||
import com.samskivert.depot.PersistentRecord;
|
import com.samskivert.depot.PersistentRecord;
|
||||||
import com.samskivert.depot.Transformer;
|
import com.samskivert.depot.Transformer;
|
||||||
@@ -33,8 +36,6 @@ import com.samskivert.util.ByteEnumUtil;
|
|||||||
import com.samskivert.util.Logger;
|
import com.samskivert.util.Logger;
|
||||||
import com.samskivert.util.StringUtil;
|
import com.samskivert.util.StringUtil;
|
||||||
|
|
||||||
import static com.google.common.base.Preconditions.checkArgument;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the marshalling and unmarshalling of a particular field of a persistent object.
|
* Handles the marshalling and unmarshalling of a particular field of a persistent object.
|
||||||
*
|
*
|
||||||
@@ -739,24 +740,22 @@ public abstract class FieldMarshaller<T>
|
|||||||
protected GeneratedValue _generatedValue;
|
protected GeneratedValue _generatedValue;
|
||||||
|
|
||||||
protected static Map<Class<?>,FieldMarshaller<?>> STOCK_MARSH =
|
protected static Map<Class<?>,FieldMarshaller<?>> STOCK_MARSH =
|
||||||
new HashMap<Class<?>,FieldMarshaller<?>>();
|
ImmutableMap.<Class<?>,FieldMarshaller<?>>builder().
|
||||||
static {
|
put(Boolean.TYPE, new BooleanMarshaller()).
|
||||||
// primitive types
|
put(Byte.TYPE, new ByteMarshaller()).
|
||||||
STOCK_MARSH.put(Boolean.TYPE, new BooleanMarshaller());
|
put(Short.TYPE, new ShortMarshaller()).
|
||||||
STOCK_MARSH.put(Byte.TYPE, new ByteMarshaller());
|
put(Integer.TYPE, new IntMarshaller()).
|
||||||
STOCK_MARSH.put(Short.TYPE, new ShortMarshaller());
|
put(Long.TYPE, new LongMarshaller()).
|
||||||
STOCK_MARSH.put(Integer.TYPE, new IntMarshaller());
|
put(Float.TYPE, new FloatMarshaller()).
|
||||||
STOCK_MARSH.put(Long.TYPE, new LongMarshaller());
|
put(Double.TYPE, new DoubleMarshaller()).
|
||||||
STOCK_MARSH.put(Float.TYPE, new FloatMarshaller());
|
|
||||||
STOCK_MARSH.put(Double.TYPE, new DoubleMarshaller());
|
|
||||||
|
|
||||||
// boxed primitive types
|
// boxed primitive types
|
||||||
STOCK_MARSH.put(Boolean.class, new ObjectMarshaller() {
|
put(Boolean.class, new ObjectMarshaller() {
|
||||||
@Override public String getColumnType (ColumnTyper typer, int length) {
|
@Override public String getColumnType (ColumnTyper typer, int length) {
|
||||||
return typer.getBooleanType(length);
|
return typer.getBooleanType(length);
|
||||||
}
|
}
|
||||||
});
|
}).
|
||||||
STOCK_MARSH.put(Byte.class, new ObjectMarshaller() {
|
put(Byte.class, new ObjectMarshaller() {
|
||||||
@Override public String getColumnType (ColumnTyper typer, int length) {
|
@Override public String getColumnType (ColumnTyper typer, int length) {
|
||||||
return typer.getByteType(length);
|
return typer.getByteType(length);
|
||||||
}
|
}
|
||||||
@@ -768,8 +767,8 @@ public abstract class FieldMarshaller<T>
|
|||||||
protected Object massageResult (Object value) {
|
protected Object massageResult (Object value) {
|
||||||
return (value == null) ? null : ((Number)value).byteValue();
|
return (value == null) ? null : ((Number)value).byteValue();
|
||||||
}
|
}
|
||||||
});
|
}).
|
||||||
STOCK_MARSH.put(Short.class, new ObjectMarshaller() {
|
put(Short.class, new ObjectMarshaller() {
|
||||||
@Override public String getColumnType (ColumnTyper typer, int length) {
|
@Override public String getColumnType (ColumnTyper typer, int length) {
|
||||||
return typer.getShortType(length);
|
return typer.getShortType(length);
|
||||||
}
|
}
|
||||||
@@ -781,18 +780,18 @@ public abstract class FieldMarshaller<T>
|
|||||||
protected Object massageResult (Object value) {
|
protected Object massageResult (Object value) {
|
||||||
return (value == null) ? null : ((Number)value).shortValue();
|
return (value == null) ? null : ((Number)value).shortValue();
|
||||||
}
|
}
|
||||||
});
|
}).
|
||||||
STOCK_MARSH.put(Integer.class, new ObjectMarshaller() {
|
put(Integer.class, new ObjectMarshaller() {
|
||||||
@Override public String getColumnType (ColumnTyper typer, int length) {
|
@Override public String getColumnType (ColumnTyper typer, int length) {
|
||||||
return typer.getIntType(length);
|
return typer.getIntType(length);
|
||||||
}
|
}
|
||||||
});
|
}).
|
||||||
STOCK_MARSH.put(Long.class, new ObjectMarshaller() {
|
put(Long.class, new ObjectMarshaller() {
|
||||||
@Override public String getColumnType (ColumnTyper typer, int length) {
|
@Override public String getColumnType (ColumnTyper typer, int length) {
|
||||||
return typer.getLongType(length);
|
return typer.getLongType(length);
|
||||||
}
|
}
|
||||||
});
|
}).
|
||||||
STOCK_MARSH.put(Float.class, new ObjectMarshaller() {
|
put(Float.class, new ObjectMarshaller() {
|
||||||
@Override public String getColumnType (ColumnTyper typer, int length) {
|
@Override public String getColumnType (ColumnTyper typer, int length) {
|
||||||
return typer.getFloatType(length);
|
return typer.getFloatType(length);
|
||||||
}
|
}
|
||||||
@@ -804,48 +803,48 @@ public abstract class FieldMarshaller<T>
|
|||||||
protected Object massageResult (Object value) {
|
protected Object massageResult (Object value) {
|
||||||
return (value == null) ? null : ((Number)value).floatValue();
|
return (value == null) ? null : ((Number)value).floatValue();
|
||||||
}
|
}
|
||||||
});
|
}).
|
||||||
STOCK_MARSH.put(Double.class, new ObjectMarshaller() {
|
put(Double.class, new ObjectMarshaller() {
|
||||||
@Override public String getColumnType (ColumnTyper typer, int length) {
|
@Override public String getColumnType (ColumnTyper typer, int length) {
|
||||||
return typer.getDoubleType(length);
|
return typer.getDoubleType(length);
|
||||||
}
|
}
|
||||||
});
|
}).
|
||||||
STOCK_MARSH.put(String.class, new ObjectMarshaller() {
|
put(String.class, new ObjectMarshaller() {
|
||||||
@Override public String getColumnType (ColumnTyper typer, int length) {
|
@Override public String getColumnType (ColumnTyper typer, int length) {
|
||||||
return typer.getStringType(length);
|
return typer.getStringType(length);
|
||||||
}
|
}
|
||||||
});
|
}).
|
||||||
|
|
||||||
// some primitive array types
|
// some primitive array types
|
||||||
STOCK_MARSH.put(byte[].class, new ByteArrayMarshaller());
|
put(byte[].class, new ByteArrayMarshaller()).
|
||||||
STOCK_MARSH.put(int[].class, new IntArrayMarshaller());
|
put(int[].class, new IntArrayMarshaller()).
|
||||||
STOCK_MARSH.put(long[].class, new LongArrayMarshaller());
|
put(long[].class, new LongArrayMarshaller()).
|
||||||
|
|
||||||
// SQL types
|
// SQL types
|
||||||
STOCK_MARSH.put(Date.class, new ObjectMarshaller() {
|
put(Date.class, new ObjectMarshaller() {
|
||||||
@Override public String getColumnType (ColumnTyper typer, int length) {
|
@Override public String getColumnType (ColumnTyper typer, int length) {
|
||||||
return typer.getDateType(length);
|
return typer.getDateType(length);
|
||||||
}
|
}
|
||||||
});
|
}).
|
||||||
STOCK_MARSH.put(Time.class, new ObjectMarshaller() {
|
put(Time.class, new ObjectMarshaller() {
|
||||||
@Override public String getColumnType (ColumnTyper typer, int length) {
|
@Override public String getColumnType (ColumnTyper typer, int length) {
|
||||||
return typer.getTimeType(length);
|
return typer.getTimeType(length);
|
||||||
}
|
}
|
||||||
});
|
}).
|
||||||
STOCK_MARSH.put(Timestamp.class, new ObjectMarshaller() {
|
put(Timestamp.class, new ObjectMarshaller() {
|
||||||
@Override public String getColumnType (ColumnTyper typer, int length) {
|
@Override public String getColumnType (ColumnTyper typer, int length) {
|
||||||
return typer.getTimestampType(length);
|
return typer.getTimestampType(length);
|
||||||
}
|
}
|
||||||
});
|
}).
|
||||||
STOCK_MARSH.put(Blob.class, new ObjectMarshaller() {
|
put(Blob.class, new ObjectMarshaller() {
|
||||||
@Override public String getColumnType (ColumnTyper typer, int length) {
|
@Override public String getColumnType (ColumnTyper typer, int length) {
|
||||||
return typer.getBlobType(length);
|
return typer.getBlobType(length);
|
||||||
}
|
}
|
||||||
});
|
}).
|
||||||
STOCK_MARSH.put(Clob.class, new ObjectMarshaller() {
|
put(Clob.class, new ObjectMarshaller() {
|
||||||
@Override public String getColumnType (ColumnTyper typer, int length) {
|
@Override public String getColumnType (ColumnTyper typer, int length) {
|
||||||
return typer.getClobType(length);
|
return typer.getClobType(length);
|
||||||
}
|
}
|
||||||
});
|
}).
|
||||||
}
|
build();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user