You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jdo-dev@db.apache.org by GitBox <gi...@apache.org> on 2021/04/29 16:19:09 UTC

[GitHub] [db-jdo] tobous commented on a change in pull request #20: Jdo 709

tobous commented on a change in pull request #20:
URL: https://github.com/apache/db-jdo/pull/20#discussion_r623196690



##########
File path: tck/src/main/java/org/apache/jdo/tck/pc/mylib/PCRectString.java
##########
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jdo.tck.pc.mylib;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.jdo.AttributeConverter;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * PersistenceCapable class to test JDO AttributeConverter interface.
+ * It#s fields of type Point are converted to strins in the datastore.

Review comment:
       ```suggestion
    * It's fields of type Point are converted to strings in the datastore.
   ```

##########
File path: tck/src/main/java/org/apache/jdo/tck/pc/mylib/PCRectString.java
##########
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jdo.tck.pc.mylib;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.jdo.AttributeConverter;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * PersistenceCapable class to test JDO AttributeConverter interface.
+ * It#s fields of type Point are converted to strins in the datastore.
+ *
+ * @author Michael Bouschen
+ */
+public class PCRectString {
+    private static long counter = new Date().getTime();
+
+    private static long newId() {

Review comment:
       Can't you just make the method `synchronized` instead of using a synchronized block on the class object?

##########
File path: tck/src/main/java/org/apache/jdo/tck/pc/mylib/PCRectString.java
##########
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jdo.tck.pc.mylib;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.jdo.AttributeConverter;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * PersistenceCapable class to test JDO AttributeConverter interface.
+ * It#s fields of type Point are converted to strins in the datastore.
+ *
+ * @author Michael Bouschen
+ */
+public class PCRectString {
+    private static long counter = new Date().getTime();
+
+    private static long newId() {
+        synchronized (PCRectString.class) {
+            return counter++;
+        }
+    }
+
+    public long id = newId();
+
+    private Point upperLeft;
+    private Point lowerRight;
+
+    public PCRectString() {
+    }
+
+    public PCRectString(long id, Point ul, Point lr) {
+        upperLeft = ul;
+        lowerRight = lr;
+    }
+
+    public PCRectString(Point ul, Point lr) {
+        upperLeft = ul;
+        lowerRight = lr;
+    }
+
+    public Point getUpperLeft() {
+        return upperLeft;
+    }
+
+    public Point getLowerRight() {
+        return lowerRight;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public String toString() {
+        String rc = null;
+        Object obj = this;
+        try {
+            //rc = Util.getClassName(this)

Review comment:
       What purpose does this comment serve?

##########
File path: tck/src/main/java/org/apache/jdo/tck/pc/mylib/PCRectString.java
##########
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jdo.tck.pc.mylib;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.jdo.AttributeConverter;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * PersistenceCapable class to test JDO AttributeConverter interface.
+ * It#s fields of type Point are converted to strins in the datastore.
+ *
+ * @author Michael Bouschen
+ */
+public class PCRectString {
+    private static long counter = new Date().getTime();
+
+    private static long newId() {
+        synchronized (PCRectString.class) {
+            return counter++;
+        }
+    }
+
+    public long id = newId();
+
+    private Point upperLeft;
+    private Point lowerRight;
+
+    public PCRectString() {
+    }
+
+    public PCRectString(long id, Point ul, Point lr) {
+        upperLeft = ul;
+        lowerRight = lr;
+    }
+
+    public PCRectString(Point ul, Point lr) {
+        upperLeft = ul;
+        lowerRight = lr;
+    }
+
+    public Point getUpperLeft() {
+        return upperLeft;
+    }
+
+    public Point getLowerRight() {
+        return lowerRight;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public String toString() {
+        String rc = null;
+        Object obj = this;
+        try {
+            //rc = Util.getClassName(this)
+            rc = obj.getClass().getName()
+                    + " ul: " + getUpperLeft().name()
+                    + " lr: " + getLowerRight().name();
+        } catch (NullPointerException ex) {
+            rc = "NPE getting PCRectString's values";
+        }
+        return rc;
+    }
+
+    /**
+     * PCRectString'S ObjectId class.
+     */
+    public static class Oid implements Serializable {
+        public long id;
+
+        public Oid() {
+        }
+
+        public Oid(String s) { id = Long.parseLong(justTheId(s)); }
+
+        public String toString() { return this.getClass().getName() + ": "  + id;}
+
+        public int hashCode() { return (int)id ; }
+
+        public boolean equals(Object other) {
+            if (other != null && (other instanceof PCRectString.Oid)) {
+                PCRectString.Oid k = (PCRectString.Oid)other;
+                return k.id == this.id;
+            }
+            return false;
+        }
+
+        protected static String justTheId(String str) {
+            return str.substring(str.indexOf(':') + 1);
+        }
+
+    }
+
+    /**
+     * AttributeConverter implementation mapping a Point instance to a string of the form x:y.
+     */
+    public static class PointToStringConverter implements AttributeConverter<Point, String> {
+
+        private static int nrOfConvertToDatastoreCalls = 0;
+        private static int nrOfConvertToAttributeCalls = 0;
+
+        // Character to separate x and y value of teh Pont instance.

Review comment:
       ```suggestion
           // Character to separate x and y value of the Point instance.
   ```

##########
File path: tck/src/main/java/org/apache/jdo/tck/pc/mylib/PCRectString.java
##########
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jdo.tck.pc.mylib;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.jdo.AttributeConverter;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * PersistenceCapable class to test JDO AttributeConverter interface.
+ * It#s fields of type Point are converted to strins in the datastore.
+ *
+ * @author Michael Bouschen
+ */
+public class PCRectString {
+    private static long counter = new Date().getTime();
+
+    private static long newId() {
+        synchronized (PCRectString.class) {
+            return counter++;
+        }
+    }
+
+    public long id = newId();
+
+    private Point upperLeft;
+    private Point lowerRight;
+
+    public PCRectString() {
+    }
+
+    public PCRectString(long id, Point ul, Point lr) {
+        upperLeft = ul;
+        lowerRight = lr;
+    }
+
+    public PCRectString(Point ul, Point lr) {
+        upperLeft = ul;
+        lowerRight = lr;
+    }
+
+    public Point getUpperLeft() {
+        return upperLeft;
+    }
+
+    public Point getLowerRight() {
+        return lowerRight;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public String toString() {
+        String rc = null;
+        Object obj = this;
+        try {
+            //rc = Util.getClassName(this)
+            rc = obj.getClass().getName()
+                    + " ul: " + getUpperLeft().name()
+                    + " lr: " + getLowerRight().name();
+        } catch (NullPointerException ex) {
+            rc = "NPE getting PCRectString's values";
+        }
+        return rc;
+    }
+
+    /**
+     * PCRectString'S ObjectId class.
+     */
+    public static class Oid implements Serializable {
+        public long id;
+
+        public Oid() {
+        }
+
+        public Oid(String s) { id = Long.parseLong(justTheId(s)); }
+
+        public String toString() { return this.getClass().getName() + ": "  + id;}
+
+        public int hashCode() { return (int)id ; }
+
+        public boolean equals(Object other) {
+            if (other != null && (other instanceof PCRectString.Oid)) {
+                PCRectString.Oid k = (PCRectString.Oid)other;
+                return k.id == this.id;
+            }
+            return false;
+        }
+
+        protected static String justTheId(String str) {
+            return str.substring(str.indexOf(':') + 1);
+        }
+
+    }
+
+    /**
+     * AttributeConverter implementation mapping a Point instance to a string of the form x:y.
+     */
+    public static class PointToStringConverter implements AttributeConverter<Point, String> {
+
+        private static int nrOfConvertToDatastoreCalls = 0;
+        private static int nrOfConvertToAttributeCalls = 0;
+
+        // Character to separate x and y value of teh Pont instance.
+        private static final String SEPARATOR = ":";
+
+        private Log logger = LogFactory.getFactory().getInstance("org.apache.jdo.tck");
+
+        /**
+         * Converts the given Point attribute value to its string representation in the datastore.
+         * @param attributeValue the attribute value of type Point to be converted
+         * @return the string representation of the Pont instance
+         */
+        @Override
+        public String convertToDatastore(Point attributeValue) {
+            nrOfConvertToDatastoreCalls++;
+            String datastoreValue = null;
+            if (attributeValue != null) {
+                StringBuilder builder = new StringBuilder();
+                builder.append(attributeValue.getX());
+                builder.append(SEPARATOR);
+                builder.append(attributeValue.getY() == null ? Integer.valueOf(0) : attributeValue.getY());
+                datastoreValue = builder.toString();
+            }
+            if (logger.isDebugEnabled()) {
+                logger.debug("PointToStringConverter.convertToDatastore " +
+                        "attributeValue=" + attributeValue + " datastoreValue=" + datastoreValue);
+            }
+            return datastoreValue;
+        }
+
+        /**
+         * Converts the given string datastore value to its representation as a persistent attribute og type Point.

Review comment:
       ```suggestion
            * Converts the given string datastore value to its representation as a persistent attribute of type Point.
   ```

##########
File path: tck/src/main/java/org/apache/jdo/tck/pc/mylib/PCRectString.java
##########
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jdo.tck.pc.mylib;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.jdo.AttributeConverter;
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * PersistenceCapable class to test JDO AttributeConverter interface.
+ * It#s fields of type Point are converted to strins in the datastore.
+ *
+ * @author Michael Bouschen
+ */
+public class PCRectString {
+    private static long counter = new Date().getTime();
+
+    private static long newId() {
+        synchronized (PCRectString.class) {
+            return counter++;
+        }
+    }
+
+    public long id = newId();
+
+    private Point upperLeft;
+    private Point lowerRight;
+
+    public PCRectString() {
+    }
+
+    public PCRectString(long id, Point ul, Point lr) {
+        upperLeft = ul;
+        lowerRight = lr;
+    }
+
+    public PCRectString(Point ul, Point lr) {
+        upperLeft = ul;
+        lowerRight = lr;
+    }
+
+    public Point getUpperLeft() {
+        return upperLeft;
+    }
+
+    public Point getLowerRight() {
+        return lowerRight;
+    }
+
+    public long getId() {
+        return id;
+    }
+
+    public void setId(long id) {
+        this.id = id;
+    }
+
+    public String toString() {
+        String rc = null;
+        Object obj = this;
+        try {
+            //rc = Util.getClassName(this)
+            rc = obj.getClass().getName()
+                    + " ul: " + getUpperLeft().name()
+                    + " lr: " + getLowerRight().name();
+        } catch (NullPointerException ex) {
+            rc = "NPE getting PCRectString's values";
+        }
+        return rc;
+    }
+
+    /**
+     * PCRectString'S ObjectId class.
+     */
+    public static class Oid implements Serializable {
+        public long id;
+
+        public Oid() {
+        }
+
+        public Oid(String s) { id = Long.parseLong(justTheId(s)); }
+
+        public String toString() { return this.getClass().getName() + ": "  + id;}
+
+        public int hashCode() { return (int)id ; }
+
+        public boolean equals(Object other) {
+            if (other != null && (other instanceof PCRectString.Oid)) {
+                PCRectString.Oid k = (PCRectString.Oid)other;
+                return k.id == this.id;
+            }
+            return false;
+        }
+
+        protected static String justTheId(String str) {
+            return str.substring(str.indexOf(':') + 1);
+        }
+
+    }
+
+    /**
+     * AttributeConverter implementation mapping a Point instance to a string of the form x:y.
+     */
+    public static class PointToStringConverter implements AttributeConverter<Point, String> {
+
+        private static int nrOfConvertToDatastoreCalls = 0;
+        private static int nrOfConvertToAttributeCalls = 0;
+
+        // Character to separate x and y value of teh Pont instance.
+        private static final String SEPARATOR = ":";
+
+        private Log logger = LogFactory.getFactory().getInstance("org.apache.jdo.tck");
+
+        /**
+         * Converts the given Point attribute value to its string representation in the datastore.
+         * @param attributeValue the attribute value of type Point to be converted
+         * @return the string representation of the Pont instance

Review comment:
       ```suggestion
            * @return the string representation of the Point instance
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org