mirror of https://github.com/apache/openjpa.git
OPENJPA-317. Added ResultSetType and FetchDirection enums. Used FetchDirection instead of FetchDirectionType because FetchDirection seemed much more natural.
git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@567893 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ede9dcbd61
commit
e26e15496e
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.openjpa.persistence.jdbc;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
|
||||
/**
|
||||
* The fetch direction to request when creating statements.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @published
|
||||
*/
|
||||
public enum FetchDirection {
|
||||
FORWARD(ResultSet.FETCH_FORWARD),
|
||||
REVERSE(ResultSet.FETCH_REVERSE),
|
||||
UNKNOWN(ResultSet.FETCH_UNKNOWN);
|
||||
|
||||
private final int resultSetConstant;
|
||||
|
||||
private FetchDirection(int value) {
|
||||
resultSetConstant = value;
|
||||
}
|
||||
|
||||
int toKernelConstant() {
|
||||
return resultSetConstant;
|
||||
}
|
||||
|
||||
static FetchDirection fromKernelConstant(int kernelConstant) {
|
||||
switch (kernelConstant) {
|
||||
case ResultSet.FETCH_FORWARD:
|
||||
return FORWARD;
|
||||
|
||||
case ResultSet.FETCH_REVERSE:
|
||||
return REVERSE;
|
||||
|
||||
case ResultSet.FETCH_UNKNOWN:
|
||||
return UNKNOWN;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException(kernelConstant + "");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -56,31 +56,23 @@ public interface JDBCFetchPlan
|
|||
|
||||
/**
|
||||
* Type of JDBC result set to use for query results.
|
||||
*
|
||||
* @see java.sql.ResultSet
|
||||
*/
|
||||
public int getResultSetType();
|
||||
public ResultSetType getResultSetType();
|
||||
|
||||
/**
|
||||
* Type of JDBC result set to use for query results.
|
||||
*
|
||||
* @see java.sql.ResultSet
|
||||
*/
|
||||
public JDBCFetchPlan setResultSetType(int type);
|
||||
public JDBCFetchPlan setResultSetType(ResultSetType type);
|
||||
|
||||
/**
|
||||
* Result set fetch direction.
|
||||
*
|
||||
* @see java.sql.ResultSet
|
||||
*/
|
||||
public int getFetchDirection();
|
||||
public FetchDirection getFetchDirection();
|
||||
|
||||
/**
|
||||
* Result set fetch direction.
|
||||
*
|
||||
* @see java.sql.ResultSet
|
||||
*/
|
||||
public JDBCFetchPlan setFetchDirection(int direction);
|
||||
public JDBCFetchPlan setFetchDirection(FetchDirection direction);
|
||||
|
||||
/**
|
||||
* How to determine the size of a large result set.
|
||||
|
|
|
@ -73,21 +73,21 @@ public class JDBCFetchPlanImpl
|
|||
return this;
|
||||
}
|
||||
|
||||
public int getResultSetType() {
|
||||
return _fetch.getResultSetType();
|
||||
public ResultSetType getResultSetType() {
|
||||
return ResultSetType.fromKernelConstant(_fetch.getResultSetType());
|
||||
}
|
||||
|
||||
public JDBCFetchPlanImpl setResultSetType(int type) {
|
||||
_fetch.setResultSetType(type);
|
||||
public JDBCFetchPlanImpl setResultSetType(ResultSetType type) {
|
||||
_fetch.setResultSetType(type.toKernelConstant());
|
||||
return this;
|
||||
}
|
||||
|
||||
public int getFetchDirection() {
|
||||
return _fetch.getFetchDirection();
|
||||
public FetchDirection getFetchDirection() {
|
||||
return FetchDirection.fromKernelConstant(_fetch.getFetchDirection());
|
||||
}
|
||||
|
||||
public JDBCFetchPlanImpl setFetchDirection(int direction) {
|
||||
_fetch.setFetchDirection(direction);
|
||||
public JDBCFetchPlanImpl setFetchDirection(FetchDirection direction) {
|
||||
_fetch.setFetchDirection(direction.toKernelConstant());
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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 org.apache.openjpa.persistence.jdbc;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
|
||||
/**
|
||||
* Type of result set to use.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @published
|
||||
*/
|
||||
public enum ResultSetType {
|
||||
FORWARD_ONLY(ResultSet.TYPE_FORWARD_ONLY),
|
||||
SCROLL_INSENSITIVE(ResultSet.TYPE_SCROLL_INSENSITIVE),
|
||||
SCROLL_SENSITIVE(ResultSet.TYPE_SCROLL_SENSITIVE);
|
||||
|
||||
private final int resultSetConstant;
|
||||
|
||||
private ResultSetType(int value) {
|
||||
resultSetConstant = value;
|
||||
}
|
||||
|
||||
int toKernelConstant() {
|
||||
return resultSetConstant;
|
||||
}
|
||||
|
||||
static ResultSetType fromKernelConstant(int kernelConstant) {
|
||||
switch (kernelConstant) {
|
||||
case ResultSet.TYPE_FORWARD_ONLY:
|
||||
return FORWARD_ONLY;
|
||||
|
||||
case ResultSet.TYPE_SCROLL_INSENSITIVE:
|
||||
return SCROLL_INSENSITIVE;
|
||||
|
||||
case ResultSet.TYPE_SCROLL_SENSITIVE:
|
||||
return SCROLL_SENSITIVE;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException(kernelConstant + "");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.apache.openjpa.persistence.jdbc;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.openjpa.jdbc.kernel.EagerFetchModes;
|
||||
import org.apache.openjpa.jdbc.kernel.LRSSizes;
|
||||
|
@ -113,6 +115,51 @@ public class TestJDBCEnumToKernelConstantMappings
|
|||
JoinSyntaxType.values().length);
|
||||
}
|
||||
|
||||
public void testResultSetType() {
|
||||
assertEquals(ResultSet.TYPE_FORWARD_ONLY,
|
||||
ResultSetType.FORWARD_ONLY.toKernelConstant());
|
||||
assertEquals(ResultSetType.FORWARD_ONLY,
|
||||
ResultSetType.fromKernelConstant(
|
||||
ResultSet.TYPE_FORWARD_ONLY));
|
||||
|
||||
assertEquals(ResultSet.TYPE_SCROLL_INSENSITIVE,
|
||||
ResultSetType.SCROLL_INSENSITIVE.toKernelConstant());
|
||||
assertEquals(ResultSetType.SCROLL_INSENSITIVE,
|
||||
ResultSetType.fromKernelConstant(
|
||||
ResultSet.TYPE_SCROLL_INSENSITIVE));
|
||||
|
||||
assertEquals(ResultSet.TYPE_SCROLL_SENSITIVE,
|
||||
ResultSetType.SCROLL_SENSITIVE.toKernelConstant());
|
||||
assertEquals(ResultSetType.SCROLL_SENSITIVE,
|
||||
ResultSetType.fromKernelConstant(
|
||||
ResultSet.TYPE_SCROLL_SENSITIVE));
|
||||
|
||||
assertEquals(3, ResultSetType.values().length);
|
||||
}
|
||||
|
||||
public void testFetchDirection() {
|
||||
assertEquals(ResultSet.FETCH_FORWARD,
|
||||
FetchDirection.FORWARD.toKernelConstant());
|
||||
assertEquals(FetchDirection.FORWARD,
|
||||
FetchDirection.fromKernelConstant(
|
||||
ResultSet.FETCH_FORWARD));
|
||||
|
||||
assertEquals(ResultSet.FETCH_REVERSE,
|
||||
FetchDirection.REVERSE.toKernelConstant());
|
||||
assertEquals(FetchDirection.REVERSE,
|
||||
FetchDirection.fromKernelConstant(
|
||||
ResultSet.FETCH_REVERSE));
|
||||
|
||||
assertEquals(ResultSet.FETCH_UNKNOWN,
|
||||
FetchDirection.UNKNOWN.toKernelConstant());
|
||||
assertEquals(FetchDirection.UNKNOWN,
|
||||
FetchDirection.fromKernelConstant(
|
||||
ResultSet.FETCH_UNKNOWN));
|
||||
|
||||
assertEquals(3, FetchDirection.values().length);
|
||||
}
|
||||
|
||||
|
||||
private int getConstantCount(Class cls) {
|
||||
return cls.getDeclaredFields().length;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue