OSDN Git Service

(no commit message)
authormanager <manager@YOUR-6D02CEEF0F>
Thu, 5 May 2016 06:38:36 +0000 (15:38 +0900)
committermanager <manager@YOUR-6D02CEEF0F>
Thu, 5 May 2016 06:38:36 +0000 (15:38 +0900)
.gitignore [new file with mode: 0644]
pom.xml
src/main/java/net/korabo/app/orientdb/AppServletContextListener.java
src/main/java/net/korabo/app/vaadin01/ent/Contact.java
src/main/java/net/korabo/app/vaadin01/srv/ContactService.java
src/main/webapp/VAADIN/themes/mytheme/addons.scss

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..a6f89c2
--- /dev/null
@@ -0,0 +1 @@
+/target/
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index 4904d54..0030677 100644 (file)
--- a/pom.xml
+++ b/pom.xml
          <version>2.1.7</version>
         </dependency>
         <dependency>
+         <groupId>com.orientechnologies</groupId>
+         <artifactId>orientdb-graphdb</artifactId>
+         <version>2.1.7</version>
+        </dependency>
+        <dependency>
+         <groupId>com.orientechnologies</groupId>
+         <artifactId>orientdb-object</artifactId>
+         <version>2.1.7</version>
+        </dependency>
+        <dependency>
          <groupId>net.korabo.lib</groupId>
          <artifactId>korabolib</artifactId>
          <version>1.2.4</version>
index 2bb83d4..e02cb7b 100644 (file)
@@ -8,10 +8,13 @@ package net.korabo.app.orientdb;
 import com.orientechnologies.orient.server.OServer;
 import com.orientechnologies.orient.server.OServerMain;
 import java.io.File;
+import java.io.FileOutputStream;
+import java.net.URI;
 import java.util.Properties;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
 import javax.servlet.annotation.WebListener;
+import net.korabo.lib.KConstant;
 import net.korabo.lib.StreamUtil;
 import net.korabo.lib.UriUtil;
 import net.korabo.lib.file.FileUriUtil;
@@ -40,21 +43,21 @@ public class AppServletContextListener implements ServletContextListener{
         String orientDB = UriUtil.concatPath(home, "OrientDB");
         String orientDBcfg = UriUtil.concatPath(orientDB, "config", "orientdb-server-config.xml");
         String orientDBwww = UriUtil.concatPath(orientDB, "www");
-               Properties props = System.getProperties();
-               props.setProperty("ORIENTDB_HOME", orientDB);
+        Properties props = System.getProperties();
+        props.setProperty("ORIENTDB_HOME", orientDB);
         props.setProperty("orientdb.www.path", orientDBwww);
                
                try {
-            File cfgFile = FileUriUtil.getFileFor(orientDBcfg);
-                SysFilesUtil.chkAndMake(cfgFile);
-            if (cfgFile.length() == 0){
-              // initialize
-              
-              
-            }
-                       OServer server = OServerMain.create();
-                       server.startup(FileUriUtil.getFileFor(orientDBcfg));
-                       server.activate();
+                    File cfgFile = FileUriUtil.getFileFor(orientDBcfg);
+                    SysFilesUtil.chkAndMake(cfgFile);
+                    if (cfgFile.length() == 0){
+                      // initialize
+                      String rp = ResourceFilesUtil.findPathFromClasspath("net.korabo.app.orientdb.smplconfig.xml");
+                      StreamUtil.copy(FileUriUtil.getUriFor(rp).toURL().openStream(), new FileOutputStream(cfgFile),true);
+                    }
+                    OServer server = OServerMain.create();
+                    server.startup(FileUriUtil.getFileFor(orientDBcfg));
+                    server.activate();
                } catch (Exception e) {
                        System.out.println(e.getMessage() + e.getStackTrace());
                }
index 2d0b564..0b8b7f0 100644 (file)
@@ -7,6 +7,7 @@ package net.korabo.app.vaadin01.ent;
 
 import java.io.Serializable;
 import java.util.Date;
+import javax.persistence.Id;
 import net.korabo.lib.beans.InstanceUtil;
 
 /**
index 651cbc3..ee540be 100644 (file)
@@ -5,6 +5,10 @@
  */
 package net.korabo.app.vaadin01.srv;
 
+import com.orientechnologies.orient.client.remote.OServerAdmin;
+import com.orientechnologies.orient.core.db.OPartitionedDatabasePool;
+import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Calendar;
 import java.util.Collections;
@@ -22,37 +26,73 @@ import net.korabo.lib.beans.InstanceUtil;
  * @author cintake
  */
 public class ContactService {
-  // Create dummy data by randomly combining first and last names
-    static String[] fnames = { "Peter", "Alice", "John", "Mike", "Olivia",
-            "Nina", "Alex", "Rita", "Dan", "Umberto", "Henrik", "Rene", "Lisa",
-            "Linda", "Timothy", "Daniel", "Brian", "George", "Scott",
-            "Jennifer" };
-    static String[] lnames = { "Smith", "Johnson", "Williams", "Jones",
-            "Brown", "Davis", "Miller", "Wilson", "Moore", "Taylor",
-            "Anderson", "Thomas", "Jackson", "White", "Harris", "Martin",
-            "Thompson", "Young", "King", "Robinson" };
+
+    // Create dummy data by randomly combining first and last names
+    static String[] fnames = {"Peter", "Alice", "John", "Mike", "Olivia",
+        "Nina", "Alex", "Rita", "Dan", "Umberto", "Henrik", "Rene", "Lisa",
+        "Linda", "Timothy", "Daniel", "Brian", "George", "Scott",
+        "Jennifer"};
+    static String[] lnames = {"Smith", "Johnson", "Williams", "Jones",
+        "Brown", "Davis", "Miller", "Wilson", "Moore", "Taylor",
+        "Anderson", "Thomas", "Jackson", "White", "Harris", "Martin",
+        "Thompson", "Young", "King", "Robinson"};
 
     private static ContactService instance;
+    private static OPartitionedDatabasePool pool;
 
-    public static ContactService createDemoService() {
+    public static ContactService createDemoService(){
+        try {
+            return createService0();
+        } catch (IOException ex) {
+            Logger.getLogger(ContactService.class.getName()).log(Level.SEVERE, null, ex);
+        }
+        return null;
+    }
+    
+    private static ContactService createService0() throws IOException {
         if (instance == null) {
 
             final ContactService contactService = new ContactService();
+            // OrientDB
+//            ODatabaseDocumentTx db = 
+//                    new ODatabaseDocumentTx("remote:127.0.0.1/DocumentTest")
+//                            .open("root", "korabo");
+//            OPartitionedDatabasePool pool = new OPartitionedDatabasePool("remote:127.0.0.1/dbtest","root","korabo");
+//            pool.
+//            OObjectDatabaseTx db = new OObjectDatabaseTx("remote:127.0.0.1/dbtest");
+            String remote = "remote:127.0.0.1/";
+            String nameDB = "TestPartitioned2";
+            String url = remote + nameDB;
 
-            Random r = new Random(0);
-            Calendar cal = Calendar.getInstance();
-            for (int i = 0; i < 100; i++) {
-                Contact contact = new Contact();
-                contact.setFirstName(fnames[r.nextInt(fnames.length)]);
-                contact.setLastName(lnames[r.nextInt(fnames.length)]);
-                contact.setEmail(contact.getFirstName().toLowerCase() + "@"
-                        + contact.getLastName().toLowerCase() + ".com");
-                contact.setPhone("+ 358 555 " + (100 + r.nextInt(900)));
-                cal.set(1930 + r.nextInt(70),
-                        r.nextInt(11), r.nextInt(28));
-                contact.setBirthDate(cal.getTime());
-                contactService.save(contact);
+            OServerAdmin serverAdmin = new OServerAdmin(url).connect("root", "korabo");
+            if (!serverAdmin.listDatabases().containsKey(nameDB)){
+                serverAdmin.createDatabase(nameDB, "object", "plocal");
+                System.out.println(" Database '" + nameDB + "' created!..");
+            }
+//            OPartitionedDatabasePool pool = new OPartitionedDatabasePool(url, "admin", "admin");
+            pool = new OPartitionedDatabasePool(url, "admin", "admin");
+
+            try (
+                    OObjectDatabaseTx db = new OObjectDatabaseTx(pool.acquire())) {
+                db.getEntityManager().registerEntityClass(Contact.class);
+                if (db.countClass(Contact.class) == 0) {
+                    // init
+                    Random r = new Random(0);
+                    Calendar cal = Calendar.getInstance();
+                    for (int i = 0; i < 100; i++) {
+                        Contact contact = db.newInstance(Contact.class);
+                        contact.setFirstName(fnames[r.nextInt(fnames.length)]);
+                        contact.setLastName(lnames[r.nextInt(fnames.length)]);
+                        contact.setEmail(contact.getFirstName().toLowerCase() + "@"
+                                + contact.getLastName().toLowerCase() + ".com");
+                        contact.setPhone("+ 358 555 " + (100 + r.nextInt(900)));
+                        cal.set(1930 + r.nextInt(70),
+                                r.nextInt(11), r.nextInt(28));
+                        contact.setBirthDate(cal.getTime());
+                        db.save(contact);
+                    }
+                    db.commit();
+                }
             }
             instance = contactService;
         }
@@ -60,53 +100,75 @@ public class ContactService {
         return instance;
     }
 
-    private HashMap<Long, Contact> contacts = new HashMap<>();
-    private long nextId = 0;
-
+//    private HashMap<Long, Contact> contacts = new HashMap<>();
+//    private long nextId = 0;
     public synchronized List<Contact> findAll(String stringFilter) {
+
         ArrayList arrayList = new ArrayList();
-        for (Contact contact : contacts.values()) {
-            try {
-                boolean passesFilter = (stringFilter == null || stringFilter.isEmpty())
-                        || contact.toString().toLowerCase()
-                                .contains(stringFilter.toLowerCase());
-                if (passesFilter) {
-                    arrayList.add(contact.clone());
+        try (
+                OObjectDatabaseTx db = new OObjectDatabaseTx(pool.acquire())) {
+            db.getEntityManager().registerEntityClass(Contact.class);
+            for (Contact contact : db.browseClass(Contact.class)) {
+                try {
+                    boolean passesFilter = (stringFilter == null || stringFilter.isEmpty())
+                            || contact.toString().toLowerCase()
+                            .contains(stringFilter.toLowerCase());
+                    if (passesFilter) {
+                        arrayList.add(contact.clone());
+                    }
+                } catch (CloneNotSupportedException ex) {
+                    Logger.getLogger(ContactService.class.getName()).log(
+                            Level.SEVERE, null, ex);
                 }
-            } catch (CloneNotSupportedException ex) {
-                Logger.getLogger(ContactService.class.getName()).log(
-                        Level.SEVERE, null, ex);
             }
-        }
-        Collections.sort(arrayList, new Comparator<Contact>() {
 
-            @Override
-            public int compare(Contact o1, Contact o2) {
-                return (int) (o2.getId() - o1.getId());
-            }
-        });
+        }
+//        for (Contact contact : contacts.values()) {
+//            try {
+//                boolean passesFilter = (stringFilter == null || stringFilter.isEmpty())
+//                        || contact.toString().toLowerCase()
+//                        .contains(stringFilter.toLowerCase());
+//                if (passesFilter) {
+//                    arrayList.add(contact.clone());
+//                }
+//            } catch (CloneNotSupportedException ex) {
+//                Logger.getLogger(ContactService.class.getName()).log(
+//                        Level.SEVERE, null, ex);
+//            }
+//        }
+//        Collections.sort(arrayList, new Comparator<Contact>() {
+//
+//            @Override
+//            public int compare(Contact o1, Contact o2) {
+//                return (int) (o2.getId() - o1.getId());
+//            }
+//        });
         return arrayList;
     }
 
     public synchronized long count() {
-        return contacts.size();
+//        return contacts.size();
+        try (
+                OObjectDatabaseTx db = new OObjectDatabaseTx(pool.acquire())) {
+            db.getEntityManager().registerEntityClass(Contact.class);
+            return db.countClass(Contact.class);
+        }
     }
 
     public synchronized void delete(Contact value) {
-        contacts.remove(value.getId());
+//        contacts.remove(value.getId());
     }
 
     public synchronized void save(Contact entry) {
-        if (entry.getId() == null) {
-            entry.setId(nextId++);
-        }
-        try {
-            entry = (Contact) InstanceUtil.dupObj(entry);
-        } catch (Exception ex) {
-            throw new RuntimeException(ex);
-        }
-        contacts.put(entry.getId(), entry);
+//        if (entry.getId() == null) {
+//            entry.setId(nextId++);
+//        }
+//        try {
+//            entry = (Contact) InstanceUtil.dupObj(entry);
+//        } catch (Exception ex) {
+//            throw new RuntimeException(ex);
+//        }
+//        contacts.put(entry.getId(), entry);
     }
 
-  
 }
index a5670b7..754ba4b 100644 (file)
@@ -1,7 +1,7 @@
-/* This file is automatically managed and will be overwritten from time to time. */
-/* Do not manually edit this file. */
-
-/* Import and include this mixin into your project theme to include the addon themes */
-@mixin addons {
-}
-
+/* This file is automatically managed and will be overwritten from time to time. */\r
+/* Do not manually edit this file. */\r
+\r
+/* Import and include this mixin into your project theme to include the addon themes */\r
+@mixin addons {\r
+}\r
+\r