log.info(LogType.LOG, String.format("[id = %s] JVM lock acquired, acquiring file lock", id)); String lockPath = String.format("%s/schema.liquibase.lock", ROOT_PATH); log.info(LogType.LOG, String.format("[id = %s] Created lock file [path='%s'].", id, lockPath)); log.info(LogType.LOG, String.format("[id = %s] Trying to acquire the file lock [file='%s']...", id, lockPath)); lock = fileChannel.tryLock(); } catch (OverlappingFileLockException e) { log.debug(LogType.LOG, String.format("[id = %s] Lock already acquired, waiting for the lock...", id)); log.debug(LogType.LOG, String.format("[id = %s] Waiting for the lock...", id)); Thread.sleep(FILE_LOCK_TIMEOUT); log.info(LogType.LOG, String.format("[id = %s] File lock acquired, running liquibase...", id)); actionResult = action.call(); lock.release(); } catch (Exception e) { log.warning(LogType.LOG, e.getMessage(), e);
@Override public void fatalError(final SAXParseException exception) throws SAXException { LogFactory.getLogger().severe(exception.getMessage()); throw exception; }
private void initLogging() { LogFactory.getLogger().setLogLevel(LogLevel.INFO); }
/** * API method. */ public CDILiquibaseConfig createCDILiquibaseConfig() { final String id = UUID.randomUUID().toString(); log.debug(LogType.LOG, String.format("[id = %s] createConfig(). Date: '%s'", id, new Date())); final InputStream is = SchemesCDIConfigBuilder.class.getResourceAsStream(SCHEMA_NAME); try { return jvmLocked(id, new Callable<CDILiquibaseConfig>() { public CDILiquibaseConfig call() throws Exception { return createCDILiquibaseConfig(id, is); } }); } catch (Exception ex) { log.warning(LogType.LOG, String.format("[id = %s] Unable to initialize liquibase where '%s'.", id, ex.getMessage()), ex); return null; } finally { try { is.close(); } catch (IOException ioe) { log.warning(LogType.LOG, String.format("[id = %s] IOException during closing an input stream '%s'.", id, ioe.getMessage()), ioe); } } }
public void afterPropertiesSet() throws Exception { if (this.dataSource == null && this.schemas == null) { this.log.info("DataSources based multitenancy enabled"); this.resolveDataSources(); this.runOnAllDataSources(); } else { if (this.dataSource == null && this.schemas != null) { throw new LiquibaseException("When schemas are defined you should also define a base dataSource"); } if (this.dataSource != null) { this.log.info("Schema based multitenancy enabled"); if (this.schemas == null || this.schemas.isEmpty()) { this.log.warning("Schemas not defined, using defaultSchema only"); this.schemas = new ArrayList(); this.schemas.add(this.defaultSchema); } this.runOnAllSchemas(); } } }
private void runOnAllDataSources() throws LiquibaseException { Iterator i$ = this.dataSources.iterator(); while(i$.hasNext()) { DataSource aDataSource = (DataSource)i$.next(); this.log.info("Initializing Liquibase for data source " + aDataSource); CustomSpringLiquibase liquibase = this.getSpringLiquibase(aDataSource); liquibase.afterPropertiesSet(); this.log.info("Liquibase ran for data source " + aDataSource); } }
if (!version.equals(OSGiXMLChangeLogSAXParser .getSchemaVersion())) { log.warning(databaseChangeLog.getPhysicalFilePath() + " is using schema version " + version + " rather than version " log.debug("includeAll for " + pathName); log.debug("Using file opener for includeAll: " + resourceAccessor.toString()); boolean isRelativeToChangelogFile = Boolean.parseBoolean(atts.getValue("relativeToChangelogFile")); File zipFileDir = OSGiXMLChangeLogSAXHandler.extractZipFile(fileUrl); if (pathName.startsWith("classpath:")) { log.debug("replace classpath"); pathName = pathName.replaceFirst("classpath:", ""); log.debug("replace classpath*"); pathName = pathName.replaceFirst("classpath\\*:", ""); fileUrl = fileUri.toURL(); } else { log.debug(fileUrl.toExternalForm() + " is not a file path"); continue; log.debug("includeAll using path " + file.getCanonicalPath()); if (!file.exists()) { throw new SAXException("includeAll path " + pathName + " could not be found. Tried in " log.debug(file.getCanonicalPath() + " is a directory"); for (File childFile : new TreeSet<File>(Arrays.asList(file.listFiles()))) {
@Override public void warning(final SAXParseException exception) throws SAXException { LogFactory.getLogger().warning(exception.getMessage()); throw exception; } });
private void resolveDataSources() throws NamingException { Context context = new InitialContext(); int lastIndexOf = this.jndiBase.lastIndexOf("/"); String jndiRoot = this.jndiBase.substring(0, lastIndexOf); String jndiParent = this.jndiBase.substring(lastIndexOf + 1); Context base = (Context)context.lookup(jndiRoot); NamingEnumeration list = base.list(jndiParent); while(list.hasMoreElements()) { NameClassPair entry = (NameClassPair)list.nextElement(); String name = entry.getName(); String jndiUrl; if (entry.isRelative()) { jndiUrl = this.jndiBase + "/" + name; } else { jndiUrl = name; } Object lookup = context.lookup(jndiUrl); if (lookup instanceof DataSource) { this.dataSources.add((DataSource)lookup); this.log.debug("Added a data source at " + jndiUrl); } else { this.log.info("Skipping a resource " + jndiUrl + " not compatible with DataSource."); } } }
public void addPackageToScan(String packageName) { logger.debug("Adding package to scan: " + packageName); packagesToScan.add(packageName); }
private void runOnAllSchemas() throws LiquibaseException { Iterator i$ = this.schemas.iterator(); while(i$.hasNext()) { String schema = (String)i$.next(); if (StringUtils.isEmpty(schema)) continue; if (schema.equals("default")) { schema = null; } this.log.info("Initializing Liquibase for schema " + schema); CustomSpringLiquibase liquibase = this.getSpringLiquibase(this.dataSource); liquibase.setDefaultSchema(schema); liquibase.afterPropertiesSet(); this.log.info("Liquibase ran for schema " + schema); } }
@Override public SqlStatement[] generateStatements(final Database database) { final SqlStatement[] superStatements = super.generateStatements(database); if (m_where == null) return superStatements; if (superStatements.length != 1) { LogFactory.getLogger().warning("expected 1 create index statement, but got " + superStatements.length); return superStatements; } return new SqlStatement[]{ new CreateIndexWithWhereStatement((CreateIndexStatement)superStatements[0], m_where) }; }
LOG.warning("Hibernate primary key name is probably truncated. " + hbnPrimaryKeyName); String newAlias = NEW_PK_ALIAS.toAliasString(hbnTableName); int newAliasLength = newAlias.length(); hbnPrimaryKeyName = newAlias; LOG.warning("Changing hibernate primary key name to " + hbnPrimaryKeyName); LOG.info("Found primary key " + pk.getName()); table.setPrimaryKey(pk); Index index = new Index();
throw new RuntimeException(String.format("[id = %s] Cannot create [%s] dirs.", id, liquibaseDir)); log.debug(LogType.LOG, String.format("[id = %s] Includes directory: [path='%s']", id, liquibaseDir.getAbsolutePath())); log.debug(LogType.LOG, String.format("[id = %s] File [path='%s'] already exists, deleting", id, path)); if (output.delete()) { log.debug(LogType.LOG, String.format("[id = %s] File [path='%s'] already exists, deleted successfully.", id, path)); } else { log.debug(LogType.LOG, String.format("[id = %s] File [path='%s'] already exists, failed to delete.", id, path)); throw new RuntimeException(String.format("[id = %s] Cannot create [%s] file.", id, output)); log.info(LogType.LOG, String.format("[id = %s] File %s was created.", id, output)); log.debug(LogType.LOG, String.format("[id = %s] Root liquibase file [path='%s'] ready.", id, path)); log.info(LogType.LOG, String.format("[id = %s] Scanning application for liquibase schemes.", id)); log.info(LogType.LOG, String.format("[id = %s] Scan complete [took=%s milliseconds].", id, System.currentTimeMillis() - start)); log.debug(LogType.LOG, String.format("[id = %s] Resolved schemes: %n%s%n", id, schemes)); log.debug(LogType.LOG, String.format("[id = %s] Generating root liquibase file...", id)); log.info(LogType.LOG, String.format("[id = %s] File %s was written.", id, output)); log.debug(LogType.LOG, String.format("[id = %s] Generation complete.", id)); log.debug(LogType.LOG, String.format("[id = %s] Root liquibase xml: %n %s %n", id, xml));
public <T> Class<? extends T>[] findClasses(Class<T> requiredInterface) throws ServiceNotFoundException { logger.debug("ServiceLocator.findClasses for " + requiredInterface.getName()); try { Class.forName(requiredInterface.getName()); if (!classesBySuperclass.containsKey(requiredInterface)) { classesBySuperclass.put(requiredInterface, findClassesImpl(requiredInterface)); } } catch (Exception e) { throw new ServiceNotFoundException(e); } List<Class> classes = classesBySuperclass.get(requiredInterface); HashSet<Class> uniqueClasses = new HashSet<Class>(classes); return uniqueClasses.toArray(new Class[uniqueClasses.size()]); }
private String copyToFile(final String id, final String liquibase, final String schema) { log.info(LogType.LOG, String.format("[id = %s] copyToFile(%s, %s)", id, liquibase, schema)); is = this.getClass().getClassLoader().getResourceAsStream(schema); log.info(LogType.LOG, String.format("[id = %s] Transferring schema [resource=%s] to directory [path=%s]...", id, schema, liquibase)); String path = schema.startsWith("/") ? schema.substring(1) : schema; log.debug(LogType.LOG, String.format("[id = %s] LiquibaseSchema path is [path='%s'].", id, path)); log.debug(LogType.LOG, String.format("[id = %s] LiquibaseSchema path contains intermediate directories [path='%s'], preparing its...", id, dirPath)); log.info(LogType.LOG, String.format("[id = %s] Directories for [path='%s'] file created.", id, file.getAbsolutePath())); log.info(LogType.LOG, String.format("[id = %s] LiquibaseSchema file [path='%s'] already exists, deleting...", id, file.getAbsolutePath())); if (file.delete()) { log.info(LogType.LOG, String.format("[id = %s] File [path='%s'] deleted.", id, file.getAbsolutePath())); log.info(LogType.LOG, String.format("[id = %s] File [path='%s'] created.", id, file.getAbsolutePath())); log.debug(LogType.LOG, String.format("[id = %s] LiquibaseSchema file [path='%s'] is ready, copying data...", id, file.getAbsolutePath())); log.info(LogType.LOG, String.format("[id = %s] Data copied, schema path is [path='%s'].", id, schemaPath)); return schemaPath; } catch (IOException e) { log.warning(LogType.LOG, String.format("IOException during closing an input stream '%s'.", ioe.getMessage()), ioe);
@Override public void executeStatements(Change change, DatabaseChangeLog changeLog, List<SqlVisitor> sqlVisitors) throws LiquibaseException { if (getConnection() != null) { // don't log if running offline Logger log = LogFactory.getInstance().getLog(); log.info("Executing " + change.getClass().getSimpleName()); } super.executeStatements(change, changeLog, sqlVisitors); } }
@Override public SqlStatement[] generateStatements(final Database database) { final SqlStatement[] superStatements = super.generateStatements(database); if (m_where == null) return superStatements; if (superStatements.length != 1) { LogFactory.getLogger().warning("expected 1 create index statement, but got " + superStatements.length); return superStatements; } return new SqlStatement[]{ new CreateIndexWithWhereStatement((CreateIndexStatement)superStatements[0], m_where) }; }
log.debug(LogType.LOG, String.format("[id = %s] build(%s)", id, schemes)); log.info(LogType.LOG, String.format("[id = %s] Sorting schemes according dependencies...", id)); log.info(LogType.LOG, String.format("[id = %s] Found [%s] not dependent schemes.", id, notDependent.size())); log.debug(LogType.LOG, String.format("[id = %s] Selected dependencies tree root [%s]", id, root.getItem())); log.debug(LogType.LOG, String.format("[id = %s] Made other non-dependent schemes children of root. [%s] dependent schemes to resolve. Resolving...", id, availableSchemes.size() log.debug(LogType.LOG, String.format("[id = %s] Resolution cycle [%s] started.", id, cycles)); int additions = 0; //we will count dependencies resolution for each resolution cycle. for (LiquibaseSchema liquibaseSchema : schemes) { log.debug(LogType.LOG, String.format( "[id = %s] LiquibaseSchema [name=%s] depends on liquibaseSchema [name=%s].", id, liquibaseSchema.name(), liquibaseSchema.depends() log.debug(LogType.LOG, String.format( "[id = %s] Dependency not found in resolved dependencies tree, skipping liquibaseSchema [name=%s] for a while.", id, liquibaseSchema.name() log.debug(LogType.LOG, String.format( "[id = %s] Dependency found for liquibaseSchema [name=%s], moving it to resolved dependencies tree.", id, liquibaseSchema.name() log.debug(LogType.LOG, String.format("[id = %s] Resolution cycle [%s] completed", id, cycles));
@Override public void error(final SAXParseException exception) throws SAXException { LogFactory.getLogger().severe(exception.getMessage()); throw exception; }