Package org.socialmusicdiscovery.server.business.logic.injections.database

Examples of org.socialmusicdiscovery.server.business.logic.injections.database.DatabaseProvider


    public EntityManagerFactory provideEntityManagerFactory() {
        if(emFactory == null) {
            // Make sure EhCache doesn't check for upgrades
            System.setProperty("net.sf.ehcache.skipUpdateCheck","true");
            String database = System.getProperty("org.socialmusicdiscovery.server.database");
            DatabaseProvider provider;
            if(database != null) {
                provider = InjectHelper.instanceWithName(DatabaseProvider.class,database);
                if(provider == null) {
                    throw new RuntimeException("No database provider exists for: "+database);
                }
            }else {
                throw new RuntimeException("No database provider specified");
            }
            emFactory = Persistence.createEntityManagerFactory("smd",provider.getProperties());
        }
        return emFactory;
     }
View Full Code Here


 
    public SMDApplication() {
        mainThread = Thread.currentThread();

        try {
            DatabaseProvider provider = null;
            String database = InjectHelper.instanceWithName(String.class, "org.socialmusicdiscovery.server.database");
            if (database != null) {
                provider = InjectHelper.instanceWithName(DatabaseProvider.class, database);
                if (provider == null) {
                    throw new RuntimeException("No database provider exists for: " + database);
                }
            } else {
                throw new RuntimeException("No database provider configured");
            }
            provider.start();
            Connection connection = provider.getConnection();
            Liquibase liquibase = new Liquibase("org/socialmusicdiscovery/server/database/smd-database.changelog.xml", new
                    ClassLoaderResourceAccessor(),
                    new JdbcConnection(connection));
            if (System.getProperty("liquibase") == null || !System.getProperty("liquibase").equals("false")) {
                // If database is locked, retry 10 times before we give up and force the lock to be released
                for(int i=0;i<10 && liquibase.listLocks().length>0;i++) {
                    Thread.sleep(1000);
                }
                if(liquibase.listLocks().length>0) {
                    liquibase.forceReleaseLocks();
                }
                liquibase.update("");
            }

            InjectHelper.injectMembers(this);

            // Add shutdown hook to exit cleanly after receiving a CTRL-C
      Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override
        public void run() {
          try {
                        System.out.println("Initiating shutdown...");
                        shutdownRequest = true;
                        mainThread.join();
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
      });

            // Initialize all installed plugins
            pluginManager.startAll();

            System.out.println("Hit Ctrl+C to stop it...");
            while(!shutdownRequest) {
                try {
                    Thread.sleep(1000);
                }catch(InterruptedException e) {
                    // Do nothing
                }
            }

            System.out.println("\n\nExiting...\n");

            this.shutdown();

            provider.stop();
            System.out.flush();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
View Full Code Here

     * @inherit
     */
    public void execute(ProcessingStatusCallback progressHandler) {
        if (getExecutionConfiguration().getBooleanParameter("deletePrevious", Boolean.FALSE)) {
            String database = InjectHelper.instanceWithName(String.class, "org.socialmusicdiscovery.server.database");
            DatabaseProvider provider = InjectHelper.instanceWithName(DatabaseProvider.class, database);
            try {
                Connection connection = provider.getConnection();
                Liquibase liquibase = new Liquibase("org/socialmusicdiscovery/server/database/smd-database-drop.xml", new
                        ClassLoaderResourceAccessor(),
                        new JdbcConnection(connection));
                liquibase.update("");
                liquibase = new Liquibase("org/socialmusicdiscovery/server/database/smd-database.changelog.xml", new
View Full Code Here

    }

    @Override
    public boolean start() throws PluginException {
        String database = InjectHelper.instanceWithName(String.class, "org.socialmusicdiscovery.server.database");
        DatabaseProvider provider = InjectHelper.instanceWithName(DatabaseProvider.class, database);
        try {
            Connection connection = provider.getConnection();
            if (database != null && (database.endsWith("-test"))) {
                execute(connection);
            }
        } catch (SQLException e) {
            e.printStackTrace();
View Full Code Here

    }

    @Override
    public void execute(ProcessingStatusCallback progressHandler) {
        String database = InjectHelper.instanceWithName(String.class, "org.socialmusicdiscovery.server.database");
        DatabaseProvider provider = InjectHelper.instanceWithName(DatabaseProvider.class, database);
        try {
            progressHandler.progress(getId(),"Deleting database contents",1L,2L);
            Connection connection = provider.getConnection();
            Liquibase liquibase = new Liquibase("org/socialmusicdiscovery/server/database/smd-database-drop.xml", new
                    ClassLoaderResourceAccessor(),
                    new JdbcConnection(connection));
            liquibase.update("");
            progressHandler.progress(getId(), "Creating fresh database", 2L, 2L);
View Full Code Here

                    writer.write("\n");
                }
                writer.close();
            }

            DatabaseProvider provider = null;
            String database = InjectHelper.instanceWithName(String.class, "org.socialmusicdiscovery.server.database");
            if (database != null) {
                provider = InjectHelper.instanceWithName(DatabaseProvider.class, database);
                if (provider == null) {
                    throw new RuntimeException("No database provider exists for: " + database);
                }
            } else {
                throw new RuntimeException("No database provider configured");
            }
            provider.start();
            Connection connection = provider.getConnection();
            Liquibase liquibase = new Liquibase("org/socialmusicdiscovery/server/database/smd-database.changelog.xml", new
                    ClassLoaderResourceAccessor(),
                    new JdbcConnection(connection));
            if (System.getProperty("liquibase") == null || !System.getProperty("liquibase").equals("false")) {
                liquibase.update("");
View Full Code Here

TOP

Related Classes of org.socialmusicdiscovery.server.business.logic.injections.database.DatabaseProvider

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.