Author: tolusha
Date: 2011-01-12 08:42:15 -0500 (Wed, 12 Jan 2011)
New Revision: 3791
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/BackupTables.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/RestoreTableRule.java
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/RestoreTables.java
Log:
EXOJCR-1096: Test on all supported database: sybase
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java 2011-01-12
09:41:40 UTC (rev 3790)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/JDBCWorkspaceDataContainer.java 2011-01-12
13:42:15 UTC (rev 3791)
@@ -65,6 +65,7 @@
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
+import java.sql.Types;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
@@ -1112,6 +1113,8 @@
{
// CONTAINER_NAME column index
restoreTableRule.setNewColumnIndex(4);
+ restoreTableRule.setNewColumnName("CONTAINER_NAME");
+ restoreTableRule.setNewColumnType(Types.VARCHAR);
// ID and PARENT_ID column indexes
Set<Integer> convertColumnIndex = new HashSet<Integer>();
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/BackupTables.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/BackupTables.java 2011-01-12
09:41:40 UTC (rev 3790)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/BackupTables.java 2011-01-12
13:42:15 UTC (rev 3791)
@@ -99,6 +99,11 @@
public static final int DB_DIALECT_PGSQL = DBConstants.DB_DIALECT_PGSQL.hashCode();
/**
+ * SYBASE dialect.
+ */
+ public static final int DB_DIALECT_SYBASE = DBConstants.DB_DIALECT_SYBASE.hashCode();
+
+ /**
* {@inheritDoc}
*/
public static void backup(File storageDir, String dsName, Map<String, String>
scripts) throws BackupException
@@ -219,9 +224,9 @@
for (int i = 0; i < columnCount; i++)
{
InputStream value;
- if (dialect == DB_DIALECT_HSQLDB)
+ if (dialect == DB_DIALECT_HSQLDB || dialect == DB_DIALECT_SYBASE)
{
- if (columnType[i] == Types.VARBINARY)
+ if (columnType[i] == Types.VARBINARY || columnType[i] ==
Types.LONGVARBINARY)
{
value = rs.getBinaryStream(i + 1);
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/RestoreTableRule.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/RestoreTableRule.java 2011-01-12
09:41:40 UTC (rev 3790)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/RestoreTableRule.java 2011-01-12
13:42:15 UTC (rev 3791)
@@ -38,15 +38,19 @@
private Integer newColumnIndex = null;
+ private String newColumnName = null;
+
+ private Integer newColumnType = null;
+
private Set<Integer> convertColumnIndex = new HashSet<Integer>();
- private String srcContainerName;
+ private String srcContainerName = null;
- private String dstContainerName;
+ private String dstContainerName = null;
- private Boolean srcMultiDb;
+ private Boolean srcMultiDb = null;
- private Boolean dstMultiDb;
+ private Boolean dstMultiDb = null;
public File getContentFile()
{
@@ -147,4 +151,25 @@
{
this.dstMultiDb = dstMultiDb;
}
+
+ public String getNewColumnName()
+ {
+ return newColumnName;
+ }
+
+ public void setNewColumnName(String newColumnName)
+ {
+ this.newColumnName = newColumnName;
+ }
+
+ public Integer getNewColumnType()
+ {
+ return newColumnType;
+ }
+
+ public void setNewColumnType(Integer newColumnType)
+ {
+ this.newColumnType = newColumnType;
+ }
+
}
Modified:
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/RestoreTables.java
===================================================================
---
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/RestoreTables.java 2011-01-12
09:41:40 UTC (rev 3790)
+++
jcr/trunk/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/storage/jdbc/backup/util/RestoreTables.java 2011-01-12
13:42:15 UTC (rev 3791)
@@ -101,6 +101,7 @@
throws RestoreException
{
Connection jdbcConn = null;
+ Connection jdbcConn1 = null;
Statement st = null;
RestoreException exc = null;
@@ -132,7 +133,8 @@
String constraint = null;
if (tableName.equals("JCR_SITEM") ||
tableName.equals("JCR_MITEM"))
{
- if (dialect != BackupTables.DB_DIALECT_MYSQL && dialect !=
BackupTables.DB_DIALECT_MYSQL_UTF8)
+ if (dialect != BackupTables.DB_DIALECT_MYSQL && dialect !=
BackupTables.DB_DIALECT_MYSQL_UTF8
+ && dialect != BackupTables.DB_DIALECT_SYBASE)
{
// resolve constraint name depends on database
String constraintName;
@@ -246,7 +248,8 @@
/**
* Restore table.
*/
- private void restore(File storageDir, Connection jdbcConn, String tableName,
RestoreTableRule restoreRule)
+ private void restore(File storageDir, Connection jdbcConn, String tableName,
+ RestoreTableRule restoreRule)
throws IOException, SQLException
{
// Need privileges
@@ -291,17 +294,6 @@
columnName.add(contentReader.readString());
}
- // collect information about target table
- List<Integer> newColumnType = new ArrayList<Integer>();
- List<String> newColumnName = new ArrayList<String>();
-
- tableMetaData = jdbcConn.getMetaData().getColumns(null, null, tableName,
"%");
- while (tableMetaData.next())
- {
- newColumnName.add(tableMetaData.getString("COLUMN_NAME"));
- newColumnType.add(tableMetaData.getInt("DATA_TYPE"));
- }
-
int targetColumnCount = sourceColumnCount;
if (restoreRule.getDeleteColumnIndex() != null)
{
@@ -310,7 +302,13 @@
else if (restoreRule.getNewColumnIndex() != null)
{
targetColumnCount++;
- columnType.add(restoreRule.getNewColumnIndex(),
newColumnType.get(restoreRule.getNewColumnIndex()));
+
+ columnType.add(restoreRule.getNewColumnIndex(),
restoreRule.getNewColumnType());
+
+ String newColumnName =
+ dialect == BackupTables.DB_DIALECT_PGSQL ?
restoreRule.getNewColumnName().toLowerCase() : restoreRule
+ .getNewColumnName();
+ columnName.add(restoreRule.getNewColumnIndex(), newColumnName);
}
// construct statement
@@ -322,7 +320,7 @@
{
continue;
}
- names += newColumnName.get(i) + (i == targetColumnCount - 1 ? "" :
",");
+ names += columnName.get(i) + (i == targetColumnCount - 1 ? "" :
",");
parameters += "?" + (i == targetColumnCount - 1 ? "" :
",");
}
insertNode =
@@ -467,9 +465,9 @@
}
else
{
- if (dialect == BackupTables.DB_DIALECT_HSQLDB)
+ if (dialect == BackupTables.DB_DIALECT_HSQLDB || dialect ==
BackupTables.DB_DIALECT_SYBASE)
{
- if (columnType.get(i) == Types.VARBINARY)
+ if (columnType.get(i) == Types.VARBINARY || columnType.get(i) ==
Types.LONGVARBINARY)
{
insertNode.setBinaryStream(targetIndex + 1, stream,
(int)len);
}
@@ -492,11 +490,10 @@
insertNode.setNull(targetIndex + 1, columnType.get(i));
}
}
- // insertNode.addBatch();
- insertNode.executeUpdate();
+ insertNode.addBatch();
}
- // insertNode.executeBatch();
+ insertNode.executeBatch();
}
finally
{