litesoft
@ 821
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt package org.litesoft.orsup.nonpublic; import java.util.*; import org.litesoft.core.typeutils.*; import org.litesoft.db.*; import org.litesoft.orsup.selection.*; public abstract class AbstractPersistenceHelper implements PersistenceHelper { /** * @return Converted pIdentifier based on the "Caseing" of this DB. */ @Override public final String normalizeIdentifier( String pIdentifier ) { if ( pIdentifier != null ) { if ( (pIdentifier = pIdentifier.trim()).length() != 0 ) { return LLnormalizeIdentifierNotNullOrEmpty( pIdentifier ); } } return pIdentifier; } /** * @return Converted pIdentifier based on the "Caseing" of this DB. */ abstract protected String LLnormalizeIdentifierNotNullOrEmpty( String pIdentifier ); /** * Determine all the tables that are made up of the 'pTableNameParts' where if only 1, then must be equal, * otherwise the found table names will: "start with" the first element of the pTableNameParts array && * "end with" the last element of the pTableNameParts array && contain (in order with no overlap) all the * the middle elements of the pTableNameParts. * * @param pTableNameParts Non-null & not-empty list of strings that make up a pattern to match table names * * @return Non-null list of the matching table names - which may be empty. * * @throws DBException - Exception regarding the DB */ @Override public final String[] getTables( String... pTableNameParts ) throws DBException { pTableNameParts = Strings.deNull( pTableNameParts ); String[] zParts = new String[pTableNameParts.length]; int zPartsLength = 0; for ( int i = 0; i < pTableNameParts.length; i++ ) { zPartsLength += (zParts[i] = Strings.deNull( pTableNameParts[i] )).length(); } if ( zPartsLength == 0 ) { return Strings.EMPTY_ARRAY; } for ( int i = zParts.length - 2; i > 0; i-- ) { if ( zParts[i].length() == 0 ) { String[] newParts = new String[zParts.length - 1]; int zTo = 0; for ( int zFrom = 0; zFrom < zParts.length; zFrom++ ) { if ( zFrom != i ) { newParts[zTo++] = zParts[zFrom]; } } zParts = newParts; } } switch ( zParts.length ) { case 1: return LLgetTablesEquals( zParts[0] ); case 2: if ( zParts[1].length() == 0 ) { return LLgetTablesStartsWith( zParts[0] ); } if ( zParts[0].length() == 0 ) { return LLgetTablesEndsWith( zParts[1] ); } return LLgetTablesStartsAndEndsWith( zParts[0], zParts[1] ); default: return LLgetTablesForParts( zParts ); } } /** * Determine all the columns for a table. * * @param pTableName Non-null & not-empty table name. * * @return Non-null list of the table's columns - which may be empty. * * @throws NoTableException - No Table was found for the given pTableName * @throws MultipleTablesException - Multiple Tables were found for the given pTableName * @throws DBException - Some other Exception regarding the DB */ @Override public final DBtableColumn[] getColumns( String pTableName ) throws NoTableException, MultipleTablesException, DBException { Map<String, DBtableColumn[]> zMap = LLgetColumns( pTableName = Strings.assertNotNullNotEmpty( "TableName", pTableName ) ); return checkMap( pTableName, zMap ); } /** * Determine all the indexes for a table. * * @param pTableName Non-null & not-empty table name. * * @return Non-null list of the table's indexes - which may be empty. * * @throws NoTableException - No Table was found for the given pTableName * @throws MultipleTablesException - Multiple Tables were found for the given pTableName * @throws DBException - Some other Exception regarding the DB */ @Override public final DBtableIndex[] getIndexes( String pTableName ) throws NoTableException, MultipleTablesException, DBException { Map<String, DBtableIndex[]> zMap = LLgetIndexes( pTableName = Strings.assertNotNullNotEmpty( "TableName", pTableName ) ); return checkMap( pTableName, zMap ); } /** * Determine all the columns for a table. * * @param pSimpleFromIdentifier Non-null * * @return Non-null list of the table's columns - which may be empty. * * @throws NoTableException - No Table was found for the given pTableName * @throws MultipleTablesException - Multiple Tables were found for the given pTableName * @throws DBException - Some other Exception regarding the DB */ @Override public final DBtableColumn[] getColumns( SimpleFromIdentifier pSimpleFromIdentifier ) throws NoTableException, MultipleTablesException, DBException { return getColumns( normalizeIdentifier( pSimpleFromIdentifier.getTableName() ) ); } /** * Determine all the indexes for a table. * * @param pSimpleFromIdentifier Non-null * * @return Non-null list of the table's indexes - which may be empty. * * @throws NoTableException - No Table was found for the given pTableName * @throws MultipleTablesException - Multiple Tables were found for the given pTableName * @throws DBException - Some other Exception regarding the DB */ @Override public final DBtableIndex[] getIndexes( SimpleFromIdentifier pSimpleFromIdentifier ) throws NoTableException, MultipleTablesException, DBException { return getIndexes( normalizeIdentifier( pSimpleFromIdentifier.getTableName() ) ); } /** * @return TRUE if index exists, * FALSE if index appears to not exist */ @Override public final boolean indexExists( SimpleFromIdentifier pSimpleFromIdentifier, String pIndexName ) throws DBException { DBtableIndex[] zIndexes = getIndexes( pSimpleFromIdentifier ); for ( DBtableIndex zIndex : zIndexes ) { if ( zIndex.getIndexName().equalsIgnoreCase( pIndexName ) ) { return true; } } return false; } abstract protected String[] LLgetTablesEquals( String pName ); abstract protected String[] LLgetTablesStartsWith( String pStart ); abstract protected String[] LLgetTablesEndsWith( String pEnd ); abstract protected String[] LLgetTablesStartsAndEndsWith( String pStart, String pEnd ); abstract protected String[] LLgetTablesForParts( String[] pParts ); abstract protected Map<String, DBtableColumn[]> LLgetColumns( String pTableName ) throws DBException; abstract protected Map<String, DBtableIndex[]> LLgetIndexes( String pTableName ) throws DBException; private <T> T checkMap( String pTableName, Map<String, T> pMap ) { if ( pMap.isEmpty() ) { throw new NoTableException( "No Table found with Name: '" + pTableName + "'" ); } if ( pMap.size() == 1 ) { return pMap.values().iterator().next(); } throw MultipleTablesException.createFrom( pTableName, pMap.keySet() ); } } |
Commits for litesoft/trunk/Java/core/Server/src/org/litesoft/orsup/nonpublic/AbstractPersistenceHelper.java
Revision | Author | Commited | Message |
---|---|---|---|
821 Diff | GeorgeS | Sun 19 Aug, 2012 00:08:41 +0000 | |
802 Diff | GeorgeS | Wed 15 Aug, 2012 04:04:47 +0000 | |
800 Diff | GeorgeS | Wed 15 Aug, 2012 03:33:38 +0000 | |
151 Diff | GeorgeS | Thu 17 Mar, 2011 04:16:22 +0000 | |
49 Diff | GeorgeS | Mon 12 Apr, 2010 02:59:10 +0000 | License Text |
24 Diff | GeorgeS | Wed 24 Feb, 2010 01:51:38 +0000 | |
2 | GeorgeS | Sun 07 Feb, 2010 12:50:58 +0000 |