• R/O
  • HTTP
  • SSH
  • HTTPS

vaadin: Commit

sample


Commit MetaInfo

Revision2085d542ee56156eb0c963f6ac253bd67c13dfc1 (tree)
Time2016-05-14 21:18:40
Authorcintake <gozilla3st@user...>
Commitercintake

Log Message

add jsp-api

Change Summary

Incremental Difference

--- a/src/main/java/net/korabo/app/vaadin01/ent/KBaseEntity.java
+++ b/src/main/java/net/korabo/app/vaadin01/KBaseEntity.java
@@ -3,7 +3,7 @@
33 * To change this template file, choose Tools | Templates
44 * and open the template in the editor.
55 */
6-package net.korabo.app.vaadin01.ent;
6+package net.korabo.app.vaadin01;
77
88 import com.orientechnologies.orient.core.id.ORID;
99 import javax.persistence.Id;
--- a/src/main/java/net/korabo/app/vaadin01/ent/Contact.java
+++ b/src/main/java/net/korabo/app/vaadin01/ent/Contact.java
@@ -5,6 +5,7 @@
55 */
66 package net.korabo.app.vaadin01.ent;
77
8+import net.korabo.app.vaadin01.KBaseEntity;
89 import com.orientechnologies.orient.core.id.ORID;
910 import java.io.Serializable;
1011 import java.util.Date;
--- a/src/main/java/net/korabo/app/vaadin01/ent/InstanceID.java
+++ /dev/null
@@ -1,32 +0,0 @@
1-/*
2- * To change this license header, choose License Headers in Project Properties.
3- * To change this template file, choose Tools | Templates
4- * and open the template in the editor.
5- */
6-package net.korabo.app.vaadin01.ent;
7-
8-/**
9- *
10- * @author manager
11- */
12-public class InstanceID {
13- private String ClassID;
14- private Long ID;
15-
16- public String getClassID() {
17- return ClassID;
18- }
19-
20- public void setClassID(String ClassID) {
21- this.ClassID = ClassID;
22- }
23-
24- public Long getID() {
25- return ID;
26- }
27-
28- public void setID(Long ID) {
29- this.ID = ID;
30- }
31-
32-}
--- a/src/main/java/net/korabo/app/vaadin01/srv/ContactBeanQuery.java
+++ b/src/main/java/net/korabo/app/vaadin01/srv/ContactBeanQuery.java
@@ -6,6 +6,7 @@
66 package net.korabo.app.vaadin01.srv;
77
88 import com.orientechnologies.orient.core.db.OPartitionedDatabasePool;
9+import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
910 import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
1011 import java.util.ArrayList;
1112 import java.util.List;
@@ -18,54 +19,35 @@ import org.vaadin.addons.lazyquerycontainer.QueryDefinition;
1819 *
1920 * @author manager
2021 */
21-public class ContactBeanQuery extends AbstractBeanQuery<Contact>{
22+public class ContactBeanQuery extends AbstractBeanQuery<Contact> {
2223
23- private final OPartitionedDatabasePool pool;
24+ private final ContactService contactSvc;
2425
25- public ContactBeanQuery(QueryDefinition definition,
26- Map<String, Object> queryConfiguration, Object[] sortPropertyIds,
27- boolean[] sortStates) {
28- super(definition, queryConfiguration, sortPropertyIds, sortStates);
29- this.pool = (OPartitionedDatabasePool)queryConfiguration.get("OPartitionedDatabasePool");
30- }
26+ public ContactBeanQuery(QueryDefinition definition,
27+ Map<String, Object> queryConfiguration, Object[] sortPropertyIds,
28+ boolean[] sortStates) {
29+ super(definition, queryConfiguration, sortPropertyIds, sortStates);
30+ this.contactSvc = (ContactService)queryConfiguration.get("ContactService");
31+ }
3132
32-
33- @Override
34- protected Contact constructBean() {
35- return new Contact();
36- }
33+ @Override
34+ protected Contact constructBean() {
35+ return new Contact();
36+ }
3737
38- @Override
39- public int size() {
40- try (
41- OObjectDatabaseTx db = new OObjectDatabaseTx(pool.acquire())) {
42- db.getEntityManager().registerEntityClass(Contact.class);
43- return (int) db.countClass(Contact.class);
44- }
45- }
38+ @Override
39+ public int size() {
40+ return (int)contactSvc.count();
41+ }
4642
47- @Override
48- protected List<Contact> loadBeans(int i, int i1) {
49- ArrayList arrayList = new ArrayList();
50- try (
51- OObjectDatabaseTx db = new OObjectDatabaseTx(pool.acquire())) {
52- db.getEntityManager().registerEntityClass(Contact.class);
53- for (Contact contact : db.browseClass(Contact.class).) {
54- boolean passesFilter = (stringFilter == null || stringFilter.isEmpty())
55- || contact.toString().toLowerCase()
56- .contains(stringFilter.toLowerCase());
57- if (passesFilter) {
58-// contact = db.detach(contact);
59- arrayList.add(db.detach(contact, true));
60- }
61- }
43+ @Override
44+ protected List<Contact> loadBeans(int i, int i1) {
45+ return contactSvc.loadBeans(i, i1);
46+ }
6247
63- }
64- }
48+ @Override
49+ protected void saveBeans(List<Contact> list, List<Contact> list1, List<Contact> list2) {
50+ throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
51+ }
6552
66- @Override
67- protected void saveBeans(List<Contact> list, List<Contact> list1, List<Contact> list2) {
68- throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
69- }
70-
7153 }
--- a/src/main/java/net/korabo/app/vaadin01/srv/ContactService.java
+++ b/src/main/java/net/korabo/app/vaadin01/srv/ContactService.java
@@ -7,6 +7,7 @@ package net.korabo.app.vaadin01.srv;
77
88 import com.orientechnologies.orient.client.remote.OServerAdmin;
99 import com.orientechnologies.orient.core.db.OPartitionedDatabasePool;
10+import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
1011 import com.orientechnologies.orient.object.db.OObjectDatabaseTx;
1112 import java.io.IOException;
1213 import java.util.ArrayList;
@@ -16,6 +17,7 @@ import java.util.Random;
1617 import java.util.logging.Level;
1718 import java.util.logging.Logger;
1819 import net.korabo.app.vaadin01.ent.Contact;
20+import net.korabo.lib.beans.ClassUtil;
1921
2022 /**
2123 *
@@ -23,99 +25,102 @@ import net.korabo.app.vaadin01.ent.Contact;
2325 */
2426 public class ContactService {
2527
26- // Create dummy data by randomly combining first and last names
27- static String[] fnames = {"Peter", "Alice", "John", "Mike", "Olivia",
28- "Nina", "Alex", "Rita", "Dan", "Umberto", "Henrik", "Rene", "Lisa",
29- "Linda", "Timothy", "Daniel", "Brian", "George", "Scott",
30- "Jennifer"};
31- static String[] lnames = {"Smith", "Johnson", "Williams", "Jones",
32- "Brown", "Davis", "Miller", "Wilson", "Moore", "Taylor",
33- "Anderson", "Thomas", "Jackson", "White", "Harris", "Martin",
34- "Thompson", "Young", "King", "Robinson"};
35-
36- private static ContactService instance;
37- private static OPartitionedDatabasePool pool;
38-
39- public static ContactService createDemoService() {
40- try {
41- return createService0();
42- } catch (IOException ex) {
43- Logger.getLogger(ContactService.class.getName()).log(Level.SEVERE, null, ex);
44- }
45- return null;
28+ // Create dummy data by randomly combining first and last names
29+ static String[] fnames = {"Peter", "Alice", "John", "Mike", "Olivia",
30+ "Nina", "Alex", "Rita", "Dan", "Umberto", "Henrik", "Rene", "Lisa",
31+ "Linda", "Timothy", "Daniel", "Brian", "George", "Scott",
32+ "Jennifer"};
33+ static String[] lnames = {"Smith", "Johnson", "Williams", "Jones",
34+ "Brown", "Davis", "Miller", "Wilson", "Moore", "Taylor",
35+ "Anderson", "Thomas", "Jackson", "White", "Harris", "Martin",
36+ "Thompson", "Young", "King", "Robinson"};
37+
38+ private static ContactService instance;
39+ private static OPartitionedDatabasePool pool;
40+
41+ public static ContactService createDemoService() {
42+ try {
43+ return createService0();
44+ } catch (IOException ex) {
45+ Logger.getLogger(ContactService.class.getName()).log(Level.SEVERE, null, ex);
4646 }
47+ return null;
48+ }
4749
48- private static ContactService createService0() throws IOException {
49- if (instance == null) {
50+ private static ContactService createService0() throws IOException {
51+ if (instance == null) {
5052
51- final ContactService contactService = new ContactService();
52- // OrientDB
53+ final ContactService contactService = new ContactService();
54+ // OrientDB
5355 // ODatabaseDocumentTx db =
5456 // new ODatabaseDocumentTx("remote:127.0.0.1/DocumentTest")
5557 // .open("root", "korabo");
5658 // OPartitionedDatabasePool pool = new OPartitionedDatabasePool("remote:127.0.0.1/dbtest","root","korabo");
5759 // pool.
5860 // OObjectDatabaseTx db = new OObjectDatabaseTx("remote:127.0.0.1/dbtest");
59- String remote = "remote:127.0.0.1/";
60- String nameDB = "TestPartitioned2";
61- String url = remote + nameDB;
62-
63- OServerAdmin serverAdmin = new OServerAdmin(url).connect("root", "korabo");
64- if (!serverAdmin.listDatabases().containsKey(nameDB)) {
65- serverAdmin.createDatabase(nameDB, "object", "plocal");
66- System.out.println(" Database '" + nameDB + "' created!..");
67- }
61+ String remote = "remote:127.0.0.1/";
62+ String nameDB = "TestPartitioned2";
63+ String url = remote + nameDB;
64+
65+ OServerAdmin serverAdmin = new OServerAdmin(url).connect("root", "korabo");
66+ if (!serverAdmin.listDatabases().containsKey(nameDB)) {
67+ serverAdmin.createDatabase(nameDB, "object", "plocal");
68+ System.out.println(" Database '" + nameDB + "' created!..");
69+ }
6870 // OPartitionedDatabasePool pool = new OPartitionedDatabasePool(url, "admin", "admin");
69- pool = new OPartitionedDatabasePool(url, "admin", "admin");
70-
71- try (
72- OObjectDatabaseTx db = new OObjectDatabaseTx(pool.acquire())) {
73- db.getEntityManager().registerEntityClass(Contact.class);
74-
75- if (db.countClass(Contact.class) == 0) {
76- // init
77- Random r = new Random(0);
78- Calendar cal = Calendar.getInstance();
79- for (int i = 0; i < 100; i++) {
80- Contact contact = db.newInstance(Contact.class);
81- contact.setFirstName(fnames[r.nextInt(fnames.length)]);
82- contact.setLastName(lnames[r.nextInt(fnames.length)]);
83- contact.setEmail(contact.getFirstName().toLowerCase() + "@"
84- + contact.getLastName().toLowerCase() + ".com");
85- contact.setPhone("+ 358 555 " + (100 + r.nextInt(900)));
86- cal.set(1930 + r.nextInt(70),
87- r.nextInt(11), r.nextInt(28));
88- contact.setBirthDate(cal.getTime());
89- db.attachAndSave(contact);
90- }
91- db.commit();
92- }
93- }
94- instance = contactService;
71+ pool = new OPartitionedDatabasePool(url, "admin", "admin");
72+
73+ try (
74+ OObjectDatabaseTx db = new OObjectDatabaseTx(pool.acquire())) {
75+ db.setAutomaticSchemaGeneration(true);
76+ db.getEntityManager().registerEntityClasses(Contact.class.getPackage().getName());
77+
78+ if (db.countClass(Contact.class) == 0) {
79+ // init
80+ Random r = new Random(0);
81+ Calendar cal = Calendar.getInstance();
82+ for (int i = 0; i < 100; i++) {
83+ Contact contact = db.newInstance(Contact.class);
84+ contact.setFirstName(fnames[r.nextInt(fnames.length)]);
85+ contact.setLastName(lnames[r.nextInt(fnames.length)]);
86+ contact.setEmail(contact.getFirstName().toLowerCase() + "@"
87+ + contact.getLastName().toLowerCase() + ".com");
88+ contact.setPhone("+ 358 555 " + (100 + r.nextInt(900)));
89+ cal.set(1930 + r.nextInt(70),
90+ r.nextInt(11), r.nextInt(28));
91+ contact.setBirthDate(cal.getTime());
92+ db.attachAndSave(contact);
93+ }
94+ db.commit();
9595 }
96-
97- return instance;
96+ }
97+ instance = contactService;
9898 }
9999
100+ return instance;
101+ }
102+
100103 // private HashMap<Long, Contact> contacts = new HashMap<>();
101104 // private long nextId = 0;
102- public synchronized List<Contact> findAll(String stringFilter) {
103-
104- ArrayList arrayList = new ArrayList();
105- try (
106- OObjectDatabaseTx db = new OObjectDatabaseTx(pool.acquire())) {
107- db.getEntityManager().registerEntityClass(Contact.class);
108- for (Contact contact : db.browseClass(Contact.class)) {
109- boolean passesFilter = (stringFilter == null || stringFilter.isEmpty())
110- || contact.toString().toLowerCase()
111- .contains(stringFilter.toLowerCase());
112- if (passesFilter) {
105+ public synchronized List<Contact> findAll(String stringFilter) {
106+
107+ ArrayList arrayList = new ArrayList();
108+ try (
109+ OObjectDatabaseTx db = new OObjectDatabaseTx(pool.acquire())) {
110+ db.setAutomaticSchemaGeneration(true);
111+ db.getEntityManager().registerEntityClasses(Contact.class.getPackage().getName());
112+
113+ for (Contact contact : db.browseClass(Contact.class)) {
114+ boolean passesFilter = (stringFilter == null || stringFilter.isEmpty())
115+ || contact.toString().toLowerCase()
116+ .contains(stringFilter.toLowerCase());
117+ if (passesFilter) {
113118 // contact = db.detach(contact);
114- arrayList.add(db.detach(contact, true));
115- }
116- }
117-
119+ arrayList.add(db.detach(contact, true));
118120 }
121+ }
122+
123+ }
119124 // for (Contact contact : contacts.values()) {
120125 // try {
121126 // boolean passesFilter = (stringFilter == null || stringFilter.isEmpty())
@@ -136,30 +141,33 @@ public class ContactService {
136141 // return (int) (o2.getId() - o1.getId());
137142 // }
138143 // });
139- return arrayList;
140- }
144+ return arrayList;
145+ }
141146
142- public synchronized long count() {
147+ public synchronized long count() {
143148 // return contacts.size();
144- try (
145- OObjectDatabaseTx db = new OObjectDatabaseTx(pool.acquire())) {
146- db.getEntityManager().registerEntityClass(Contact.class);
147- return db.countClass(Contact.class);
148- }
149+ try (
150+ OObjectDatabaseTx db = new OObjectDatabaseTx(pool.acquire())) {
151+ db.setAutomaticSchemaGeneration(true);
152+ db.getEntityManager().registerEntityClasses(Contact.class.getPackage().getName());
153+ return db.countClass(Contact.class);
149154 }
155+ }
150156
151- public synchronized void delete(Contact value) {
157+ public synchronized void delete(Contact value) {
152158 // contacts.remove(value.getId());
153- }
159+ }
154160
155- public synchronized void save(Contact entry) {
156- try (
157- OObjectDatabaseTx db = new OObjectDatabaseTx(pool.acquire())) {
158- db.getEntityManager().registerEntityClass(Contact.class);
159- db.begin();
160- db.attachAndSave(entry);
161- db.commit();
162- }
161+ public synchronized void save(Contact entry) {
162+ try (
163+ OObjectDatabaseTx db = new OObjectDatabaseTx(pool.acquire())) {
164+ db.setAutomaticSchemaGeneration(true);
165+ db.getEntityManager().registerEntityClasses(Contact.class.getPackage().getName());
166+
167+ db.begin();
168+ db.attachAndSave(entry);
169+ db.commit();
170+ }
163171 // if (entry.getId() == null) {
164172 // entry.setId(nextId++);
165173 // }
@@ -169,6 +177,24 @@ public class ContactService {
169177 // throw new RuntimeException(ex);
170178 // }
171179 // contacts.put(entry.getId(), entry);
180+ }
181+
182+
183+ public List<Contact> loadBeans(int i, int i1) {
184+ ArrayList<Contact> arrayList = new ArrayList<>();
185+ try (
186+ OObjectDatabaseTx db = new OObjectDatabaseTx(pool.acquire())) {
187+ db.setAutomaticSchemaGeneration(true);
188+ db.getEntityManager().registerEntityClasses(Contact.class.getPackage().getName());
189+
190+ //SELECT FROM <target> [WHERE ...] SKIP <records-to-skip> LIMIT <max-records>
191+ final OSQLSynchQuery<Contact> query = new OSQLSynchQuery<>("select * from Contact SKIP ? LIMIT ?");
192+ List<Contact> result = db.query(query, i, i1);
193+ result.stream().forEach((contact) -> {
194+ arrayList.add(db.detach(contact, true));
195+ });
172196 }
197+ return arrayList;
198+ }
173199
174200 }
--- a/src/main/java/net/korabo/app/vaadin01/AddressbookUI.java
+++ b/src/main/java/net/korabo/app/vaadin01/ui/AddressbookUI.java
@@ -3,7 +3,7 @@
33 * To change this template file, choose Tools | Templates
44 * and open the template in the editor.
55 */
6-package net.korabo.app.vaadin01;
6+package net.korabo.app.vaadin01.ui;
77
88 import com.vaadin.annotations.Theme;
99 import com.vaadin.annotations.Title;
--- /dev/null
+++ b/src/main/java/net/korabo/app/vaadin01/ui/AddressbookUI2.java
@@ -0,0 +1,122 @@
1+/*
2+ * To change this license header, choose License Headers in Project Properties.
3+ * To change this template file, choose Tools | Templates
4+ * and open the template in the editor.
5+ */
6+package net.korabo.app.vaadin01.ui;
7+
8+import com.vaadin.annotations.Theme;
9+import com.vaadin.annotations.Title;
10+import com.vaadin.annotations.VaadinServletConfiguration;
11+import com.vaadin.annotations.Widgetset;
12+import com.vaadin.data.util.BeanItemContainer;
13+import com.vaadin.server.VaadinRequest;
14+import com.vaadin.server.VaadinServlet;
15+import com.vaadin.ui.Button;
16+import com.vaadin.ui.Grid;
17+import com.vaadin.ui.HorizontalLayout;
18+import com.vaadin.ui.TextField;
19+import com.vaadin.ui.UI;
20+import com.vaadin.ui.VerticalLayout;
21+import java.util.HashMap;
22+import java.util.Map;
23+import javax.servlet.annotation.WebServlet;
24+import net.korabo.app.vaadin01.ent.Contact;
25+import net.korabo.app.vaadin01.srv.ContactBeanQuery;
26+import net.korabo.app.vaadin01.srv.ContactService;
27+import org.vaadin.addons.lazyquerycontainer.BeanQueryFactory;
28+import org.vaadin.addons.lazyquerycontainer.LazyQueryContainer;
29+import org.vaadin.addons.lazyquerycontainer.LazyQueryDefinition;
30+import org.vaadin.addons.lazyquerycontainer.QueryDefinition;
31+
32+/**
33+ *
34+ * @author cintake
35+ */
36+@Title("Addressbook2")
37+@Theme("valo")
38+@Widgetset("net.korabo.app.vaadin01.MyAppWidgetset")
39+public class AddressbookUI2 extends UI {
40+
41+ TextField filter = new TextField();
42+ Grid contactList = new Grid();
43+ Button newContact = new Button("New contact");
44+
45+ // ContactForm is an example of a custom component class
46+ ContactForm contactForm = new ContactForm();
47+
48+ // ContactService is a in-memory mock DAO that mimics
49+ // a real-world datasource. Typically implemented for
50+ // example as EJB or Spring Data based service.
51+ LazyQueryContainer container;
52+ ContactService service = ContactService.createDemoService();
53+
54+ @Override
55+ protected void init(VaadinRequest request) {
56+ configureComponents();
57+ buildLayout();
58+ }
59+
60+ private void configureComponents() {
61+
62+ newContact.addClickListener(e -> contactForm.edit(new Contact()));
63+
64+ filter.setInputPrompt("Filter contacts...");
65+ filter.addTextChangeListener(e -> refreshContacts(e.getText()));
66+
67+ BeanQueryFactory<ContactBeanQuery> queryFactory = new BeanQueryFactory<>(ContactBeanQuery.class);
68+
69+Map<String,Object> queryConfiguration=new HashMap<>();
70+queryConfiguration.put("ContactService",ContactService.createDemoService());
71+queryFactory.setQueryConfiguration(queryConfiguration);
72+
73+container = new LazyQueryContainer(new LazyQueryDefinition(false, 50, "ContactID"), queryFactory);
74+contactList.setContainerDataSource(container);
75+// contactList.setContainerDataSource(new BeanItemContainer<>(Contact.class));
76+// contactList.setColumnOrder("firstName", "lastName", "email");
77+// contactList.removeColumn("id");
78+// contactList.removeColumn("birthDate");
79+// contactList.removeColumn("phone");
80+// contactList.setSelectionMode(Grid.SelectionMode.SINGLE);
81+// contactList.addSelectionListener(e
82+// -> contactForm.edit((Contact) contactList.getSelectedRow()));
83+ refreshContacts();
84+ }
85+
86+ private void buildLayout() {
87+ HorizontalLayout actions = new HorizontalLayout(filter, newContact);
88+ actions.setWidth("100%");
89+ filter.setWidth("100%");
90+ actions.setExpandRatio(filter, 1);
91+
92+ VerticalLayout left = new VerticalLayout(actions, contactList);
93+ left.setSizeFull();
94+ contactList.setSizeFull();
95+ left.setExpandRatio(contactList, 1);
96+
97+ HorizontalLayout mainLayout = new HorizontalLayout(left, contactForm);
98+ mainLayout.setSizeFull();
99+ mainLayout.setExpandRatio(left, 1);
100+
101+ // Split and allow resizing
102+ setContent(mainLayout);
103+ }
104+
105+ void refreshContacts() {
106+ refreshContacts(filter.getValue());
107+ }
108+
109+ private void refreshContacts(String stringFilter) {
110+ container.refresh();
111+// contactList.setContainerDataSource(new BeanItemContainer<>(
112+// Contact.class, service.findAll(stringFilter)));
113+ contactForm.setVisible(false);
114+ }
115+
116+ @WebServlet(urlPatterns = "/2/*")
117+ @VaadinServletConfiguration(ui = AddressbookUI2.class, productionMode = false)
118+ public static class MyUIServlet extends VaadinServlet {
119+
120+ }
121+
122+}
--- a/src/main/java/net/korabo/app/vaadin01/ContactForm.java
+++ b/src/main/java/net/korabo/app/vaadin01/ui/ContactForm.java
@@ -3,7 +3,7 @@
33 * To change this template file, choose Tools | Templates
44 * and open the template in the editor.
55 */
6-package net.korabo.app.vaadin01;
6+package net.korabo.app.vaadin01.ui;
77
88 import com.vaadin.data.fieldgroup.BeanFieldGroup;
99 import com.vaadin.data.fieldgroup.FieldGroup;
--- a/src/main/java/net/korabo/app/vaadin01/MyUI.java
+++ b/src/main/java/net/korabo/app/vaadin01/ui/MyUI.java
@@ -1,4 +1,4 @@
1-package net.korabo.app.vaadin01;
1+package net.korabo.app.vaadin01.ui;
22
33 import javax.servlet.annotation.WebServlet;
44
--- a/src/main/webapp/VAADIN/themes/mytheme/addons.scss
+++ b/src/main/webapp/VAADIN/themes/mytheme/addons.scss
@@ -1,7 +1,7 @@
1-/* This file is automatically managed and will be overwritten from time to time. */
2-/* Do not manually edit this file. */
3-
4-/* Import and include this mixin into your project theme to include the addon themes */
5-@mixin addons {
6-}
7-
1+/* This file is automatically managed and will be overwritten from time to time. */
2+/* Do not manually edit this file. */
3+
4+/* Import and include this mixin into your project theme to include the addon themes */
5+@mixin addons {
6+}
7+
Show on old repository browser