Package org.apache.ddlutils

Examples of org.apache.ddlutils.Platform


        // Find needed information fr DdlUtils
        ConnectionRepository cr = MetadataManager.getInstance().connectionRepository();
        PBKey connKey = cr.getStandardPBKeyForJcdAlias( "pv" );
        JdbcConnectionDescriptor connDesc = cr.getDescriptor( connKey );
        String jdbcDriver = connDesc.getDriver();
        Platform platform = null;
        if ( jdbcDriver.equals( "org.apache.derby.jdbc.EmbeddedDriver" ) ) {
            platform = PlatformFactory.createNewPlatformInstance( "derby" );           
        } else if ( jdbcDriver.equals( "com.mysql.jdbc.Driver" ) ){
            platform = PlatformFactory.createNewPlatformInstance( "mysql" );
        }
        platform.getPlatformInfo().setDelimiterToken( "" );
       
        // Get the database schema XML file
        InputStream schemaIS = getClass().getClassLoader().getResourceAsStream( "photovault_schema.xml" );
        DatabaseIO dbio = new DatabaseIO();
        dbio.setValidateXml( false );
        Database dbModel = dbio.read( new InputStreamReader( schemaIS ) );
       
        // Alter tables to match corrent schema
        PersistenceBroker broker = PersistenceBrokerFactory.createPersistenceBroker( connKey );
        broker.beginTransaction();
        try {
            Connection con = broker.serviceConnectionManager().getConnection();
            /*
             TODO:
             Derby alter table statements created by DdlUtils have wrong syntax.
             Luckily we do not need to do such modifications for now. There is
             error report for DdlUtils (http://issues.apache.org/jira/browse/DDLUTILS-53),
             after it has been corrected the alterColumns flag should be set to
             true.
             */
             log.info( platform.getAlterTablesSql( con, dbModel, false, true, true ) );
             platform.alterTables( con, dbModel, false, true, true );
        } catch (DynaSqlException ex) {
            ex.printStackTrace();
        } catch ( LookupException ex ) {
            ex.printStackTrace();
        }
View Full Code Here


    /**
     * Creates the required tables for this component.
     */
    public void createSchema() {
        String ddlPath = getDDLPath(getDatabaseName());
        Platform platform = PlatformFactory.createNewPlatformInstance(getDataSource());
        try {
            String sqlString = FileUtils.readFileString(new File(ddlPath));
            platform.evaluateBatch(sqlString, true);
        } catch (FileNotFoundException e) {
            if (isLoggingError()) {
                logError("Can't create schema. ", e);
            }
        } catch (IOException e) {
View Full Code Here

    } else {
      ds.setUrl(props.getProperty("bbdd.url"));
    }
    ds.setUsername(props.getProperty("bbdd.user"));
    ds.setPassword(props.getProperty("bbdd.password"));
    Platform platform = PlatformFactory.createNewPlatformInstance(ds);
    platform.getModelLoader().setOnlyLoadTableColumns(true);
    return platform.loadModelFromDatabase(null);
  }
View Full Code Here

    } else {
      ds.setUrl(props.getProperty("bbdd.url"));
    }
    ds.setUsername(props.getProperty("bbdd.user"));
    ds.setPassword(props.getProperty("bbdd.password"));
    Platform platform = PlatformFactory.createNewPlatformInstance(ds);
    platform.getModelLoader().setOnlyLoadTableColumns(true);
    return platform.loadModelFromDatabase(null);
  }
View Full Code Here

    {
        File[] schemaFiles = getSchemaFiles();
        if ( schemaFiles.length > 0)
        {
            Database model = readModel(schemaFiles);
            Platform platforms[] = new Platform[databases.length];
            if ( databases.length == 0 )
            {
                getLog().warn("No databases specified, no ddl generated");
            }
            else
            {
                for ( int i = 0; i < databases.length; i++ )
                {           
                    try
                    {
                        platforms[i] = PlatformFactory.createNewPlatformInstance(databases[i]);
                    }
                    catch (Exception ex)
                    {
                        throw new MojoExecutionException("Database type "+databases[i]+" is not supported.", ex);
                    }
                    if (platforms[i] == null)
                    {
                        throw new MojoExecutionException("Database type "+databases[i]+" is not supported.");
                    }
                    platforms[i].setDelimitedIdentifierModeOn(useDelimitedSqlIdentifiers);
                    platforms[i].setForeignKeysSorted(sortForeignKeys);
                }
               
                for (int i = 0; i < platforms.length; i++ )
                {
                    Platform platform = platforms[i];
                    platform.setScriptModeOn(true);
                    File outputDir = new File(outputTarget,databases[i].toLowerCase());
                    if ( !outputDir.exists() )
                    {
                        outputDir.mkdirs();
                    }
                    if (platform.getPlatformInfo().isSqlCommentsSupported())
                    {
                        // we're generating SQL comments if possible
                        platform.setSqlCommentsOn(true);
                    }
                    if ( platform instanceof Oracle8Platform )
                    {
                        // hack to map LONGVARCHAR to VARCHAR2(4000) on Oracle, the predefined CLOB type really isn't usable
                        platform.getPlatformInfo().addNativeTypeMapping("LONGVARCHAR", "VARCHAR2(4000)");
                    }
                    CreationParameters params = getFilteredParameters(model, platform.getName(), useDelimitedSqlIdentifiers);
                    try
                    {
                        StringWriter stringWriter = new StringWriter();
                        platform.getSqlBuilder().setWriter(stringWriter);
                        platform.getSqlBuilder().createTables(model, params, false);
                        int createSchemaLength = stringWriter.getBuffer().length();
                        writeOutput(new File(outputDir,"create-schema.sql"),stringWriter.toString());
                        stringWriter.getBuffer().setLength(0);
                        platform.getSqlBuilder().createTables(model, params, true);
                        stringWriter.getBuffer().setLength(stringWriter.getBuffer().length()-createSchemaLength);
                        writeOutput(new File(outputDir,"drop-schema.sql"), stringWriter.toString());
                    }
                    catch (IOException ioe)
                    {
View Full Code Here

    {
        File[] schemaFiles = getSchemaFiles();
        if ( schemaFiles.length > 0)
        {
            Database model = readModel(schemaFiles);
            Platform platforms[] = new Platform[databases.length];
            if ( databases.length == 0 )
            {
                getLog().warn("No databases specified, no ddl generated");
            }
            else
            {
                for ( int i = 0; i < databases.length; i++ )
                {           
                    try
                    {
                        platforms[i] = PlatformFactory.createNewPlatformInstance(databases[i]);
                    }
                    catch (Exception ex)
                    {
                        throw new MojoExecutionException("Database type "+databases[i]+" is not supported.", ex);
                    }
                    if (platforms[i] == null)
                    {
                        throw new MojoExecutionException("Database type "+databases[i]+" is not supported.");
                    }
                    platforms[i].setDelimitedIdentifierModeOn(useDelimitedSqlIdentifiers);
                    platforms[i].setForeignKeysSorted(sortForeignKeys);
                }
               
                for (int i = 0; i < platforms.length; i++ )
                {
                    Platform platform = platforms[i];
                    platform.setScriptModeOn(true);
                    File outputDir = new File(outputTarget,databases[i].toLowerCase());
                    if ( !outputDir.exists() )
                    {
                        outputDir.mkdirs();
                    }
                    if (platform.getPlatformInfo().isSqlCommentsSupported())
                    {
                        // we're generating SQL comments if possible
                        platform.setSqlCommentsOn(true);
                    }
                    if ( platform instanceof Oracle8Platform )
                    {
                        // hack to map LONGVARCHAR to VARCHAR2(4000) on Oracle, the predefined CLOB type really isn't usable
                        platform.getPlatformInfo().addNativeTypeMapping("LONGVARCHAR", "VARCHAR2(4000)");
                    }
                    CreationParameters params = getFilteredParameters(model, platform.getName(), useDelimitedSqlIdentifiers);
                    try
                    {
                        StringWriter stringWriter = new StringWriter();
                        platform.getSqlBuilder().setWriter(stringWriter);
                        // use cglib enhanced wrapper for SqlBuilder to allow overriding ddlutils 1.0 behavior at runtime for
                        // https://issues.apache.org/jira/browse/DDLUTILS-75 which is fixed in ddlutils 1.1 but hasn't been released yet.
                        SqlBuilder sqlBuilder = new EnhancedSqlBuilder(platform.getSqlBuilder());
                        sqlBuilder.createTables(model, params, false);
                        int createSchemaLength = stringWriter.getBuffer().length();
                        writeOutput(new File(outputDir,"create-schema.sql"),stringWriter.toString());
                        stringWriter.getBuffer().setLength(0);
                        sqlBuilder.createTables(model, params, true);
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.