Permalink
Browse files

use CRTP for AbsctractRow as well

  • Loading branch information...
1 parent bdad7e6 commit 35a0d27b92742b8954a1b532f840788d07b1109f @kazuho committed Jul 14, 2014
@@ -3,12 +3,12 @@
import java.sql.Connection;
import java.sql.SQLException;
-@SuppressWarnings({"rawtypes", "unchecked"})
-public abstract class AbstractRow {
+public abstract class AbstractRow<Row extends AbstractRow<Row>> {
+ @SuppressWarnings("unchecked")
public void insert(Connection conn) throws SQLException {
- _getTableDefinition().insert(conn, this);
+ _getTableDefinition().insert(conn, (Row)this);
}
- protected abstract TableDefinition _getTableDefinition();
+ protected abstract TableDefinition<Row> _getTableDefinition();
}
@@ -6,7 +6,7 @@
import net.examp1e.picoorm.types.AnyType;
-public class Condition<Row extends AbstractRow> {
+public class Condition<Row extends AbstractRow<Row>> {
public static abstract class OrderBy {
public abstract String getFieldName();
@@ -8,7 +8,7 @@
import net.examp1e.picoorm.types.AnyType;
-public abstract class TableDefinition<Row extends AbstractRow> {
+public abstract class TableDefinition<Row extends AbstractRow<Row>> {
public final String TABLE_NAME;
private ArrayList<AnyType.Predicate<Row>> columnDefinitions = new ArrayList<AnyType.Predicate<Row>>();
@@ -4,7 +4,7 @@
import net.examp1e.picoorm.types.*;
// this class definition should be automatically generated from the DDL
-public class Member extends AbstractRow {
+public class Member extends AbstractRow<Member> {
// serdes
public static final TableDefinition<Member> TABLE_DEFINITION = new TableDefinition<Member>("member") {
@@ -14,9 +14,9 @@
public abstract void unbind(ResultSet rs, int parameterIndex) throws SQLException;
- public static abstract class Predicate<Row extends AbstractRow> extends Condition.OrderBy {
+ public static abstract class Predicate<Row extends AbstractRow<Row>> extends Condition.OrderBy {
- private static class OrderPredicate<Row extends AbstractRow> extends Condition.OrderBy {
+ private static class OrderPredicate<Row extends AbstractRow<Row>> extends Condition.OrderBy {
private Predicate<Row> predicate;
OrderPredicate<Row> init(Predicate<Row> predicate) {
this.predicate = predicate;
@@ -27,7 +27,7 @@ public String getFieldName() {
return this.predicate.getFieldName();
}
}
- private static class DescendingOrderPredicate<Row extends AbstractRow> extends OrderPredicate<Row> implements Condition.OrderByIsDescending {
+ private static class DescendingOrderPredicate<Row extends AbstractRow<Row>> extends OrderPredicate<Row> implements Condition.OrderByIsDescending {
}
protected TableDefinition<Row> tableDefinition;
@@ -74,7 +74,7 @@ public void set(ValueType value) {
this.isSet = true;
}
- public static abstract class Predicate<ThisType, Row extends AbstractRow, ValueType> extends AnyType.Predicate<Row> {
+ public static abstract class Predicate<ThisType, Row extends AbstractRow<Row>, ValueType> extends AnyType.Predicate<Row> {
@SuppressWarnings("unchecked")
public ThisType init(TableDefinition<Row> tableDefinition, String fieldName) {
_init(tableDefinition, fieldName);
@@ -24,7 +24,7 @@ public void unbind(ResultSet rs, int parameterIndex) throws SQLException {
value = null;
}
- public static class Predicate<Row extends AbstractRow> extends AnyTypeImpl.Predicate<Predicate<Row>, Row, Integer> {
+ public static class Predicate<Row extends AbstractRow<Row>> extends AnyTypeImpl.Predicate<Predicate<Row>, Row, Integer> {
@Override
protected IntegerType createParameter(Integer value) {
return new IntegerType().init(value);
@@ -24,7 +24,7 @@ public void unbind(ResultSet rs, int parameterIndex) throws SQLException {
value = null;
}
- public static class Predicate<Row extends AbstractRow> extends AnyTypeImpl.Predicate<Predicate<Row>, Row, Long> {
+ public static class Predicate<Row extends AbstractRow<Row>> extends AnyTypeImpl.Predicate<Predicate<Row>, Row, Long> {
@Override
protected LongType createParameter(Long value) {
return new LongType().init(value);
@@ -22,7 +22,7 @@ public void unbind(ResultSet rs, int parameterIndex) throws SQLException {
value = rs.getString(parameterIndex);
}
- public static class Predicate<Row extends AbstractRow> extends AnyTypeImpl.Predicate<Predicate<Row>, Row, String> {
+ public static class Predicate<Row extends AbstractRow<Row>> extends AnyTypeImpl.Predicate<Predicate<Row>, Row, String> {
@Override
protected StringType createParameter(String value) {
return new StringType().init(value);

0 comments on commit 35a0d27

Please sign in to comment.