You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XmlStringAdapter.java 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright 2014 James Moger.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.iciql.adapter.postgresql;
  17. import com.iciql.Iciql.DataTypeAdapter;
  18. import com.iciql.Iciql.Mode;
  19. import org.postgresql.util.PGobject;
  20. import java.sql.SQLException;
  21. /**
  22. * Handles transforming raw strings to/from the Postgres XML data type.
  23. */
  24. public class XmlStringAdapter implements DataTypeAdapter<String> {
  25. protected Mode mode;
  26. @Override
  27. public void setMode(Mode mode) {
  28. this.mode = mode;
  29. }
  30. @Override
  31. public String getDataType() {
  32. return "xml";
  33. }
  34. @Override
  35. public Class<String> getJavaType() {
  36. return String.class;
  37. }
  38. @Override
  39. public Object serialize(String value) {
  40. PGobject pg = new PGobject();
  41. pg.setType(getDataType());
  42. try {
  43. pg.setValue(value);
  44. } catch (SQLException e) {
  45. // not thrown on base PGobject
  46. }
  47. return pg;
  48. }
  49. @Override
  50. public String deserialize(Object value) {
  51. return value.toString();
  52. }
  53. }