Search in sources :

Example 1 with ResourceName

use of org.flywaydb.core.internal.resource.ResourceName in project flyway by flyway.

the class SqlMigrationResolver method addMigrations.

private void addMigrations(List<ResolvedMigration> migrations, String prefix, String[] suffixes, boolean repeatable) {
    ResourceNameParser resourceNameParser = new ResourceNameParser(configuration);
    for (LoadableResource resource : resourceProvider.getResources(prefix, suffixes)) {
        String filename = resource.getFilename();
        ResourceName result = resourceNameParser.parse(filename);
        if (!result.isValid() || isSqlCallback(result) || !prefix.equals(result.getPrefix())) {
            continue;
        }
        SqlScript sqlScript = sqlScriptFactory.createSqlScript(resource, configuration.isMixed(), resourceProvider);
        List<LoadableResource> resources = new ArrayList<>();
        resources.add(resource);
        Integer checksum = getChecksumForLoadableResource(repeatable, resources);
        Integer equivalentChecksum = getEquivalentChecksumForLoadableResource(repeatable, resources);
        migrations.add(new ResolvedMigrationImpl(result.getVersion(), result.getDescription(), resource.getRelativePath(), checksum, equivalentChecksum, MigrationType.SQL, resource.getAbsolutePathOnDisk(), new SqlMigrationExecutor(sqlScriptExecutorFactory, sqlScript, false, false)) {

            @Override
            public void validate() {
            }
        });
    }
}
Also used : ResourceName(org.flywaydb.core.internal.resource.ResourceName) ResourceNameParser(org.flywaydb.core.internal.resource.ResourceNameParser) LoadableResource(org.flywaydb.core.api.resource.LoadableResource) ArrayList(java.util.ArrayList) SqlScript(org.flywaydb.core.internal.sqlscript.SqlScript) ResolvedMigrationImpl(org.flywaydb.core.internal.resolver.ResolvedMigrationImpl)

Example 2 with ResourceName

use of org.flywaydb.core.internal.resource.ResourceName in project flyway by flyway.

the class Parser method parse.

/**
 * Parses this resource into a stream of statements.
 *
 * @param resource The resource to parse.
 * @param metadata The resource's metadata.
 * @return The statements.
 */
public final SqlStatementIterator parse(LoadableResource resource, SqlScriptMetadata metadata) {
    PositionTracker tracker = new PositionTracker();
    Recorder recorder = new Recorder();
    ParserContext context = new ParserContext(getDefaultDelimiter());
    String filename = resource.getFilename();
    LOG.debug("Parsing " + filename + " ...");
    ResourceName result = new ResourceNameParser(configuration).parse(filename);
    parsingContext.updateFilenamePlaceholder(result);
    PeekingReader peekingReader = new PeekingReader(new RecordingReader(recorder, new PositionTrackingReader(tracker, replacePlaceholders(new BomStrippingReader(new UnboundedReadAheadReader(new BufferedReader(resource.read(), 4096))), metadata))), supportsPeekingMultipleLines());
    return new ParserSqlStatementIterator(peekingReader, resource, recorder, tracker, context);
}
Also used : ResourceName(org.flywaydb.core.internal.resource.ResourceName) BomStrippingReader(org.flywaydb.core.internal.util.BomStrippingReader) ResourceNameParser(org.flywaydb.core.internal.resource.ResourceNameParser) BufferedReader(java.io.BufferedReader)

Aggregations

ResourceName (org.flywaydb.core.internal.resource.ResourceName)2 ResourceNameParser (org.flywaydb.core.internal.resource.ResourceNameParser)2 BufferedReader (java.io.BufferedReader)1 ArrayList (java.util.ArrayList)1 LoadableResource (org.flywaydb.core.api.resource.LoadableResource)1 ResolvedMigrationImpl (org.flywaydb.core.internal.resolver.ResolvedMigrationImpl)1 SqlScript (org.flywaydb.core.internal.sqlscript.SqlScript)1 BomStrippingReader (org.flywaydb.core.internal.util.BomStrippingReader)1