Skip to content

Commit

Permalink
0005945: support compare and repair http, use of dyna SQL
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Sep 7, 2023
1 parent de86102 commit 4f93158
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 3 deletions.
Expand Up @@ -47,6 +47,7 @@
import org.jumpmind.symmetric.transport.ConnectionDuplicateException;
import org.jumpmind.symmetric.transport.ConnectionRejectedException;
import org.jumpmind.symmetric.transport.NoReservationException;
import org.jumpmind.symmetric.transport.ServiceNotReadyException;
import org.jumpmind.symmetric.transport.ServiceUnavailableException;
import org.jumpmind.symmetric.transport.SyncDisabledException;
import org.jumpmind.util.ExceptionUtils;
Expand Down Expand Up @@ -84,7 +85,11 @@ protected void fireOffline(Exception exception, Node remoteNode, RemoteNodeStatu
status.setStatus(Status.OFFLINE);
} else if (isServiceUnavailable(exception)) {
ServiceUnavailableException e = (ServiceUnavailableException) exception;
logTransportMessage(remoteNode, "Remote node {} at {} was unavailable{}", remoteNode, syncUrl, e.getMessage() == null ? "" : ": " + e.getMessage());
logTransportMessage(remoteNode, "Remote node {} at {} was unavailable {}", remoteNode, syncUrl, e.getMessage() == null ? ""
: ": " + e.getMessage());
status.setStatus(Status.OFFLINE);
} else if (isServiceNotReady(exception)) {
logTransportMessage(remoteNode, "Remote node {} at {} service not ready", remoteNode, syncUrl);
status.setStatus(Status.OFFLINE);
} else if (isBusy(exception)) {
logTransportMessage(remoteNode, "Remote node {} at {} was busy", remoteNode, syncUrl);
Expand Down Expand Up @@ -190,6 +195,10 @@ protected boolean isServiceUnavailable(Exception ex) {
return is(ex, ServiceUnavailableException.class);
}

protected boolean isServiceNotReady(Exception ex) {
return is(ex, ServiceNotReadyException.class);
}

protected boolean isSyncDisabled(Exception ex) {
return is(ex, SyncDisabledException.class);
}
Expand Down
Expand Up @@ -559,7 +559,10 @@ protected Trigger buildTriggerForSymmetricTable(String tableName, Set<String> co
} else if (TableConstants.getTableName(tablePrefix, TableConstants.SYM_MONITOR_EVENT).equals(tableName) ||
TableConstants.getTableName(tablePrefix, TableConstants.SYM_TABLE_RELOAD_REQUEST).equals(tableName) ||
TableConstants.getTableName(tablePrefix, TableConstants.SYM_TABLE_RELOAD_STATUS).equals(tableName) ||
TableConstants.getTableName(tablePrefix, TableConstants.SYM_EXTRACT_REQUEST).equals(tableName)) {
TableConstants.getTableName(tablePrefix, TableConstants.SYM_EXTRACT_REQUEST).equals(tableName) ||
TableConstants.getTableName(tablePrefix, TableConstants.SYM_COMPARE_REQUEST).equals(tableName) ||
TableConstants.getTableName(tablePrefix, TableConstants.SYM_COMPARE_STATUS).equals(tableName) ||
TableConstants.getTableName(tablePrefix, TableConstants.SYM_COMPARE_TABLE_STATUS).equals(tableName)) {
trigger.setChannelId(Constants.CHANNEL_MONITOR);
trigger.setUseCaptureOldData(true);
} else if (TableConstants.getTableName(tablePrefix, TableConstants.SYM_FILE_SNAPSHOT)
Expand Down
@@ -0,0 +1,25 @@
/**
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU General Public License, version 3.0 (GPLv3)
* (the "License"); you may not use this file except in compliance
* with the License.
*
* You should have received a copy of the GNU General Public License,
* version 3.0 (GPLv3) along with this library; if not, see
* <http://www.gnu.org/licenses/>.
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.jumpmind.symmetric.transport;

public class ServiceNotReadyException extends OfflineException {
private static final long serialVersionUID = 1L;
}
Expand Up @@ -40,6 +40,7 @@
import org.jumpmind.symmetric.transport.ConnectionRejectedException;
import org.jumpmind.symmetric.transport.IIncomingTransport;
import org.jumpmind.symmetric.transport.NoContentException;
import org.jumpmind.symmetric.transport.ServiceNotReadyException;
import org.jumpmind.symmetric.transport.ServiceUnavailableException;
import org.jumpmind.symmetric.transport.SyncDisabledException;
import org.jumpmind.symmetric.transport.TransportUtils;
Expand Down Expand Up @@ -139,6 +140,8 @@ public InputStream openStream() throws IOException {
throw new ConnectionDuplicateException();
case WebConstants.SC_SERVICE_UNAVAILABLE:
throw new ServiceUnavailableException();
case WebConstants.SC_SERVICE_NOT_READY:
throw new ServiceNotReadyException();
case WebConstants.SC_FORBIDDEN:
httpTransportManager.clearSession(connection);
throw new AuthenticationException();
Expand Down
Expand Up @@ -48,6 +48,7 @@
import org.jumpmind.symmetric.transport.ConnectionRejectedException;
import org.jumpmind.symmetric.transport.IOutgoingWithResponseTransport;
import org.jumpmind.symmetric.transport.NoReservationException;
import org.jumpmind.symmetric.transport.ServiceNotReadyException;
import org.jumpmind.symmetric.transport.ServiceUnavailableException;
import org.jumpmind.symmetric.transport.SyncDisabledException;
import org.jumpmind.symmetric.web.WebConstants;
Expand Down Expand Up @@ -259,6 +260,8 @@ private void analyzeResponseCode(int code) {
throw new ConnectionRejectedException();
} else if (WebConstants.SC_SERVICE_UNAVAILABLE == code) {
throw new ServiceUnavailableException();
} else if (WebConstants.SC_SERVICE_NOT_READY == code) {
throw new ServiceNotReadyException();
} else if (WebConstants.SC_NO_RESERVATION == code) {
throw new NoReservationException();
} else if (WebConstants.SC_ALREADY_CONNECTED == code) {
Expand Down
Expand Up @@ -46,6 +46,7 @@ public class WebConstants {
public static final int SC_AUTH_EXPIRED = 669;
public static final int SC_SERVICE_UNAVAILABLE = 660;
public static final int SC_SERVICE_BUSY = 670;
public static final int SC_SERVICE_NOT_READY = 671;
public static final int SC_SERVICE_ERROR = 601;
public static final int SC_NO_RESERVATION = 604;
public static final int SC_ALREADY_CONNECTED = 605;
Expand Down
Expand Up @@ -106,6 +106,8 @@ public H2DdlBuilder() {
databaseInfo.setEmptyStringNulled(false);
databaseInfo.setNullAsDefaultValueRequired(true);
databaseInfo.setGeneratedColumnsSupported(true);
databaseInfo.setBinaryQuoteStart("X'");
databaseInfo.setBinaryQuoteEnd("'");
}

@Override
Expand Down
Expand Up @@ -439,7 +439,7 @@ public Object[] getValueArray(Map<String, Object> params) {

public String buildDynamicSql(BinaryEncoding encoding, Row row,
boolean useVariableDates, boolean useJdbcTimestampFormat, Column[] columns) {
String newSql = sql;
String newSql = getSql(false);
String quote = databaseInfo.getValueQuoteToken();
String binaryQuoteStart = databaseInfo.getBinaryQuoteStart();
String binaryQuoteEnd = databaseInfo.getBinaryQuoteEnd();
Expand Down Expand Up @@ -473,6 +473,10 @@ public String buildDynamicSql(BinaryEncoding encoding, Row row,
newSql = newSql.replaceFirst(regex, (useJdbcTimestampFormat ? "{t " : "")
+ quote + FormatUtils.TIME_FORMATTER.format(date) + quote
+ (useJdbcTimestampFormat ? "}" : ""));
} else if (type == Types.DATE) {
newSql = newSql.replaceFirst(regex, (useJdbcTimestampFormat ? "{d " : "")
+ quote + FormatUtils.DATE_FORMATTER.format(date) + quote
+ (useJdbcTimestampFormat ? "}" : ""));
} else {
newSql = newSql.replaceFirst(regex, (useJdbcTimestampFormat ? "{ts " : "")
+ quote + FormatUtils.TIMESTAMP_FORMATTER.format(date) + quote
Expand Down
Expand Up @@ -97,6 +97,11 @@ public DmlStatementOptions textColumnExpression(String textColumnExpression) {
return this;
}

public DmlStatementOptions dmlType(DmlType dmlType) {
this.dmlType = dmlType;
return this;
}

public DmlType getDmlType() {
return dmlType;
}
Expand Down
Expand Up @@ -54,6 +54,7 @@ public final class FormatUtils {
};
public static final FastDateFormat TIMESTAMP_FORMATTER = FastDateFormat
.getInstance("yyyy-MM-dd HH:mm:ss.SSS");
public static final FastDateFormat DATE_FORMATTER = FastDateFormat.getInstance("yyyy-MM-dd");
public static final DateTimeFormatter TIMESTAMP9_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.nnnnnnnnn").withZone(ZoneId.systemDefault());
public static final FastDateFormat TIME_FORMATTER = FastDateFormat.getInstance("HH:mm:ss.SSS");
public static final DateTimeFormatter TIME9_FORMATTER = DateTimeFormatter.ofPattern("HH:mm:ss.nnnnnnnnn").withZone(ZoneId.systemDefault());
Expand Down

0 comments on commit 4f93158

Please sign in to comment.