Fix issue with fields being doubled
This commit is contained in:
parent
93b07e29a5
commit
c283f52f44
1
.gitignore
vendored
1
.gitignore
vendored
@ -152,3 +152,4 @@ gradle-app.setting
|
||||
# JDT-specific (Eclipse Java Development Tools)
|
||||
.classpath
|
||||
|
||||
database.db
|
17
.idea/dataSources.xml
Normal file
17
.idea/dataSources.xml
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="DataSourceManagerImpl" format="xml" multifile-model="true">
|
||||
<data-source source="LOCAL" name="database" uuid="2fe95eab-37d1-457a-b059-1c37b3035173">
|
||||
<driver-ref>sqlite.xerial</driver-ref>
|
||||
<synchronize>true</synchronize>
|
||||
<jdbc-driver>org.sqlite.JDBC</jdbc-driver>
|
||||
<jdbc-url>jdbc:sqlite:C:\Users\svtra\IdeaProjects\OSQL4J\database.db</jdbc-url>
|
||||
<working-dir>$ProjectFileDir$</working-dir>
|
||||
<libraries>
|
||||
<library>
|
||||
<url>file://$APPLICATION_CONFIG_DIR$/jdbc-drivers/Xerial SQLiteJDBC/3.39.2/sqlite-jdbc-3.39.2.jar</url>
|
||||
</library>
|
||||
</libraries>
|
||||
</data-source>
|
||||
</component>
|
||||
</project>
|
@ -5,7 +5,7 @@ plugins {
|
||||
}
|
||||
|
||||
group 'tech.nevets.osql4j'
|
||||
version '1.1.0'
|
||||
version '1.1.1'
|
||||
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
|
@ -213,7 +213,7 @@ public class SQLConnection<T> {
|
||||
try {
|
||||
String sql = "CREATE TABLE IF NOT EXISTS " +
|
||||
clazz.getSimpleName() +
|
||||
" (id INT PRIMARY KEY, " +
|
||||
" ( " +
|
||||
sqlFormattedFields +
|
||||
" );";
|
||||
statement.executeUpdate(sql);
|
||||
@ -257,7 +257,7 @@ public class SQLConnection<T> {
|
||||
}
|
||||
|
||||
private List<Field> getFields() {
|
||||
List<Field> fieldsList = new ArrayList<>(List.of(clazz.getDeclaredFields()));
|
||||
List<Field> fieldsList = new ArrayList<>();
|
||||
for (Class<?> c = clazz; c != null; c = c.getSuperclass()) {
|
||||
fieldsList.addAll(Arrays.asList(c.getDeclaredFields()));
|
||||
}
|
||||
|
11
src/test/java/NewDBTest.java
Normal file
11
src/test/java/NewDBTest.java
Normal file
@ -0,0 +1,11 @@
|
||||
import examplebeans.Animal;
|
||||
import tech.nevets.osql4j.SQLConnection;
|
||||
|
||||
public class NewDBTest {
|
||||
public static void main(String[] args) {
|
||||
SQLConnection.setGlobalDBLocation("./database.db");
|
||||
SQLConnection<Animal> connection = new SQLConnection<>(Animal.class);
|
||||
connection.writeObject(new Animal("Fuzzy", 6, "brown"));
|
||||
connection.close();
|
||||
}
|
||||
}
|
44
src/test/java/examplebeans/Animal.java
Normal file
44
src/test/java/examplebeans/Animal.java
Normal file
@ -0,0 +1,44 @@
|
||||
package examplebeans;
|
||||
|
||||
public class Animal {
|
||||
private String name;
|
||||
private int age;
|
||||
private String color;
|
||||
|
||||
public Animal() {}
|
||||
|
||||
public Animal(String name, int age, String color) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
public void setAge(int age) {
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public String getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
public void setColor(String color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Animal: " + name + ", " + age + ", " + color;
|
||||
}
|
||||
}
|
5
src/test/java/examplebeans/Cat.java
Normal file
5
src/test/java/examplebeans/Cat.java
Normal file
@ -0,0 +1,5 @@
|
||||
package examplebeans;
|
||||
|
||||
public class Cat extends Animal {
|
||||
|
||||
}
|
4
src/test/java/examplebeans/Dog.java
Normal file
4
src/test/java/examplebeans/Dog.java
Normal file
@ -0,0 +1,4 @@
|
||||
package examplebeans;
|
||||
|
||||
public class Dog extends Animal {
|
||||
}
|
Loading…
Reference in New Issue
Block a user