-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
modules/dbsupport/src/main/java/org/jpos/ee/converter/TagsConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* jPOS Project [http://jpos.org] | ||
* Copyright (C) 2000-2015 Alejandro P. Revilla | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.jpos.ee.converter; | ||
|
||
import org.jpos.util.Tags; | ||
import javax.persistence.AttributeConverter; | ||
import javax.persistence.Converter; | ||
|
||
@Converter(autoApply = true) | ||
public class TagsConverter implements AttributeConverter<Tags,String> { | ||
@Override | ||
public String convertToDatabaseColumn(Tags attribute) { | ||
return attribute.toString(); | ||
} | ||
|
||
@Override | ||
public Tags convertToEntityAttribute(String dbData) { | ||
return new Tags(dbData); | ||
} | ||
} | ||
|
101 changes: 101 additions & 0 deletions
101
modules/dbsupport/src/main/java/org/jpos/ee/usertype/TagsType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* jPOS Project [http://jpos.org] | ||
* Copyright (C) 2000-2015 Alejandro P. Revilla | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.jpos.ee.usertype; | ||
|
||
import org.hibernate.HibernateException; | ||
import org.hibernate.engine.spi.SessionImplementor; | ||
import org.hibernate.usertype.UserType; | ||
|
||
import java.io.Serializable; | ||
import java.sql.PreparedStatement; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import java.sql.Types; | ||
|
||
import org.jpos.util.Tags; | ||
|
||
public class TagsType implements UserType { | ||
private static int[] TYPES = { Types.VARCHAR }; | ||
|
||
@Override | ||
public int[] sqlTypes() { | ||
return TYPES; | ||
} | ||
|
||
@Override | ||
public Class returnedClass() { | ||
return Tags.class; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object a, Object b) throws HibernateException { | ||
return (a == b) || ((a != null) && (b != null) && (a.equals(b))); | ||
} | ||
|
||
@Override | ||
public int hashCode(Object o) throws HibernateException { | ||
return o.hashCode(); | ||
} | ||
|
||
@Override | ||
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner) throws HibernateException, SQLException { | ||
String tags = rs.getString(names[0]); | ||
if (rs.wasNull()) | ||
return null; | ||
return new Tags(tags); | ||
} | ||
|
||
@Override | ||
public void nullSafeSet(PreparedStatement st, Object value, int index, SessionImplementor session) throws HibernateException, SQLException { | ||
if (value==null) { | ||
st.setNull(index, Types.VARCHAR); | ||
} else { | ||
st.setString (index, value.toString()); | ||
} | ||
} | ||
|
||
@Override | ||
public Object deepCopy(Object value) throws HibernateException { | ||
if (value == null) | ||
return null; | ||
return new Tags(value.toString()); | ||
|
||
} | ||
|
||
@Override | ||
public boolean isMutable() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public Serializable disassemble(Object value) throws HibernateException { | ||
return (Serializable) value; | ||
} | ||
|
||
@Override | ||
public Object assemble(Serializable cached, Object owner) throws HibernateException { | ||
return cached; | ||
} | ||
|
||
@Override | ||
public Object replace(Object original, Object target, Object owner) throws HibernateException { | ||
return new Tags(original.toString()); | ||
} | ||
} | ||
|