Skip to content

Commit

Permalink
introduce JdbcDataType
Browse files Browse the repository at this point in the history
  • Loading branch information
pan3793 committed Jan 26, 2021
1 parent 4867176 commit 264bc50
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.github.housepower.jdbc.type;

public interface JdbcDataType<JDBC> {

int sqlTypeId();

Class<JDBC> javaType();

boolean nullable();

int getPrecision();

int getScale();

boolean isSigned();

default String format(JDBC value) {
return value.toString();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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.github.housepower.jdbc.type;

public class JdbcDataTypeFactory {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.github.housepower.jdbc.type;

import com.github.housepower.data.IDataType;

import java.math.BigDecimal;
import java.sql.Types;

public class JdbcDecimal extends WrappedJdbcDataType<BigDecimal> {

public JdbcDecimal(IDataType<BigDecimal, BigDecimal> ckDataType) {
super(ckDataType);
}

@Override
public int sqlTypeId() {
return Types.DECIMAL;
}

@Override
public Class<BigDecimal> javaType() {
return BigDecimal.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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.github.housepower.jdbc.type;

import com.github.housepower.data.IDataType;

public abstract class WrappedJdbcDataType<JDBC> implements JdbcDataType<JDBC> {

protected final IDataType<JDBC, JDBC> ckDataType;

protected WrappedJdbcDataType(IDataType<JDBC, JDBC> ckDataType) {
this.ckDataType = ckDataType;
}

@Override
public boolean nullable() {
return ckDataType.nullable();
}

@Override
public int getPrecision() {
return ckDataType.getPrecision();
}

@Override
public int getScale() {
return ckDataType.getScale();
}

@Override
public boolean isSigned() {
return ckDataType.isSigned();
}

@Override
public String format(JDBC value) {
return ckDataType.serializeText(value);
}
}

0 comments on commit 264bc50

Please sign in to comment.