Skip to content

Commit 96a4902

Browse files
committed
introduce JdbcDataType
1 parent d01c051 commit 96a4902

File tree

4 files changed

+141
-0
lines changed

4 files changed

+141
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package com.github.housepower.jdbc.type;
16+
17+
public interface JdbcDataType<JDBC> {
18+
19+
int sqlTypeId();
20+
21+
Class<JDBC> javaType();
22+
23+
boolean nullable();
24+
25+
int getPrecision();
26+
27+
int getScale();
28+
29+
boolean isSigned();
30+
31+
default String format(JDBC value) {
32+
return value.toString();
33+
}
34+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package com.github.housepower.jdbc.type;
16+
17+
public class JdbcDataTypeFactory {
18+
19+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package com.github.housepower.jdbc.type;
16+
17+
import com.github.housepower.data.IDataType;
18+
19+
import java.math.BigDecimal;
20+
import java.sql.Types;
21+
22+
public class JdbcDecimal extends WrappedJdbcDataType<BigDecimal> {
23+
24+
public JdbcDecimal(IDataType<BigDecimal, BigDecimal> ckDataType) {
25+
super(ckDataType);
26+
}
27+
28+
@Override
29+
public int sqlTypeId() {
30+
return Types.DECIMAL;
31+
}
32+
33+
@Override
34+
public Class<BigDecimal> javaType() {
35+
return BigDecimal.class;
36+
}
37+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
15+
package com.github.housepower.jdbc.type;
16+
17+
import com.github.housepower.data.IDataType;
18+
19+
public abstract class WrappedJdbcDataType<JDBC> implements JdbcDataType<JDBC> {
20+
21+
protected final IDataType<JDBC, JDBC> ckDataType;
22+
23+
protected WrappedJdbcDataType(IDataType<JDBC, JDBC> ckDataType) {
24+
this.ckDataType = ckDataType;
25+
}
26+
27+
@Override
28+
public boolean nullable() {
29+
return ckDataType.nullable();
30+
}
31+
32+
@Override
33+
public int getPrecision() {
34+
return ckDataType.getPrecision();
35+
}
36+
37+
@Override
38+
public int getScale() {
39+
return ckDataType.getScale();
40+
}
41+
42+
@Override
43+
public boolean isSigned() {
44+
return ckDataType.isSigned();
45+
}
46+
47+
@Override
48+
public String format(JDBC value) {
49+
return ckDataType.serializeText(value);
50+
}
51+
}

0 commit comments

Comments
 (0)