Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions buildtools/src/main/resources/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,7 @@
<property name="severity" value="error"/>
</module>

<!-- Check that finds import statements that use the * notation. -->
<module name="AvoidStarImport"/>
<!-- Checks for long lines. -->

<module name="LineLength">
<property name="max" value="120"/>
</module>
Expand Down
19 changes: 16 additions & 3 deletions db/src/main/java/org/trellisldp/ext/db/DBNamespaceService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*/
package org.trellisldp.ext.db;

import static org.slf4j.LoggerFactory.getLogger;

import java.util.AbstractMap.SimpleImmutableEntry;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -21,13 +23,17 @@
import javax.sql.DataSource;

import org.jdbi.v3.core.Jdbi;
import org.jdbi.v3.core.statement.StatementException;
import org.slf4j.Logger;
import org.trellisldp.api.NamespaceService;

/**
* A namespace service that stores data in a database.
*/
public class DBNamespaceService implements NamespaceService {

private static final Logger LOGGER = getLogger(DBNamespaceService.class);

private final Jdbi jdbi;

/**
Expand Down Expand Up @@ -59,8 +65,15 @@ public Map<String, String> getNamespaces() {

@Override
public boolean setPrefix(final String prefix, final String namespace) {
jdbi.useHandle(handle ->
handle.execute("INSERT INTO namespaces (prefix, namespace) VALUES (?, ?)", prefix, namespace));
return true;
if (!prefix.isEmpty()) {
try {
jdbi.useHandle(handle ->
handle.execute("INSERT INTO namespaces (prefix, namespace) VALUES (?, ?)", prefix, namespace));
return true;
} catch (final StatementException ex) {
LOGGER.warn("Could not save prefix {} with namespace {}: {}", prefix, namespace, ex.getMessage());
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
package org.trellisldp.ext.db;

import static java.io.File.separator;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.condition.OS.WINDOWS;
import static org.slf4j.LoggerFactory.getLogger;

Expand Down Expand Up @@ -75,6 +74,8 @@ public void testNamespaceService() {
assertTrue(svc.setPrefix("ex", "http://example.com/"));
assertEquals(size + 1, svc.getNamespaces().size());
assertEquals("http://example.com/", svc.getNamespaces().get("ex"));
assertFalse(svc.setPrefix("ex", "http://example.com/Other/"));
assertFalse(svc.setPrefix("", "http://example.com/Resource/"));
}
}