syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmarte...@apache.org
Subject svn commit: r1450761 - in /syncope/trunk/core/src/main/java/org/apache/syncope/core: init/JobInstanceLoader.java util/ImportExport.java util/multiparent/MultiParentNodeOp.java
Date Wed, 27 Feb 2013 12:38:52 GMT
Author: fmartelli
Date: Wed Feb 27 12:38:51 2013
New Revision: 1450761

URL: http://svn.apache.org/r1450761
Log:
SYNCOPE-278 - fix for a mysql db export

Modified:
    syncope/trunk/core/src/main/java/org/apache/syncope/core/init/JobInstanceLoader.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ImportExport.java
    syncope/trunk/core/src/main/java/org/apache/syncope/core/util/multiparent/MultiParentNodeOp.java

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/init/JobInstanceLoader.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/init/JobInstanceLoader.java?rev=1450761&r1=1450760&r2=1450761&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/init/JobInstanceLoader.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/init/JobInstanceLoader.java Wed
Feb 27 12:38:51 2013
@@ -214,7 +214,7 @@ public class JobInstanceLoader {
     }
 
     @SuppressWarnings("unchecked")
-    @Transactional(readOnly = true)
+    @Transactional
     public void load() {
         // 1. jobs for SchedTasks
         Set<SchedTask> tasks = new HashSet(taskDAO.findAll(SchedTask.class));

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ImportExport.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ImportExport.java?rev=1450761&r1=1450760&r2=1450761&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ImportExport.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/util/ImportExport.java Wed Feb
27 12:38:51 2013
@@ -21,6 +21,7 @@ package org.apache.syncope.core.util;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.lang.String;
 import java.sql.Blob;
 import java.sql.Connection;
 import java.sql.DatabaseMetaData;
@@ -43,6 +44,7 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
 import java.util.TreeMap;
+import java.util.TreeSet;
 import javax.persistence.EntityManager;
 import javax.persistence.Query;
 import javax.persistence.TemporalType;
@@ -93,15 +95,15 @@ public class ImportExport extends Defaul
     @Autowired
     private DataSource dataSource;
 
-    private final Set<String> tablePrefixesToBeExcluded = new HashSet<String>(
-            Arrays.asList(new String[]{"QRTZ_", "LOGGING", "REPORTEXEC", "TASKEXEC",
+    private final static Set<String> TABLE_PREFIXES_TO_BE_EXCLUDED =
+            new HashSet<String>(Arrays.asList(new String[]{"QRTZ_", "LOGGING", "REPORTEXEC",
"TASKEXEC",
                 "SYNCOPEUSER", "UATTR", "UATTRVALUE", "UATTRUNIQUEVALUE", "UDERATTR", "UVIRATTR",
-                "MEMBERSHIP", "MATTR", "MATTRVALUE", "MATTRUNIQUEVALUE", "MDERATTR", "MVIRATTR"}));
+                "MEMBERSHIP", "MATTR", "MATTRVALUE", "MATTRUNIQUEVALUE", "MDERATTR", "MVIRATTR",
"USERREQUEST"}));
 
-    private final Map<String, String> tablesTobeFiltered =
+    private final static Map<String, String> TABLES_TO_BE_FILTERED =
             Collections.singletonMap("TASK", "DTYPE <> 'PropagationTask'");
 
-    private final Map<String, Set<String>> columnsToBeNullified =
+    private final static Map<String, Set<String>> COLUMNS_TO_BE_NULLIFIED =
             Collections.singletonMap("SYNCOPEROLE", Collections.singleton("USEROWNER_ID"));
 
     private String[] wfInitSQLStatements;
@@ -305,6 +307,8 @@ public class ImportExport extends Defaul
     private void doExportTable(final TransformerHandler handler, final Connection conn, final
String tableName,
             final String whereClause) throws SQLException, SAXException {
 
+        LOG.debug("Export table {}", tableName);
+
         AttributesImpl attrs = new AttributesImpl();
 
         PreparedStatement stmt = null;
@@ -352,8 +356,8 @@ public class ImportExport extends Defaul
 
                     // Retrieve value taking care of binary values.
                     String value = getValues(rs, columnName, columnType);
-                    if (value != null && (!columnsToBeNullified.containsKey(tableName)
-                            || !columnsToBeNullified.get(tableName).contains(columnName)))
{
+                    if (value != null && (!COLUMNS_TO_BE_NULLIFIED.containsKey(tableName)
+                            || !COLUMNS_TO_BE_NULLIFIED.get(tableName).contains(columnName)))
{
 
                         attrs.addAttribute("", "", columnName, "CDATA", value);
                     }
@@ -361,6 +365,8 @@ public class ImportExport extends Defaul
 
                 handler.startElement("", "", tableName, attrs);
                 handler.endElement("", "", tableName);
+
+                LOG.debug("Add record {}", attrs);
             }
         } finally {
             if (rs != null) {
@@ -448,16 +454,20 @@ public class ImportExport extends Defaul
         final List<String> sortedTableNames = new ArrayList<String>(tableNames.size());
         MultiParentNodeOp.traverseTree(roots, sortedTableNames);
 
-        Collections.reverse(sortedTableNames);
         // remove from sortedTableNames any table possibly added during lookup 
         // but matching some item in this.tablePrefixesToBeExcluded
         sortedTableNames.retainAll(tableNames);
+
+        LOG.debug("Tables after retainAll {}", sortedTableNames);
+
+        Collections.reverse(sortedTableNames);
+
         return sortedTableNames;
     }
 
     private boolean isTableAllowed(final String tableName) {
         boolean allowed = true;
-        for (String prefix : tablePrefixesToBeExcluded) {
+        for (String prefix : TABLE_PREFIXES_TO_BE_EXCLUDED) {
             if (tableName.toUpperCase().startsWith(prefix)) {
                 allowed = false;
             }
@@ -469,7 +479,7 @@ public class ImportExport extends Defaul
             throws SAXException, TransformerConfigurationException {
 
         if (StringUtils.isNotBlank(wfTablePrefix)) {
-            tablePrefixesToBeExcluded.add(wfTablePrefix);
+            TABLE_PREFIXES_TO_BE_EXCLUDED.add(wfTablePrefix);
         }
 
         StreamResult streamResult = new StreamResult(os);
@@ -493,18 +503,25 @@ public class ImportExport extends Defaul
 
             rs = meta.getTables(null, schema, null, new String[]{"TABLE"});
 
-            final Set<String> tableNames = new HashSet<String>();
+            final Set<String> tableNames = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
 
             while (rs.next()) {
                 String tableName = rs.getString("TABLE_NAME");
+                LOG.debug("Found table {}", tableName);
                 if (isTableAllowed(tableName)) {
                     tableNames.add(tableName);
                 }
             }
 
+            LOG.debug("Tables to be exported {}", tableNames);
+
             // then sort tables based on foreign keys and dump
             for (String tableName : sortByForeignKeys(conn, tableNames, schema)) {
-                doExportTable(handler, conn, tableName, tablesTobeFiltered.get(tableName.toUpperCase()));
+                try {
+                    doExportTable(handler, conn, tableName, TABLES_TO_BE_FILTERED.get(tableName.toUpperCase()));
+                } catch (Exception e) {
+                    LOG.error("Failure exporting table {}", tableName, e);
+                }
             }
         } catch (SQLException e) {
             LOG.error("While exporting database content", e);

Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/util/multiparent/MultiParentNodeOp.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/util/multiparent/MultiParentNodeOp.java?rev=1450761&r1=1450760&r2=1450761&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/util/multiparent/MultiParentNodeOp.java
(original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/util/multiparent/MultiParentNodeOp.java
Wed Feb 27 12:38:51 2013
@@ -18,7 +18,7 @@
  */
 package org.apache.syncope.core.util.multiparent;
 
-import java.util.List;
+import java.util.Collection;
 import java.util.Set;
 
 public class MultiParentNodeOp {
@@ -26,13 +26,13 @@ public class MultiParentNodeOp {
     private MultiParentNodeOp() {
     }
 
-    public static <T> void traverseTree(final Set<MultiParentNode<T>> roots,
final List<T> objects) {
+    public static <T> void traverseTree(final Set<MultiParentNode<T>> roots,
final Collection<T> objects) {
         for (MultiParentNode<T> root : roots) {
             traverseTree(root, objects);
         }
     }
 
-    public static <T> void traverseTree(final MultiParentNode<T> root, final
List<T> objects) {
+    public static <T> void traverseTree(final MultiParentNode<T> root, final
Collection<T> objects) {
 
         root.setExploited(true);
 



Mime
View raw message