datubaze.files.wordpress.com · web view(*), which is considered equivalent to specifying a list of...

67
1 Grafiskās datu bāzes grafisko datu piemērs Y ass 20 18 16 14 12 10 2 0 2 4 6 8 10 12 14 16 18 X ass Slānis – mājas (poligoni): 1. MĀJA1 1,0, 1,4, 5,4, 5,0, 1,0 2. MĀJA2 7,0, 7,4, 11,4, 11,0, 7,0 3. MĀJA3 13,0, 13,4, 17,4, 17,0, 13,0 4. SKOLA 1,10, 1,19, 9,19, 9,10, 7,10, 7,12, 3,12, 3,10, 1,10 5. BASEINS 10,14, 10,19, 14,19, 14,14, 10,14 6. VEIKALS 15,8, 15,19, 19,19, 19,8, 15, 8 7. KIOSKS 10,8,10,11, 13,11, 13,8, 10,8 Slānis – ielas (taisnes nogriežņu virknes): S K O L A B A S E V I E N I S K A L K I - S O S - K S K O K S 1 K O K S 2 I E L A 1 I E L A 2 I E L A 3 M Ā J A M Ā J A M Ā J A 1 2 3

Upload: hanhu

Post on 16-May-2018

219 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

1

Grafiskās datu bāzes grafisko datu piemērs

Y ass 20

18

16

14

12

10

8

6

4 2 0

2 4 6 8 10 12 14 16 18 X ass

Slānis – mājas (poligoni):1. MĀJA1 1,0, 1,4, 5,4, 5,0, 1,02. MĀJA2 7,0, 7,4, 11,4, 11,0, 7,03. MĀJA3 13,0, 13,4, 17,4, 17,0, 13,04. SKOLA 1,10, 1,19, 9,19, 9,10, 7,10, 7,12, 3,12, 3,10, 1,105. BASEINS 10,14, 10,19, 14,19, 14,14, 10,146. VEIKALS 15,8, 15,19, 19,19, 19,8, 15, 87. KIOSKS 10,8,10,11, 13,11, 13,8, 10,8

Slānis – ielas (taisnes nogriežņu virknes):8. IELA1 0,6, 12,6, 19,6 20,69. IELA2 12,0, 12,610. IELA3 19,0, 19,6, 19,20

Slānis – Koki (riņķis, kuru definē trīs punkti):1. KOKS1 3,8.5, 3,9,5, 3.5,9 2. KOKS2 7,8.5, 7,9.5, 7.5,9

S K O L A B A S E VI EN IS K

AL

K I - SO S -K S

K O K S 1 K O K S 2

I E L A 1 I E L A 2 I E L A 3

M Ā J A M Ā J A M Ā J A1 2 3

Page 2: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

2

Grafiskās datu bāzes slāņa tabulu izveidošana

1. slāņa definēšana - celtnescreate table CELTNES (C_NUM number CONSTRAINT Ier_PA_Celtnes PRIMARY KEY,GEOMETRIJA MDSYS.SDO_GEOMETRY,C_NOS varchar2(20) );

2. slāņa definēšana - ielascreate table IELAS (I_NUM number CONSTRAINT Ier_PA_Ielas PRIMARY KEY,GEOMETRIJA MDSYS.SDO_GEOMETRY,I_NOS varchar2(20) );

3. slāņa definēšana - kokicreate table KOKI (K_NUM number CONSTRAINT Ier_PA_Koki PRIMARY KEY,GEOMETRIJA MDSYS.SDO_GEOMETRY,K_NOS varchar2(20) );

Page 3: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

3

Metadatu (slāņu dimensiju datu) ievade

delete from USER_SDO_GEOM_METADATA where TABLE_NAME = 'CELTNES';

delete from USER_SDO_GEOM_METADATA where TABLE_NAME = 'IELAS';

delete from USER_SDO_GEOM_METADATA where TABLE_NAME = 'KOKI';

insert into USER_SDO_GEOM_METADATA(TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) VALUES('CELTNES', 'GEOMETRIJA', MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X', 0, 20, 0.05),MDSYS.SDO_DIM_ELEMENT('Y', 0, 20, 0.05)), NULL);

insert into USER_SDO_GEOM_METADATA(TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) VALUES('IELAS', 'GEOMETRIJA', MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X', 0, 20, 0.05), MDSYS.SDO_DIM_ELEMENT('Y', 0, 20, 0.05)), NULL);

insert into USER_SDO_GEOM_METADATA(TABLE_NAME, COLUMN_NAME, DIMINFO, SRID) VALUES('KOKI', 'GEOMETRIJA', MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('X', 0, 20, 0.05), MDSYS.SDO_DIM_ELEMENT('Y', 0, 20, 0.05)), NULL);

Page 4: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

4

Informāciju par visiem ģeometriju slāņiem iespējams iegūt no datu bāzes datu vārdnīcas skata USER_SDO_GEOM_METADATA

SELECT * FROM USER_SDO_GEOM_METADATA;

Page 5: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

5

Datu ievade tabulā CELTNESinsert into CELTNES values(1,MDSYS.SDO_GEOMETRY(2003, NULL, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1, 3, 1),MDSYS.SDO_ORDINATE_ARRAY(1,0, 1,4, 5,4, 5,0, 1,0)), 'MĀJA1');

insert into CELTNES values(2,MDSYS.SDO_GEOMETRY(2003, NULL, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1, 3, 1),MDSYS.SDO_ORDINATE_ARRAY(7,0, 7,4, 11,4, 11,0, 7,0)), 'MĀJA2');

insert into CELTNES values(3,MDSYS.SDO_GEOMETRY(2003, NULL, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1, 3, 1),MDSYS.SDO_ORDINATE_ARRAY(13,0, 13,4, 17,4, 17,0, 13,0)), 'MĀJA3');

insert into CELTNES values(4,MDSYS.SDO_GEOMETRY(2003, NULL, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1, 3, 1),MDSYS.SDO_ORDINATE_ARRAY(1,10, 1,19, 9,19, 9,10, 7,10, 7,12,3,12, 3,10, 1,10)), 'SKOLA');

insert into CELTNES values(5,MDSYS.SDO_GEOMETRY(2003, NULL, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1, 3, 1),MDSYS.SDO_ORDINATE_ARRAY(10,14, 10,19, 14,19, 14,14, 10,14)), 'BASEINS');

insert into CELTNES values(6,MDSYS.SDO_GEOMETRY(2003, NULL, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1, 3, 1),MDSYS.SDO_ORDINATE_ARRAY(15,8, 15,19, 19,19, 19,8, 15,8)), 'VEIKALS');

insert into CELTNES values(7,MDSYS.SDO_GEOMETRY(2003, NULL, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1, 3, 1),MDSYS.SDO_ORDINATE_ARRAY(10,8, 10,11, 13,11, 13,8, 10,8)), 'KIOSKS');

Page 6: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

6

Tabulas CELTNES datu izvadeselect A.GEOMETRIJA.SDO_ORDINATESfrom CELTNES A;

Page 7: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

7

Datu ievade tabulā IELAS

insert into IELAS values(1,MDSYS.SDO_GEOMETRY(2002, NULL, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1, 2, 1),MDSYS.SDO_ORDINATE_ARRAY(0,6, 12,6, 19,6, 20,6)), 'IELA1');

insert into IELAS values(2,MDSYS.SDO_GEOMETRY(2002, NULL, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1, 2, 1),MDSYS.SDO_ORDINATE_ARRAY(12,0, 12,6)), 'IELA2');

insert into IELAS values(3,MDSYS.SDO_GEOMETRY(2002, NULL, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1, 2, 1),MDSYS.SDO_ORDINATE_ARRAY(19,0, 19,6, 19,20)), 'IELA3');

select A.GEOMETRIJA.SDO_ORDINATES from IELAS A;

Page 8: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

8

Datu ievade tabulā KOKI

insert into KOKI values(1,MDSYS.SDO_GEOMETRY(2003, NULL, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1, 3, 4),MDSYS.SDO_ORDINATE_ARRAY(3,8.5, 3.5,9, 3,9.5 )), 'KOKS1');

insert into KOKI values(2,MDSYS.SDO_GEOMETRY(2003, NULL, NULL, MDSYS.SDO_ELEM_INFO_ARRAY(1, 3, 4),MDSYS.SDO_ORDINATE_ARRAY(7,8.5, 7.5,9, 7,9.5)), 'KOKS2');

select A.GEOMETRIJA.SDO_ORDINATES from KOKI A;

Page 9: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

9

Slāņu grafisko indeksu izveidošana

Fiksētā indeksa veidošana:

create index IND_CELTNES ON CELTNES(GEOMETRIJA)indextype is MDSYS.SPATIAL_INDEX parameters ('SDO_LEVEL = 4');

Hibrīda tipa indeksa veidošana:

create index IND_KOKI ON KOKI(GEOMETRIJA)indextype is MDSYS.SPATIAL_INDEX parameters ('SDO_LEVEL = 4, SDO_NUMTILES =4');

R-tree koka indeksa veidošana:

create index IND_IELAS ON IELAS(GEOMETRIJA)indextype is MDSYS.SPATIAL_INDEX;

Page 10: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

10

Ievadīto datu pārbaude

Page 11: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

11

Ievadīto datu vizualizācija ar Map View programmu (iekļauta vizualizācijas programma)

View Map View

Page 12: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

12

Page 13: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

13

Page 14: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

14

Page 15: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

15

Java Developer Kit (JDK) instalēšana un sistēmas parametru vērtību norādīšana

In

setting up JDK and Java applications, you will encounter these environment variables: PATH, CLASSPATH, JAVA_HOME and JRE_HOME. In short:1) PATH: maintains a list of directories. The OS searches the PATH entries for executable programs, such as Java Compiler (javac) and Java Runtime (java).2) CLASSPATH: maintain a list of directories (containing many Java class files) and JAR file (a single-file archive of Java classes). The Java Compiler and Java Runtime searches the CLASSPATH entries for Java classes referenced in your program.3) JAVA_HOME and JRE_HOME: maintain the locations of JDK and JRE installed directory, respectively.

Page 16: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

16

Set the PATH environment variable if you want to be able to conveniently run the executables (javac.exe, java.exe, javadoc.exe, and so on) from any directory without having to type the full path of the command. If you do not set the PATH variable, you need to specify the full path to the executable every time you run it, such as:C:\Java\jdk1.7.0\bin\javac MyClass.javaThe PATH environment variable is a series of directories separated by semicolons (;). Microsoft Windows looks for programs in the PATH directories in order, from left to right. You should have only one bin directory for the JDK in the path at a time (those following the first are ignored), so if one is already present, you can update that particular entry.The following is an example of a PATH environment variable:C:\Java\jdk1.7.0\bin;C:\Windows\System32\;C:\Windows\;C:\Windows\System32\Wbem

The class path is the path that the Java Runtime Environment (JRE) searches for classes and other resource files.

Class path entries can contain the base name wildcard character (*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example, the class path entry mydir/* specifies all JAR files in the directory named mydir. A class path entry consisting of * expands to a list of all the jar files in the current directory. Files are considered regardless of whether they are hidden (have names beginning with '.').

Page 17: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

17

Ģeometriskās datu bāzes ģeometriju vizualizēšana ar GeoRaptor

Lai vizualizētu datus, var izmantot SQL Developer paplašinājumu Oracle Georaptor. Šis rīks ir brīvi pieejams oficiālā lapā, kur arī izvietotas pamācības rīka izmantošanai:(http://sourceforge.net/apps/mediawiki/georaptor/index.php?title=Main_Page).

Lai izmantotu Georaptor, vispirms ir jāinstalē SQL Developer. Pēc tā instalācijas, Georaptor instalējas kā papildus spraudnis PlugIn.

Georaptor spraudni var instalēt sekojoši: 1. Click menu item "Help" and "Check for update"2. Dialog "Check for Updates - Welcome"   Click on button "Next". 3.  Dialog "Check for Updates - Step 1 of 3: Source"      Add new Update center. Click on button "Add" and insert values:     

Name: GeoRaptor     Location: http://georaptor.sourceforge.net/install.xml

Click "Next" when new update center is added.4. Dialog "Check for Updates - Step 2 of 3: Updates"Select "GeoRaptor" and click button "Next".5. Dialog "Check for Updates - Summary"    Click button "Finish".6. After Project Raptor restart, GeoRaptor should be installed.

Page 18: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

18

Tabulas ģeometriju ievietošana GeoRaptor grafiskajā attēlojumā

Grafiskais attēlojums

Page 19: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

19

Norādītas visas trīs tabulas. Krāsas - Random

Krāsu norāde

Page 20: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

20

Krāsas izvēle

Modificētais (krāsu izmaiņa)attēlojums

Page 21: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

21

Vaicājuma veidošana

Meklēšanas vietas un apgabala izmēru norādīšana

Page 22: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

22

Vaicājuma izpildes iegūtais rezultāts

Page 23: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

23

Poligona izveidošdana (zīmēšana)View GeoRaptor Open Map

Page 24: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

24

Informācijas sistēma ar grafikas izmantošanu.Objektu transformēšanas nepieciešamība

SQL objekts

Datu bāzes sistēma

Datu bāze

Datu bāzes vadības sistēma

SDO_GEOMETRY

Lietojums

JDBC interfeiss

Java objekts

JDBC DBS draiverisJava API

Page 25: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

25

Datu bāzes objektu transformēšana Java objektos

1. Vāji tipizētās noklusētās Java klases (weakly typed default Java class) Struct (Java) vai STRUCT (Oracle) izmantošana objektu transformēšanai. Šis variants ir efektīvāks un vienkāršāks.

2. Stipri tipizētas pašveidotās Java klases (strongly typed custom Java classe) izveidošana Oracle objektiem.

Literatūra

1. R. M. Menon. Expert Oracle JDBC Programming. Apress, 2005, 744. Lpp.

2.Kuassi Mensah. Oracle Database programming using Java and Web Services. Elsevier Digital Press publications, 2006.

Programmēšanas Java objekti

Relāciju-objektu datu bāzes objekti

Javas objekts

SQL objekts

JDBC SQLData interfeiss

Objekta tipu transformāciju apraksti

JDBC

Struct (Java)STRUCT (Oracle)

Page 26: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

26

Klases java.sql.Struct izmantošana datu bāzes un Java objektu savstarpējai transformēšanai

ResultSet rs= stmt.executeQuery("SELECT * FROM TABULA");java.sql.Struct jdbcStruct = (java.sql.Struct)rs.getObject(1);

java.sql.Struct instance and use the following standard methods:1) getAttributes(map). This method retrieves the values of the

attributes, using entries in the specified type map to determine the Java classes to use in materializing any attribute that is a structured object type. The Java types for other attribute values would be the same as for a getObject call on data of the underlying SQL type.

2) getAttributes. This method is the same as the preceding getAttributes(map) method, except it uses the default type map for the connection.

3) getSQLTypeName. This method returns a Java String that represents the fully qualified name of the Oracle object type that this Struct represents.

You can use standard JDBC functionality, such as getObject, to retrieve an Oracle object from the database as an instance of java.sql.Struct. Because getObject returns a java.lang.Object, you must cast the output of the method to Struct. For example:

Struktūra:java.sql.Struct

Datu bāzes sistēma

Struktūrasjava.sql.Struct

metodes:1) getAttributes(map)2) get Attributes3) getSQLTypeName

Page 27: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

27

Klases oracle.sql.STRUCT izmantošana datu bāzes un Java objektu savstarpējai transformēšanai

oracle.sql.Datum[] attrs = oracleSTRUCT.getOracleAttributes();

oracle.sql.Datum[] attrs = ((oracle.sql.STRUCT)jdbcStruct).getOracleAttributes();

Object[] attrs = jdbcStruct.getAttributes();

You can select data from the database into STRUCT objects and create STRUCT objects for inserting data into the database. STRUCT objects completely preserve data, because they maintain the data in SQL format. Using STRUCT objects is more efficient and more precise in situations where you do not need the information in an application specific form.If you want to take advantage of the extended functionality offered by Oracle-defined methods, then use an oracle.sql.STRUCT instance.The oracle.sql.STRUCT class implements the java.sql.Struct interface and provides extended functionality beyond the JDBC 2.0 standard.The STRUCT class includes the following methods in addition to standard Struct functionality:

1) getOracleAttributes. Retrieves the values of the values array as oracle.sql.* objects2) getDescriptor. Returns the StructDescriptor object for the SQL type that corresponds

to this STRUCT object.3) getJavaSQLConnection. Returns the current connection instance.4) toJdbc. Consults the default type map of the connection to determine what class to map to

and, then, uses toClass.5) toJdbc(map). Consults the specified type map to determine what class to map to, and then

uses toClass

Struktūra:oracle.sql.STRUCT Datu bāzes

sistēma

Struktūrasoracle.sql.STRUCT

metodes:1) getOracleAttributes2) getDescriptor3) getJavaSQLConnection4) toJdbc5) toJdbc(map)

Page 28: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

MDSYS.SDO_GEOMETRYJGeometry

28

Grafiskās datu bāzes datu vizualizācija izmantojot Java klasi JGeometry

java.lang.Object   oracle.spatial.geometry.JGeometry

Datu bāzes sistēma

Datu bāze

Datu bāzes

vadības sistēma

SDO_GEOMETRY

Lietojums

JDBC interfeiss

JGeometry

Java2D(vizualizācija)

Page 29: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

29

oracle.spatial.geometry.JGeometry klase

Nodrošina:1) SDO_GEOMETRY tipa objektu nolasīšana un ievade datu bāzē;2) SDO_GEOMETRY tipa objektu pārbaude;3) jaunu SDO_GEOMETRY tipa objektu izveidošana;4) SDO_GEOMETRY tipa objektu transformāciju veikšana.

SDO_GEOMETRY SELECT JDBC

oracle.sql.STRUCT objekts JGeometry

JGeometry INSERT JDBC UPDATE

oracle.sql.STRUCT objekts SDO_GEOMETRY

Page 30: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

30

oracle.sql.STRUCT objekts JGeometry objekts

1. variants load()oracle.sql.STRUCT oracle.spatial.JGeometry objekts objekts store()

// SDO_GEOMETRY tipa objekta nolasīšana no datu bāzes.// Tabula VALSTIS, SDO_GEOMETRY tipa kolona GEOMETRIJA.ResultSet rs = statement.executeQuery("select GEOMETRIJA from VALSTIS where NOSAUKUMS = 'Latvija'");//SDO_GEOMETRY tipa objekta transformēšana JGeometry tipa objektā.STRUCT st = (oracle.sql.STRUCT) rs.getObject(1);JGeometry j_geom = JGeometry.load(st);

// SDO_GEOMETRY tipa objekta ierakstīšanas datu bāzē komandas// definēšana.PreparedStatement ps = connection.prepareStatement("update VALSTIS set GEOMETRIJA =? where NOSAUKUMS = 'Latvija'");//JGeometry tipa objekta transformēšana SDO_GEOMETRY tipa objektāSTRUCT obj = JGeometry.store(j_geom, connection);ps.setObject(1, obj);ps.execute();

Prasības:1) Oracle JDBC driver ver. 8.1.7 or higher;2) JDK 1.2 or higher (for Java2D support).

Page 31: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

31

oracle.sql.STRUCT objekts JGeometry objekts

2. variants (pickling, unpicling)

1. variants load()SDO_GEOMETRY byte[] oracle.spatial. objekts masīvs JGeometry store()

// SDO_GEOMETRY tipa objekta nolasīšana no datu bāzes.// Tabula VALSTIS, SDO_GEOMETRY tipa kolona GEOMETRIJA.ResultSet rs = statement.executeQuery("select GEOMETRIJA from VALSTIS where NOSAUKUMS = 'Latvija'");byte[] image = ((OracleResultSet)rs).getBytes(1);//convert image into a JGeometry object using the SDO picklerJGeometry j_geom = JGeometry.load(image);

// SDO_GEOMETRY tipa objekta ierakstīšanas datu bāzē komandas// definēšanaPreparedStatement ps = connection.prepareStatement("update VALSTIS set GEOMETRIJA =? where NOSAUKUMS = 'Latvija'");//JGeometry tipa objekta transformēšana SDO_GEOMETRY tipa objektāSTRUCT obj = JGeometry.store(connection, j_geom);ps.setObject(1, obj);ps.execute();

Page 32: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

Lietojums

IDE NetBeans

Datu bāzes sistēma

JDBC interfeiss

JDK 8

SQL Developer

DBVS

Grafikas datu bāze

Bibliotēkas

32

Grafikas datu bāzes lietojuma izveidošana izmantojot IDE rīku NetBeans 8

Page 33: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

33

Nepieciešamo papildbibliotēku piesaiste

1. JGeometry tipa objektu klase:oracle.spatial.geometry.JGeometryE:\app\Janis\product\11.2.0\dbhome_1\md\jlib\sdoapi.jar;

2. Oracle JDBC draivera klase:oracle.jdbc.driver.OracleDriverE:\app\Janis\product\11.2.0\dbhome_1\jdbc\lib\ojdbc6.jar;

Control Panel User Accounts and Family Safety User Accounts Change my environment variables

Desktop Power User Task Menu System Advanced System Settings Environment Variables Path Edit

Control panel System and Security System Advanced System Settings Advaced Environment variables

Page 34: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

34

DBVS Oracle draiveri

Divas vienāda nosaukuma klases

Page 35: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

35

Grafikas datu bāzes lietojuma izveidošana izmantojot IDE rīku NetBeans

Projekts Grafika Properties

Page 36: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

36

Grafisko datu vizualizēšanas programma

class dbc

Savienojuma ar datu bāzi objekta conn izveidošanas metode connect()

Grafisko datu (SDO_GEOMETRY) izgūšana no datu bāzes un transformācijaJGeometry tipa Javas objektos (metode getData())

Rezultātu JGeometry objektu kolekcijas saraksta iegūšanas metodes getList() izveidošana

class Vizualizacija

JGeometry objektu kolekcijas saraksta iegūšana (getList())

JGeometry objektu attēlošana

class GalvenaKlase

Jauna dbc klases objekta (dbcon) izveidošana

Savienojuma izveidošanas metodes connect() izsaukšna

Grafisko datu izgūšana no datu bāzes un transformācija (metodes getData() izsaukšana)

Grafisko datu kolekcijas saraksta iegūšana (metode getJList())

Datu vizualizācijas loga izveidošana un datu vizualizācija(metode Vizualizacija())

Page 37: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

37

Pievienošanās datu bāzei un grafisko datu izgūšanaKlases dbc izveidošana (fails: dbc.java)

create or replace JAVA source named "dbc" as// Nepieciešamo bibliotēku (pakešu) pievienošanaimport java.sql.*; //JDBC interfeisa programmu pakete (otra javax.sql)import java.util.ArrayList; import java.util.List; import oracle.core.lmx.CoreException; import oracle.spatial.geometry.JGeometry; import oracle.sql.STRUCT; // Klases dbc izveidošana, kura:// 1) izveido metodi connect() savienojuma ar datu bāzes sistēmu izveidošanai;// 2) izveido metodi getData() grafiskos datu (SDO_GEOMETRY) // izgūšanai no datu bāzes un to transformācijai JGeometry tipa // objektos;// 3) kolekciju tipa objektu izveidošana.

Page 38: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

38

public class dbc { public dbc() { } // Konstruktora metode(vai vajag?)private Connection conn; // Savienojuma objekta izveidošana.// Savienojuma metodes izveidošana.public void connect() { String URL = "jdbc:oracle:thin:@localhost:1521:BAZE";String USER = "system"; String PASSWORD = "Janis1946"; //Kļūdu pārbaudes uzsākšana.try { conn = DriverManager.getConnection(URL, USER, PASSWORD); } catch (SQLException e) { e.printStackTrace(); } }

// Grafisko datu slāņu tabulu nosaukumu ierakstīšana masīvā.private String[] tblArray = {"CELTNES", "IELAS", "KOKI" };

//List – interfeiss sakārtotam sarakstam ar norādītu tipu (<JGeometry>).// Rezultātu JGeometry objektu kolelkcijas saraksta (result) definēšanaprivate List<JGeometry> result = new ArrayList<JGeometry>(0); //Rezultātu JGeometry tipa objektu kolekcijas saraksta (result) iegūšanas metodes // izveidošana.public List<JGeometry> getJList(){ return result; }

// Anotācija brīdinājuma ziņojuma izvades aizliegšanai.@SuppressWarnings("deprecation")

// Datu izgūšana un transformēšanapublic void getData() { for (int i = 0; i < tblArray.length; i++) { try { Statement stmt = conn.createStatement();String sql = "SELECT a.geometrija geom FROM "+ tblArray[i] + " a";ResultSet rs = stmt.executeQuery(sql);while (rs.next()) { oracle.sql.STRUCT st = (STRUCT) rs.getObject("geom"); JGeometry geom = JGeometry.load(st);result.add(geom); } } catch (SQLException e) { e.printStackTrace(); } } } }

Page 39: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

39

Grafisko datu vizualizācijas programma

import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Shape; import java.util.List; import javax.swing.JPanel; import oracle.spatial.geometry.JGeometry; import java.awt.geom.AffineTransform;

public class Vizualizacija extends JPanel { // Konstruktora metodepublic Vizualizacija (dbc dbcon) { this.dbcon = dbcon; }// Grafisko objektu (g2) attēlošanapublic void paintComponent(Graphics g) {Graphics2D g2 = (Graphics2D) g;// Koordināšu sistēmas transformācija.// Attēlojuma lauka sākuma punkta novirze uz punktu X = 0, Y = 500.AffineTransform tform = AffineTransform.getTranslateInstance(0, 500); // Attēlojumu mēroga izmaiņa (reizes). Y ass būs vērsta uz augšu.tform.scale(20, -20); // Var izmantot arī koordināšu sistēmu pagriešanu par notektu leņķi.// tform.rotate(Math.PI/2); // Pagriešana par 90 grādiem.// JGeometry objektu kolekcijas saraksta iegūšanaList<JGeometry> lst = dbcon.getJList(); // JGeometry objektu attēlošanafor(int i=0; i<=lst.size()-1; i++){ if(lst.get(i) != null){ Shape a = lst.get(i).createShape(tform); g2.draw(a); } } } private dbc dbcon; // Serializācijas versijas norāde, lai viena un tā pati versija tiktu// izmantota gan serializācijā, gan deserializācijā.private static final long serialVersionUID = 1L; }

Page 40: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

40

Galvenās klases GalvenaKlase definēšana (GalvenaKlase.java)

import java.util.List;import javax.swing.JFrame; import javax.swing.JPanel; import oracle.spatial.geometry.JGeometry; public class GalvenaKlase { // Galvenā metode (main), kura tiek izsaukta un viss process notiek.public final static void main(String[] args) { // Jauna dbc klases objekta (savienojums ar DB, vaicājums, izgūtie dati) izveidošanadbc dbcon = new dbc(); // Savienojuma metodes ar datu bāzi (klases dbc metode) izsaukšanadbcon.connect(); // Grafisko datu izgūšana no datu bāzes un transformācija dbcon.getData(); // Grafisko datu kolekcijas saraksta iegūšanaList<JGeometry> lst = dbcon.getJList();// Jauna JPanel klases attēlojuma loga Vizualizacija tipa loga izveidošanaJPanel panel = new Vizualizacija(dbcon); // Jauna Window loga (freima) izveidošanaJFrame frame = new JFrame("JavaGeometry"); // Top level container// Loga satura izvade freimāframe.setContentPane(panel); // Freima izmēru norādeframe.setSize(500, 500); // Freima attēlošanas atļaujaframe.setVisible(true); } }

JFrame – A frame is an instance of JFrame. Frame is a window that can have title, border, menu, buttons, text fields and several other components. A Swing application must have a frame to have the components added to it.

JPanel – A panel is an instance of JPanel. A frame can have more than one panels and each panel can have several components. You can also call them parts of Frame. Panels are useful for grouping components and placing them to appropriate locations in a frame.

Page 41: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

41

Ģeometrijas datu izvade izmantojot Java klases AWT un SWING. Vienkārša loga karkasa jeb freima (JFrame) izveidošana

JFrame is the most commonly used top-level container. It adds basic functionality such as minimize, maximize, close, title and border to basic frames and windows.

import javax.swing.*;public class GrafPiem1 extends JFrame{// Konstruktora metode.GrafPiem1() {setTitle("Vienkāršs freims");setBounds(100,100,300,100); // (X, Y, W, H)// Freimu aizverot, programmai jābeidz darbs.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// Freima attēlošana.setVisible(true); }public static void main(String args[]) {new GrafPiem1();}}

Page 42: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

42

Satura paneļa JPanel izveidošana

JPanel is the most commonly used content pane. An instance of the pane is created and then added to a frame.

import java.awt.*; import javax.swing.*;public class GrafPiem1 extends JFrame{JPanel pane = new JPanel();// Konstruktora metodeGrafPiem1() {setTitle("Freims ar paneli.");setBounds(100,100,300,100);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);Container con=this.getContentPane(); // Tiek izveidots satura panelis.con.add(pane); // Tiek ievietots freimā (pamatkonteinerī).// pane.add(vadības rīku (pogu, izvēlņu, ... iekļaušana);// Freima attēlošanasetVisible(true); }public static void main(String args[]) {new GrafPiem1();}}

Page 43: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

43

Freima logs ar paneli un ģeometriju attēlojumu

//import java.awt.Graphics;//import java.awt.Graphics2D;import java.awt.*; //import javax.swing.JFrame;//import javax.swing.JPanel;import javax.swing.*;

public class GrafPiem1 extends JPanel{public static void main(String args[]){JFrame fr = new JFrame("Freima logs");fr.add(new GrafPiem1()); //Freimam pievieno paneli GrafPiem1fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);fr.setSize(250,200);fr.setVisible(true);}

public void paint(Graphics g) {// Krāsas norādīšanag.setColor(Color.red);// Taisnstūra zīmēšana, izmantojot klasi Graphics.g.drawRect(50,50,100,100);// Graphics tipa objekta transformācija Graphics2D tipa objektā.Graphics2D g2d = (Graphics2D)g;// Krāsas norādīšana.g2d.setColor(Color.blue);// Taisnstūra zīmēšana, izmantojot Graphics2D klasi.g2d.drawRect(75,75,150,50);} }

Page 44: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

44

Grafikas datu bāzes lietojuma izveidošana izmantojot IDE rīku NetBeans

Page 45: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

45

import java.sql.*; import java.util.ArrayList; import java.util.List; import oracle.core.lmx.CoreException; import oracle.spatial.geometry.JGeometry; import oracle.sql.STRUCT; public class dbc { public dbc() { }private Connection conn; public void connect() { String URL = "jdbc:oracle:thin:@localhost:1521:BAZE";String USER = "system"; String PASS = "Janis1946"; try { conn = DriverManager.getConnection(URL, USER, PASS); } catch (SQLException e) { e.printStackTrace(); } }private String[] tblArray = {"CELTNES", "IELAS", "KOKI"};private List<JGeometry> result = new ArrayList<JGeometry>(0); public List<JGeometry> getJList(){return result;} //@SuppressWarnings("deprecation")  public void getData() { for (int i = 0; i < tblArray.length; i++) { try { Statement stmt = conn.createStatement();String sql = "SELECT a.geometrija geom FROM "+ tblArray[i] + " a";ResultSet rs = stmt.executeQuery(sql);while (rs.next()) { oracle.sql.STRUCT st = (STRUCT) rs.getObject("geom"); JGeometry geom = JGeometry.load(st);result.add(geom); } } catch (SQLException e) { e.printStackTrace(); } } } }

Page 46: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

46

import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Shape; import java.util.List; import javax.swing.JPanel; import oracle.spatial.geometry.JGeometry; import java.awt.geom.AffineTransform;public class Vizualizacija extends JPanel { public Vizualizacija (dbc dbcon) { this.dbcon = dbcon; }public void paintComponent(Graphics g) {Graphics2D g2 = (Graphics2D) g;AffineTransform tform = AffineTransform.getTranslateInstance(0, 500); tform.scale(20, -20); List<JGeometry> lst = dbcon.getJList(); for(int i=0; i<=lst.size()-1; i++){ if(lst.get(i) != null){ Shape a = lst.get(i).createShape(tform); g2.draw(a); } } } private dbc dbcon; private static final long serialVersionUID = 1L; }

Page 47: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

47

import java.util.List;import javax.swing.JFrame; import javax.swing.JPanel; import oracle.spatial.geometry.JGeometry; public class GalvenaKlase { public final static void main(String[] args) { dbc dbcon = new dbc(); dbcon.connect(); dbcon.getData(); List<JGeometry> lst = dbcon.getJList();JPanel panel = new Vizualizacija(dbcon); // Augšējā līmeņa konteinersJFrame frame = new JFrame("Grafikas datu bāze"); frame.setContentPane(panel); frame.setSize(500, 500); frame.setVisible(true); } }

Page 48: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

48

Page 49: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

49

Paskaidrojumi

The java.util.List interface is a subtype of the java.util.Collection interface. It represents an ordered list of objects, meaning you can access the elements of a List in a specific order, and by an index too. You can also add the same element more than once to a List. Being a Collection subtype all methods in the Collection interface are also available in the List interface. Since List is an interface you need to instantiate a concrete implementation of the interface in order to use it. You can choose between the following List implementations in the Java Collections API:

1) java.util.ArrayList2) java.util.LinkedList3) java.util.Vector4) java.util.Stack

Here are a few examples of how to create a List instance: List listA = new ArrayList();List listB = new LinkedList();List listC = new Vector();List listD = new Stack();

To add elements to a List you call its add() method. This method is inherited from the Collection interface. Here are a few examples: List listA = new ArrayList();listA.add("element 1");listA.add("element 2");listA.add("element 3");listA.add(0, "element 0");

The first three add() calls add a String instance to the end of the list. The last add() call adds a String at index 0, meaning at the beginning of the list. The order in which the elements are added to the List is stored, so you can access the elements in the same order. You can do so using either the get(int index) method, or via the Iterator returned by the iterator() method. Here is how: List listA = new ArrayList();listA.add("element 0");listA.add("element 1");listA.add("element 2");

//access via indexString element0 = listA.get(0);String element1 = listA.get(1);String element3 = listA.get(2);

//access via IteratorIterator iterator = listA.iterator();while(iterator.hasNext(){ String element = (String) iterator.next();}

//access via new for-loopfor(Object object : listA) { String element = (String) object;}

When iterating the list via its Iterator or via the for-loop (which also uses the Iterator behind the scene), the elements are iterated in the same sequence they are stored in the list.

Page 50: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

50

You can remove elements in two ways: 1. remove(Object element)2. remove(int index)remove(Object element) removes that element in the list, if it is present. All subsequent elements in the list are then moved up in the list. Their index thus decreases by 1. remove(int index) removes the element at the given index. All subsequent elements in the list are then moved up in the list. Their index thus decreases by 1.

Generic ListsBy default you can put any Object into a List, but from Java 5, Java Generics makes it possible to

limit the types of object you can insert into a List. Here is an example: List<MyObject> list = new ArrayList<MyObject>();

This List can now only have MyObject instances inserted into it. You can then access and iterate its elements without casting them. Here is how it looks: MyObject myObject = list.get(0);for(MyObject anObject : list){ //do someting to anObject... }

The docs for java.io.Serializable are probably about as good an explanation as you'll get:The serialization runtime associates with each serializable class a version number, called a serialVersionUID, which is used during deserialization to verify that the sender and receiver of a serialized object have loaded classes for that object that are compatible with respect to serialization. If the receiver has loaded a class for the object that has a different serialVersionUID than that of the corresponding sender's class, then deserialization will result in an InvalidClassException. A serializable class can declare its own serialVersionUID explicitly by declaring a field named "serialVersionUID" that must be static, final, and of type long:

ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;

If a serializable class does not explicitly declare a serialVersionUID, then the serialization runtime will calculate a default serialVersionUID value for that class based on various aspects of the class, as described in the Java(TM) Object Serialization Specification. However, it is strongly recommended that all serializable classes explicitly declare serialVersionUID values, since the default serialVersionUID computation is highly sensitive to class details that may vary depending on compiler implementations, and can thus result in unexpected InvalidClassExceptions during deserialization. Therefore, to guarantee a consistent serialVersionUID value across different java compiler implementations, a serializable class must declare an explicit serialVersionUID value. It is also strongly advised that explicit serialVersionUID declarations use the private modifier where possible, since such declarations apply only to the immediately declaring class--serialVersionUID fields are not useful as inherited members.

Page 51: datubaze.files.wordpress.com · Web view(*), which is considered equivalent to specifying a list of all of the files in the directory with the extension .jar or .JAR. For example,

51