
org.efaps.admin.datamodel.Dimension Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of efaps-kernel Show documentation
Show all versions of efaps-kernel Show documentation
eFaps is a framework used to map objects with or without attached files to
a relational database and optional file systems (only for attaches files). Configurable access control can be provided down to object and attribute level depending on implementation and use case. Depending on requirements, events (like triggers) allow to implement business logic and to separate business logic from user interface.
The framework includes integrations (e.g. webdav, full text search) and a web application as 'simple' configurable user interface. Some best practises, example web application modules (e.g. team work module) support administrators and implementers using this framework.
The newest version!
/*
* Copyright 2003 - 2013 The eFaps Team
*
* 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.
*
* Revision: $Rev$
* Last Changed: $Date$
* Last Changed By: $Author$
*/
package org.efaps.admin.datamodel;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import org.efaps.admin.AbstractAdminObject;
import org.efaps.db.Context;
import org.efaps.db.transaction.ConnectionResource;
import org.efaps.db.wrapper.SQLPart;
import org.efaps.db.wrapper.SQLSelect;
import org.efaps.util.EFapsException;
import org.efaps.util.cache.CacheLogListener;
import org.efaps.util.cache.CacheReloadException;
import org.efaps.util.cache.InfinispanCache;
import org.infinispan.Cache;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Class for Dimensions inside eFaps.
*
* @author The eFaps Team
* @version $Id$
*/
public class Dimension
extends AbstractAdminObject
{
/**
* Needed for serialization.
*/
private static final long serialVersionUID = 1L;
/**
* Logging instance used in this class.
*/
private static final Logger LOG = LoggerFactory.getLogger(Dimension.class);
/**
* This is the sql select statement to select all UoM from the database.
*
* @see #initialise
*/
private static final String SQL_SELECT_UOM4DIMID = new SQLSelect()
.column("ID")
.column("DIMID")
.column("NAME")
.column("NUMERATOR")
.column("DENOMINATOR")
.from("T_DMUOM", 0)
.addPart(SQLPart.WHERE).addColumnPart(0, "DIMID").addPart(SQLPart.EQUAL).addValuePart("?")
.toString();
/**
* This is the sql select statement to select all UoM from the database.
*
* @see #initialise
*/
private static final String SQL_SELECT_UOM4ID = new SQLSelect()
.column("ID")
.column("DIMID")
.column("NAME")
.column("NUMERATOR")
.column("DENOMINATOR")
.from("T_DMUOM", 0)
.addPart(SQLPart.WHERE).addColumnPart(0, "ID").addPart(SQLPart.EQUAL).addValuePart("?").toString();
/**
* This is the SQL select statement to select a role from the database by
* ID.
*/
private static final String SQL_ID = new SQLSelect()
.column("ID")
.column("NAME")
.column("UUID")
.column("DESCR")
.column("BASEUOM")
.from("T_DMDIM", 0)
.addPart(SQLPart.WHERE).addColumnPart(0, "ID").addPart(SQLPart.EQUAL).addValuePart("?").toString();
/**
* This is the SQL select statement to select a role from the database by
* Name.
*/
private static final String SQL_NAME = new SQLSelect()
.column("ID")
.column("NAME")
.column("UUID")
.column("DESCR")
.column("BASEUOM")
.from("T_DMDIM", 0)
.addPart(SQLPart.WHERE).addColumnPart(0, "NAME").addPart(SQLPart.EQUAL).addValuePart("?")
.toString();
/**
* This is the SQL select statement to select a role from the database by
* UUID.
*/
private static final String SQL_UUID = new SQLSelect()
.column("ID")
.column("NAME")
.column("UUID")
.column("DESCR")
.column("BASEUOM")
.from("T_DMDIM", 0)
.addPart(SQLPart.WHERE).addColumnPart(0, "UUID").addPart(SQLPart.EQUAL).addValuePart("?")
.toString();
/**
* Name of the Cache by UUID.
*/
private static final String UUIDCACHE = Dimension.class.getName() + ".UUID";
/**
* Name of the Cache by ID.
*/
private static final String IDCACHE = Dimension.class.getName() + ".ID";
/**
* Name of the Cache by Name.
*/
private static final String NAMECACHE = Dimension.class.getName() + ".Name";
/**
* Name of the Cache by ID.
*/
private static final String IDCACHE4UOM = Dimension.class.getName() + ".UoM4ID";
/**
* List of UoM belonging to this Dimension.
*/
private final List uoMs = new ArrayList();
/**
* Id of the base UoM.
*/
private final long baseUoMId;
/**
* Base UoM.
*/
private UoM baseUoM;
/**
* Constructor.
*
* @param _id id of this dimension
* @param _uuid UUID of this dimension
* @param _name Name of this dimension
* @param _description description for this dimension
* @param _baseUoMId id of the base UoM for this dimension
*/
protected Dimension(final long _id,
final String _uuid,
final String _name,
final String _description,
final long _baseUoMId)
{
super(_id, _uuid, _name);
this.baseUoMId = _baseUoMId;
}
/**
* Method to add an UoM to this dimension.
*
* @param _uom UoM to add
*/
private void addUoM(final UoM _uom)
{
this.uoMs.add(_uom);
if (_uom.getId() == this.baseUoMId) {
this.baseUoM = _uom;
}
}
/**
* Getter method for instance variable {@link #uoMs}.
*
* @return value of instance variable {@link #uoMs}
*/
public List getUoMs()
{
return this.uoMs;
}
/**
* Getter method for instance variable {@link #baseUoM}.
*
* @return value of instance variable {@link #baseUoM}
*/
public UoM getBaseUoM()
{
return this.baseUoM;
}
/**
* Method to initialize the Cache of this CacheObjectInterface.
*
* @param _class class that called the method
* @throws CacheReloadException on error
*/
public static void initialize(final Class> _class)
throws CacheReloadException
{
if (InfinispanCache.get().exists(Dimension.UUIDCACHE)) {
InfinispanCache.get().getCache(Dimension.UUIDCACHE).clear();
} else {
InfinispanCache.get().getCache(Dimension.UUIDCACHE)
.addListener(new CacheLogListener(Dimension.LOG));
}
if (InfinispanCache.get().exists(Dimension.IDCACHE)) {
InfinispanCache.get().getCache(Dimension.IDCACHE).clear();
} else {
InfinispanCache.get().getCache(Dimension.IDCACHE)
.addListener(new CacheLogListener(Dimension.LOG));
}
if (InfinispanCache.get().exists(Dimension.NAMECACHE)) {
InfinispanCache.get().getCache(Dimension.NAMECACHE).clear();
} else {
InfinispanCache.get().getCache(Dimension.NAMECACHE)
.addListener(new CacheLogListener(Dimension.LOG));
}
if (InfinispanCache.get().exists(Dimension.IDCACHE4UOM)) {
InfinispanCache.get().getCache(Dimension.IDCACHE4UOM).clear();
} else {
InfinispanCache.get().getCache(Dimension.IDCACHE4UOM)
.addListener(new CacheLogListener(Dimension.LOG));
}
}
/**
* Method to initialize the Cache of this CacheObjectInterface.
*
* @throws CacheReloadException on error
*/
public static void initialize()
throws CacheReloadException
{
Dimension.initialize(Dimension.class);
}
/**
* Returns for given parameter _id the instance of class
* {@link Dimension} .
*
* @param _id id of the type to get
* @return instance of class {@link Dimension}
* @throws CacheReloadException on error
*/
public static Dimension get(final long _id)
throws CacheReloadException
{
final Cache cache = InfinispanCache.get().getCache(Dimension.IDCACHE);
if (!cache.containsKey(_id)) {
Dimension.getDimensionFromDB(Dimension.SQL_ID, _id);
}
return cache.get(_id);
}
/**
* Returns for given parameter _name the instance of class
* {@link Dimension}.
*
* @param _name name of the type to get
* @return instance of class {@link Dimension}
* @throws CacheReloadException on error
*/
public static Dimension get(final String _name)
throws CacheReloadException
{
final Cache cache = InfinispanCache.get().getCache(Dimension.NAMECACHE);
if (!cache.containsKey(_name)) {
Dimension.getDimensionFromDB(Dimension.SQL_NAME, _name);
}
return cache.get(_name);
}
/**
* Returns for given parameter _uuid the instance of class
* {@link Dimension}.
*
* @param _uuid uuid of the type to get
* @return instance of class {@link Dimension}
* @throws CacheReloadException on error
*/
public static Dimension get(final UUID _uuid)
throws CacheReloadException
{
final Cache cache = InfinispanCache.get().getCache(Dimension.UUIDCACHE);
if (!cache.containsKey(_uuid)) {
Dimension.getDimensionFromDB(Dimension.SQL_UUID, String.valueOf(_uuid));
}
return cache.get(_uuid);
}
/**
* Static Method to get an UoM for an id.
*
* @param _uoMId if the UoM is wanted for.
* @return UoM
*/
public static UoM getUoM(final Long _uoMId)
{
final Cache cache = InfinispanCache.get().getCache(Dimension.IDCACHE4UOM);
if (!cache.containsKey(_uoMId)) {
try {
Dimension.getUoMFromDB(Dimension.SQL_SELECT_UOM4ID, _uoMId);
} catch (final CacheReloadException e) {
Dimension.LOG.error("read UoM from DB failed for id: '{}'", _uoMId);
}
}
return cache.get(_uoMId);
}
/**
* @param _sql sql statment to be executed
* @param _criteria filter criteria
* @throws CacheReloadException on error
*/
private static void getUoMFromDB(final String _sql,
final Object _criteria)
throws CacheReloadException
{
ConnectionResource con = null;
try {
final List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy