aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/com/iciql/adapter/postgresql
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2014-11-09 13:33:27 -0500
committerJames Moger <james.moger@gitblit.com>2014-11-10 21:46:26 -0500
commit4b9a61d0ef0fc2a9230a53a0ade45a20889aa9e3 (patch)
tree5b93bd2ad0425d46c0fea61c66ab56128e29b29c /src/main/java/com/iciql/adapter/postgresql
parent97358035987e26ea801abac461bf5b5c9a406aa7 (diff)
downloadiciql-4b9a61d0ef0fc2a9230a53a0ade45a20889aa9e3.tar.gz
iciql-4b9a61d0ef0fc2a9230a53a0ade45a20889aa9e3.zip
Revise built-in type adapter class names again, add Yaml type adapter
Diffstat (limited to 'src/main/java/com/iciql/adapter/postgresql')
-rw-r--r--src/main/java/com/iciql/adapter/postgresql/JsonObjectAdapter.java52
-rw-r--r--src/main/java/com/iciql/adapter/postgresql/JsonStringAdapter.java55
-rw-r--r--src/main/java/com/iciql/adapter/postgresql/JsonbObjectAdapter.java52
-rw-r--r--src/main/java/com/iciql/adapter/postgresql/JsonbStringAdapter.java55
-rw-r--r--src/main/java/com/iciql/adapter/postgresql/XmlObjectAdapter.java35
-rw-r--r--src/main/java/com/iciql/adapter/postgresql/XmlStringAdapter.java55
6 files changed, 304 insertions, 0 deletions
diff --git a/src/main/java/com/iciql/adapter/postgresql/JsonObjectAdapter.java b/src/main/java/com/iciql/adapter/postgresql/JsonObjectAdapter.java
new file mode 100644
index 0000000..118cfc1
--- /dev/null
+++ b/src/main/java/com/iciql/adapter/postgresql/JsonObjectAdapter.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2014 James Moger.
+ *
+ * Licensed 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 com.iciql.adapter.postgresql;
+
+import java.sql.SQLException;
+
+import org.postgresql.util.PGobject;
+
+import com.iciql.adapter.GsonTypeAdapter;
+
+/**
+ * Postgres JSON data type adapter maps a JSON column to a domain object using
+ * Google GSON.
+ *
+ * @author James Moger
+ *
+ * @param <T>
+ */
+public abstract class JsonObjectAdapter<T> extends GsonTypeAdapter<T> {
+
+ @Override
+ public String getDataType() {
+ return "json";
+ }
+
+ @Override
+ public Object serialize(T value) {
+
+ String json = gson().toJson(value);
+ PGobject pg = new PGobject();
+ pg.setType(getDataType());
+ try {
+ pg.setValue(json);
+ } catch (SQLException e) {
+ // not thrown on base PGobject
+ }
+ return pg;
+ }
+}
diff --git a/src/main/java/com/iciql/adapter/postgresql/JsonStringAdapter.java b/src/main/java/com/iciql/adapter/postgresql/JsonStringAdapter.java
new file mode 100644
index 0000000..c4fbd6a
--- /dev/null
+++ b/src/main/java/com/iciql/adapter/postgresql/JsonStringAdapter.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2014 James Moger.
+ *
+ * Licensed 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 com.iciql.adapter.postgresql;
+
+import java.sql.SQLException;
+
+import org.postgresql.util.PGobject;
+
+import com.iciql.Iciql.DataTypeAdapter;
+
+/**
+ * Handles transforming raw strings to/from the Postgres JSON data type.
+ */
+public class JsonStringAdapter implements DataTypeAdapter<String> {
+
+ @Override
+ public String getDataType() {
+ return "json";
+ }
+
+ @Override
+ public Class<String> getJavaType() {
+ return String.class;
+ }
+
+ @Override
+ public Object serialize(String value) {
+ PGobject pg = new PGobject();
+ pg.setType(getDataType());
+ try {
+ pg.setValue(value);
+ } catch (SQLException e) {
+ // not thrown on base PGobject
+ }
+ return pg;
+ }
+
+ @Override
+ public String deserialize(Object value) {
+ return value.toString();
+ }
+} \ No newline at end of file
diff --git a/src/main/java/com/iciql/adapter/postgresql/JsonbObjectAdapter.java b/src/main/java/com/iciql/adapter/postgresql/JsonbObjectAdapter.java
new file mode 100644
index 0000000..6d8ad2c
--- /dev/null
+++ b/src/main/java/com/iciql/adapter/postgresql/JsonbObjectAdapter.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2014 James Moger.
+ *
+ * Licensed 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 com.iciql.adapter.postgresql;
+
+import java.sql.SQLException;
+
+import org.postgresql.util.PGobject;
+
+import com.iciql.adapter.GsonTypeAdapter;
+
+/**
+ * Postgres JSONB data type adapter maps a JSONB column to a domain object using
+ * Google GSON.
+ *
+ * @author James Moger
+ *
+ * @param <T>
+ */
+public abstract class JsonbObjectAdapter<T> extends GsonTypeAdapter<T> {
+
+ @Override
+ public String getDataType() {
+ return "jsonb";
+ }
+
+ @Override
+ public Object serialize(T value) {
+
+ String json = gson().toJson(value);
+ PGobject pg = new PGobject();
+ pg.setType(getDataType());
+ try {
+ pg.setValue(json);
+ } catch (SQLException e) {
+ // not thrown on base PGobject
+ }
+ return pg;
+ }
+}
diff --git a/src/main/java/com/iciql/adapter/postgresql/JsonbStringAdapter.java b/src/main/java/com/iciql/adapter/postgresql/JsonbStringAdapter.java
new file mode 100644
index 0000000..cc2d9c4
--- /dev/null
+++ b/src/main/java/com/iciql/adapter/postgresql/JsonbStringAdapter.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2014 James Moger.
+ *
+ * Licensed 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 com.iciql.adapter.postgresql;
+
+import java.sql.SQLException;
+
+import org.postgresql.util.PGobject;
+
+import com.iciql.Iciql.DataTypeAdapter;
+
+/**
+ * Handles transforming raw strings to/from the Postgres JSONB data type.
+ */
+public class JsonbStringAdapter implements DataTypeAdapter<String> {
+
+ @Override
+ public String getDataType() {
+ return "jsonb";
+ }
+
+ @Override
+ public Class<String> getJavaType() {
+ return String.class;
+ }
+
+ @Override
+ public Object serialize(String value) {
+ PGobject pg = new PGobject();
+ pg.setType(getDataType());
+ try {
+ pg.setValue(value);
+ } catch (SQLException e) {
+ // not thrown on base PGobject
+ }
+ return pg;
+ }
+
+ @Override
+ public String deserialize(Object value) {
+ return value.toString();
+ }
+} \ No newline at end of file
diff --git a/src/main/java/com/iciql/adapter/postgresql/XmlObjectAdapter.java b/src/main/java/com/iciql/adapter/postgresql/XmlObjectAdapter.java
new file mode 100644
index 0000000..eba7c06
--- /dev/null
+++ b/src/main/java/com/iciql/adapter/postgresql/XmlObjectAdapter.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2014 James Moger.
+ *
+ * Licensed 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 com.iciql.adapter.postgresql;
+
+import com.iciql.adapter.XStreamTypeAdapter;
+
+/**
+ * Postgres XML data type adapter maps an XML column to a domain object using
+ * XStream.
+ *
+ * @author James Moger
+ *
+ */
+public abstract class XmlObjectAdapter extends XStreamTypeAdapter {
+
+ @Override
+ public String getDataType() {
+ return "xml";
+ }
+
+}
diff --git a/src/main/java/com/iciql/adapter/postgresql/XmlStringAdapter.java b/src/main/java/com/iciql/adapter/postgresql/XmlStringAdapter.java
new file mode 100644
index 0000000..defe9f9
--- /dev/null
+++ b/src/main/java/com/iciql/adapter/postgresql/XmlStringAdapter.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2014 James Moger.
+ *
+ * Licensed 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 com.iciql.adapter.postgresql;
+
+import java.sql.SQLException;
+
+import org.postgresql.util.PGobject;
+
+import com.iciql.Iciql.DataTypeAdapter;
+
+/**
+ * Handles transforming raw strings to/from the Postgres XML data type.
+ */
+public class XmlStringAdapter implements DataTypeAdapter<String> {
+
+ @Override
+ public String getDataType() {
+ return "xml";
+ }
+
+ @Override
+ public Class<String> getJavaType() {
+ return String.class;
+ }
+
+ @Override
+ public Object serialize(String value) {
+ PGobject pg = new PGobject();
+ pg.setType(getDataType());
+ try {
+ pg.setValue(value);
+ } catch (SQLException e) {
+ // not thrown on base PGobject
+ }
+ return pg;
+ }
+
+ @Override
+ public String deserialize(Object value) {
+ return value.toString();
+ }
+} \ No newline at end of file