Package org.apache.ddlutils

Examples of org.apache.ddlutils.Platform


      }
 
      // get the Database model
      Database database = generator.getDatabase();
 
      Platform platform = PlatformFactory.createNewPlatformInstance("mysql");
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      Connection connection = DriverManager.getConnection(url, username, password);
     
      System.out.println(platform.getAlterTablesSql(connection, database));
     
      // this will perform the database changes
      CreationParameters cp = new CreationParameters();
      // to search, it requires MyISAM
      cp.addParameter(database.findTable("discoveries_search"), "ENGINE", "MyISAM");
      cp.addParameter(database.findTable("discoveries_search2"), "ENGINE", "MyISAM");

      platform.alterTables(connection, database, cp, true);
       
      connection.close();
     
      pm = new JdbcPersistenceManager();
      pm.init(p);
View Full Code Here


      }
 
      // get the Database model
      Database database = generator.getDatabase();
 
      Platform platform = PlatformFactory.createNewPlatformInstance("postgresql");
      Class.forName(driver);
      Connection connection = DriverManager.getConnection(url, username, password);
     
      System.out.println(platform.getAlterTablesSql(connection, database));
     
      // this will perform the database changes
      platform.alterTables(connection, database, true);
 
      connection.close();
     
      pm = new PostgresqlPersistenceManager();
      pm.init(p);
View Full Code Here

     *
     * @return The platform
     */
    public Platform getPlatform() throws BuildException
    {
        Platform platform = null;

        if (_databaseType == null)
        {
            if (_dataSource == null)
            {
                throw new BuildException("No database specified.");
            }
            if (_databaseType == null)
            {
                _databaseType = new PlatformUtils().determineDatabaseType(_dataSource.getDriverClassName(),
                                                                          _dataSource.getUrl());
            }
            if (_databaseType == null)
            {
                _databaseType = new PlatformUtils().determineDatabaseType(_dataSource);
            }
        }
        try
        {
            platform = PlatformFactory.createNewPlatformInstance(_databaseType);
        }
        catch (Exception ex)
        {
            throw new BuildException("Database type "+_databaseType+" is not supported.", ex);
        }
        if (platform == null)
        {
            throw new BuildException("Database type "+_databaseType+" is not supported.");
        }
        platform.setDataSource(_dataSource);
        platform.setDelimitedIdentifierModeOn(isUseDelimitedSqlIdentifiers());
        platform.setForeignKeysSorted(isSortForeignKeys());

        return platform;
    }
View Full Code Here

        if (_outputFile.exists() && !_outputFile.canWrite())
        {
            throw new BuildException("Cannot overwrite output file "+_outputFile.getAbsolutePath());
        }

        Platform           platform        = getPlatform();
        boolean            isCaseSensitive = platform.isDelimitedIdentifierModeOn();
        CreationParameters params          = getFilteredParameters(model, platform.getName(), isCaseSensitive);

        try
        {
            FileWriter writer = new FileWriter(_outputFile);

            platform.setScriptModeOn(true);
            if (platform.getPlatformInfo().isSqlCommentsSupported())
            {
                // we're generating SQL comments if possible
                platform.setSqlCommentsOn(true);
            }
            platform.getSqlBuilder().setWriter(writer);

            boolean shouldAlter = isAlterDatabase();

            if (shouldAlter)
            {
                if (getDataSource() == null)
                {
                    shouldAlter = false;
                    _log.warn("Cannot alter the database because no database connection was specified." +
                              " SQL for database creation will be generated instead.");
                }
                else
                {
                    try
                    {
                        Connection connection = getDataSource().getConnection();

                        connection.close();
                    }
                    catch (SQLException ex)
                    {
                        shouldAlter = false;
                        _log.warn("Could not establish a connection to the specified database, " +
                                  "so SQL for database creation will be generated instead.",
                                  ex);
                    }
                }
            }
            if (shouldAlter)
            {
                Database currentModel = (getCatalogPattern() != null) || (getSchemaPattern() != null) ?
                                             platform.readModelFromDatabase("unnamed", getCatalogPattern(), getSchemaPattern(), null) :
                                             platform.readModelFromDatabase("unnamed");

                platform.getSqlBuilder().alterDatabase(currentModel, model, params);
            }
            else
            {
                platform.getSqlBuilder().createTables(model, params, _doDrops);
            }
            writer.close();
            _log.info("Written schema SQL to " + _outputFile.getAbsolutePath());
        }
        catch (Exception ex)
View Full Code Here

        if ((_singleDataFile != null) && !_fileSets.isEmpty())
        {
            throw new BuildException("Please use either the datafile attribute or the sub fileset element, but not both");
        }

        Platform   platform   = getPlatform();
        DataReader dataReader = null;

        platform.setIdentityOverrideOn(_useExplicitIdentityValues);
        try
        {
            dataReader = getDataIO().getConfiguredDataReader(platform, model);
            dataReader.getSink().start();
            if (_singleDataFile != null)
View Full Code Here

        if (dataSource == null)
        {
            throw new BuildException("No database specified.");
        }

        Platform platform = getPlatform();

        try
        {
            platform.dropDatabase(dataSource.getDriverClassName(),
                                  dataSource.getUrl(),
                                  dataSource.getUsername(),
                                  dataSource.getPassword());

            _log.info("Dropped database");
        }
        catch (UnsupportedOperationException ex)
        {
            _log.error("Database platform " + platform.getName() + " does not support database dropping via JDBC",
                       ex);
        }
        catch (Exception ex)
        {
            handleException(ex, ex.getMessage());
View Full Code Here

        if (getDataSource() == null)
        {
            throw new BuildException("No database specified.");
        }

        Platform           platform        = getPlatform();
        boolean            isCaseSensitive = platform.isDelimitedIdentifierModeOn();
        CreationParameters params          = getFilteredParameters(model, platform.getName(), isCaseSensitive);

        platform.setScriptModeOn(false);
        // we're disabling the comment generation because we're writing directly to the database
        platform.setSqlCommentsOn(false);
        try
        {
            if (isAlterDatabase())
            {
                if ((getCatalogPattern() != null) || (getSchemaPattern() != null))
                {
                    platform.alterTables(getCatalogPattern(),
                                         getSchemaPattern(),
                                         null,
                                         model,
                                         params,
                                         true);
                }
                else
                {
                    platform.alterTables(model,
                                         params,
                                         true);
                }
            }
            else
            {
                platform.createTables(model,
                                      params,
                                      _doDrops,
                                      true);
            }
View Full Code Here

        if (dataSource == null)
        {
            throw new BuildException("No database specified.");
        }

        Platform platform = getPlatform();
       
        try
        {
            platform.createDatabase(dataSource.getDriverClassName(),
                                    dataSource.getUrl(),
                                    dataSource.getUsername(),
                                    dataSource.getPassword(),
                                    getFilteredParameters(platform.getName()));

            _log.info("Created database");
        }
        catch (UnsupportedOperationException ex)
        {
            _log.error("Database platform " + platform.getName() + " does not support database creation " +
                       "via JDBC or there was an error while creating it.",
                       ex);
        }
        catch (Exception ex)
        {
View Full Code Here

  public Database loadDatabase(DataModel dataModel) {
    /*if (isDatabaseOnFile(dataModel))
      database = new DatabaseIO().read(getFileSourceName(dataModel));   
    else
    {*/       
      Platform platform = PlatformFactory.createNewPlatformInstance(dataModel.getBasicDataSource());
      platform.getModelReader().setDefaultSchemaPattern(dataModel.getSchema());
      setType(platform);
      database = platform.readModelFromDatabase("TEST");
      writeDatabase(database, dataModel);
    //}
      return this;
  }
View Full Code Here

            mysqlDs.setUser( user );
            mysqlDs.setPassword( passwd );
            ds = mysqlDs;
        }
       
        Platform platform = PlatformFactory.createNewPlatformInstance( ds );
       
        /*
         * Do not use delimiters for the database object names in SQL statements.
         * This is to avoid case sensitivity problems with SQL92 compliant
         * databases like Derby - non-delimited identifiers are interpreted as case
         *  insensitive.
         *
         * I am not sure if this is the correct way to solve the issue, however,
         * I am not willing to make a big change of schema definitions either.
         */
        platform.getPlatformInfo().setDelimiterToken( "" );
        platform.setUsername( user );
        platform.setPassword( passwd );
        platform.createTables( dbModel, true, true );
       
        // Insert the seed data to database
        DataToDatabaseSink sink = new DataToDatabaseSink( platform, dbModel );
        DataReader reader = new DataReader();
        reader.setModel( dbModel );
        reader.setSink( sink );
       

        InputStream seedDataStream = this.getClass().getClassLoader().getResourceAsStream( "photovault_seed_data.xml" );
        try {
            reader.parse( seedDataStream );
        } catch (SAXException ex) {
            ex.printStackTrace();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
       
        if ( seedDataResource != null ) {
            seedDataStream = this.getClass().getClassLoader().getResourceAsStream( seedDataResource );
            try {
                reader.parse( seedDataStream );
            } catch (SAXException ex) {
                ex.printStackTrace();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        }
       
        // Create the database
       
        // TODO: Since the seed has only 48 significant bits this id is not really an
        // 128-bit random number!!!
        Random rnd = new Random();
        String idStr = "";
        StringBuffer idBuf = new StringBuffer();
        for ( int n=0; n < 4; n++ ) {
            int r = rnd.nextInt();
            idBuf.append( Integer.toHexString( r ) );
        }
        idStr = idBuf.toString();
        DynaBean dbInfo = dbModel.createDynaBeanFor( "database_info", false );
        dbInfo.set( "database_id", idStr );
        dbInfo.set( "schema_version", new Integer( CURRENT_SCHEMA_VERSION ) );
        dbInfo.set( "create_time", new Timestamp( System.currentTimeMillis() ) );
        platform.insert( dbModel, dbInfo );
    }       
View Full Code Here

TOP

Related Classes of org.apache.ddlutils.Platform

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.