I'm using a database to pass data to my model. This is very convenient if a little slow (as I need to constantly query the DB during the run) but that is another story.
AnyLogic has a great looking object on the "Connectivity" pallet called a Key-Value Table which enables you to create a key-value (hashmap?) by simply specifying things like the table name and the key and value fields. It also requires you to specify the database - which is where my problem arises...
The database I am using is the internal database which is accessible from getEngine().getModelDatabase() however this is of type ModelDatabase whereas the Key-Value object expects a database of the type Database. Database and ModelDatabase seem to be from different inheritance trees so I am unable to cast the ModelDatabase to Database.
This is what I tried:
But I get the error "Cannot cast from ModelDatabase to Database" when compiling.
My database table looks like this:
I'd prefer to not have to import the database as a separate database object if possible.
Has anyone tried to use this object with the ModelDatabase and come across a solution to this problem?
No need to use the key-value table if you use the internal database (which I use all the time :D ). Just use the "database query wizard" (see help) to read data and turn it into a LHM yourself. The key-value object is a remnant from before the internal dbase was even around...
Related
I've been trying with no success to run evolutions + slick to generate schema for a MSQLServer database.
I am using Play 2.3.x, scala 2.11.6, slick, and SQLServer 2014.
I could make it connect as well, but the script which is generated contains lots of "errors" relates to data types, like the use of BOOLEAN and TIMESTAMP which are types that SQLServer does not use.
The script should use the types BIT instead of BOOLEAN, DATETIME instead of TIMESTAMP, and UNIQUEIDENTIFIER instead of UUID.
Does anyone know a workaround for that?
These datatypes and all specific to database so there is no workaround here.
You have change the data types based on the selected database otherwise you will get the same error in another database as well.
I'm trying to copy a database for use in testing/developing, in SQLDeveloper I can only see the user views, the data objects are not accessible for me.
Is there anyway to copy the views only and get a dll that creates some sort of phantom structure for the data objects that are not reachable but referenced in the sql queries for those views? Problem is there are over a thousand such references,
In the example below I cannot reach the header object due too permissions,
Example:
CREATE OR REPLACE FORCE VIEW "TRADE"."EXCHANGE" ("MSGQUE", "MSGQUE2") AS
select msgque, msgque2
from head.msgqueues;
I have tryed to export the views in SQL developer but when I import it in my Oracle test database the views contain error and are unusable because the data object did not get exported in the export.sql file,
Thanks in advance
I recommend using the expdp utility to perform this. You can explicitly say to grab views and tables.
Example parfile:
SCHEMAS=SCOTT
INCLUDE=TABLE:"IN ('DEPT')"
INCLUDE=VIEW
DIRECTORY=datapump
DUMPFILE=dept.dmp
LOGFILE=dept.log
Then you can impdp that parfile into the DB you wish and you will have the TABLE and the VIEW that goes in the schema. You can modify the IN clause to grab whatever naming scheme you would need.
I plan to use ORM in my project.
How should I approach DDL creation?
Is this all handled by ORM and i should use ORM CREATE objects for this?
Traditionally - I would create DDL scipt in plain SQL standard on hands, and move to another DB easily. But today there are many tools to create DB from Java classes or vice versa.
Point is: I don't want to get in trouble when I have to move to another DB and must perform manual DB column type conversion and similar things?
thank you very much for your time!
its so easy ... you cant create orm class (or use many old orm ) and then change db name, only you must create class to migrate,
this class read all data from old db and write in new db with new structure
only i suggest read db structure, many db ( like noSQL db) have different structure.
I was reading about ORMs and one of the descriptions I read said that the ORM interacts with database metadata.
Why is this important or relevant?
Metadata, as I understand, is just a way of describing what the database contains. So, for example, the database might have an internal table that lists what user tables have been created. Why would something like this be useful to an ORM?
What this means is that the ORM maps the schema, or structure, of the database to objects. Typically, this means mapping tables to classes (User table to User class), fields to attributes (Age field to User.Age attribute), and each record then represents an instance of that object.
The ORM uses the metadata to generate the code used to access the tables. For example, if it's a date column then it generates the code to deal with that column as a date.
It will read foreign keys and primary keys to build relationships in the code as well as for generating the proper SQL syntax.
This is just a few of the ways it uses the metadata.
We are in the process of a multi-year project where we're building a new system and a new database to eventually replace the old system and database. The users are using the new and old systems as we're changing them.
The problem we keep running into is when an object in one system is dependent on an object in the other system. We've been using views, but have run into a limitation with one of the technologies (Entity Framework) and are considering other options.
The other option we're looking at right now is replication. My boss isn't excited about the extra maintenance that would cause. So, what other options are there for getting dependent data into the database that needs it?
Update:
The technologies we're using are SQL Server 2008 and Entity Framework. Both databases are within the same sql server instance so linked servers shouldn't be necessary.
The limitation we're facing with Entity Framework is we can't seem to create the relationships between the table-based-entities and the view-based-entities. No relationship can exist in the database between a view and a table, as far as I know, so the edmx diagram can't infer it. And I cannot seem to create the relationship manually without getting errors. It thinks all columns in the view are keys.
If I leave it that way I get an error like this for each column in the view:
Association End key property [...] is
not mapped.
If I try to change the "Entity Key" property to false on the columns that are not the key I get this error:
All the key properties of the
EntitySet [...] must be mapped to all
the key properties [...] of table
viewName.
According to this forum post it sounds like a limitation of the Entity Framework.
Update #2
I should also mention the main limitation of the Entity Framework is that it only supports one database at a time. So we need the old data to appear to be in the new database for the Entity Framework to see it. We only need read access of the old system data in the new system.
You can use linked server queries to leave the data where it is, but connect to it from the other db.
Depending on how up-to-date the data in each db needs to be & if one data source can remain read-only you can:
Use the Database Copy Wizard to create an SSIS package
that you can run periodically as a SQL Agent Task
Use snapshot replication
Create a custom BCP in/out process
to get the data to the other db
Use transactional replication, which
can be near-realtime.
If data needs to be read-write in both database then you can use:
transactional replication with
update subscriptions
merge replication
As you go down the list the amount of work involved in maintaining the solution increases. Using linked server queries will work best if its the right fit for what you're trying to achieve.
EDIT: If they're the same server then as suggested by another user you should be able to access the table with servername.databasename.schema.tablename Looks like it's an entity-framework issues & not a db issue.
I don't know about EntityToSql but I know in LinqToSql you can connect to multiple databases/servers in one .dbml if you prefix the tables with:
ServerName.DatabaseName.SchemaName.TableName
MyServer.MyOldDatabase.dbo.Customers
I have been able to click on a table in the .dbml and copy and paste it into the .dbml of the alternate project prefix the name and set up the relationships and it works... like I said this was in LinqToSql, though have not tried it with EntityToSql. I would give it shot before you go though all the work of replication and such.
If Linq-to-Entities cannot cross DB's then Replication or something that emulates it is the only thing that will work.
For performance purposes you probably want either Merge replication or Transactional with queued (not immediate) updating.
Thanks for the responses. We're going to try adding triggers to the old database tables to insert/update/delete records in the new tables of the new database. This way we can continue to use Entity Framework and also do any data transformations we need.
Once the UI functions move over to the new system for a particular feature, we'll remove the table from the old database and add a view to the old database with the same name that points to the new database table for backwards compatibility.
One thing that I realized needs to happen before we can do this is we have to search all our code and sql for ##Identity and replace it with scope_identity() so the triggers don't mess up the Ids in the old system.