Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
committing in case I ever want to come back to this, but for now, i'm…
… deleting the orm stuff, let's just do this the easy way
- Loading branch information
1 parent
7501b6c
commit 6cbe6cd
Showing
5 changed files
with
110 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
discord/src/main/java/me/piggypiglet/docdex/db/orm/query/types/InsertQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package me.piggypiglet.docdex.db.orm.query.types; | ||
|
||
import me.piggypiglet.docdex.db.orm.structure.TableStructure; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
// ------------------------------ | ||
// Copyright (c) PiggyPiglet 2020 | ||
// https://www.piggypiglet.me | ||
// ------------------------------ | ||
public final class InsertQuery { | ||
@NotNull | ||
public String insert(@NotNull final Map<String, Object> data, @NotNull final TableStructure table) { | ||
final Map<String, Object> mappedData = new HashMap<>(); | ||
|
||
Map<TableStructure, Object> datum = Map.of(table, data); | ||
do { | ||
datum.forEach((structure, object) -> mappedData.put(structure.getName(), object)); | ||
|
||
final Map<TableStructure, Object> newDatum = new HashMap<>(); | ||
|
||
for (final TableStructure parent : datum.keySet()) { | ||
final String parentName = parent.getName(); | ||
final Map<String, Object> parentMap = (Map<String, Object>) datum.get(parent); | ||
|
||
for (final TableStructure sub : parent.getSubStructures()) { | ||
System.out.println(sub.getName() + " - " + parentMap + " - " + sub.getClazz() + " - " + parent.getIdentifier().getName()); | ||
|
||
if (parent.getIdentifier().getName().equals("key")) { | ||
final Set<Map<String, Object>> set = new HashSet<>(); | ||
parentMap.forEach((key, m) -> { | ||
final Map<String, Object> dasd = new HashMap<>(); | ||
dasd.put("key", key); | ||
((Map<String, Object>) m).forEach(dasd::put); | ||
set.add(dasd); | ||
}); | ||
|
||
newDatum.put(sub, set); | ||
} else { | ||
newDatum.put(sub, parentMap.get(sub.getName().replace(parentName + '_', ""))); | ||
} | ||
} | ||
} | ||
|
||
datum = newDatum; | ||
} while (!datum.isEmpty()); | ||
|
||
System.out.println(mappedData); | ||
|
||
// final Set<TableStructure> all = Stream.concat(Stream.of(table), Query.getAll(table)).collect(Collectors.toSet()); | ||
// final Map<TableStructure, TableStructure> parents = new HashMap<>(); | ||
// | ||
// all.forEach(structure -> structure.getSubStructures().forEach(sub -> parents.put(sub, structure))); | ||
// | ||
// final Map<Integer, Map<TableStructure, Map<String, Object>>> levels = new HashMap<>(); | ||
// | ||
// final Map<String, Map<String, Object>> splitData = new HashMap<>(); | ||
// | ||
// all.forEach(structure -> { | ||
// final Map<String, Object> map = new HashMap<>(); | ||
// | ||
// structure.getColumns().forEach(column -> { | ||
// final String name = column.getLevel() + ":" + column.getName(); | ||
// | ||
// Map<String, Object> level = data.get(column.getLevel()); | ||
// for (int j = column.getLevel(); j > 0; --j) { | ||
// | ||
// } | ||
// }); | ||
// | ||
// splitData.put(structure.getName(), map); | ||
// }); | ||
|
||
return ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters