@Override protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot snapshot) throws DatabaseException, InvalidExampleException { throw new DatabaseException("No views in Hibernate mapping"); }
try { //Open or create the database Database db = DatabaseFactory.openOrCreate("MyBudgetTracker.db"); //Retrieve Data from db Statement statement1 = db.createStatement("SELECT * FROM "+Globalvalue.planCategoryTable); statement1.prepare(); statement1.execute(); statement1.close(); db.close(); } catch(DatabaseException dbe) { System.err.println(dbe.toString()); }
@Override public boolean acquireLock() { if (hasChangeLogLock) { // We already have a lock return true; } Executor executor = ExecutorService.getInstance().getExecutor(database); try { database.rollback(); // Ensure table created and lock record inserted this.init(); } catch (DatabaseException de) { throw new IllegalStateException("Failed to retrieve lock", de); } try { log.debug("Trying to lock database"); executor.execute(new LockDatabaseChangeLogStatement()); log.debug("Successfully acquired database lock"); hasChangeLogLock = true; database.setCanCacheLiquibaseTableInfo(true); return true; } catch (DatabaseException de) { log.warn("Lock didn't yet acquired. Will possibly retry to acquire lock. Details: " + de.getMessage()); if (log.isTraceEnabled()) { log.debug(de.getMessage(), de); } return false; } }
log.warn("Failed to create lock table. Maybe other transaction created in the meantime. Retrying..."); if (log.isTraceEnabled()) { log.trace(de.getMessage(), de); //Log details at trace level log.warn("Failed to insert first record to the lock table. Maybe other transaction inserted in the meantime. Retrying..."); if (log.isTraceEnabled()) { log.trace(de.getMessage(), de); // Log details at trace level
protected void configurePhysicalNamingStrategy(String physicalNamingStrategy, MetadataBuilder builder) throws DatabaseException { String namingStrategy; namingStrategy = getHibernateConnection().getProperties().getProperty(AvailableSettings.PHYSICAL_NAMING_STRATEGY, physicalNamingStrategy); try { if (namingStrategy != null) { builder.applyPhysicalNamingStrategy((PhysicalNamingStrategy) Class.forName(namingStrategy).newInstance()); } } catch (Exception e) { throw new DatabaseException(e); } }
protected void configureNewIdentifierGeneratorSupport(String value, MetadataBuilder builder) throws DatabaseException { String _value; _value = getHibernateConnection().getProperties().getProperty(AvailableSettings.USE_NEW_ID_GENERATOR_MAPPINGS, value); try { if (_value != null) { builder.enableNewIdentifierGeneratorSupport(Boolean.valueOf(_value)); } } catch (Exception e) { throw new DatabaseException(e); } }
public void processSchemaLiquibase(List<String> schemas) throws Exception { Liquibase liquibase = null; for (String schema : schemas) { Connection c = dataSource.getConnection(); try { setDefaultSchema(schema); c.setSchema(schema); liquibase = createLiquibase(c); performUpdate(liquibase); } catch (SQLException e) { throw new DatabaseException(e); } finally { if (c != null) { try { c.rollback(); c.close(); } catch (SQLException e) { //nothing to do } } } } } }
@Override public void close() throws DatabaseException{ if( database.getConnection().isClosed() ){ throw new DatabaseException("Connection closed"); } // database.close() will now also close the connection. // simple solution: we don't close the liquibase database anymore database.close(); } }
/** * Called by {@link #setConnection(DatabaseConnection)} to create the Metadata stored in this database. * If the URL path is configured for a {@link CustomMetadataFactory}, create the metadata from that class. * Otherwise, it delegates to {@link #buildMetadataFromPath()} */ protected final Metadata buildMetadata() throws DatabaseException { String path = getHibernateConnection().getPath(); if (!path.contains("/")) { try { Class<?> clazz = Class.forName(path); if (CustomMetadataFactory.class.isAssignableFrom(clazz)) { try { return ((CustomMetadataFactory) clazz.newInstance()).getMetadata(this, getHibernateConnection()); } catch (InstantiationException | IllegalAccessException e) { throw new DatabaseException(e); } } } catch (ClassNotFoundException ignore) { //not really a class, continue } } return buildMetadataFromPath(); }
public String getDatabaseProductName() throws DatabaseException { Connection connection = null; Database database = null; String name = "unknown"; try { connection = this.getDataSource().getConnection(); database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection)); name = database.getDatabaseProductName(); } catch (SQLException var12) { throw new DatabaseException(var12); } finally { if (database != null) { database.close(); } else if (connection != null) { try { if (!connection.getAutoCommit()) { connection.rollback(); } connection.close(); } catch (Exception var11) { this.log.warning("problem closing connection", var11); } } } return name; }
protected void configureImplicitNamingStrategy(String implicitNamingStrategy, MetadataBuilder builder) throws DatabaseException { String namingStrategy; namingStrategy = getHibernateConnection().getProperties().getProperty(AvailableSettings.IMPLICIT_NAMING_STRATEGY, implicitNamingStrategy); try { if (namingStrategy != null) { switch (namingStrategy) { case "default": case "jpa": builder.applyImplicitNamingStrategy(org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl.INSTANCE); break; case "legacy-hbm": builder.applyImplicitNamingStrategy(org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyHbmImpl.INSTANCE); break; case "legacy-jpa": builder.applyImplicitNamingStrategy(org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl.INSTANCE); break; case "component-path": builder.applyImplicitNamingStrategy(org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl.INSTANCE); break; default: builder.applyImplicitNamingStrategy((ImplicitNamingStrategy) Class.forName(namingStrategy).newInstance()); break; } } } catch (Exception e) { throw new DatabaseException(e); } }
private void performUpdate() throws LiquibaseException { Connection c = null; Liquibase liquibase = null; try { c = dataSource.getConnection(); liquibase = createLiquibase(c); liquibase.update(new Contexts(config.getContexts()), new LabelExpression(config.getLabels())); updateSuccessful = true; } catch (SQLException e) { throw new DatabaseException(e); } catch (LiquibaseException ex) { updateSuccessful = false; throw ex; } finally { if ((liquibase != null) && (liquibase.getDatabase() != null)) { liquibase.getDatabase().close(); } else if (c != null) { try { c.rollback(); c.close(); } catch (SQLException e) { //nothing to do } } } }
throw (DatabaseException) e; } else { throw new DatabaseException(e);
/** * Creates the base {@link MetadataSources} to use for this database. * Normally, the result of this method is passed through {@link #configureSources(MetadataSources)}. */ protected MetadataSources createMetadataSources() throws DatabaseException { String dialectString = findDialectName(); if (dialectString != null) { try { dialect = (Dialect) Class.forName(dialectString).newInstance(); LOG.info("Using dialect " + dialectString); } catch (Exception e) { throw new DatabaseException(e); } } else { LOG.info("Could not determine hibernate dialect, using HibernateGenericDialect"); dialect = new HibernateGenericDialect(); } ServiceRegistry standardRegistry = new StandardServiceRegistryBuilder() .applySetting(AvailableSettings.DIALECT, dialect) .addService(ConnectionProvider.class, new NoOpConnectionProvider()) .addService(MultiTenantConnectionProvider.class, new NoOpConnectionProvider()) .build(); return new MetadataSources(standardRegistry); }
var9 = false; } catch (SQLException var10) { throw new DatabaseException(var10); } finally { if (var9) {
throw new DatabaseException("Unable to find column data type for column " + hibernateColumn.getName());
DataType dataType = toDataType(hibernateType, hibernateColumn.getSqlTypeCode()); if (dataType == null) { throw new DatabaseException("Unable to find column data type for column " + hibernateColumn.getName());