summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon/carbonado/repo
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2007-08-05 20:09:53 +0000
committerBrian S. O'Neill <bronee@gmail.com>2007-08-05 20:09:53 +0000
commitd1f058804bd5dd1c18e95d94e3f90aff112216d0 (patch)
treed31f2ed811992d8a44ac17b87257e64950611ac4 /src/main/java/com/amazon/carbonado/repo
parent35316f62f705ca59ecb40107bebb355d865f60a7 (diff)
Moved static inner classes to separate files.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/repo')
-rw-r--r--src/main/java/com/amazon/carbonado/repo/jdbc/CompositeStatement.java53
-rw-r--r--src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java130
-rw-r--r--src/main/java/com/amazon/carbonado/repo/jdbc/LiteralStatement.java55
-rw-r--r--src/main/java/com/amazon/carbonado/repo/jdbc/NullablePropertyStatement.java62
-rw-r--r--src/main/java/com/amazon/carbonado/repo/jdbc/SQLStatement.java56
5 files changed, 234 insertions, 122 deletions
diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/CompositeStatement.java b/src/main/java/com/amazon/carbonado/repo/jdbc/CompositeStatement.java
new file mode 100644
index 0000000..48b81e5
--- /dev/null
+++ b/src/main/java/com/amazon/carbonado/repo/jdbc/CompositeStatement.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2007 Amazon Technologies, Inc. or its affiliates.
+ * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks
+ * of Amazon Technologies, Inc. or its affiliates. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.amazon.carbonado.repo.jdbc;
+
+import java.util.List;
+
+import com.amazon.carbonado.Storable;
+
+import com.amazon.carbonado.filter.FilterValues;
+
+/**
+ *
+ *
+ * @author Brian S O'Neill
+ */
+class CompositeStatement<S extends Storable> extends SQLStatement<S> {
+ private final SQLStatement<S>[] mStatements;
+
+ @SuppressWarnings("unchecked")
+ CompositeStatement(List<SQLStatement<S>> statements) {
+ mStatements = statements.toArray(new SQLStatement[statements.size()]);
+ }
+
+ public int maxLength() {
+ int max = 0;
+ for (SQLStatement<S> statement : mStatements) {
+ max += statement.maxLength();
+ }
+ return max;
+ }
+
+ public void appendTo(StringBuilder b, FilterValues<S> filterValues) {
+ for (SQLStatement<S> statement : mStatements) {
+ statement.appendTo(b, filterValues);
+ }
+ }
+}
diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java
index 70894b6..9d60741 100644
--- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java
+++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java
@@ -407,9 +407,9 @@ class JDBCStorage<S extends Storable> extends StandardQueryFactory<S>
private final Filter<S> mFilter;
private final OrderingList<S> mOrdering;
- private final Statement<S> mSelectStatement;
+ private final SQLStatement<S> mSelectStatement;
private final int mMaxSelectStatementLength;
- private final Statement<S> mFromWhereStatement;
+ private final SQLStatement<S> mFromWhereStatement;
private final int mMaxFromWhereStatementLength;
// The following arrays all have the same length, or they may all be null.
@@ -427,8 +427,8 @@ class JDBCStorage<S extends Storable> extends StandardQueryFactory<S>
Executor(Filter<S> filter,
OrderingList<S> ordering,
- Statement<S> selectStatement,
- Statement<S> fromWhereStatement,
+ SQLStatement<S> selectStatement,
+ SQLStatement<S> fromWhereStatement,
PropertyFilter<S>[] propertyFilters,
boolean[] propertyFilterNullable)
throws RepositoryException
@@ -936,130 +936,16 @@ class JDBCStorage<S extends Storable> extends StandardQueryFactory<S>
}
}
- /**
- * Simple DOM representing a SQL statement.
- */
- private static abstract class Statement<S extends Storable> {
- public abstract int maxLength();
-
- /**
- * Builds a statement string from the given values.
- *
- * @param initialCapacity expected size of finished string
- * length. Should be value returned from maxLength.
- * @param filterValues values may be needed to build complete statement
- */
- public String buildStatement(int initialCapacity, FilterValues<S> filterValues) {
- StringBuilder b = new StringBuilder(initialCapacity);
- this.appendTo(b, filterValues);
- return b.toString();
- }
-
- public abstract void appendTo(StringBuilder b, FilterValues<S> filterValues);
-
- /**
- * Just used for debugging.
- */
- public String toString() {
- StringBuilder b = new StringBuilder();
- appendTo(b, null);
- return b.toString();
- }
- }
-
- private static class LiteralStatement<S extends Storable> extends Statement<S> {
- private final String mStr;
-
- LiteralStatement(String str) {
- mStr = str;
- }
-
- public int maxLength() {
- return mStr.length();
- }
-
- public String buildStatement(int initialCapacity, FilterValues<S> filterValues) {
- return mStr;
- }
-
- public void appendTo(StringBuilder b, FilterValues<S> filterValues) {
- b.append(mStr);
- }
-
- /**
- * Returns the literal value.
- */
- public String toString() {
- return mStr;
- }
- }
-
- private static class NullablePropertyStatement<S extends Storable> extends Statement<S> {
- private final PropertyFilter<S> mFilter;
- private final boolean mIsNullOp;
-
- NullablePropertyStatement(PropertyFilter<S> filter, boolean isNullOp) {
- mFilter = filter;
- mIsNullOp = isNullOp;
- }
-
- public int maxLength() {
- return mIsNullOp ? 8 : 12; // for " IS NULL" or " IS NOT NULL"
- }
-
- public void appendTo(StringBuilder b, FilterValues<S> filterValues) {
- if (filterValues != null
- && filterValues.getValue(mFilter) == null
- && filterValues.isAssigned(mFilter))
- {
- if (mIsNullOp) {
- b.append(" IS NULL");
- } else {
- b.append(" IS NOT NULL");
- }
- } else {
- if (mIsNullOp) {
- b.append("=?");
- } else {
- b.append("<>?");
- }
- }
- }
- }
-
- private static class CompositeStatement<S extends Storable> extends Statement<S> {
- private final Statement<S>[] mStatements;
-
- @SuppressWarnings("unchecked")
- CompositeStatement(List<Statement<S>> statements) {
- mStatements = statements.toArray(new Statement[statements.size()]);
- }
-
- public int maxLength() {
- int max = 0;
- for (Statement<S> statement : mStatements) {
- max += statement.maxLength();
- }
- return max;
- }
-
- public void appendTo(StringBuilder b, FilterValues<S> filterValues) {
- for (Statement<S> statement : mStatements) {
- statement.appendTo(b, filterValues);
- }
- }
- }
-
private class StatementBuilder {
- private List<Statement<S>> mStatements;
+ private List<SQLStatement<S>> mStatements;
private StringBuilder mLiteralBuilder;
StatementBuilder() {
- mStatements = new ArrayList<Statement<S>>();
+ mStatements = new ArrayList<SQLStatement<S>>();
mLiteralBuilder = new StringBuilder();
}
- public Statement<S> build() {
+ public SQLStatement<S> build() {
if (mStatements.size() == 0 || mLiteralBuilder.length() > 0) {
mStatements.add(new LiteralStatement<S>(mLiteralBuilder.toString()));
mLiteralBuilder.setLength(0);
@@ -1083,7 +969,7 @@ class JDBCStorage<S extends Storable> extends StandardQueryFactory<S>
append(statement.toString());
}
- public void append(Statement<S> statement) {
+ public void append(SQLStatement<S> statement) {
if (statement instanceof LiteralStatement) {
append((LiteralStatement<S>) statement);
} else {
diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/LiteralStatement.java b/src/main/java/com/amazon/carbonado/repo/jdbc/LiteralStatement.java
new file mode 100644
index 0000000..8fa0933
--- /dev/null
+++ b/src/main/java/com/amazon/carbonado/repo/jdbc/LiteralStatement.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2007 Amazon Technologies, Inc. or its affiliates.
+ * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks
+ * of Amazon Technologies, Inc. or its affiliates. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.amazon.carbonado.repo.jdbc;
+
+import com.amazon.carbonado.Storable;
+
+import com.amazon.carbonado.filter.FilterValues;
+
+/**
+ *
+ *
+ * @author Brian S O'Neill
+ */
+class LiteralStatement<S extends Storable> extends SQLStatement<S> {
+ private final String mStr;
+
+ LiteralStatement(String str) {
+ mStr = str;
+ }
+
+ public int maxLength() {
+ return mStr.length();
+ }
+
+ public String buildStatement(int initialCapacity, FilterValues<S> filterValues) {
+ return mStr;
+ }
+
+ public void appendTo(StringBuilder b, FilterValues<S> filterValues) {
+ b.append(mStr);
+ }
+
+ /**
+ * Returns the literal value.
+ */
+ public String toString() {
+ return mStr;
+ }
+}
diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/NullablePropertyStatement.java b/src/main/java/com/amazon/carbonado/repo/jdbc/NullablePropertyStatement.java
new file mode 100644
index 0000000..4c7e4db
--- /dev/null
+++ b/src/main/java/com/amazon/carbonado/repo/jdbc/NullablePropertyStatement.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2007 Amazon Technologies, Inc. or its affiliates.
+ * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks
+ * of Amazon Technologies, Inc. or its affiliates. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.amazon.carbonado.repo.jdbc;
+
+import com.amazon.carbonado.Storable;
+
+import com.amazon.carbonado.filter.FilterValues;
+import com.amazon.carbonado.filter.PropertyFilter;
+
+/**
+ *
+ *
+ * @author Brian S O'Neill
+ */
+class NullablePropertyStatement<S extends Storable> extends SQLStatement<S> {
+ private final PropertyFilter<S> mFilter;
+ private final boolean mIsNullOp;
+
+ NullablePropertyStatement(PropertyFilter<S> filter, boolean isNullOp) {
+ mFilter = filter;
+ mIsNullOp = isNullOp;
+ }
+
+ public int maxLength() {
+ return mIsNullOp ? 8 : 12; // for " IS NULL" or " IS NOT NULL"
+ }
+
+ public void appendTo(StringBuilder b, FilterValues<S> filterValues) {
+ if (filterValues != null
+ && filterValues.getValue(mFilter) == null
+ && filterValues.isAssigned(mFilter))
+ {
+ if (mIsNullOp) {
+ b.append(" IS NULL");
+ } else {
+ b.append(" IS NOT NULL");
+ }
+ } else {
+ if (mIsNullOp) {
+ b.append("=?");
+ } else {
+ b.append("<>?");
+ }
+ }
+ }
+}
diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/SQLStatement.java b/src/main/java/com/amazon/carbonado/repo/jdbc/SQLStatement.java
new file mode 100644
index 0000000..0317e3f
--- /dev/null
+++ b/src/main/java/com/amazon/carbonado/repo/jdbc/SQLStatement.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2007 Amazon Technologies, Inc. or its affiliates.
+ * Amazon, Amazon.com and Carbonado are trademarks or registered trademarks
+ * of Amazon Technologies, Inc. or its affiliates. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.amazon.carbonado.repo.jdbc;
+
+import com.amazon.carbonado.Storable;
+
+import com.amazon.carbonado.filter.FilterValues;
+
+/**
+ * Simple DOM representing a SQL statement.
+ *
+ * @author Brian S O'Neill
+ */
+abstract class SQLStatement<S extends Storable> {
+ public abstract int maxLength();
+
+ /**
+ * Builds a statement string from the given values.
+ *
+ * @param initialCapacity expected size of finished string
+ * length. Should be value returned from maxLength.
+ * @param filterValues values may be needed to build complete statement
+ */
+ public String buildStatement(int initialCapacity, FilterValues<S> filterValues) {
+ StringBuilder b = new StringBuilder(initialCapacity);
+ this.appendTo(b, filterValues);
+ return b.toString();
+ }
+
+ public abstract void appendTo(StringBuilder b, FilterValues<S> filterValues);
+
+ /**
+ * Just used for debugging.
+ */
+ public String toString() {
+ StringBuilder b = new StringBuilder();
+ appendTo(b, null);
+ return b.toString();
+ }
+}