Skip to content

Commit 536403c

Browse files
authored
Merge pull request boylegu#2 from boylegu/issue/1/support_sqlite
close boylegu#1 connect sqlite and design models
2 parents 1c80c14 + a72b436 commit 536403c

File tree

6 files changed

+324
-0
lines changed

6 files changed

+324
-0
lines changed

info.db

2 KB
Binary file not shown.

pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@
2525
</properties>
2626

2727
<dependencies>
28+
<dependency>
29+
<groupId>org.xerial</groupId>
30+
<artifactId>sqlite-jdbc</artifactId>
31+
<version>3.7.2</version>
32+
</dependency>
33+
<!-- <dependency>
34+
<groupId>org.springframework.boot</groupId>
35+
<artifactId>spring-boot-starter-web</artifactId>
36+
</dependency> -->
37+
<dependency>
38+
<groupId>org.springframework.boot</groupId>
39+
<artifactId>spring-boot-starter-data-jpa</artifactId>
40+
</dependency>
41+
2842
<dependency>
2943
<groupId>org.springframework.boot</groupId>
3044
<artifactId>spring-boot-starter-web</artifactId>
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
package com.boylegu.springboot_vue.config;
2+
3+
/*
4+
* The author disclaims copyright to this source code. In place of
5+
* a legal notice, here is a blessing:
6+
*
7+
* May you do good and not evil.
8+
* May you find forgiveness for yourself and forgive others.
9+
* May you share freely, never taking more than you give.
10+
*
11+
*/
12+
13+
import java.sql.Types;
14+
import org.hibernate.dialect.Dialect;
15+
16+
import org.hibernate.dialect.function.AbstractAnsiTrimEmulationFunction;
17+
import org.hibernate.dialect.function.NoArgSQLFunction;
18+
import org.hibernate.dialect.function.SQLFunction;
19+
import org.hibernate.dialect.function.SQLFunctionTemplate;
20+
import org.hibernate.dialect.function.StandardSQLFunction;
21+
import org.hibernate.dialect.function.VarArgsSQLFunction;
22+
import org.hibernate.type.StandardBasicTypes;
23+
24+
public class SQLiteDialect extends Dialect {
25+
public SQLiteDialect() {
26+
registerColumnType(Types.BIT, "boolean");
27+
registerColumnType(Types.TINYINT, "tinyint");
28+
registerColumnType(Types.SMALLINT, "smallint");
29+
registerColumnType(Types.INTEGER, "integer");
30+
registerColumnType(Types.BIGINT, "bigint");
31+
registerColumnType(Types.FLOAT, "float");
32+
registerColumnType(Types.REAL, "real");
33+
registerColumnType(Types.DOUBLE, "double");
34+
registerColumnType(Types.NUMERIC, "numeric($p, $s)");
35+
registerColumnType(Types.DECIMAL, "decimal");
36+
registerColumnType(Types.CHAR, "char");
37+
registerColumnType(Types.VARCHAR, "varchar($l)");
38+
registerColumnType(Types.LONGVARCHAR, "longvarchar");
39+
registerColumnType(Types.DATE, "date");
40+
registerColumnType(Types.TIME, "time");
41+
registerColumnType(Types.TIMESTAMP, "datetime");
42+
registerColumnType(Types.BINARY, "blob");
43+
registerColumnType(Types.VARBINARY, "blob");
44+
registerColumnType(Types.LONGVARBINARY, "blob");
45+
registerColumnType(Types.BLOB, "blob");
46+
registerColumnType(Types.CLOB, "clob");
47+
registerColumnType(Types.BOOLEAN, "boolean");
48+
49+
//registerFunction( "abs", new StandardSQLFunction("abs") );
50+
registerFunction( "concat", new VarArgsSQLFunction(StandardBasicTypes.STRING, "", "||", "") );
51+
//registerFunction( "length", new StandardSQLFunction("length", StandardBasicTypes.LONG) );
52+
//registerFunction( "lower", new StandardSQLFunction("lower") );
53+
registerFunction( "mod", new SQLFunctionTemplate(StandardBasicTypes.INTEGER, "?1 % ?2" ) );
54+
registerFunction( "quote", new StandardSQLFunction("quote", StandardBasicTypes.STRING) );
55+
registerFunction( "random", new NoArgSQLFunction("random", StandardBasicTypes.INTEGER) );
56+
registerFunction( "round", new StandardSQLFunction("round") );
57+
registerFunction( "substr", new StandardSQLFunction("substr", StandardBasicTypes.STRING) );
58+
registerFunction( "substring", new SQLFunctionTemplate( StandardBasicTypes.STRING, "substr(?1, ?2, ?3)" ) );
59+
registerFunction( "trim", new AbstractAnsiTrimEmulationFunction() {
60+
protected SQLFunction resolveBothSpaceTrimFunction() {
61+
return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?1)");
62+
}
63+
64+
protected SQLFunction resolveBothSpaceTrimFromFunction() {
65+
return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?2)");
66+
}
67+
68+
protected SQLFunction resolveLeadingSpaceTrimFunction() {
69+
return new SQLFunctionTemplate(StandardBasicTypes.STRING, "ltrim(?1)");
70+
}
71+
72+
protected SQLFunction resolveTrailingSpaceTrimFunction() {
73+
return new SQLFunctionTemplate(StandardBasicTypes.STRING, "rtrim(?1)");
74+
}
75+
76+
protected SQLFunction resolveBothTrimFunction() {
77+
return new SQLFunctionTemplate(StandardBasicTypes.STRING, "trim(?1, ?2)");
78+
}
79+
80+
protected SQLFunction resolveLeadingTrimFunction() {
81+
return new SQLFunctionTemplate(StandardBasicTypes.STRING, "ltrim(?1, ?2)");
82+
}
83+
84+
protected SQLFunction resolveTrailingTrimFunction() {
85+
return new SQLFunctionTemplate(StandardBasicTypes.STRING, "rtrim(?1, ?2)");
86+
}
87+
} );
88+
//registerFunction( "upper", new StandardSQLFunction("upper") );
89+
}
90+
91+
public boolean supportsIdentityColumns() {
92+
return true;
93+
}
94+
95+
/*
96+
public boolean supportsInsertSelectIdentity() {
97+
return true; // As specify in NHibernate dialect
98+
}
99+
*/
100+
101+
public boolean hasDataTypeInIdentityColumn() {
102+
return false; // As specify in NHibernate dialect
103+
}
104+
105+
/*
106+
public String appendIdentitySelectToInsert(String insertString) {
107+
return new StringBuffer(insertString.length()+30). // As specify in NHibernate dialect
108+
append(insertString).
109+
append("; ").append(getIdentitySelectString()).
110+
toString();
111+
}
112+
*/
113+
114+
public String getIdentityColumnString() {
115+
// return "integer primary key autoincrement";
116+
return "integer";
117+
}
118+
119+
public String getIdentitySelectString() {
120+
return "select last_insert_rowid()";
121+
}
122+
123+
public boolean supportsLimit() {
124+
return true;
125+
}
126+
127+
public boolean bindLimitParametersInReverseOrder() {
128+
return true;
129+
}
130+
131+
protected String getLimitString(String query, boolean hasOffset) {
132+
return new StringBuffer(query.length()+20).
133+
append(query).
134+
append(hasOffset ? " limit ? offset ?" : " limit ?").
135+
toString();
136+
}
137+
138+
public boolean supportsTemporaryTables() {
139+
return true;
140+
}
141+
142+
public String getCreateTemporaryTableString() {
143+
return "create temporary table if not exists";
144+
}
145+
146+
public boolean dropTemporaryTableAfterUse() {
147+
return true; // TODO Validate
148+
}
149+
150+
public boolean supportsCurrentTimestampSelection() {
151+
return true;
152+
}
153+
154+
public boolean isCurrentTimestampSelectStringCallable() {
155+
return false;
156+
}
157+
158+
public String getCurrentTimestampSelectString() {
159+
return "select current_timestamp";
160+
}
161+
162+
public boolean supportsUnionAll() {
163+
return true;
164+
}
165+
166+
public boolean hasAlterTable() {
167+
return false; // As specify in NHibernate dialect
168+
}
169+
170+
public boolean dropConstraints() {
171+
return false;
172+
}
173+
174+
/*
175+
public String getAddColumnString() {
176+
return "add column";
177+
}
178+
*/
179+
180+
public String getForUpdateString() {
181+
return "";
182+
}
183+
184+
public boolean supportsOuterJoinForUpdate() {
185+
return false;
186+
}
187+
188+
public String getDropForeignKeyString() {
189+
throw new UnsupportedOperationException("No drop foreign key syntax supported by SQLiteDialect");
190+
}
191+
192+
public String getAddForeignKeyConstraintString(String constraintName,
193+
String[] foreignKey, String referencedTable, String[] primaryKey,
194+
boolean referencesPrimaryKey) {
195+
throw new UnsupportedOperationException("No add foreign key syntax supported by SQLiteDialect");
196+
}
197+
198+
public String getAddPrimaryKeyConstraintString(String constraintName) {
199+
throw new UnsupportedOperationException("No add primary key syntax supported by SQLiteDialect");
200+
}
201+
202+
public boolean supportsIfExistsBeforeTableName() {
203+
return true;
204+
}
205+
206+
public boolean supportsCascadeDelete() {
207+
return true;
208+
}
209+
210+
/* not case insensitive for unicode characters by default (ICU extension needed)
211+
public boolean supportsCaseInsensitiveLike() {
212+
return true;
213+
}
214+
*/
215+
216+
public boolean supportsTupleDistinctCounts() {
217+
return false;
218+
}
219+
220+
public String getSelectGUIDString() {
221+
return "select hex(randomblob(16))";
222+
}
223+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.boylegu.springboot_vue.dao;
2+
3+
4+
import org.springframework.data.jpa.repository.JpaRepository;
5+
import org.springframework.data.jpa.repository.query.Jpa21Utils;
6+
import org.springframework.stereotype.Repository;
7+
8+
import com.boylegu.springboot_vue.entities.Persons;
9+
10+
11+
public interface PersonsRepository extends JpaRepository <Persons, Long> {
12+
13+
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.boylegu.springboot_vue.entities;
2+
3+
import javax.persistence.*;
4+
import java.awt.*;
5+
import java.util.Date;
6+
7+
8+
@Entity
9+
public class Persons {
10+
@Id
11+
@GeneratedValue(strategy = GenerationType.AUTO)
12+
13+
private long id;
14+
private Date create_datetime;
15+
private String username;
16+
private String email;
17+
private String phone;
18+
private String sex;
19+
private TextArea zone;
20+
21+
public long getId() {
22+
return id;
23+
}
24+
25+
public void setId(long id) {
26+
this.id = id;
27+
}
28+
29+
public Date getCreate_datetime() {
30+
return create_datetime;
31+
32+
}
33+
34+
public void setCreate_datetime(Date create_datetime) {
35+
this.create_datetime = create_datetime;
36+
}
37+
38+
public String getUsername() {
39+
return username;
40+
}
41+
42+
public void setUsername(String username) {
43+
this.username = username;
44+
}
45+
46+
public String getEmail() {
47+
return email;
48+
}
49+
50+
public void setEmail(String email) {
51+
this.email = email;
52+
}
53+
54+
public String getPhone() {
55+
return phone;
56+
}
57+
58+
public void setPhone(String phone) {
59+
this.phone = phone;
60+
}
61+
62+
public String getSex() {
63+
return sex;
64+
}
65+
66+
public void setSex(String sex) {
67+
this.sex = sex;
68+
}
69+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
spring.jpa.properties.hibernate.hbm2ddl.auto=create-drop
3+
spring.datasource.url=jdbc:sqlite:info.db
4+
spring.datasource.driver-class-name = org.sqlite.JDBC
5+
spring.jpa.database-platform=com.boylegu.springboot_vue.config.SQLiteDialect

0 commit comments

Comments
 (0)