Package mydatagenerator.core.database.operations

Examples of mydatagenerator.core.database.operations.DatabaseTableUtils


                    
                     // flag to indicates if the user want clean also the ARCHIVE tables
                     boolean cleanArchiveTable = cleanArchiveTableSubPanel.getEnableArchiveCleaningCheckBox().isSelected();
                  
                    DatabaseCleaner databaseCleaner = new DatabaseCleaner();                   
                    DatabaseTableUtils databaseTableUtils = new DatabaseTableUtils();
                    
                     /* the TOTAL tables to clean */
                     int tableToClean = databaseTableUtils.getTableCount();
                    
                     logOutputTextArea.setBorder(BorderFactory.createLineBorder(Color.black)); //reset some error
                    logOutputTextArea.setText("Database analisys started...\n");
                    logOutputTextArea.append("Total database tables: "+tableToClean+"\n");
                   
                    /* ALL the database tables */
                    List<String> allTables = databaseTableUtils.getTableNamesOrdered();
                    
                    /* the tables with 'ARCHIVE' engine type */
                     List<String> archiveTables = databaseTableUtils.getArchiveTables();     
                    
                     //the tables without the Archive type ones
                     List<String> effectiveTablesToClean = new ArrayList<String>();                    
                    
                    long startTime = 0;
                    long endTime = 0;
                   
                    logOutputTextArea.append("Checking the presence of tables with unsupported store engine (ie 'ARCHIVE')...\n");
                   
                     if(!archiveTables.isEmpty()) // found Archive tables
                    
                       if(cleanArchiveTable)
                       { 
                         if(Log4jManager.IS_LOGGING_CONFIGURED)
                       logger.info("User want clean also the ARCHIVE tables");
                        
                           logOutputTextArea.append("* ATTENTION * Found "+archiveTables.size()+" tables with 'ARCHIVE' engine: trying to clean them changing engine type... \n");
                           logOutputTextArea.append("Total tables to clean: "+tableToClean+"\n");
                          
                           // change the engine type of the ARCHIVE tables
                           for(int i=0;i<archiveTables.size();i++)
                           {                           
                             databaseTableUtils.changeTableEngine(archiveTables.get(i),"InnoDB");
                            
                             if(Log4jManager.IS_LOGGING_CONFIGURED)
                         logger.debug("Changed the engine type of table "+archiveTables.get(i)+" to InnoDB");
                           }
                          
                           // clean ALL the tables
                           startTime = System.currentTimeMillis();                      
                           databaseCleaner.deleteAll(allTables.toArray(new String[]{}));                     
                           endTime = System.currentTimeMillis();
                          
                       }else{    // User don't want clean Archive tables
                        
                         if(Log4jManager.IS_LOGGING_CONFIGURED)
                       logger.info("The user DON'T want clean the ARCHIVE tables");
                        
                           logOutputTextArea.append("* ATTENTION * Found "+archiveTables.size()+" tables with 'ARCHIVE' engine: they will not be cleaned (See Mysql doc) !\n");
                           logOutputTextArea.append("Total tables cleanable: "+(tableToClean-archiveTables.size())+"\n");
                        
                           logOutputTextArea.append("Database cleaning started...\n");
                      
                           // remove tables with a storage engine that don't support the sql 'delete' operation (ie 'ARCHIVE' engine )
                           for(int i=0;i<allTables.size();i++)
                           {
                            if(!archiveTables.contains(allTables.get(i)))
                              effectiveTablesToClean.add(allTables.get(i));  
                           }
                      
                           // clean only the NON-ARCHIVE tables
                           startTime = System.currentTimeMillis();                      
                           databaseCleaner.deleteAll(effectiveTablesToClean.toArray(new String[]{}));                     
                           endTime = System.currentTimeMillis();                      
                       }
                      
                     }else{   
                        logOutputTextArea.append("No tables found with 'ARCHIVE' engine \n");
                        logOutputTextArea.append("Total tables cleanable: "+allTables.size()+"\n");
                        logOutputTextArea.append("Database cleaning started...\n");
                      
                        startTime = System.currentTimeMillis();                     
                       databaseCleaner.deleteAll(allTables.toArray(new String[]{}));                            
                       endTime = System.currentTimeMillis();                      
                    
                    
                     /*  Restore the previously modified engine type from InnoDB to ARCHIVE  */
                     if(cleanArchiveTable)
                     {                     
                       logOutputTextArea.append("Restoring the engine type to ARCHIVE...\n");                      
                     
                         for(int i=0;i<archiveTables.size();i++)
                         {                           
                          databaseTableUtils.changeTableEngine(archiveTables.get(i),"ARCHIVE");
                          
                          if(Log4jManager.IS_LOGGING_CONFIGURED)
                        logger.debug("Restored the engine type to ARCHIVE for table "+archiveTables.get(i));
                         }
                     }
View Full Code Here


            Thread cleanDatabaseThread = new Thread() {
                             
             public void run() {                                
                 
                 try {                              
                     DatabaseTableUtils databaseTableUtils = new DatabaseTableUtils();
                     List<String> tableNames = databaseTableUtils.getTableNamesOrdered();                    
                     databaseTableList.setListData(tableNames.toArray())
                     exportTableAsCsvButton.setEnabled(true);
                  
                    // stop and hide the animation
                    busyLabelPanel.getJxBusyLabel().setBusy(false);
View Full Code Here

      {
         JList list = (JList) listSelectionEvent.getSource();
         int selections[] = list.getSelectedIndices();
         Object selectionValues[] = list.getSelectedValues();
        
         DatabaseTableUtils databaseTableUtils = new DatabaseTableUtils();
         ArrayList<MetadataTableInfoBean> tableFieldInfoBean = null; // the info about the table fields
         ArrayList<AdvancedMetadataTableInfo> advancedTableInfoBean = null; //the advanced table info
        
         try{  
           for (int i = 0, n = selections.length; i < n; i++)
           {
            selectedTableName = (String) selectionValues[i]; // the selected value (ie a table name)          
              tableFieldInfoBean = databaseTableUtils.getFieldsInfo(selectedTableName);
              advancedTableInfoBean = databaseTableUtils.getAdvancedTableInfo(selectedTableName);
           }
         
          // update the data showed in the field info table with the one coming form the DB
          DatabaseTableInfoModel c = (DatabaseTableInfoModel) fieldDetailsTable.getModel();         
          c.setTableFieldInfoBeanList(tableFieldInfoBean);
View Full Code Here

        /* The current table and his current column. Field used like a cursor moved forward during the filling operation */
    String currentFieldName = null;
    String currentTable = null;
       
    try{     
      DatabaseTableUtils databaseTableUtils = new DatabaseTableUtils();
        List<String> tableNames = databaseTableUtils.getTableNamesOrdered();      
       
      // 1) obtain a native jdbc connection to use for insert generated data      
      conn = DatabaseConnectionFactory.getDataSource().getConnection()
     
      /*
       * TIPS: set the mysql variable "wait_timeout" to an high value for long operation if the connection is closed automatically
       * It is "The number of seconds the server waits for activity on a no interactive connection before closing it"
       *
       * SET GLOBAL wait_timeout = 28800;  value 1  to 2147483
             * show global variables like 'wait_timeout' ;
       */
     
      Statement statement = conn.createStatement();
     
      // 1b) If required, prepare the file where write the sql statement(s)
      if(!this.outputSqlFile.equalsIgnoreCase("") && this.outputSqlFile !=null)
      {       
        outputFile = new File(this.outputSqlFile);
        if(outputFile.exists())
          outputFile.delete();
       
        outputFile.createNewFile(); //create a new file
        fileWriter = new FileWriter(outputFile);
        out = new BufferedWriter(fileWriter);
        saveToFile = true;
       
        // a fix header message
        out.write("\n\n");
        out.write("---- NOTE: the following query don't have the insert part for the auto-increment field(s) \n")
      }
     
      // 2 for each table get informations about the fields and the FK constraints (if any)
      for(int i=0; i<tableNames.size(); i++)
      { 
        currentTable = tableNames.get(i);
       
        if(Log4jManager.IS_LOGGING_CONFIGURED)
           logger.info("----- Starting filling of table: "+currentTable);
       
        if(saveToFile)  {
           out.write("\n\n")
           out.write("---- Table: "+currentTable+" ----"+"\n")
           out.flush();
        }  
       
        ArrayList<MetadataTableInfoBean> tableFieldsInfoList = databaseTableUtils.getFieldsInfo(currentTable);       
        // All the FK relations of the current table (ie which table references)
        ArrayList<TableFKconstraintsBean> tableFKinfoList = databaseTableUtils.getFkInformation(currentTable);       
       
        /* Flag to indicates if the current field references another field in a child table */
        boolean fieldHasChild = false
       
        /* Start the query Building */
        for(int k=0;k<recordToInsert;k++)
        {         
          /* The current table column names to use in the sql insert query */
          String columnNameList = "";
         
          /* The list of values place in the sql query that we are building */
          String valuesList = "'";
       
          // 3 for each field, depending on his data type choose the right generator type to use
          for(int j=0;j<tableFieldsInfoList.size();j++)
          {         
            MetadataTableInfoBean field = tableFieldsInfoList.get(j);           
            currentFieldName = field.getFieldName();
           
            fieldHasChild = false
           
            // the type of the current field ( eg varchar(10) bigint(10) )
            String fieldType = field.getFieldType();
            String childColumn = null;
            String childTable = null;
           
            if(Log4jManager.IS_LOGGING_CONFIGURED)
               logger.debug("Current field: "+currentFieldName +" of Type:"+fieldType);
           
            // check if the current field has child
            for(TableFKconstraintsBean fkInfoList:tableFKinfoList)
            {             
              //true if the current field point another table
              if(fkInfoList.getParentColumnName().equalsIgnoreCase(currentFieldName)) {
               
                fieldHasChild = true;
               
                //get who is the referenced column+table pair
                childColumn = fkInfoList.getReferencedColumnName();               
                childTable = fkInfoList.getReferencedTableName();
              }               
            } 
           
            /**
             * Note the child table is already filled because our table list is in the filling order
             */
            if(fieldHasChild && childTable !=null && childColumn !=null)
            {
              if(Log4jManager.IS_LOGGING_CONFIGURED)
                 logger.info("- Table "+currentTable+"("+currentFieldName+") references the Table:"+childTable+"("+childColumn+") ");
             
              /* the fields with "auto_increment" option don't appear in the insert query: is mysql that generate his value */
              if(!field.getExtraInfo().equalsIgnoreCase("auto_increment")) {
                  columnNameList += field.getFieldName()+",";
             
                // Get the allowed values for the current field from the child column
                ArrayList<String> allowedValues = databaseTableUtils.getColumnValue(childTable,childColumn);
               
                String chosenValue = allowedValues.get(k); //use the 'k' index because all the table have the same total row
                valuesList +=chosenValue+"','";
              }
             
View Full Code Here

            Thread cleanDatabaseThread = new Thread() {
                             
             public void run() {                              
                 
                 try {                              
                     DatabaseTableUtils databaseTableUtils = new DatabaseTableUtils();
                     List<String> tableNames = databaseTableUtils.getTableNamesOrdered();                    
                    
                     List<TableInfoPartialExportBean> tableInfoPartialExporterList = new ArrayList<TableInfoPartialExportBean>();
                    
                     for(int i=0; i<tableNames.size(); i++)
                     {                    
View Full Code Here

TOP

Related Classes of mydatagenerator.core.database.operations.DatabaseTableUtils

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.