Skip to content

Commit

Permalink
Fix multiple ASE 12.5 compatibility issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
abrougher committed May 24, 2013
1 parent b4f4686 commit 8e28076
Show file tree
Hide file tree
Showing 7 changed files with 164 additions and 61 deletions.
@@ -1,7 +1,9 @@
package org.jumpmind.symmetric.db.ase;

import java.sql.Types;
import java.util.HashMap;

import org.apache.commons.lang.NotImplementedException;
import org.jumpmind.db.model.Column;
import org.jumpmind.db.model.Table;
import org.jumpmind.symmetric.db.AbstractTriggerTemplate;
Expand All @@ -20,8 +22,9 @@ public AseTriggerTemplate(ISymmetricDialect symmetricDialect) {
stringColumnTemplate = "case when $(tableAlias).\"$(columnName)\" is null then '' else '\"' + str_replace(str_replace($(tableAlias).\"$(columnName)\",'\\','\\\\'),'\"','\\\"') + '\"' end" ;
numberColumnTemplate = "case when $(tableAlias).\"$(columnName)\" is null then '' else ('\"' + convert(varchar,$(tableAlias).\"$(columnName)\") + '\"') end" ;
datetimeColumnTemplate = "case when $(tableAlias).\"$(columnName)\" is null then '' else ('\"' + str_replace(convert(varchar,$(tableAlias).\"$(columnName)\",102),'.','-') + ' ' + convert(varchar,$(tableAlias).\"$(columnName)\",108) + '\"') end" ;
clobColumnTemplate = "case when $(origTableAlias).\"$(columnName)\" is null then '' else '\"' + str_replace(str_replace(cast($(origTableAlias).\"$(columnName)\" as varchar(16384)),'\\','\\\\'),'\"','\\\"') + '\"' end" ;
clobColumnTemplate = "case when datalength($(origTableAlias).\"$(columnName)\") is null or datalength($(origTableAlias).\"$(columnName)\")=0 then '' else '\"' + str_replace(str_replace(cast($(origTableAlias).\"$(columnName)\" as varchar(16384)),'\\','\\\\'),'\"','\\\"') + '\"' end" ;
blobColumnTemplate = "case when $(origTableAlias).\"$(columnName)\" is null then '' else '\"' + bintostr(convert(varbinary(16384),$(origTableAlias).\"$(columnName)\")) + '\"' end" ;
imageColumnTemplate = "case when datalength($(origTableAlias).\"$(columnName)\") is null or datalength($(origTableAlias).\"$(columnName)\")=0 then '' else '\"' + bintostr(convert(varbinary(16384),$(origTableAlias).\"$(columnName)\")) + '\"' end" ;
booleanColumnTemplate = "case when $(tableAlias).\"$(columnName)\" is null then '' when $(tableAlias).\"$(columnName)\" = 1 then '\"1\"' else '\"0\"' end" ;
triggerConcatCharacter = "+" ;
newTriggerValue = "inserted" ;
Expand Down Expand Up @@ -144,7 +147,9 @@ public AseTriggerTemplate(ISymmetricDialect symmetricDialect) {
protected String replaceTemplateVariables(DataEventType dml, Trigger trigger,
TriggerHistory history, Channel channel, String tablePrefix, Table originalTable, Table table,
String defaultCatalog, String defaultSchema, String ddl) {
ddl = super.replaceTemplateVariables(dml, trigger, history, channel, tablePrefix, originalTable, table,
ddl = FormatUtils.replace("oldColumns", trigger.isUseCaptureOldData() ?
super.buildColumnString(ORIG_TABLE_ALIAS, oldTriggerValue, oldColumnPrefix, table.getColumns(), dml, true, channel, trigger).toString() : "convert(VARCHAR,null)", ddl);
ddl = super.replaceTemplateVariables(dml, trigger, history, channel, tablePrefix, originalTable, table,
defaultCatalog, defaultSchema, ddl);
Column[] columns = table.getPrimaryKeyColumns();
ddl = FormatUtils.replace("declareOldKeyVariables",
Expand All @@ -154,4 +159,71 @@ protected String replaceTemplateVariables(DataEventType dml, Trigger trigger,
return ddl;
}

@Override
protected String buildKeyVariablesDeclare(Column[] columns, String prefix) {
String text = "";
for (int i = 0; i < columns.length; i++) {
text += "declare @" + prefix + "pk" + i + " ";
switch (columns[i].getMappedTypeCode()) {
case Types.TINYINT:
case Types.SMALLINT:
case Types.INTEGER:
case Types.BIGINT:
// ASE does not support bigint
text += "NUMERIC(19,0)\n";
break;
case Types.NUMERIC:
case Types.DECIMAL:
text += "decimal\n";
break;
case Types.FLOAT:
case Types.REAL:
case Types.DOUBLE:
text += "float\n";
break;
case Types.CHAR:
case Types.VARCHAR:
case Types.LONGVARCHAR:
text += "varchar(1000)\n";
break;
case Types.DATE:
text += "date\n";
break;
case Types.TIME:
text += "time\n";
break;
case Types.TIMESTAMP:
text += "datetime\n";
break;
case Types.BOOLEAN:
case Types.BIT:
text += "bit\n";
break;
case Types.CLOB:
text += "varchar(max)\n";
break;
case Types.BLOB:
case Types.BINARY:
case Types.VARBINARY:
case Types.LONGVARBINARY:
case -10: // SQL-Server ntext binary type
text += "varbinary(max)\n";
break;
case Types.OTHER:
text += "varbinary(max)\n";
break;
default:
if (columns[i].getJdbcTypeName() != null
&& columns[i].getJdbcTypeName().equalsIgnoreCase("interval")) {
text += "interval";
break;
}
throw new NotImplementedException(columns[i] + " is of type "
+ columns[i].getMappedType());
}
}

return text;
}

}
@@ -1,22 +1,22 @@
/*
* Licensed to JumpMind Inc under one or more contributor
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU Lesser General Public License (the
* "License"); you may not use this file except in compliance
* with the License.
*
* with the License.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see
* License 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.
* under the License.
*/

package org.jumpmind.symmetric.db;
Expand Down Expand Up @@ -84,6 +84,8 @@ abstract public class AbstractTriggerTemplate {

protected String blobColumnTemplate;

protected String imageColumnTemplate;

protected String wrappedBlobColumnTemplate;

protected String booleanColumnTemplate;
Expand All @@ -104,17 +106,17 @@ abstract public class AbstractTriggerTemplate {

protected AbstractTriggerTemplate() {
}

protected AbstractTriggerTemplate(ISymmetricDialect symmetricDialect) {
this.symmetricDialect = symmetricDialect;
}

public String createInitalLoadSql(Node node, TriggerRouter triggerRouter, Table originalTable,
TriggerHistory triggerHistory, Channel channel, String overrideSelectSql) {

Table table = originalTable.copyAndFilterColumns(triggerHistory.getParsedColumnNames(),
triggerHistory.getParsedPkColumnNames(), true);

String sql = sqlTemplates.get(INITIAL_LOAD_SQL_TEMPLATE);
Column[] columns = symmetricDialect.orderColumns(triggerHistory.getParsedColumnNames(),
table);
Expand Down Expand Up @@ -171,7 +173,7 @@ protected String getSourceTablePrefix(TriggerHistory triggerHistory) {
.getSourceCatalogName()) + "." : "")
+ schemaPlus;
return catalogPlus;
}
}

protected String replaceDefaultSchemaAndCatalog(String sql) {
String defaultCatalog = symmetricDialect.getPlatform().getDefaultCatalog();
Expand All @@ -183,10 +185,10 @@ protected String replaceDefaultSchemaAndCatalog(String sql) {

public String createCsvDataSql(Trigger trigger, TriggerHistory triggerHistory, Table originalTable,
Channel channel, String whereClause) {

Table table = originalTable.copyAndFilterColumns(triggerHistory.getParsedColumnNames(),
triggerHistory.getParsedPkColumnNames(), true);
triggerHistory.getParsedPkColumnNames(), true);

String sql = sqlTemplates.get(INITIAL_LOAD_SQL_TEMPLATE);

Column[] columns = table.getColumns();
Expand Down Expand Up @@ -242,14 +244,14 @@ public String createCsvPrimaryKeySql(Trigger trigger, TriggerHistory triggerHist
public String createTriggerDDL(DataEventType dml, Trigger trigger, TriggerHistory history,
Channel channel, String tablePrefix, Table originalTable, String defaultCatalog,
String defaultSchema) {

Table table = originalTable.copyAndFilterColumns(history.getParsedColumnNames(),
history.getParsedPkColumnNames(), true);

String ddl = sqlTemplates.get(dml.name().toLowerCase() + "TriggerTemplate");
if (dml.getDmlType().equals(DmlType.UPDATE) && trigger.isUseHandleKeyUpdates()) {
ddl = sqlTemplates.get(dml.name().toLowerCase() + "HandleKeyUpdates" + "TriggerTemplate");
}
}
if (ddl == null) {
throw new NotImplementedException(dml.name() + " trigger is not implemented for "
+ symmetricDialect.getPlatform().getName());
Expand All @@ -261,10 +263,10 @@ public String createTriggerDDL(DataEventType dml, Trigger trigger, TriggerHistor
public String createPostTriggerDDL(DataEventType dml, Trigger trigger, TriggerHistory history,
Channel channel, String tablePrefix, Table originalTable, String defaultCatalog,
String defaultSchema) {

Table table = originalTable.copyAndFilterColumns(history.getParsedColumnNames(),
history.getParsedPkColumnNames(), true);

String ddl = sqlTemplates.get(dml.name().toLowerCase() + "PostTriggerTemplate");
return replaceTemplateVariables(dml, trigger, history, channel, tablePrefix, originalTable, table,
defaultCatalog, defaultSchema, ddl);
Expand Down Expand Up @@ -608,6 +610,14 @@ protected ColumnString buildColumnString(String origTableAlias, String tableAlia
.contains(TypeMap.GEOMETRY))
&& StringUtils.isNotBlank(geometryColumnTemplate)) {
templateToUse = geometryColumnTemplate;
} else if (column.getJdbcTypeName()!=null && (column.getJdbcTypeName().toUpperCase()
.contains(TypeMap.IMAGE))
&& StringUtils.isNotBlank(imageColumnTemplate)) {
if (isOld) {
templateToUse = emptyColumnTemplate;
} else {
templateToUse = imageColumnTemplate;
}
} else if (isOld && symmetricDialect.needsToSelectLobData()) {
templateToUse = emptyColumnTemplate;
} else {
Expand Down Expand Up @@ -855,6 +865,14 @@ public void setDateColumnTemplate(String dateColumnTemplate) {
this.dateColumnTemplate = dateColumnTemplate;
}

public String getImageColumnTemplate() {
return imageColumnTemplate;
}

public void setImageColumnTemplate(String imageColumnTemplate) {
this.imageColumnTemplate = imageColumnTemplate;
}

protected class ColumnString {

String columnString;
Expand Down
@@ -1,22 +1,22 @@
/*
* Licensed to JumpMind Inc under one or more contributor
* Licensed to JumpMind Inc under one or more contributor
* license agreements. See the NOTICE file distributed
* with this work for additional information regarding
* with this work for additional information regarding
* copyright ownership. JumpMind Inc licenses this file
* to you under the GNU Lesser General Public License (the
* "License"); you may not use this file except in compliance
* with the License.
*
* with the License.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see
* License 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.
* under the License.
*/
package org.jumpmind.symmetric.service.impl;

Expand Down Expand Up @@ -80,7 +80,7 @@ public class RegistrationService extends AbstractService implements IRegistratio
private INodePasswordFilter nodePasswordFilter;

private IStatisticManager statisticManager;

private IConfigurationService configurationService;

public RegistrationService(IParameterService parameterService,
Expand Down Expand Up @@ -217,7 +217,7 @@ public boolean registerNode(Node nodePriorToRegistration, String remoteHost,
remoteHost, remoteAddress));

statisticManager.incrementNodesRegistered(1);

return true;

} catch (RegistrationNotOpenException ex) {
Expand Down Expand Up @@ -270,7 +270,9 @@ public void saveRegisgtrationRequest(RegistrationRequest request) {
getSql("insertRegistrationRequestSql"),
new Object[] { request.getLastUpdateBy(), request.getLastUpdateTime(),
request.getRegisteredNodeId(), request.getStatus().name(), nodeGroupId,
externalId, request.getIpAddress(), request.getHostName(), request.getErrorMessage() });
externalId, request.getIpAddress(), request.getHostName(), request.getErrorMessage() },
new int[] { Types.VARCHAR, Types.DATE, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR,
Types.VARCHAR, Types.VARCHAR, Types.VARCHAR, Types.VARCHAR });
}

}
Expand Down Expand Up @@ -315,7 +317,7 @@ public void markNodeAsRegistered(String nodeId) {
if (transaction != null) {
transaction.rollback();
}
throw ex;
throw ex;
} finally {
symmetricDialect.enableSyncTriggers(transaction);
close(transaction);
Expand Down Expand Up @@ -371,7 +373,7 @@ public void registerWithServer() {
+ identity.getNodeId() + "'", false, -1, null);
}
}

if (registered) {
Node node = nodeService.findIdentity();
if (node != null) {
Expand Down Expand Up @@ -435,8 +437,8 @@ public synchronized String openRegistration(String nodeGroup, String externalId)
public synchronized String openRegistration(Node node) {
return openRegistration(node, null, null);
}
protected String openRegistration(Node node, String remoteHost, String remoteAddress) {

protected String openRegistration(Node node, String remoteHost, String remoteAddress) {
Node me = nodeService.findIdentity();
if (me != null) {
String nodeId = nodeService.getNodeIdCreator().generateNodeId(node, remoteHost, remoteAddress);
Expand All @@ -449,7 +451,7 @@ protected String openRegistration(Node node, String remoteHost, String remoteAdd

// make sure there isn't a node security row lying around w/out
// a node row
nodeService.deleteNodeSecurity(nodeId);
nodeService.deleteNodeSecurity(nodeId);
String password = nodeService.getNodeIdCreator().generatePassword(node);
password = filterPasswordOnSaveIfNeeded(password);
sqlTemplate.update(getSql("openRegistrationNodeSecuritySql"), new Object[] {
Expand Down Expand Up @@ -479,9 +481,9 @@ private String filterPasswordOnSaveIfNeeded(String password) {
}
return s;
}

public void setNodePasswordFilter(INodePasswordFilter nodePasswordFilter) {
this.nodePasswordFilter = nodePasswordFilter;
this.nodePasswordFilter = nodePasswordFilter;
}

public boolean isRegistrationOpen(String nodeGroupId, String externalId) {
Expand Down
2 changes: 1 addition & 1 deletion symmetric-core/src/test/resources/test-schema.xml
Expand Up @@ -139,7 +139,7 @@
<column name="three_column" type="VARCHAR" size="50" required="true" />
</table>

<table name="initial_load_from_client_table">
<table name="init_load_from_client_table">
<column name="id" type="INTEGER" primaryKey="true" required="true" />
<column name="data" type="VARCHAR" size="10" />
</table>
Expand Down

0 comments on commit 8e28076

Please sign in to comment.