List of usage examples for org.apache.commons.io FileUtils touch
public static void touch(File file) throws IOException
From source file:com.liferay.portal.tools.service.builder.ServiceBuilder.java
private void _createSQLIndexes() throws Exception { File sqlDir = new File(_sqlDirName); if (!sqlDir.exists()) { return;/* w w w . j a va 2 s.c om*/ } // indexes.sql loading File sqlFile = new File(_sqlDirName + "/" + _sqlIndexesFileName); if (!sqlFile.exists()) { FileUtils.touch(sqlFile); } Map<String, List<IndexMetadata>> indexMetadataMap = new TreeMap<>(); try (UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader(new FileReader(sqlFile))) { while (true) { String indexSQL = unsyncBufferedReader.readLine(); if (indexSQL == null) { break; } indexSQL = indexSQL.trim(); if (Validator.isNull(indexSQL)) { continue; } IndexMetadata indexMetadata = IndexMetadataFactoryUtil.createIndexMetadata(indexSQL); _addIndexMetadata(indexMetadataMap, indexMetadata.getTableName(), indexMetadata); } } // indexes.sql appending for (int i = 0; i < _ejbList.size(); i++) { Entity entity = _ejbList.get(i); if (!_isTargetEntity(entity)) { continue; } if (!entity.isDefaultDataSource()) { continue; } List<EntityFinder> finderList = entity.getFinderList(); for (int j = 0; j < finderList.size(); j++) { EntityFinder finder = finderList.get(j); if (finder.isDBIndex()) { List<String> finderColsNames = new ArrayList<>(); List<EntityColumn> finderColsList = finder.getColumns(); for (int k = 0; k < finderColsList.size(); k++) { EntityColumn col = finderColsList.get(k); finderColsNames.add(col.getDBName()); } if (finderColsNames.isEmpty()) { continue; } IndexMetadata indexMetadata = IndexMetadataFactoryUtil.createIndexMetadata(finder.isUnique(), entity.getTable(), finderColsNames.toArray(new String[finderColsNames.size()])); _addIndexMetadata(indexMetadataMap, indexMetadata.getTableName(), indexMetadata); } } } for (Map.Entry<String, EntityMapping> entry : _entityMappings.entrySet()) { EntityMapping entityMapping = entry.getValue(); _getCreateMappingTableIndex(entityMapping, indexMetadataMap); } StringBundler sb = new StringBundler(); for (List<IndexMetadata> indexMetadataList : indexMetadataMap.values()) { Collections.sort(indexMetadataList); for (IndexMetadata indexMetadata : indexMetadataList) { sb.append(indexMetadata.getCreateSQL()); sb.append(StringPool.NEW_LINE); } sb.append(StringPool.NEW_LINE); } if (!indexMetadataMap.isEmpty()) { sb.setIndex(sb.index() - 2); } writeFileRaw(sqlFile, sb.toString(), _modifiedFileNames); // indexes.properties File file = new File(_sqlDirName, "indexes.properties"); file.delete(); }
From source file:com.liferay.portal.tools.service.builder.ServiceBuilder.java
private void _createSQLMappingTables(File sqlFile, String newCreateTableString, EntityMapping entityMapping, boolean addMissingTables) throws IOException { if (!sqlFile.exists()) { FileUtils.touch(sqlFile); }//from w w w .j a v a 2s . c om String content = FileUtils.readFileToString(sqlFile); int x = content.indexOf(_SQL_CREATE_TABLE + entityMapping.getTable() + " ("); int y = content.indexOf(");", x); if (x != -1) { String oldCreateTableString = content.substring(x + 1, y); if (!oldCreateTableString.equals(newCreateTableString)) { content = content.substring(0, x) + newCreateTableString + content.substring(y + 2); writeFileRaw(sqlFile, content, _modifiedFileNames); } } else if (addMissingTables) { try (UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader( new UnsyncStringReader(content))) { StringBundler sb = new StringBundler(); String line = null; boolean appendNewTable = true; while ((line = unsyncBufferedReader.readLine()) != null) { if (appendNewTable && line.startsWith(_SQL_CREATE_TABLE)) { x = _SQL_CREATE_TABLE.length(); y = line.indexOf(" ", x); String tableName = line.substring(x, y); if (tableName.compareTo(entityMapping.getTable()) > 0) { sb.append(newCreateTableString); sb.append("\n\n"); appendNewTable = false; } } sb.append(line); sb.append("\n"); } if (appendNewTable) { sb.append("\n"); sb.append(newCreateTableString); } writeFileRaw(sqlFile, sb.toString(), _modifiedFileNames); } } }
From source file:com.liferay.portal.tools.service.builder.ServiceBuilder.java
private void _createSQLSequences() throws IOException { File sqlDir = new File(_sqlDirName); if (!sqlDir.exists()) { return;/* ww w . j av a 2 s . c o m*/ } File sqlFile = new File(_sqlDirName + "/" + _sqlSequencesFileName); if (!sqlFile.exists()) { FileUtils.touch(sqlFile); } Set<String> sequenceSQLs = new TreeSet<>(); try (UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader(new FileReader(sqlFile))) { while (true) { String sequenceSQL = unsyncBufferedReader.readLine(); if (sequenceSQL == null) { break; } if (Validator.isNotNull(sequenceSQL)) { sequenceSQLs.add(sequenceSQL); } } } for (int i = 0; i < _ejbList.size(); i++) { Entity entity = _ejbList.get(i); if (!_isTargetEntity(entity)) { continue; } if (!entity.isDefaultDataSource()) { continue; } List<EntityColumn> columnList = entity.getColumnList(); for (int j = 0; j < columnList.size(); j++) { EntityColumn column = columnList.get(j); if ("sequence".equals(column.getIdType())) { StringBundler sb = new StringBundler(); String sequenceName = column.getIdParam(); if (sequenceName.length() > 30) { sequenceName = sequenceName.substring(0, 30); } sb.append("create sequence "); sb.append(sequenceName); sb.append(";"); String sequenceSQL = sb.toString(); if (!sequenceSQLs.contains(sequenceSQL)) { sequenceSQLs.add(sequenceSQL); } } } } StringBundler sb = new StringBundler(sequenceSQLs.size() * 2); for (String sequenceSQL : sequenceSQLs) { sb.append(sequenceSQL); sb.append("\n"); } if (!sequenceSQLs.isEmpty()) { sb.setIndex(sb.index() - 1); } writeFileRaw(sqlFile, sb.toString(), _modifiedFileNames); }
From source file:com.liferay.portal.tools.service.builder.ServiceBuilder.java
private void _createSQLTables() throws Exception { File sqlDir = new File(_sqlDirName); if (!sqlDir.exists()) { return;/*w ww . j ava 2s. co m*/ } File sqlFile = new File(_sqlDirName + "/" + _sqlFileName); if (!sqlFile.exists()) { FileUtils.touch(sqlFile); } for (int i = 0; i < _ejbList.size(); i++) { Entity entity = _ejbList.get(i); if (!_isTargetEntity(entity)) { continue; } if (!entity.isDefaultDataSource()) { continue; } String createTableSQL = _getCreateTableSQL(entity); if (Validator.isNotNull(createTableSQL)) { _createSQLTables(sqlFile, createTableSQL, entity, true); _updateSQLFile("update-6.2.0-7.0.0.sql", createTableSQL, entity); } } for (Map.Entry<String, EntityMapping> entry : _entityMappings.entrySet()) { EntityMapping entityMapping = entry.getValue(); String createMappingTableSQL = _getCreateMappingTableSQL(entityMapping); if (Validator.isNotNull(createMappingTableSQL)) { _createSQLMappingTables(sqlFile, createMappingTableSQL, entityMapping, true); } } String content = FileUtils.readFileToString(sqlFile); writeFileRaw(sqlFile, content.trim(), _modifiedFileNames); }
From source file:com.liferay.portal.tools.service.builder.ServiceBuilder.java
private void _createSQLTables(File sqlFile, String newCreateTableString, Entity entity, boolean addMissingTables) throws IOException { if (!sqlFile.exists()) { FileUtils.touch(sqlFile); }/* w ww . ja v a2s . c o m*/ String content = FileUtils.readFileToString(sqlFile); int x = content.indexOf(_SQL_CREATE_TABLE + entity.getTable() + " ("); int y = content.indexOf(");", x); if (x != -1) { String oldCreateTableString = content.substring(x, y + 2); if (!oldCreateTableString.equals(newCreateTableString)) { content = content.substring(0, x) + newCreateTableString + content.substring(y + 2); FileUtils.write(sqlFile, content); } } else if (addMissingTables) { try (UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader( new UnsyncStringReader(content))) { StringBundler sb = new StringBundler(); String line = null; boolean appendNewTable = true; while ((line = unsyncBufferedReader.readLine()) != null) { if (appendNewTable && line.startsWith(_SQL_CREATE_TABLE)) { x = _SQL_CREATE_TABLE.length(); y = line.indexOf(" ", x); String tableName = line.substring(x, y); if (tableName.compareTo(entity.getTable()) > 0) { sb.append(newCreateTableString); sb.append("\n\n"); appendNewTable = false; } } sb.append(line); sb.append("\n"); } if (appendNewTable) { sb.append("\n"); sb.append(newCreateTableString); } writeFileRaw(sqlFile, sb.toString(), _modifiedFileNames); } } }
From source file:net.sourceforge.vulcan.core.support.WorkingCopyUpdateExpertTest.java
public void testRequestedButPreviousBuildNotPresent() throws Exception { assertTrue("Cannot create test directory", workDir.mkdirs()); FileUtils.touch(new File(workDir, "foo")); config.setUpdateStrategy(UpdateStrategy.IncrementalAlways); assertEquals(UpdateType.Full, expert.determineUpdateStrategy(config, null)); }
From source file:net.sourceforge.vulcan.core.support.WorkingCopyUpdateExpertTest.java
public void testRequestedButPreviousBuildError() throws Exception { assertTrue("Cannot create test directory", workDir.mkdirs()); FileUtils.touch(new File(workDir, "foo")); config.setUpdateStrategy(UpdateStrategy.IncrementalAlways); previousStatus.setStatus(ERROR);//from ww w . j av a2 s . co m assertEquals(UpdateType.Full, expert.determineUpdateStrategy(config, previousStatus)); }
From source file:net.sourceforge.vulcan.core.support.WorkingCopyUpdateExpertTest.java
public void testAllowedOnPreviousBuildErrorWithVcsFlag() throws Exception { assertTrue("Cannot create test directory", workDir.mkdirs()); FileUtils.touch(new File(workDir, "foo")); config.setUpdateStrategy(UpdateStrategy.IncrementalAlways); config.setRepositoryTagName("trunk"); previousStatus.setStatus(ERROR);//from w w w . j a v a 2 s . com previousStatus.setWorkDirSupportsIncrementalUpdate(true); previousStatus.setTagName("trunk"); assertEquals(UpdateType.Incremental, expert.determineUpdateStrategy(config, previousStatus)); }
From source file:net.sourceforge.vulcan.core.support.WorkingCopyUpdateExpertTest.java
public void testRequestedButPreviousBuildDifferentTag() throws Exception { assertTrue("Cannot create test directory", workDir.mkdirs()); FileUtils.touch(new File(workDir, "foo")); config.setUpdateStrategy(UpdateStrategy.IncrementalAlways); config.setRepositoryTagName("trunk"); previousStatus.setStatus(PASS);/*from w ww .j ava 2 s .c om*/ previousStatus.setTagName("branches/1.0"); assertEquals(UpdateType.Full, expert.determineUpdateStrategy(config, previousStatus)); }
From source file:net.sourceforge.vulcan.core.support.WorkingCopyUpdateExpertTest.java
public void testRequestedAllCriteriaMet() throws Exception { assertTrue("Cannot create test directory", workDir.mkdirs()); FileUtils.touch(new File(workDir, "foo")); config.setUpdateStrategy(UpdateStrategy.IncrementalAlways); config.setRepositoryTagName("trunk"); previousStatus.setStatus(PASS);/*from w ww . ja va 2s . com*/ previousStatus.setTagName("trunk"); assertEquals(UpdateType.Incremental, expert.determineUpdateStrategy(config, previousStatus)); }