Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
69 changed files
with
11,613 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>org.jumpmind.symmetric</groupId> | ||
<artifactId>symmetric-jdbc</artifactId> | ||
<packaging>jar</packaging> | ||
<version>3.0.0-SNAPSHOT</version> | ||
<name>jdbc</name> | ||
<url>http://symmetricds.org</url> | ||
|
||
<parent> | ||
<groupId>org.jumpmind.symmetric</groupId> | ||
<artifactId>symmetric-parent</artifactId> | ||
<version>3.0.0-SNAPSHOT</version> | ||
<relativePath>../symmetric-parent/pom.xml</relativePath> | ||
</parent> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>2.2</version> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>test-jar</goal> | ||
</goals> | ||
<phase>test-compile</phase> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<outputDirectory>${basedir}\target</outputDirectory> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jumpmind.symmetric</groupId> | ||
<artifactId>symmetric-util</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jumpmind.symmetric</groupId> | ||
<artifactId>symmetric-db</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>log4j</groupId> | ||
<artifactId>log4j</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-jdbc</artifactId> | ||
</dependency> | ||
<!-- Databases --> | ||
<dependency> | ||
<groupId>org.apache.derby</groupId> | ||
<artifactId>derby</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.derby</groupId> | ||
<artifactId>derbytools</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>mysql</groupId> | ||
<artifactId>mysql-connector-java</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>postgresql</groupId> | ||
<artifactId>postgresql</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>net.sourceforge.jtds</groupId> | ||
<artifactId>jtds</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.hsqldb</groupId> | ||
<artifactId>hsqldb</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.h2database</groupId> | ||
<artifactId>h2</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
</dependencies> | ||
</project> |
81 changes: 81 additions & 0 deletions
81
...c/symmetric-jdbc/src/main/java/org/jumpmind/db/platform/AbstractJdbcDatabasePlatform.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,81 @@ | ||
package org.jumpmind.db.platform; | ||
|
||
import java.sql.SQLException; | ||
|
||
import javax.sql.DataSource; | ||
|
||
import org.jumpmind.db.AbstractDatabasePlatform; | ||
import org.jumpmind.db.sql.ISqlTemplate; | ||
import org.jumpmind.db.sql.jdbc.JdbcSqlTemplate; | ||
import org.jumpmind.log.Log; | ||
|
||
abstract public class AbstractJdbcDatabasePlatform extends AbstractDatabasePlatform { | ||
|
||
protected DataSource dataSource; | ||
|
||
protected ISqlTemplate sqlTemplate; | ||
|
||
protected DatabasePlatformSettings settings; | ||
|
||
public AbstractJdbcDatabasePlatform(DataSource dataSource, DatabasePlatformSettings settings, Log log) { | ||
super(log); | ||
this.dataSource = dataSource; | ||
this.settings = settings; | ||
createSqlTemplate(); | ||
} | ||
|
||
protected void createSqlTemplate() { | ||
this.sqlTemplate = new JdbcSqlTemplate(dataSource, settings, null); | ||
} | ||
|
||
@Override | ||
public ISqlTemplate getSqlTemplate() { | ||
return sqlTemplate; | ||
} | ||
|
||
public boolean isPrimaryKeyViolation(Exception ex) { | ||
boolean primaryKeyViolation = false; | ||
if (primaryKeyViolationCodes != null || primaryKeyViolationSqlStates != null) { | ||
SQLException sqlEx = findSQLException(ex); | ||
if (sqlEx != null) { | ||
if (primaryKeyViolationCodes != null) { | ||
int errorCode = sqlEx.getErrorCode(); | ||
for (int primaryKeyViolationCode : primaryKeyViolationCodes) { | ||
if (primaryKeyViolationCode == errorCode) { | ||
primaryKeyViolation = true; | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if (primaryKeyViolationSqlStates != null) { | ||
String sqlState = sqlEx.getSQLState(); | ||
if (sqlState != null) { | ||
for (String primaryKeyViolationSqlState : primaryKeyViolationSqlStates) { | ||
if (primaryKeyViolationSqlState != null | ||
&& primaryKeyViolationSqlState.equals(sqlState)) { | ||
primaryKeyViolation = true; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return primaryKeyViolation; | ||
} | ||
|
||
protected SQLException findSQLException(Throwable ex) { | ||
if (ex instanceof SQLException) { | ||
return (SQLException) ex; | ||
} else { | ||
Throwable cause = ex.getCause(); | ||
if (cause != null && !cause.equals(ex)) { | ||
return findSQLException(cause); | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
} |
Oops, something went wrong.