From d1f058804bd5dd1c18e95d94e3f90aff112216d0 Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Sun, 5 Aug 2007 20:09:53 +0000 Subject: Moved static inner classes to separate files. --- .../carbonado/repo/jdbc/CompositeStatement.java | 53 +++++++++ .../amazon/carbonado/repo/jdbc/JDBCStorage.java | 130 ++------------------- .../carbonado/repo/jdbc/LiteralStatement.java | 55 +++++++++ .../repo/jdbc/NullablePropertyStatement.java | 62 ++++++++++ .../amazon/carbonado/repo/jdbc/SQLStatement.java | 56 +++++++++ 5 files changed, 234 insertions(+), 122 deletions(-) create mode 100644 src/main/java/com/amazon/carbonado/repo/jdbc/CompositeStatement.java create mode 100644 src/main/java/com/amazon/carbonado/repo/jdbc/LiteralStatement.java create mode 100644 src/main/java/com/amazon/carbonado/repo/jdbc/NullablePropertyStatement.java create mode 100644 src/main/java/com/amazon/carbonado/repo/jdbc/SQLStatement.java (limited to 'src/main/java/com/amazon/carbonado') 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 extends SQLStatement { + private final SQLStatement[] mStatements; + + @SuppressWarnings("unchecked") + CompositeStatement(List> statements) { + mStatements = statements.toArray(new SQLStatement[statements.size()]); + } + + public int maxLength() { + int max = 0; + for (SQLStatement statement : mStatements) { + max += statement.maxLength(); + } + return max; + } + + public void appendTo(StringBuilder b, FilterValues filterValues) { + for (SQLStatement 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 extends StandardQueryFactory private final Filter mFilter; private final OrderingList mOrdering; - private final Statement mSelectStatement; + private final SQLStatement mSelectStatement; private final int mMaxSelectStatementLength; - private final Statement mFromWhereStatement; + private final SQLStatement 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 extends StandardQueryFactory Executor(Filter filter, OrderingList ordering, - Statement selectStatement, - Statement fromWhereStatement, + SQLStatement selectStatement, + SQLStatement fromWhereStatement, PropertyFilter[] propertyFilters, boolean[] propertyFilterNullable) throws RepositoryException @@ -936,130 +936,16 @@ class JDBCStorage extends StandardQueryFactory } } - /** - * Simple DOM representing a SQL statement. - */ - private static abstract class Statement { - 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 filterValues) { - StringBuilder b = new StringBuilder(initialCapacity); - this.appendTo(b, filterValues); - return b.toString(); - } - - public abstract void appendTo(StringBuilder b, FilterValues filterValues); - - /** - * Just used for debugging. - */ - public String toString() { - StringBuilder b = new StringBuilder(); - appendTo(b, null); - return b.toString(); - } - } - - private static class LiteralStatement extends Statement { - private final String mStr; - - LiteralStatement(String str) { - mStr = str; - } - - public int maxLength() { - return mStr.length(); - } - - public String buildStatement(int initialCapacity, FilterValues filterValues) { - return mStr; - } - - public void appendTo(StringBuilder b, FilterValues filterValues) { - b.append(mStr); - } - - /** - * Returns the literal value. - */ - public String toString() { - return mStr; - } - } - - private static class NullablePropertyStatement extends Statement { - private final PropertyFilter mFilter; - private final boolean mIsNullOp; - - NullablePropertyStatement(PropertyFilter 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 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 extends Statement { - private final Statement[] mStatements; - - @SuppressWarnings("unchecked") - CompositeStatement(List> statements) { - mStatements = statements.toArray(new Statement[statements.size()]); - } - - public int maxLength() { - int max = 0; - for (Statement statement : mStatements) { - max += statement.maxLength(); - } - return max; - } - - public void appendTo(StringBuilder b, FilterValues filterValues) { - for (Statement statement : mStatements) { - statement.appendTo(b, filterValues); - } - } - } - private class StatementBuilder { - private List> mStatements; + private List> mStatements; private StringBuilder mLiteralBuilder; StatementBuilder() { - mStatements = new ArrayList>(); + mStatements = new ArrayList>(); mLiteralBuilder = new StringBuilder(); } - public Statement build() { + public SQLStatement build() { if (mStatements.size() == 0 || mLiteralBuilder.length() > 0) { mStatements.add(new LiteralStatement(mLiteralBuilder.toString())); mLiteralBuilder.setLength(0); @@ -1083,7 +969,7 @@ class JDBCStorage extends StandardQueryFactory append(statement.toString()); } - public void append(Statement statement) { + public void append(SQLStatement statement) { if (statement instanceof LiteralStatement) { append((LiteralStatement) 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 extends SQLStatement { + private final String mStr; + + LiteralStatement(String str) { + mStr = str; + } + + public int maxLength() { + return mStr.length(); + } + + public String buildStatement(int initialCapacity, FilterValues filterValues) { + return mStr; + } + + public void appendTo(StringBuilder b, FilterValues 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 extends SQLStatement { + private final PropertyFilter mFilter; + private final boolean mIsNullOp; + + NullablePropertyStatement(PropertyFilter 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 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 { + 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 filterValues) { + StringBuilder b = new StringBuilder(initialCapacity); + this.appendTo(b, filterValues); + return b.toString(); + } + + public abstract void appendTo(StringBuilder b, FilterValues filterValues); + + /** + * Just used for debugging. + */ + public String toString() { + StringBuilder b = new StringBuilder(); + appendTo(b, null); + return b.toString(); + } +} -- cgit v1.2.3