Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
0003751: PostgreSQL 9.5 can use "insert on conflict do nothing" for
better performance
- Loading branch information
Showing
9 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
symmetric-db/src/main/java/org/jumpmind/db/platform/postgresql/PostgreSqlDmlStatement95.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package org.jumpmind.db.platform.postgresql; | ||
|
||
import java.util.Map; | ||
|
||
import org.jumpmind.db.model.Column; | ||
import org.jumpmind.db.platform.DatabaseInfo; | ||
|
||
public class PostgreSqlDmlStatement95 extends PostgreSqlDmlStatement { | ||
|
||
public PostgreSqlDmlStatement95(DmlType type, String catalogName, String schemaName, String tableName, | ||
Column[] keysColumns, Column[] columns, boolean[] nullKeyValues, DatabaseInfo databaseInfo, | ||
boolean useQuotedIdentifiers, String textColumnExpression) { | ||
super(type, catalogName, schemaName, tableName, keysColumns, columns, nullKeyValues, databaseInfo, useQuotedIdentifiers, | ||
textColumnExpression); | ||
} | ||
|
||
@Override | ||
public String buildInsertSql(String tableName, Column[] keys, Column[] columns) { | ||
StringBuilder sql = new StringBuilder("insert into " + tableName + " ("); | ||
appendColumns(sql, columns, false); | ||
sql.append(") values ("); | ||
appendColumnParameters(sql, columns); | ||
sql.append(") on conflict do nothing"); | ||
return sql.toString(); | ||
} | ||
|
||
@Override | ||
public Column[] getMetaData() { | ||
if (dmlType == DmlType.INSERT) { | ||
return getColumns(); | ||
} else { | ||
return super.getMetaData(); | ||
} | ||
} | ||
|
||
@Override | ||
public <T> T[] getValueArray(T[] columnValues, T[] keyValues) { | ||
if (dmlType == DmlType.INSERT) { | ||
return columnValues; | ||
} else { | ||
return super.getValueArray(columnValues, keyValues); | ||
} | ||
} | ||
|
||
@Override | ||
public Object[] getValueArray(Map<String, Object> params) { | ||
if (dmlType == DmlType.INSERT) { | ||
int index = 0; | ||
Object[] args = new Object[columns.length]; | ||
for (Column column : columns) { | ||
args[index++] = params.get(column.getName()); | ||
} | ||
return args; | ||
} | ||
return super.getValueArray(params); | ||
} | ||
|
||
@Override | ||
protected int[] buildTypes(Column[] keys, Column[] columns, boolean isDateOverrideToTimestamp) { | ||
if (dmlType == DmlType.INSERT) { | ||
return buildTypes(columns, isDateOverrideToTimestamp); | ||
} else { | ||
return super.buildTypes(keys, columns, isDateOverrideToTimestamp); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
...-jdbc/src/main/java/org/jumpmind/db/platform/postgresql/PostgreSql95DatabasePlatform.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.jumpmind.db.platform.postgresql; | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* 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. | ||
*/ | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.jumpmind.db.platform.DatabaseNamesConstants; | ||
import org.jumpmind.db.sql.SqlTemplateSettings; | ||
|
||
public class PostgreSql95DatabasePlatform extends PostgreSqlDatabasePlatform { | ||
|
||
public PostgreSql95DatabasePlatform(DataSource dataSource, SqlTemplateSettings settings) { | ||
super(dataSource, settings); | ||
} | ||
|
||
public String getName() { | ||
return DatabaseNamesConstants.POSTGRESQL95; | ||
} | ||
|
||
} |