You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cayenne.apache.org by "Artyom Sokolov (JIRA)" <de...@cayenne.apache.org> on 2008/10/13 13:56:11 UTC

[jira] Created: (CAY-1123) Add UUID support

Add UUID support
----------------

                 Key: CAY-1123
                 URL: https://issues.apache.org/cayenne/browse/CAY-1123
             Project: Cayenne
          Issue Type: New Feature
         Environment: PostgreSQL
            Reporter: Artyom Sokolov
            Assignee: Andrus Adamchik


To work properly with PostgreSQL's UUID columnt type I use next class which extends ExtendedType:

package sandbox.orm.cayenne;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Types;
import java.util.UUID;

import org.apache.cayenne.CayenneRuntimeException;
import org.apache.cayenne.access.types.ExtendedType;
import org.apache.cayenne.map.DbAttribute;
import org.apache.cayenne.validation.ValidationResult;

public class UUIDType implements ExtendedType {

	@Override
	public String getClassName() {
		return UUID.class.getName();
	}

	@Override
	public Object materializeObject(ResultSet rs, int index, int type)
			throws Exception {
		UUID uuid = null;
		switch (type) {
		case Types.NULL:
			uuid = null;
			break;
		default:
			try {
				uuid = UUID.fromString(rs.getObject(index).toString());
			} catch (IllegalArgumentException e) {
				throw new CayenneRuntimeException(
						"Expected an instance of java.util.UUID, instead got "
								+ uuid.getClass().getName()
								+ ", column index: " + index);
			}
		}
		return uuid;
	}

	@Override
	public Object materializeObject(CallableStatement rs, int index, int type)
			throws Exception {
		UUID uuid = null;
		switch (type) {
		case Types.NULL:
			uuid = null;
			break;
		default:
			try {
				uuid = UUID.fromString(rs.getObject(index).toString());
			} catch (IllegalArgumentException e) {
				throw new CayenneRuntimeException(
						"Expected an instance of java.util.UUID, instead got "
								+ uuid.getClass().getName()
								+ ", column index: " + index);
			}
		}
		return uuid;
	}

	@Override
	public void setJdbcObject(PreparedStatement statement, Object value,
			int pos, int type, int precision) throws Exception {
		if (value == null) {
			statement.setNull(pos, type);
		} else if (value instanceof UUID) {
			statement.setObject(pos, value);
		} else {
			throw new IllegalArgumentException("Expected java.util.UUID, got "
					+ value.getClass().getName());
		}
	}

	@Override
	public boolean validateProperty(Object source, String property,
			Object value, DbAttribute dbAttribute,
			ValidationResult validationResult) {
		return true;
	}

}

Then I register it with Configuration.getSharedConfiguration().getDomain().getNode("MyNode").getAdapter().getExtendedTypes().registerType(new UUIDType());

Wouldn't it better to have same functionality in Cayenne core?

Thanks,
Artyom

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CAY-1123) Add UUID support

Posted by "Artyom Sokolov (JIRA)" <de...@cayenne.apache.org>.
     [ https://issues.apache.org/cayenne/browse/CAY-1123?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Artyom Sokolov updated CAY-1123:
--------------------------------

    Attachment: UUIDType.java

> Add UUID support
> ----------------
>
>                 Key: CAY-1123
>                 URL: https://issues.apache.org/cayenne/browse/CAY-1123
>             Project: Cayenne
>          Issue Type: New Feature
>         Environment: PostgreSQL
>            Reporter: Artyom Sokolov
>            Assignee: Andrus Adamchik
>         Attachments: UUIDType.java
>
>
> To work properly with PostgreSQL's UUID columnt type I use next class which extends ExtendedType:
> package sandbox.orm.cayenne;
> import java.sql.CallableStatement;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.Types;
> import java.util.UUID;
> import org.apache.cayenne.CayenneRuntimeException;
> import org.apache.cayenne.access.types.ExtendedType;
> import org.apache.cayenne.map.DbAttribute;
> import org.apache.cayenne.validation.ValidationResult;
> public class UUIDType implements ExtendedType {
> 	@Override
> 	public String getClassName() {
> 		return UUID.class.getName();
> 	}
> 	@Override
> 	public Object materializeObject(ResultSet rs, int index, int type)
> 			throws Exception {
> 		UUID uuid = null;
> 		switch (type) {
> 		case Types.NULL:
> 			uuid = null;
> 			break;
> 		default:
> 			try {
> 				uuid = UUID.fromString(rs.getObject(index).toString());
> 			} catch (IllegalArgumentException e) {
> 				throw new CayenneRuntimeException(
> 						"Expected an instance of java.util.UUID, instead got "
> 								+ uuid.getClass().getName()
> 								+ ", column index: " + index);
> 			}
> 		}
> 		return uuid;
> 	}
> 	@Override
> 	public Object materializeObject(CallableStatement rs, int index, int type)
> 			throws Exception {
> 		UUID uuid = null;
> 		switch (type) {
> 		case Types.NULL:
> 			uuid = null;
> 			break;
> 		default:
> 			try {
> 				uuid = UUID.fromString(rs.getObject(index).toString());
> 			} catch (IllegalArgumentException e) {
> 				throw new CayenneRuntimeException(
> 						"Expected an instance of java.util.UUID, instead got "
> 								+ uuid.getClass().getName()
> 								+ ", column index: " + index);
> 			}
> 		}
> 		return uuid;
> 	}
> 	@Override
> 	public void setJdbcObject(PreparedStatement statement, Object value,
> 			int pos, int type, int precision) throws Exception {
> 		if (value == null) {
> 			statement.setNull(pos, type);
> 		} else if (value instanceof UUID) {
> 			statement.setObject(pos, value);
> 		} else {
> 			throw new IllegalArgumentException("Expected java.util.UUID, got "
> 					+ value.getClass().getName());
> 		}
> 	}
> 	@Override
> 	public boolean validateProperty(Object source, String property,
> 			Object value, DbAttribute dbAttribute,
> 			ValidationResult validationResult) {
> 		return true;
> 	}
> }
> Then I register it with Configuration.getSharedConfiguration().getDomain().getNode("MyNode").getAdapter().getExtendedTypes().registerType(new UUIDType());
> Wouldn't it better to have same functionality in Cayenne core?
> Thanks,
> Artyom

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (CAY-1123) Add UUID support

Posted by "Andrus Adamchik (JIRA)" <de...@cayenne.apache.org>.
     [ https://issues.apache.org/cayenne/browse/CAY-1123?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andrus Adamchik closed CAY-1123.
--------------------------------

       Resolution: Fixed
    Fix Version/s: 3.0

added UUID to the Modeler as one of the ObjAttribute type choices and added an extendedtype similar ot to the one in the attached patch

> Add UUID support
> ----------------
>
>                 Key: CAY-1123
>                 URL: https://issues.apache.org/cayenne/browse/CAY-1123
>             Project: Cayenne
>          Issue Type: New Feature
>         Environment: PostgreSQL
>            Reporter: Artyom Sokolov
>            Assignee: Andrus Adamchik
>             Fix For: 3.0
>
>         Attachments: UUIDType.java
>
>
> To work properly with PostgreSQL's UUID columnt type I use next class which extends ExtendedType:
> package sandbox.orm.cayenne;
> import java.sql.CallableStatement;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.Types;
> import java.util.UUID;
> import org.apache.cayenne.CayenneRuntimeException;
> import org.apache.cayenne.access.types.ExtendedType;
> import org.apache.cayenne.map.DbAttribute;
> import org.apache.cayenne.validation.ValidationResult;
> public class UUIDType implements ExtendedType {
> 	@Override
> 	public String getClassName() {
> 		return UUID.class.getName();
> 	}
> 	@Override
> 	public Object materializeObject(ResultSet rs, int index, int type)
> 			throws Exception {
> 		UUID uuid = null;
> 		switch (type) {
> 		case Types.NULL:
> 			uuid = null;
> 			break;
> 		default:
> 			try {
> 				uuid = UUID.fromString(rs.getObject(index).toString());
> 			} catch (IllegalArgumentException e) {
> 				throw new CayenneRuntimeException(
> 						"Expected an instance of java.util.UUID, instead got "
> 								+ uuid.getClass().getName()
> 								+ ", column index: " + index);
> 			}
> 		}
> 		return uuid;
> 	}
> 	@Override
> 	public Object materializeObject(CallableStatement rs, int index, int type)
> 			throws Exception {
> 		UUID uuid = null;
> 		switch (type) {
> 		case Types.NULL:
> 			uuid = null;
> 			break;
> 		default:
> 			try {
> 				uuid = UUID.fromString(rs.getObject(index).toString());
> 			} catch (IllegalArgumentException e) {
> 				throw new CayenneRuntimeException(
> 						"Expected an instance of java.util.UUID, instead got "
> 								+ uuid.getClass().getName()
> 								+ ", column index: " + index);
> 			}
> 		}
> 		return uuid;
> 	}
> 	@Override
> 	public void setJdbcObject(PreparedStatement statement, Object value,
> 			int pos, int type, int precision) throws Exception {
> 		if (value == null) {
> 			statement.setNull(pos, type);
> 		} else if (value instanceof UUID) {
> 			statement.setObject(pos, value);
> 		} else {
> 			throw new IllegalArgumentException("Expected java.util.UUID, got "
> 					+ value.getClass().getName());
> 		}
> 	}
> 	@Override
> 	public boolean validateProperty(Object source, String property,
> 			Object value, DbAttribute dbAttribute,
> 			ValidationResult validationResult) {
> 		return true;
> 	}
> }
> Then I register it with Configuration.getSharedConfiguration().getDomain().getNode("MyNode").getAdapter().getExtendedTypes().registerType(new UUIDType());
> Wouldn't it better to have same functionality in Cayenne core?
> Thanks,
> Artyom

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAY-1123) Add UUID support

Posted by "Artyom Sokolov (JIRA)" <de...@cayenne.apache.org>.
    [ https://issues.apache.org/cayenne/browse/CAY-1123?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13163#action_13163 ] 

Artyom Sokolov commented on CAY-1123:
-------------------------------------

Ooops. Could anybody edit this issue and delete code stuff? I've already attached it. I am a bit new to JIRA, so... sorry :)

Thanks, 
Artyom

> Add UUID support
> ----------------
>
>                 Key: CAY-1123
>                 URL: https://issues.apache.org/cayenne/browse/CAY-1123
>             Project: Cayenne
>          Issue Type: New Feature
>         Environment: PostgreSQL
>            Reporter: Artyom Sokolov
>            Assignee: Andrus Adamchik
>         Attachments: UUIDType.java
>
>
> To work properly with PostgreSQL's UUID columnt type I use next class which extends ExtendedType:
> package sandbox.orm.cayenne;
> import java.sql.CallableStatement;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.Types;
> import java.util.UUID;
> import org.apache.cayenne.CayenneRuntimeException;
> import org.apache.cayenne.access.types.ExtendedType;
> import org.apache.cayenne.map.DbAttribute;
> import org.apache.cayenne.validation.ValidationResult;
> public class UUIDType implements ExtendedType {
> 	@Override
> 	public String getClassName() {
> 		return UUID.class.getName();
> 	}
> 	@Override
> 	public Object materializeObject(ResultSet rs, int index, int type)
> 			throws Exception {
> 		UUID uuid = null;
> 		switch (type) {
> 		case Types.NULL:
> 			uuid = null;
> 			break;
> 		default:
> 			try {
> 				uuid = UUID.fromString(rs.getObject(index).toString());
> 			} catch (IllegalArgumentException e) {
> 				throw new CayenneRuntimeException(
> 						"Expected an instance of java.util.UUID, instead got "
> 								+ uuid.getClass().getName()
> 								+ ", column index: " + index);
> 			}
> 		}
> 		return uuid;
> 	}
> 	@Override
> 	public Object materializeObject(CallableStatement rs, int index, int type)
> 			throws Exception {
> 		UUID uuid = null;
> 		switch (type) {
> 		case Types.NULL:
> 			uuid = null;
> 			break;
> 		default:
> 			try {
> 				uuid = UUID.fromString(rs.getObject(index).toString());
> 			} catch (IllegalArgumentException e) {
> 				throw new CayenneRuntimeException(
> 						"Expected an instance of java.util.UUID, instead got "
> 								+ uuid.getClass().getName()
> 								+ ", column index: " + index);
> 			}
> 		}
> 		return uuid;
> 	}
> 	@Override
> 	public void setJdbcObject(PreparedStatement statement, Object value,
> 			int pos, int type, int precision) throws Exception {
> 		if (value == null) {
> 			statement.setNull(pos, type);
> 		} else if (value instanceof UUID) {
> 			statement.setObject(pos, value);
> 		} else {
> 			throw new IllegalArgumentException("Expected java.util.UUID, got "
> 					+ value.getClass().getName());
> 		}
> 	}
> 	@Override
> 	public boolean validateProperty(Object source, String property,
> 			Object value, DbAttribute dbAttribute,
> 			ValidationResult validationResult) {
> 		return true;
> 	}
> }
> Then I register it with Configuration.getSharedConfiguration().getDomain().getNode("MyNode").getAdapter().getExtendedTypes().registerType(new UUIDType());
> Wouldn't it better to have same functionality in Cayenne core?
> Thanks,
> Artyom

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAY-1123) Add UUID support

Posted by "Andrus Adamchik (JIRA)" <de...@cayenne.apache.org>.
    [ https://issues.apache.org/cayenne/browse/CAY-1123?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13164#action_13164 ] 

Andrus Adamchik commented on CAY-1123:
--------------------------------------

no problem if it sits there. It is clear what you were trying to say here.

> Add UUID support
> ----------------
>
>                 Key: CAY-1123
>                 URL: https://issues.apache.org/cayenne/browse/CAY-1123
>             Project: Cayenne
>          Issue Type: New Feature
>         Environment: PostgreSQL
>            Reporter: Artyom Sokolov
>            Assignee: Andrus Adamchik
>         Attachments: UUIDType.java
>
>
> To work properly with PostgreSQL's UUID columnt type I use next class which extends ExtendedType:
> package sandbox.orm.cayenne;
> import java.sql.CallableStatement;
> import java.sql.PreparedStatement;
> import java.sql.ResultSet;
> import java.sql.Types;
> import java.util.UUID;
> import org.apache.cayenne.CayenneRuntimeException;
> import org.apache.cayenne.access.types.ExtendedType;
> import org.apache.cayenne.map.DbAttribute;
> import org.apache.cayenne.validation.ValidationResult;
> public class UUIDType implements ExtendedType {
> 	@Override
> 	public String getClassName() {
> 		return UUID.class.getName();
> 	}
> 	@Override
> 	public Object materializeObject(ResultSet rs, int index, int type)
> 			throws Exception {
> 		UUID uuid = null;
> 		switch (type) {
> 		case Types.NULL:
> 			uuid = null;
> 			break;
> 		default:
> 			try {
> 				uuid = UUID.fromString(rs.getObject(index).toString());
> 			} catch (IllegalArgumentException e) {
> 				throw new CayenneRuntimeException(
> 						"Expected an instance of java.util.UUID, instead got "
> 								+ uuid.getClass().getName()
> 								+ ", column index: " + index);
> 			}
> 		}
> 		return uuid;
> 	}
> 	@Override
> 	public Object materializeObject(CallableStatement rs, int index, int type)
> 			throws Exception {
> 		UUID uuid = null;
> 		switch (type) {
> 		case Types.NULL:
> 			uuid = null;
> 			break;
> 		default:
> 			try {
> 				uuid = UUID.fromString(rs.getObject(index).toString());
> 			} catch (IllegalArgumentException e) {
> 				throw new CayenneRuntimeException(
> 						"Expected an instance of java.util.UUID, instead got "
> 								+ uuid.getClass().getName()
> 								+ ", column index: " + index);
> 			}
> 		}
> 		return uuid;
> 	}
> 	@Override
> 	public void setJdbcObject(PreparedStatement statement, Object value,
> 			int pos, int type, int precision) throws Exception {
> 		if (value == null) {
> 			statement.setNull(pos, type);
> 		} else if (value instanceof UUID) {
> 			statement.setObject(pos, value);
> 		} else {
> 			throw new IllegalArgumentException("Expected java.util.UUID, got "
> 					+ value.getClass().getName());
> 		}
> 	}
> 	@Override
> 	public boolean validateProperty(Object source, String property,
> 			Object value, DbAttribute dbAttribute,
> 			ValidationResult validationResult) {
> 		return true;
> 	}
> }
> Then I register it with Configuration.getSharedConfiguration().getDomain().getNode("MyNode").getAdapter().getExtendedTypes().registerType(new UUIDType());
> Wouldn't it better to have same functionality in Cayenne core?
> Thanks,
> Artyom

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.