Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[refactor] remove Predicate class

  • Loading branch information...
commit d916d431aac2463aa1d449ef535b0e74719fc2d7 1 parent 0e479d3
@kazuho authored
View
2  net/examp1e/picoorm/Condition.java
@@ -9,7 +9,7 @@
public class Condition<Row extends AbstractRow> {
public static abstract class OrderBy {
- abstract String toOrderBySQL();
+ public abstract String toOrderBySQL();
}
final TableDefinition<Row> tableDefinition;
View
33 net/examp1e/picoorm/Predicate.java
@@ -1,33 +0,0 @@
-package net.examp1e.picoorm;
-
-public abstract class Predicate<Row extends AbstractRow> extends Condition.OrderBy {
-
- public static class OrderPredicate<Row extends AbstractRow> extends Condition.OrderBy {
- Predicate<Row> predicate;
- boolean isAsc;
- OrderPredicate(Predicate<Row> predicate, boolean isAsc) {
- this.predicate = predicate;
- this.isAsc = isAsc;
- }
- @Override
- String toOrderBySQL() {
- return this.predicate.fieldName + (isAsc ? " ASC" : " DESC");
- }
- }
-
- protected TableDefinition<Row> tableDefinition;
- protected String fieldName;
- public final OrderPredicate<Row> asc = new OrderPredicate<Row>(this, true);
- public final OrderPredicate<Row> desc = new OrderPredicate<Row>(this, false);
-
- protected void _init(TableDefinition<Row> tableDefinition, String fieldName) {
- this.tableDefinition = tableDefinition;
- this.fieldName = fieldName;
- tableDefinition.addColumnDefinition(this);
- }
-
- @Override
- String toOrderBySQL() {
- return this.asc.toOrderBySQL();
- }
-}
View
12 net/examp1e/picoorm/TableDefinition.java
@@ -11,7 +11,7 @@
public abstract class TableDefinition<Row extends AbstractRow> {
public final String TABLE_NAME;
- private ArrayList<Predicate<Row>> columnDefinitions = new ArrayList<Predicate<Row>>();
+ private ArrayList<AnyType.Predicate<Row>> columnDefinitions = new ArrayList<AnyType.Predicate<Row>>();
protected TableDefinition(String tableName) {
TABLE_NAME = tableName;
@@ -38,7 +38,7 @@ protected TableDefinition(String tableName) {
return ret;
}
- void addColumnDefinition(Predicate<Row> columnDefinition) {
+ public void addColumnDefinition(AnyType.Predicate<Row> columnDefinition) {
this.columnDefinitions.add(columnDefinition);
}
@@ -79,15 +79,15 @@ public void update(Connection conn, Condition<Row> cond, Row changes) throws SQL
private ArrayList<String> _getColumnNames(Row row) {
ArrayList<String> columnNames = new ArrayList<String>();
if (row == null) {
- for (Predicate<Row> c : columnDefinitions)
- columnNames.add(c.fieldName);
+ for (AnyType.Predicate<Row> c : columnDefinitions)
+ columnNames.add(c.getFieldName());
} else {
// only name the columns that are being set
AnyType[] columns = getColumns(row);
int columnIndex = 0;
- for (Predicate<Row> c : columnDefinitions) {
+ for (AnyType.Predicate<Row> c : columnDefinitions) {
if (columns[columnIndex++].isSet())
- columnNames.add(c.fieldName);
+ columnNames.add(c.getFieldName());
}
}
return columnNames;
View
38 net/examp1e/picoorm/types/AnyType.java
@@ -14,6 +14,42 @@
public abstract void unbind(ResultSet rs, int parameterIndex) throws SQLException;
+ public static abstract class Predicate<Row extends AbstractRow> extends Condition.OrderBy {
+
+ public static class OrderPredicate<Row extends AbstractRow> extends Condition.OrderBy {
+ Predicate<Row> predicate;
+ boolean isAsc;
+ OrderPredicate(Predicate<Row> predicate, boolean isAsc) {
+ this.predicate = predicate;
+ this.isAsc = isAsc;
+ }
+ @Override
+ public String toOrderBySQL() {
+ return this.predicate.fieldName + (isAsc ? " ASC" : " DESC");
+ }
+ }
+
+ protected TableDefinition<Row> tableDefinition;
+ protected String fieldName;
+ public final OrderPredicate<Row> asc = new OrderPredicate<Row>(this, true);
+ public final OrderPredicate<Row> desc = new OrderPredicate<Row>(this, false);
+
+ protected void _init(TableDefinition<Row> tableDefinition, String fieldName) {
+ this.tableDefinition = tableDefinition;
+ this.fieldName = fieldName;
+ tableDefinition.addColumnDefinition(this);
+ }
+
+ public String getFieldName() {
+ return fieldName;
+ }
+
+ @Override
+ public String toOrderBySQL() {
+ return this.asc.toOrderBySQL();
+ }
+ }
+
}
abstract class AnyTypeImpl<ThisType, ValueType> extends AnyType {
@@ -41,7 +77,7 @@ public void set(ValueType value) {
this.isSet = true;
}
- public static abstract class Predicate<ThisType, Row extends AbstractRow, ValueType> extends net.examp1e.picoorm.Predicate<Row> {
+ public static abstract class Predicate<ThisType, Row extends AbstractRow, ValueType> extends AnyType.Predicate<Row> {
@SuppressWarnings("unchecked")
public ThisType init(TableDefinition<Row> tableDefinition, String fieldName) {
_init(tableDefinition, fieldName);
Please sign in to comment.
Something went wrong with that request. Please try again.