Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
re-apply code formatting, missed by mistake
Signed-off-by: Gabriel Roldan <groldan@boundlessgeo.com>
  • Loading branch information
Gabriel Roldan committed Nov 23, 2018
1 parent 42f7077 commit f34c8df
Show file tree
Hide file tree
Showing 19 changed files with 1,875 additions and 1,818 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -13,3 +13,5 @@ nb-configuration.xml
.DS_store
# IntelliJ module files
*.iml
#KDE
.directory
Expand Up @@ -127,10 +127,12 @@ public Repository open(URI repositoryLocation) throws RepositoryConnectionExcept
hints.set(Hints.REPOSITORY_URL, repositoryLocation.toString());
Context context = GlobalContextBuilder.builder().build(hints);
Repository repository = new GeoGIG(context).getRepository();
// Ensure the repository exists. If it's null, we might have a non-existing repo URI location
// Ensure the repository exists. If it's null, we might have a non-existing repo URI
// location
if (repository == null) {
throw new RepositoryConnectionException("Could not connect to repository. Check that the URI is valid: " +
repositoryLocation);
throw new RepositoryConnectionException(
"Could not connect to repository. Check that the URI is valid: "
+ repositoryLocation);
}
repository.open();
return repository;
Expand Down
Expand Up @@ -26,38 +26,38 @@
* @since 1.2.1
*/
public class CreateDDL extends AbstractGeoGigOp<List<String>> {
private Environment environment;

private URI baseURI;

protected @Override List<String> _call() {
Environment env = resolveEnvironment();
Version dbVersion = PGStorage.getServerVersion(env);
PGStorageTableManager tableManager = PGStorageTableManager.forVersion(dbVersion);
List<String> ddl = tableManager.createDDL(env);
return ddl;
}

private Environment resolveEnvironment() {
Preconditions.checkArgument(environment != null || baseURI != null,
"Environment or base URI argument not provided");
if (environment != null) {
return environment;
}
EnvironmentBuilder environmentBuilder = new EnvironmentBuilder(baseURI, true);
Environment env = environmentBuilder.build();
return env;
}

public CreateDDL setEnvironment(Environment env) {
this.environment = env;
this.baseURI = null;
return this;
}

public CreateDDL setBaseURI(URI baseURI) {
this.environment = null;
this.baseURI = baseURI;
return this;
}
private Environment environment;

private URI baseURI;

protected @Override List<String> _call() {
Environment env = resolveEnvironment();
Version dbVersion = PGStorage.getServerVersion(env);
PGStorageTableManager tableManager = PGStorageTableManager.forVersion(dbVersion);
List<String> ddl = tableManager.createDDL(env);
return ddl;
}

private Environment resolveEnvironment() {
Preconditions.checkArgument(environment != null || baseURI != null,
"Environment or base URI argument not provided");
if (environment != null) {
return environment;
}
EnvironmentBuilder environmentBuilder = new EnvironmentBuilder(baseURI, true);
Environment env = environmentBuilder.build();
return env;
}

public CreateDDL setEnvironment(Environment env) {
this.environment = env;
this.baseURI = null;
return this;
}

public CreateDDL setBaseURI(URI baseURI) {
this.environment = null;
this.baseURI = baseURI;
return this;
}
}
Expand Up @@ -33,95 +33,98 @@
*/
public class PGDatabaseUpgrade extends AbstractGeoGigOp<Void> {

private Environment environment;

private URI baseURI;

protected @Override Void _call() {
Environment env = resolveEnvironment();
Version serverVersion = PGStorage.getServerVersion(env);
PGStorageTableManager tableManager = PGStorageTableManager.forVersion(serverVersion);
TableNames tables = env.getTables();
DataSource dataSource = PGStorage.newDataSource(env);

// DDL to tell the user to run if we don't have priviledges to
List<String> DDL = new ArrayList<>();
try (Connection cx = dataSource.getConnection()) {
final int currentSchemaVersion = tableManager.getSchemaVersion(cx, tables);
final boolean createMetadataTable = currentSchemaVersion == 0;
if (createMetadataTable) {
tableManager.createMetadata(DDL, tables);
}
final SchemaUpgrade0To1 upgrade = new SchemaUpgrade0To1(env);
final boolean runUpgrade = upgrade.shouldRun(cx);
if (runUpgrade) {
DDL.addAll(upgrade.createDDL());
}

if (DDL.isEmpty()) {
getProgressListener().setDescription(
"Database schema is up to date, checking for non DDL related upgrade actions...");
} else {
getProgressListener().setDescription("Running DDL script:");
String script = "-- SCRIPT START --\n" + Joiner.on('\n').join(DDL) + "\n-- SCRIPT END --\n";
getProgressListener().setDescription(script);

cx.setAutoCommit(false);
if (runScript(cx, DDL, tableManager)) {
cx.commit();
cx.setAutoCommit(true);
} else {
cx.rollback();
return null;
}
}
if (runUpgrade) {
upgrade.run(cx, tableManager, getProgressListener());
getProgressListener().setDescription("Finished upgrading the geogig database to the latest version.");
} else {
getProgressListener().setDescription("Nothing to upgrade. Database schema is up to date");
}
} catch (SQLException e) {
throw new IllegalStateException(e);
}
return null;
}

private boolean runScript(Connection cx, List<String> ddl, PGStorageTableManager tableManager) {
if (ddl.isEmpty()) {
return true;
}
try {
tableManager.runScript(cx, ddl);
return true;
} catch (SQLException e) {
getProgressListener().setDescription("Error running DDL script: " + e.getMessage()
+ "\n Please run the script above manually and re-run this command.");
}
return false;
}

private Environment resolveEnvironment() {
Preconditions.checkArgument(environment != null || baseURI != null,
"Environment or base URI argument not provided");
if (environment != null) {
return environment;
}
EnvironmentBuilder environmentBuilder = new EnvironmentBuilder(baseURI, true);
Environment env = environmentBuilder.build();
return env;
}

public PGDatabaseUpgrade setEnvironment(Environment env) {
this.environment = env;
this.baseURI = null;
return this;
}

public PGDatabaseUpgrade setBaseURI(URI baseURI) {
this.environment = null;
this.baseURI = baseURI;
return this;
}
private Environment environment;

private URI baseURI;

protected @Override Void _call() {
Environment env = resolveEnvironment();
Version serverVersion = PGStorage.getServerVersion(env);
PGStorageTableManager tableManager = PGStorageTableManager.forVersion(serverVersion);
TableNames tables = env.getTables();
DataSource dataSource = PGStorage.newDataSource(env);

// DDL to tell the user to run if we don't have priviledges to
List<String> DDL = new ArrayList<>();
try (Connection cx = dataSource.getConnection()) {
final int currentSchemaVersion = tableManager.getSchemaVersion(cx, tables);
final boolean createMetadataTable = currentSchemaVersion == 0;
if (createMetadataTable) {
tableManager.createMetadata(DDL, tables);
}
final SchemaUpgrade0To1 upgrade = new SchemaUpgrade0To1(env);
final boolean runUpgrade = upgrade.shouldRun(cx);
if (runUpgrade) {
DDL.addAll(upgrade.createDDL());
}

if (DDL.isEmpty()) {
getProgressListener().setDescription(
"Database schema is up to date, checking for non DDL related upgrade actions...");
} else {
getProgressListener().setDescription("Running DDL script:");
String script = "-- SCRIPT START --\n" + Joiner.on('\n').join(DDL)
+ "\n-- SCRIPT END --\n";
getProgressListener().setDescription(script);

cx.setAutoCommit(false);
if (runScript(cx, DDL, tableManager)) {
cx.commit();
cx.setAutoCommit(true);
} else {
cx.rollback();
return null;
}
}
if (runUpgrade) {
upgrade.run(cx, tableManager, getProgressListener());
getProgressListener().setDescription(
"Finished upgrading the geogig database to the latest version.");
} else {
getProgressListener()
.setDescription("Nothing to upgrade. Database schema is up to date");
}
} catch (SQLException e) {
throw new IllegalStateException(e);
}
return null;
}

private boolean runScript(Connection cx, List<String> ddl, PGStorageTableManager tableManager) {
if (ddl.isEmpty()) {
return true;
}
try {
tableManager.runScript(cx, ddl);
return true;
} catch (SQLException e) {
getProgressListener().setDescription("Error running DDL script: " + e.getMessage()
+ "\n Please run the script above manually and re-run this command.");
}
return false;
}

private Environment resolveEnvironment() {
Preconditions.checkArgument(environment != null || baseURI != null,
"Environment or base URI argument not provided");
if (environment != null) {
return environment;
}
EnvironmentBuilder environmentBuilder = new EnvironmentBuilder(baseURI, true);
Environment env = environmentBuilder.build();
return env;
}

public PGDatabaseUpgrade setEnvironment(Environment env) {
this.environment = env;
this.baseURI = null;
return this;
}

public PGDatabaseUpgrade setBaseURI(URI baseURI) {
this.environment = null;
this.baseURI = baseURI;
return this;
}

}

0 comments on commit f34c8df

Please sign in to comment.