Skip to content

Commit

Permalink
Added a simpler way to persist a not annotated object
Browse files Browse the repository at this point in the history
  • Loading branch information
jansoren committed Apr 9, 2024
1 parent 381fe22 commit 5eb18a5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/main/java/io/github/filelize/Filelizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public Filelizer(String basePath, ObjectMapper objectMapper, FilelizeType defaul
this.defaultFilelizeType = defaultFilelizeType;
}

@Override
public <T> T find(String id, Class<T> valueType) {
var filelizeType = getFilelizeType(valueType, defaultFilelizeType);
if(filelizeType == FilelizeType.SINGLE_FILE) {
Expand All @@ -54,6 +55,7 @@ public <T> Map<String, T> findAll(Class<T> valueType) {
return filelizerObject.findAll(valueType);
}

@Override
public <T> String save(T object) {
var filelizeType = getFilelizeType(object, defaultFilelizeType);
if(filelizeType == FilelizeType.SINGLE_FILE) {
Expand All @@ -64,16 +66,18 @@ public <T> String save(T object) {
return filelizerObject.save(object);
}

public <T> String save(String filename, T object) {
@Override
public <T> String save(String id, T object) {
var filelizeType = getFilelizeType(object, defaultFilelizeType);
if(filelizeType == FilelizeType.SINGLE_FILE) {
return filelizerSingle.save(object);
return filelizerSingle.save(id, object);
} else if(filelizeType == FilelizeType.MULTIPLE_FILES) {
return filelizerMultiple.save(object);
return filelizerMultiple.save(id, object);
}
return filelizerObject.save(object);
return filelizerObject.save(id, object);
}

@Override
public <T> List<String> saveAll(List<T> objects) {
var filelizeType = getFilelizeTypeOfList(objects, defaultFilelizeType);
if(filelizeType == FilelizeType.SINGLE_FILE) {
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/io/github/filelize/FilelizerSomethingElseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@ public void testSave() {
assertNotNull(response);
}

@Test
public void testSaveWithId() {
var somethingElse = createSomethingElse("e2");
var id = filelizer.save("my_something_else", somethingElse);
assertEquals("my_something_else", id);

var response = filelizer.find(id, SomethingElse.class);
assertNotNull(response);
}

@Test
public void testSaveAll() {
var somethings = createSomethingElseList();
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/something_else/my_something_else.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"id" : "e2",
"value" : "Some Value"
}

0 comments on commit 5eb18a5

Please sign in to comment.