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
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,6 @@ public void setRequestUniqueId(String requestUniqueId) {
this.requestUniqueId = requestUniqueId;
}

public String getResourceName() {
return resourceName;
}

public void setResourceName(String resourceName) {
this.resourceName = resourceName;
}

/**
* Generates JSON from this object.
*/
Expand Down Expand Up @@ -191,10 +183,6 @@ public static String generate(Context obj)
generator.write("purpose", obj.getPurpose());
}

if (obj.getResourceName() != null) {
generator.write("resource_name", obj.getResourceName());
}

if (obj.getStartTime() != null) {
generator.write("start_time", obj.getStartTime());
}
Expand Down Expand Up @@ -275,12 +263,6 @@ public static Context parse(InputStream in)
builder.purpose(purpose);
}

t = jsonObject.get("resource_name");
if (t != null) {
String resourceName = jsonObject.getString("resource_name");
builder.resourceName(resourceName);
}

t = jsonObject.get("start_time");
if (t != null) {
String startTime = jsonObject.getString("start_time");
Expand Down Expand Up @@ -387,11 +369,6 @@ public Builder requestUniqueId(String requestUniqueId) {
return this;
}

public Builder resourceName(String resourceName) {
context.setResourceName(resourceName);
return this;
}

public Context build() {
return context;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,6 @@ public static String generate(FHIRContext obj)
generator.write("purpose", obj.getPurpose());
}

if (obj.getResourceName() != null) {
generator.write("resource_name", obj.getResourceName());
}

if (obj.getStartTime() != null) {
generator.write("start_time", obj.getStartTime());
}
Expand Down Expand Up @@ -228,12 +224,6 @@ public static FHIRContext parse(InputStream in)
builder.purpose(purpose);
}

t = jsonObject.get("resource_name");
if (t != null) {
String resourceName = jsonObject.getString("resource_name");
builder.resourceName(resourceName);
}

t = jsonObject.get("start_time");
if (t != null) {
String startTime = jsonObject.getString("start_time");
Expand Down Expand Up @@ -395,11 +385,6 @@ public FHIRBuilder requestUniqueId(String requestUniqueId) {
return this;
}

public FHIRBuilder resourceName(String resourceName) {
fhirContext.setResourceName(resourceName);
return this;
}

public FHIRContext build() {
return fhirContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ public void testContextEmptyNull() throws FHIRException, IOException {
assertNull(ctx.getPurpose());
assertNull(ctx.getQueryParameters());
assertNull(ctx.getRequestUniqueId());
assertNull(ctx.getResourceName());
assertNull(ctx.getStartTime());
}

Expand Down Expand Up @@ -175,7 +174,6 @@ public void testContext() throws FHIRException, IOException {
builder.purpose("purpose");
builder.queryParameters("queryParameters");
builder.requestUniqueId("requestUniqueId");
builder.resourceName("test");
builder.startTime("startTime");

Context ctx = builder.build();
Expand Down Expand Up @@ -204,9 +202,6 @@ public void testContext() throws FHIRException, IOException {
assertNotNull(ctx.getRequestUniqueId());
assertEquals(ctx.getRequestUniqueId(), "requestUniqueId");

assertNotNull(ctx.getResourceName());
assertEquals(ctx.getResourceName(), "test");

assertNotNull(ctx.getStartTime());
assertEquals(ctx.getStartTime(), "startTime");

Expand Down Expand Up @@ -236,9 +231,6 @@ public void testContext() throws FHIRException, IOException {
assertNotNull(ctx.getRequestUniqueId());
assertEquals(ctx.getRequestUniqueId(), "requestUniqueId");

assertNotNull(ctx.getResourceName());
assertEquals(ctx.getResourceName(), "test");

assertNotNull(ctx.getStartTime());
assertEquals(ctx.getStartTime(), "startTime");
}
Expand Down Expand Up @@ -349,7 +341,6 @@ public void testFHIRContext() throws IOException, FHIRException {
builder.purpose("purpose");
builder.queryParameters("queryParameters");
builder.requestUniqueId("requestUniqueId");
builder.resourceName("test");
builder.startTime("startTime");

builder.clientCertCn("clientCertCn");
Expand Down Expand Up @@ -386,9 +377,6 @@ public void testFHIRContext() throws IOException, FHIRException {
assertNotNull(fhirCtx.getRequestUniqueId());
assertEquals(fhirCtx.getRequestUniqueId(), "requestUniqueId");

assertNotNull(fhirCtx.getResourceName());
assertEquals(fhirCtx.getResourceName(), "test");

assertNotNull(fhirCtx.getStartTime());
assertEquals(fhirCtx.getStartTime(), "startTime");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ public class FHIRConfiguration {
public static final String PROPERTY_AUDIT_SERVICE_CLASS_NAME = "fhirServer/audit/serviceClassName";
public static final String PROPERTY_AUDIT_SERVICE_PROPERTIES = "fhirServer/audit/serviceProperties";
public static final String PROPERTY_AUDIT_PATIENT_ID_EXTURL = "fhirServer/audit/patientIdExtensionUrl";
public static final String PROPERTY_AUDIT_RESOURCE_NAME_EXTURL = "fhirServer/audit/resourceNameExtensionUrl";
public static final String PROPERTY_UPDATE_CREATE_ENABLED = "fhirServer/persistence/common/updateCreateEnabled";

// Notification config properties
public static final String PROPERTY_NOTIFICATION_RESOURCE_TYPES = "fhirServer/notifications/common/includeResourceTypes";
Expand All @@ -59,6 +57,7 @@ public class FHIRConfiguration {
public static final String PROPERTY_KAFKA_CONNECTIONPROPS = "fhirServer/notifications/kafka/connectionProperties";

// Persistence layer properties
public static final String PROPERTY_UPDATE_CREATE_ENABLED = "fhirServer/persistence/common/updateCreateEnabled";
public static final String PROPERTY_PERSISTENCE_FACTORY = "fhirServer/persistence/factoryClassname";
public static final String PROPERTY_DATASOURCES = "fhirServer/persistence/datasources";
public static final String PROPERTY_JDBC_BOOTSTRAP_DB = "fhirServer/persistence/jdbc/bootstrapDb";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* (C) Copyright IBM Corp. 2019
*
* SPDX-License-Identifier: Apache-2.0
*/

package com.ibm.fhir.database.utils.api;

/**
* The name of the object to be created is identical to an existing name.
*/
public class DuplicateNameException extends DataAccessException {
// Generated serial number
private static final long serialVersionUID = 4082017119186491651L;

public DuplicateNameException(Throwable t) {
super(t);
}

public DuplicateNameException(String msg, Throwable t) {
super(msg, t);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ public interface IDatabaseTranslator {
*/
boolean isDuplicate(SQLException x);

/**
* Check the exception to see if it is reporting that THE NAME OF THE OBJECT TO BE CREATED
* OR THE TARGET OF A RENAME STATEMENT IS IDENTICAL TO THE EXISTING NAME OF THE OBJECT TYPE
* @param x
* @return
*/
boolean isAlreadyExists(SQLException x);
Comment thread
prb112 marked this conversation as resolved.

/**
* Database timed out waiting to get a lock. This is not the same as a deadlock, of course
* @param x
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
/**
* Translation of a duplicate key or value constraint SQLException.
*/
public class DuplicateValueException extends DataAccessException {
public class UniqueConstraintViolationException extends DataAccessException {

// Generated serial number
private static final long serialVersionUID = -2753101534110619540L;

public DuplicateValueException(Throwable t) {
public UniqueConstraintViolationException(Throwable t) {
super(t);
}

public DuplicateValueException(String msg, Throwable t) {
public UniqueConstraintViolationException(String msg, Throwable t) {
super(msg, t);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.logging.Logger;
import java.util.stream.Collectors;

import com.ibm.fhir.database.utils.api.DuplicateValueException;
import com.ibm.fhir.database.utils.api.UniqueConstraintViolationException;
import com.ibm.fhir.database.utils.api.IConnectionProvider;
import com.ibm.fhir.database.utils.api.IDatabaseAdapter;
import com.ibm.fhir.database.utils.api.IDatabaseStatement;
Expand Down Expand Up @@ -345,7 +345,7 @@ public int allocateTenant(String adminSchemaName, String schemaName, String tena
AddTenantDAO adder = new AddTenantDAO(adminSchemaName, tenantId, tenantName);
runStatement(adder);
}
catch (DuplicateValueException x) {
catch (UniqueConstraintViolationException x) {
// Concurrent operation, so try again
logger.info("Duplicate value, so try the next one");
tenantId = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.logging.Logger;

import com.ibm.fhir.database.utils.api.DataAccessException;
import com.ibm.fhir.database.utils.api.DuplicateNameException;
import com.ibm.fhir.database.utils.api.IConnectionProvider;
import com.ibm.fhir.database.utils.api.IDatabaseTarget;
import com.ibm.fhir.database.utils.api.ITransaction;
Expand Down Expand Up @@ -430,9 +431,17 @@ public boolean checkCompatibility(String adminSchema) {

@Override
public void createFhirSchemas(String schemaName, String adminSchemaName) {
String ddl = "CREATE SCHEMA " + schemaName;
runStatement(ddl);
ddl = "CREATE SCHEMA " + adminSchemaName;
runStatement(ddl);
try {
String ddl = "CREATE SCHEMA " + schemaName;
runStatement(ddl);
} catch (DuplicateNameException e) {
logger.log(Level.WARNING, "The schema '" + schemaName + "' already exists; proceed with caution.");
}
try {
String ddl = "CREATE SCHEMA " + adminSchemaName;
runStatement(ddl);
} catch (DuplicateNameException e) {
logger.log(Level.WARNING, "The schema '" + adminSchemaName + "' already exists; proceed with caution.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import com.ibm.fhir.database.utils.api.ConnectionDetails;
import com.ibm.fhir.database.utils.api.ConnectionException;
import com.ibm.fhir.database.utils.api.DataAccessException;
import com.ibm.fhir.database.utils.api.DuplicateValueException;
import com.ibm.fhir.database.utils.api.DuplicateNameException;
import com.ibm.fhir.database.utils.api.UniqueConstraintViolationException;
import com.ibm.fhir.database.utils.api.IDatabaseTranslator;
import com.ibm.fhir.database.utils.api.LockException;
import com.ibm.fhir.database.utils.api.UndefinedNameException;
Expand Down Expand Up @@ -49,6 +50,12 @@ public boolean isDuplicate(SQLException x) {
return "23505".equals(x.getSQLState());
}

@Override
public boolean isAlreadyExists(SQLException x) {
// SQL-Error: -601, SQL State 42710
return "42710".equals(x.getSQLState());
}

@Override
public boolean isLockTimeout(SQLException x) {
// lock timeout (not deadlock)
Expand Down Expand Up @@ -88,7 +95,10 @@ else if (isConnectionError(x)) {
return new ConnectionException(x);
}
else if (isDuplicate(x)) {
return new DuplicateValueException(x);
return new UniqueConstraintViolationException(x);
}
else if (isAlreadyExists(x)) {
return new DuplicateNameException(x);
}
else if (isUndefinedName(x)) {
return new UndefinedNameException(x);
Expand Down Expand Up @@ -145,7 +155,7 @@ public String timestampDiff(String left, String right, String alias) {
return String.format("timestampdiff(2, %s, %s)", left, right);
}
else {
return String.format("timestampdiff(2, %s, %s) AS %s", left, right, alias);
return String.format("timestampdiff(2, %s, %s) AS %s", left, right, alias);
}
}

Expand All @@ -167,7 +177,7 @@ public String getDriverClassName() {
@Override
public String getUrl(Properties connectionProperties) {
Db2PropertyAdapter adapter = new Db2PropertyAdapter(connectionProperties);
return "jdbc:db2://" + adapter.getHost() + ":" + adapter.getPort() + "/" + adapter.getDatabase();
return "jdbc:db2://" + adapter.getHost() + ":" + adapter.getPort() + "/" + adapter.getDatabase();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import com.ibm.fhir.database.utils.api.ConnectionDetails;
import com.ibm.fhir.database.utils.api.ConnectionException;
import com.ibm.fhir.database.utils.api.DataAccessException;
import com.ibm.fhir.database.utils.api.DuplicateValueException;
import com.ibm.fhir.database.utils.api.UniqueConstraintViolationException;
import com.ibm.fhir.database.utils.api.IDatabaseTranslator;
import com.ibm.fhir.database.utils.api.LockException;
import com.ibm.fhir.database.utils.api.UndefinedNameException;
Expand Down Expand Up @@ -50,6 +50,11 @@ public boolean isDuplicate(SQLException x) {
return "23505".equals(x.getSQLState());
}

@Override
public boolean isAlreadyExists(SQLException x) {
return "42710".equals(x.getSQLState());
}

@Override
public boolean isLockTimeout(SQLException x) {
return false;
Expand Down Expand Up @@ -79,7 +84,7 @@ else if (isConnectionError(x)) {
return new ConnectionException(x);
}
else if (isDuplicate(x)) {
return new DuplicateValueException(x);
return new UniqueConstraintViolationException(x);
}
else if (isUndefinedName(x)) {
return new UndefinedNameException(x);
Expand Down
Loading