MCPcopy Create free account
hub / github.com/jOOQ/jOOQ / loadSQL

Method loadSQL

jOOQ/src/main/java/org/jooq/impl/CommitsImpl.java:304–360  ·  view source on GitHub ↗
(FilePattern pattern, List<Source> files)

Source from the content-addressed store, hash-verified

302 }
303
304 private final Commits loadSQL(FilePattern pattern, List<Source> files) throws IOException {
305
306 // [#9506] TODO: Turning a directory into a MigrationsType (and various other conversion)
307 // could be made reusable. This is certainly very useful for testing and interop,
308 // e.g. also to support other formats (Flyway, Liquibase) as source
309 TreeMap<String, CommitType> idToCommit = new TreeMap<>(comparing(
310 java.io.File::new,
311 pattern.fileComparator()
312 ));
313
314 List<FileData> list = files.stream().map(s -> new FileData(pattern, s)).collect(toList());
315
316 if (log.isDebugEnabled())
317 list.forEach(f -> log.debug("Reading file", f));
318
319 for (FileData f : list)
320 idToCommit.putIfAbsent(f.id, new CommitType()
321 .withId(f.id)
322 .withAuthor(f.author)
323 .withMessage(f.message)
324 .withTags(f.tags)
325 );
326
327 for (FileData f : list) {
328 CommitType commit = idToCommit.get(f.id);
329
330 // Parents are implicit
331 // [#9506] TODO: What cases of implicit parents are possible. What edge cases aren't?
332 if (f.parents.isEmpty()) {
333 Entry<String, CommitType> e = idToCommit.lowerEntry(f.id);
334
335 if (e != null)
336 commit.setParents(asList(new ParentType().withId(e.getKey())));
337 }
338
339 // Parents are explicit
340 else {
341 for (String parent : f.parents)
342 if (idToCommit.containsKey(parent))
343 commit.getParents().add(new ParentType().withId(parent));
344 else
345 throw new DataMigrationVerificationException("Parent " + parent + " is not defined");
346 }
347
348 commit.getFiles().add(new FileType()
349 .withPath(f.path)
350 .withContentType(f.contentType)
351 .withContent(f.source.readString())
352 .withChange(ChangeType.MODIFY)
353 );
354 }
355
356 if (log.isDebugEnabled())
357 log.debug("Loading files into: " + new MigrationsType().withCommits(idToCommit.values()));
358
359 return load(new MigrationsType().withCommits(idToCommit.values()));
360 }
361

Callers 1

loadMethod · 0.95

Calls 15

setParentsMethod · 0.95
getParentsMethod · 0.95
getFilesMethod · 0.95
loadMethod · 0.95
fileComparatorMethod · 0.80
withTagsMethod · 0.80
withAuthorMethod · 0.80
withChangeMethod · 0.80
withContentMethod · 0.80
withContentTypeMethod · 0.80
withPathMethod · 0.80
readStringMethod · 0.80

Tested by

no test coverage detected