private VDBKey vdbKey(Database db) { return new VDBKey(db.getName(), db.getVersion()); }
public static MetadataFactory createMF(DatabaseStore events, Schema schema, boolean useSchema) { MetadataFactory mf = new MetadataFactory(events.getCurrentDatabase().getName(), events.getCurrentDatabase().getVersion(), schema==null?"undefined":schema.getName(), events.getCurrentDatabase().getMetadataStore().getDatatypes(), new Properties(), null); //$NON-NLS-1$ Map<String, String> nss = events.getNameSpaces(); for (String key:nss.keySet()) { mf.addNamespace(key, nss.get(key)); } if (useSchema && schema != null) { mf.setSchema(schema); } return mf; }
public Schema getSchema(String schemaName) { verifyDatabaseExists(); return this.currentDatabase.getSchema(schemaName); }
protected Server verifyServerExists(String serverName) { verifyDatabaseExists(); Server server = this.currentDatabase.getServer(serverName); if (server == null) { throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31220, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31220, serverName, this.currentDatabase.getName())); } return server; }
protected Role verifyRoleExists(String roleName) { verifyDatabaseExists(); Role role = this.currentDatabase.getRole(roleName); if (role == null) { throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31222, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31222, roleName, this.currentDatabase.getName())); } return role; }
public static Database convert(VDBMetaData vdb, MetadataStore metadataStore) { Database db = new Database(vdb.getName(), vdb.getVersion()); db.setProperties(vdb.getPropertiesMap()); if (vdb.getDescription() != null) { db.setAnnotation(vdb.getDescription()); db.setProperty("connection-type", vdb.getConnectionType().name()); db.getMetadataStore().addDataTypes(metadataStore.getDatatypes()); if (db.getDataWrapper(t.getType()) == null) { DataWrapper dw = new DataWrapper(t.getType()); db.addDataWrapper(dw); if (db.getDataWrapper(t.getName()) == null) { DataWrapper dw = new DataWrapper(t.getName()); dw.setType(t.getType()); db.addDataWrapper(dw); if (db.getDataWrapper(s.getTranslatorName()) == null) { DataWrapper dw = new DataWrapper(s.getTranslatorName()); db.addDataWrapper(dw); if (db.getServer(s.getName()) == null) { db.addServer(server); schema.addServer(server); db.addSchema(schema);
append("/*").append(NEWLINE); append("###########################################").append(NEWLINE); append("# START DATABASE ").append(database.getName()).append(NEWLINE); append("###########################################").append(NEWLINE); append("*/").append(NEWLINE); .append(SQLStringVisitor.escapeSinglePart(database.getName())).append(SPACE).append(VERSION) .append(SPACE).append(new Constant(database.getVersion())); appendOptions(database); append(SEMICOLON); append(NEWLINE); append(USE).append(SPACE).append(DATABASE).append(SPACE); append(SQLStringVisitor.escapeSinglePart(database.getName())).append(SPACE); append(VERSION).append(SPACE).append(new Constant(database.getVersion())); append(SEMICOLON); append(NEWLINE); for (Datatype dt : database.getMetadataStore().getDatatypes().values()) { if (dt.getType() == Datatype.Type.Domain) { outputDt = true; for (Datatype dt : database.getMetadataStore().getDatatypes().values()) { if (dt.isBuiltin()) { continue; if (!database.getDataWrappers().isEmpty()){ append(NEWLINE); append("--############ Translators ############"); append(NEWLINE);
public static VDBMetaData convert(Database database) { VDBMetaData vdb = new VDBMetaData(); vdb.setName(database.getName()); vdb.setVersion(database.getVersion()); vdb.setDescription(database.getAnnotation()); if (database.getProperty("connection-type", false) != null) { vdb.setConnectionType(VDB.ConnectionType.valueOf(database.getProperty("connection-type", false))); vdb.getPropertiesMap().putAll(database.getProperties()); for (DataWrapper dw : database.getDataWrappers()) { if (dw.getType() == null) { for(Schema schema : database.getSchemas()) { ModelMetaData mmd = new ModelMetaData(); mmd.setName(schema.getName());
@Test public void testAlterDatabase() throws Exception { String ddl = "CREATE DATABASE FOO VERSION '2' OPTIONS (k1 'v1', k2 'v2');" + "USE DATABASE FOO version '2';" + "ALTER DATABASE FOO OPTIONS (ADD k3 'v3', SET k1 'v4', DROP k2);"; Database db = helpParse(ddl); assertEquals("FOO", db.getName()); assertEquals("2", db.getVersion()); assertEquals("v4", db.getProperty("k1", false)); assertNull(db.getProperty("k2", false)); assertEquals("v3", db.getProperty("k3", false)); }
public void schemaCreated(Schema schema, List<String> serverNames) { if (!assertInEditMode(Mode.DATABASE_STRUCTURE)) { return; } assertGrant(Grant.Permission.Privilege.CREATE, Database.ResourceType.SCHEMA, schema); verifyDatabaseExists(); setUUID(this.currentDatabase.getName(), this.currentDatabase.getVersion(), schema); this.currentDatabase.addSchema(schema); if (schema.isPhysical()) { for (String serverName:serverNames) { Server server = verifyServerExists(serverName); schema.addServer(server); } } else { if (!serverNames.isEmpty()) { throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31236, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31236, schema.getName())); } } }
if (schema == null) { throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31234, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31234, name, getCurrentDatabase().getName())); Server server = getCurrentDatabase().getServer(name); if (server == null) { throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31220, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31220, name, getCurrentDatabase().getName())); DataWrapper dw = getCurrentDatabase().getDataWrapper(name); if (dw == null) { throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31247, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31247, name, getCurrentDatabase().getName()));
@Test public void testCreateServerNoType() throws Exception { String ddl = "CREATE DATABASE FOO VERSION '2';" + "USE DATABASE FOO version '2';" + "CREATE FOREIGN DATA WRAPPER orcl;" + "CREATE SERVER x FOREIGN DATA WRAPPER orcl;"; Database db = helpParse(ddl); assertEquals("FOO", db.getName()); assertEquals("2", db.getVersion()); Server s = db.getServer("x"); assertNotNull(s); assertTrue(s.isVirtual()); }
dbStore.databaseCreated(new Database("x", "1")); //$NON-NLS-1$ //$NON-NLS-2$ dbStore.databaseSwitched("x", "1"); //$NON-NLS-1$ //$NON-NLS-2$ dbStore.setMode(Mode.DOMAIN); QueryParser.getQueryParser().parseDDL(dbStore, new StringReader(value)); dbStore.stopEditing(); store.addDataTypes(dbStore.getDatabase("x", "1").getMetadataStore().getDatatypes()); //$NON-NLS-1$ //$NON-NLS-2$
protected Schema verifySchemaExists(String schemaName) { verifyDatabaseExists(); Schema schema = this.currentDatabase.getSchema(schemaName); if (schema == null) { throw new org.teiid.metadata.MetadataException(QueryPlugin.Event.TEIID31234, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31234, schemaName, this.currentDatabase.getName())); } return schema; }
public void databaseCreated(Database db) { if (!assertInEditMode(Mode.DATABASE_STRUCTURE)) { return; } assertGrant(Grant.Permission.Privilege.CREATE, Database.ResourceType.DATABASE, db); Database database = this.databases.get(vdbKey(db)); if ( database != null) { throw new DuplicateRecordException(QueryPlugin.Event.TEIID31232, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31232, db.getName())); } if (this.currentDatabase != null) { throw new MetadataException(QueryPlugin.Event.TEIID31242, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID31242)); } db.getMetadataStore().addDataTypes(getRuntimeTypes()); this.databases.put(vdbKey(db), db); }
@Test public void testSchema() throws Exception { Database db = new Database("foo", "2"); db.addDataWrapper(dw); s.setJndiName("java://test-server"); s.setType("orcl"); db.addServer(s); schema.addTable(t); schema.addServer(s); db.addSchema(schema);
@Test public void testCreateSchema() throws Exception { String ddl = "CREATE DATABASE FOO;" + "USE DATABASE FOO ;" + "CREATE FOREIGN DATA WRAPPER orcl;" + "CREATE SERVER x TYPE 'oracle' VERSION '2.0' FOREIGN DATA WRAPPER orcl OPTIONS (k1 'v1');" + "CREATE SCHEMA S1 SERVER x OPTIONS (x 'y');"; Database db = helpParse(ddl); // schema test Schema schema = db.getSchema("S1"); assertNotNull(schema); assertEquals("y", schema.getProperty("x", false)); //server test assertNotNull(db.getServer("x")); assertNotNull(schema.getServer("x")); assertEquals("v1", db.getServer("x").getProperty("k1", false)); // data wrapper test assertNotNull(db.getDataWrapper("orcl")); assertEquals("orcl", db.getServer("x").getDataWrapper()); }
final public void createDatabase(DatabaseStore dbStore) throws ParseException { String name = null; Database database = null; String version = null; jj_consume_token(CREATE); jj_consume_token(DATABASE); name = id(Boolean.TRUE); database = new Database(name); switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case VERSION: jj_consume_token(VERSION); version = stringVal(); database.setVersion(version); break; default: jj_la1[345] = jj_gen; ; } switch ((jj_ntk==-1)?jj_ntk():jj_ntk) { case OPTIONS: optionsClause(database, database.getNamespaceContainer()); OptionsUtil.setOptions(database); break; default: jj_la1[346] = jj_gen; ; } dbStore.databaseCreated(database); }