Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
chenson42 committed Dec 29, 2011
1 parent 2c5c303 commit 494a6c4
Show file tree
Hide file tree
Showing 69 changed files with 11,613 additions and 0 deletions.
98 changes: 98 additions & 0 deletions symmetric/symmetric-jdbc/pom.xml
@@ -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>
@@ -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;
}

}

0 comments on commit 494a6c4

Please sign in to comment.