org.wso2.carbon.utils.dbcreator.DatabaseCreator Java Examples
The following examples show how to use
org.wso2.carbon.utils.dbcreator.DatabaseCreator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LocalDatabaseCreator.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Creates registry database if the script exists; returns otherwise. * * @throws Exception */ public void createRegistryDatabase() throws Exception{ String databaseType = DatabaseCreator.getDatabaseType(this.dataSource.getConnection()); String scripPath = getDbScriptLocation(databaseType); File scripFile = new File(scripPath); if(scripFile.exists()){ super.createRegistryDatabase(); } }
Example #2
Source File: LocalDatabaseCreatorTestCase.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Before public void setup() throws Exception { System.setProperty(CARBON_HOME, ""); localDatabaseCreator = new LocalDatabaseCreator(Mockito.mock(DataSource.class)); PowerMockito.mockStatic(DatabaseCreator.class); PowerMockito.when(DatabaseCreator.getDatabaseType(Matchers.any(Connection.class))).thenReturn("mysql"); PowerMockito.whenNew(File.class).withAnyArguments().thenReturn(file); }
Example #3
Source File: LocalDatabaseCreatorTestCase.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testCreateRegistryDatabaseWhenFileExists() throws Exception { Mockito.when(file.exists()).thenReturn(true); Method method = PowerMockito.method(DatabaseCreator.class, "createRegistryDatabase"); PowerMockito.suppress(method); localDatabaseCreator.createRegistryDatabase(); Mockito.verify(file, Mockito.times(1)).exists(); }
Example #4
Source File: LocalDatabaseCreatorTestCase.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testCreateRegistryDatabaseWhenFileDoesNotExist() throws Exception { Mockito.when(file.exists()).thenReturn(false); Method method = PowerMockito.method(DatabaseCreator.class, "createRegistryDatabase"); PowerMockito.suppress(method); localDatabaseCreator.createRegistryDatabase(); Mockito.verify(file, Mockito.times(1)).exists(); }
Example #5
Source File: MigrationDatabaseCreator.java From product-es with Apache License 2.0 | 4 votes |
/** * executes content in SQL script * * @throws IOException,SQLException */ private void executeSQLScript(String dbscriptName) throws IOException, SQLException { String delimiter = ";"; boolean keepFormat = false; StringBuffer sql = new StringBuffer(); try (InputStream is = getClass().getResourceAsStream(dbscriptName); InputStreamReader inputStreamReader = new InputStreamReader(is); BufferedReader reader = new BufferedReader(inputStreamReader )) { String line; while ((line = reader.readLine()) != null) { line = line.trim(); if (!keepFormat) { if (line.startsWith("//")) { continue; } if (line.startsWith("--")) { continue; } StringTokenizer st = new StringTokenizer(line); if (st.hasMoreTokens()) { String token = st.nextToken(); if ("REM".equalsIgnoreCase(token)) { continue; } } } sql.append(keepFormat ? "\n" : " ").append(line); if (!keepFormat && line.indexOf("--") >= 0) { sql.append("\n"); } if ((DatabaseCreator.checkStringBufferEndsWith(sql, delimiter))) { executeSQL(sql.substring(0, sql.length() - delimiter.length())); sql.replace(0, sql.length(), ""); } } if (sql.length() > 0) { executeSQL(sql.toString()); } } }