List of usage examples for org.hibernate.internal SessionFactoryImpl getProperties
@Override
public Map<String, Object> getProperties()
From source file:com.court.controller.GeneralSettingsFxmlController.java
@FXML private void onDbBacupAction(ActionEvent event) throws MalformedURLException, IOException, InterruptedException, SQLException { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); SessionFactoryImpl sfi = (SessionFactoryImpl) sessionFactory; Properties p = sfi.getProperties(); String db_user = p.getProperty("hibernate.connection.username"); String db_pass = p.getProperty("hibernate.connection.password"); String db_url = p.getProperty("hibernate.connection.url").replace("jdbc:mysql:", "http:"); String server_v = getMysqlServerV(sessionFactory); URL aURL = new URL(db_url); String db_host = aURL.getHost(); String db_port = String.valueOf(aURL.getPort()); String db_name = "court_loan"; DirectoryChooser chooser = new DirectoryChooser(); chooser.setTitle("Select backup directory"); File defaultDirectory = new File(System.getProperty("user.home")); chooser.setInitialDirectory(defaultDirectory); File file = chooser.showDialog(null); if (file != null) { String path = file.getAbsolutePath() + "\\courtbackup_" + new SimpleDateFormat("yyyyMMdd").format(new Date()) + ".sql"; //System.out.println("PATH - " + path); Runtime r = Runtime.getRuntime(); String command = System.getenv("ProgramFiles") + "\\MYSQL\\MySQL Server " + server_v + "\\bin\\mysqldump.exe" + " --user=" + db_user + " --password=" + db_pass + " --host=" + db_host + " --protocol=tcp" + " --port=" + db_port + " --default-character-set=utf8 --routines --events" + " --result-file=\"" + path + "\"" + " --databases " + db_name; //System.out.println("COMMAND - " + command); Process pr = r.exec(command); int pComplete = pr.waitFor(); if (pComplete == 0) { Alert alert_success = new Alert(Alert.AlertType.INFORMATION); alert_success.setTitle("Success"); alert_success.setHeaderText("Backup created successfully !"); alert_success.show();/*from w ww .jav a 2 s .c o m*/ } else { Alert alert_error = new Alert(Alert.AlertType.ERROR); alert_error.setTitle("Error"); alert_error.setHeaderText("Backup create failure !"); alert_error.show(); } } // sessionFactory.close(); }
From source file:com.court.controller.GeneralSettingsFxmlController.java
@FXML private void onDbRestoreAction(ActionEvent event) throws IOException, InterruptedException, SQLException { SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); SessionFactoryImpl sfi = (SessionFactoryImpl) sessionFactory; Properties p = sfi.getProperties(); String db_user = p.getProperty("hibernate.connection.username"); String db_pass = p.getProperty("hibernate.connection.password"); String server_v = getMysqlServerV(sessionFactory); FileChooser chooser = new FileChooser(); FileChooser.ExtensionFilter sqlFilter = new FileChooser.ExtensionFilter("SQL files", "*.sql"); chooser.getExtensionFilters().addAll(sqlFilter); File file = chooser.showOpenDialog(null); if (file != null) { String path = file.getAbsolutePath(); Runtime r = Runtime.getRuntime(); String command = System.getenv("ProgramFiles") + "\\MYSQL\\MySQL Server " + server_v + "\\bin\\mysql.exe" + " --user=" + db_user + " --password=" + db_pass + " -e source " + path; Process pr = r.exec(command); int pComplete = pr.waitFor(); if (pComplete == 0) { Alert alert_success = new Alert(Alert.AlertType.INFORMATION); alert_success.setTitle("Success"); alert_success.setHeaderText("Database restored successfully !"); alert_success.show();/*w ww. j av a 2 s.c o m*/ } else { Alert alert_error = new Alert(Alert.AlertType.ERROR); alert_error.setTitle("Error"); alert_error.setHeaderText("Database restore failure !"); alert_error.show(); } } else { Alert alert_error = new Alert(Alert.AlertType.ERROR); alert_error.setTitle("Error"); alert_error.setHeaderText("File selection failed or invalid file !"); alert_error.show(); } // sessionFactory.close(); }
From source file:de.uniwue.info6.webapp.session.AuthorizationFilter.java
License:Apache License
/** * * * @return//from ww w. j a v a 2 s . com */ // TODO: Funktion vom ConnectionManager nehmen private boolean[] checkDBExists() { Connection connection = null; Statement statement = null; ResultSet resultSet = null; boolean catalogExists = false; boolean tableExists = false; try { String dbUser = "", dbPass = "", dbName = "", url = ""; SessionFactoryImpl sessionFactoryImpl = (SessionFactoryImpl) HibernateUtil.getSessionFactory(); Properties props = sessionFactoryImpl.getProperties(); url = props.get("hibernate.connection.url").toString(); dbUser = props.get("hibernate.connection.username").toString(); dbName = props.get("hibernate.default_catalog").toString(); Object optionalPass = props.get("hibernate.connection.password"); if (optionalPass != null) { dbPass = optionalPass.toString(); } Class.forName("org.mariadb.jdbc.Driver"); // Register JDBC Driver connection = DriverManager.getConnection(url, dbUser, dbPass); resultSet = connection.getMetaData().getCatalogs(); while (resultSet.next()) { String databaseName = resultSet.getString(1); if (databaseName.equalsIgnoreCase(dbName)) { catalogExists = true; break; } } connection.setCatalog(dbName); ResultSet rs = connection.getMetaData().getTables(null, null, "%", null); while (rs.next()) { tableExists = true; } } catch (Exception e) { return new boolean[] { false, false }; } finally { try { if (resultSet != null) { resultSet.close(); } if (statement != null) { statement.close(); } if (connection != null) { connection.close(); } } catch (Exception e) { e.printStackTrace(); } } return new boolean[] { catalogExists, tableExists }; }
From source file:org.accretegb.modules.customswingcomponent.Utils.java
License:Apache License
static public Map<String, String> getAuthorizationStrs() { Map<String, String> map = new HashMap<String, String>(); Configuration config = new Configuration(); config.configure("pmhibernate.cfg.xml"); SessionFactoryImpl sessionFactoryImpl = (SessionFactoryImpl) HibernateSessionFactory.getSessionFactory(); Properties props = sessionFactoryImpl.getProperties(); String username = props.get("hibernate.connection.username").toString(); String password = props.get("hibernate.connection.password").toString(); String url = props.get("hibernate.connection.url").toString(); String server = url.split(":")[2].replace("//", ""); String port = url.split(":")[3].substring(0, url.split(":")[3].indexOf("/")); if (password.equals("")) { password = ""; }/*w w w .j a v a 2 s . c o m*/ map.put("username", username); map.put("password", password); map.put("url", url); map.put("server", server); map.put("port", port); return map; }
From source file:org.babyfish.hibernate.cfg.Configuration.java
License:Open Source License
@Override public XSessionFactory buildSessionFactory(ServiceRegistry serviceRegistry) throws HibernateException { Arguments.mustBeInstanceOfValue("serviceRegistry", Arguments.mustNotBeNull("serviceRegistry", serviceRegistry), StandardServiceRegistryImpl.class); replacePersisterClassResolver((AbstractServiceRegistryImpl) serviceRegistry); String originalCurrentSessionContext = this.getProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS); this.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, "thread"); SessionFactoryImpl factory; try {/*from w ww . ja va 2 s . c om*/ pathPlanKeyVlidationSuspended = true; try { factory = (SessionFactoryImpl) super.buildSessionFactory(serviceRegistry); } finally { pathPlanKeyVlidationSuspended = false; } } finally { if (originalCurrentSessionContext != null) { this.setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, originalCurrentSessionContext); } else { this.getProperties().remove(Environment.CURRENT_SESSION_CONTEXT_CLASS); } } if (originalCurrentSessionContext != null) { factory.getProperties().setProperty(Environment.CURRENT_SESSION_CONTEXT_CLASS, originalCurrentSessionContext); } else { factory.getProperties().remove(Environment.CURRENT_SESSION_CONTEXT_CLASS); } Dialect dialect = factory.getDialect(); if (dialect instanceof InstallableDialect) { ((InstallableDialect) dialect).install(factory); } EventListenerGroup<MergeEventListener> mergeEventListenerGroup = factory.getServiceRegistry() .getService(EventListenerRegistry.class).getEventListenerGroup(EventType.MERGE); MergeEventListener mergeEventListener = new ObjectModelMergeEventListener( mergeEventListenerGroup.listeners()); mergeEventListenerGroup.clear(); mergeEventListenerGroup.appendListener(mergeEventListener); setQueryPlanceCache(factory, this.createQueryPlanCache(factory)); for (ClassMetadata classMetadata : factory.getAllClassMetadata().values()) { if (Metadatas.getObjectModelFactoryProvider(classMetadata.getMappedClass()) != null) { //Validate whether JPA configuration is same with object model configuration HibernateMetadatas.of(classMetadata.getMappedClass()).getPersistentClass(factory); } } return SessionFactoryImplWrapper.wrap(factory); }
From source file:org.jasig.ssp.dao.DirectoryPersonSearchDao.java
License:Apache License
private Boolean isPostgresSession() { try {// w w w . j av a 2s.co m Properties properties = System.getProperties(); String dialect = properties.getProperty("db_dialect"); if (StringUtils.isBlank(dialect)) { SessionFactoryImpl sfi = (SessionFactoryImpl) sessionFactory; Properties props = sfi.getProperties(); dialect = props.get("hibernate.dialect").toString(); } return dialect.toUpperCase().contains("POSTGRES") ? true : false; } catch (Exception exp) { } return true; }